1
$\begingroup$

I need some help. I have written a program that simulates protein cleavage but I need to modify it so that it produces fasta formatted output.

here is all of my sequence in .fas file

>jgi|Cormi1|6|CCM_00006m.01
MSSFTRAIRPALQGGRRVLLAQRLSTPRIAHPIAATALRSLSTTAPRRSVDLSELQPTPI
THLSEVETAMADAVSKFATEVVLPKAREMDEAEAMDPAVVEQLFEQGLMGIEIPEEYGGA
GMNFTAAIIAIEELARADPSVSVLVDVHNTLCNTALMKWGSDALKKKYLPRLATNTVASF
CLSEPVSGSDAFALATRATETPDGYTITGSKMWITNSMEAGFFIVFANLDPAKGYKGITA
FVVDKDTPGFSIAKKEKKLGIRASSTCVLNFDDVAVPKENLLGKPGEGYKYAIGILNEGR
IGIAAQMTGLALGAFENAVRYVWNDRKQFGTLVGEFQGMQHQIAQSYTEIAAARALVYNA
ARKKEAGEDFVRDAAMAKLYASQVAGRVAGLAVEWMGGMGFVREGLAEKYWRDSKIGAIY
EGTSNIQLNTIAKLLQKEYTA*
>jgi|Cormi1|8|CCM_00008m.01
MLAGSNARILRYIVVAGIILIFFYHFSGSRYDTLPRPVPAPDHAQAASQPSPPNDEATTA
GRPVDSTQKSIPADRDRPNSGFPKSVSASTDAAASTLADIDPGPRANATFVSLARNADVW
DIARSIRQVEDRFNRRFNYDWVFLNDKPFDDNFRNITSALVSGTARFGQIPVEHWSVPDW
IDEDKATKVREDMKERKIIYGDSMSYRHMCRFESGFFFQHPIMKNYDFYWRVEPSIELFC
DIAQDPFRFMKENGKKYSFTISLLEYVDTIPTLWDSAVKFIENYPQHVAADNSMEFLSDD
GGQTYNMCHFWSNFEIGSLEWMRSDAYVDFFNSLDQDGGFFYERWGDAPVHSIAAGLLLN
KTELHFFDEIAYFHMPFTHCPNDVQSRIDLKCHCNPKDNFDWSRYSCTSRYFEMMGMQKP
DGVD*
>jgi|Cormi1|10|CCM_00010m.01
MSTSPSDGTVDVDLPDAPTAPFPLHSDTHTANHVENDEDDDPITASYPVFLNPALPLGRR
LLVLQHPNRTDD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GRPMFASFVPAASVVFVSQASV
ASGAVASYGLRKRVEAVRGCRTVGKADMRFNDAMPKMRVDPESYTVEADGEVCTAEPAET
LPLTQSWYGILDNQNAPA*
>jgi|Cormi1|100|CCM_00100m.01
MAARLSAAALAPLRPISSSVCAARQLSQSLLQSQQTRGVAQTYLKKVAEGEERWKARAER
IQNGEQRHVWDILDERGYIKDVAGNTDRIKEVMRIKRIGAYVGIDPTADSLHVGHMLPLM
PLFWLWFHGYPAVTLIGGSTARIGDPTGRLQSREHITNSDISKNITKIHYQLSKLWHNVV
QMRIKYGYEDDWAAKRSLLNNNMWLQGLTLYDFIKRLARDTRIGPMLSRDTAKRKLTDGD
GMSLGEFMYPLLQGWDFWHMYNKIGVQMQIGGSDQYGNIVSGIESLKTIRETEEAPYARM
ESGWQHDPIGFTVPLLTDSAGVKFGKSAGNAIWLDEFKTSAFELYGYFMRRTDDEVEKLL
KLFTFLPMPKIQSIMEEHNADPAKRIAQHNLAFEFVSLIHGSQKALEEAQQHSFRFGGEL
PSIVKEPAASSGIINANTAPRSDIKLPRSVMKLSPAKLLFATGLAPSAAEGQRLVKMQGA
YVAAQPGQKRGLVPGNLNWTPMKMWYPEETSKFLLDDRMLILRKGKHNVRIVELVDDEEW
KASGEFYPGEPYTGEVRRRKQEIIAQAAEDGKTLTMTQVNKMLKKKGRQEGLRVANNPDI
ELPTKTEVRERVRLTHMHKKEERRTRGDEHEW*

My current code:

import re

myprotein = ""
my_protein = []
for protein in myprotein:
    myprotein = protein.rstrip('\n')
    my_protein.append(myprotein)
    my_pro = (''.join(my_protein))

   #cleaves sequence    
peptides = re.sub(r'(?<=[^HRK][^P][^R])(?=[FLWY][^P])|(?<=[^HRK][^P][FLWY])(?=.[^P]?)','\n', my_pro)

print (peptides)

the output is like

MSS
F
TRAIRPAL
QGGRRVLL
AQRL
STPRIAHPIAATA
L
RS
LSTTAPRRSVD
L
SE
L
QPTPITH
L
SEVETAMADAVSK
F
ATEVVL
PKAREMDEAEAMDPAVVEQ
L
F
EQG
L
MGIEIPEE
Y
GGAGMN
F
TAAIIAIEE
L
ARADPSVSV
L
VDVHNTL
CNTA
L
MK
W
GSDA
L
KKKYLPRL
ATNTVAS
F
C
L
SEPVSGSDA
F
A
L
ATRATETPDG
Y
TITGSKM
WITNSMEAG
F
F
IV
F
AN
L
DPAKG
YKGITA
F
VVDKDTPGF
SIAKKEKK
LGIRASSTCV
L
N
F
DDVAVPKENL
L
GKPGEG
Y
K
Y
AIGI
L
NEGRIGIAAQMTG
L
A
L
GA
F
ENAVRY
VW
NDRKQFGT
L
VGE
F
QGMQHQIAQS
Y
TEIAAARA
LV
Y
NAARKKEAGED
F
VRDAAMAK
L
YASQVAGRVAG
L
AVE
W
MGGMG
F
VREGL
AEK
Y
WRDSKIGAI
Y
EGTSNIQ
L
NTIAK
L
LQKE
YTA

I need every sequence on a separate line, starting with the sequence header like:

>jgi|Cormi1|6|CCM_00006m.01 frag.1
MSS
>jgi|Cormi1|6|CCM_00006m.01 frag.2
F
>jgi|Cormi1|6|CCM_00006m.01 frag.3
TRAIRPAL

enter image description here How could I make this work?

import sys
import re

sequence = open(input('Enter input filename: '),'r')
def digest(sequence):
    return re.sub(r'(?<=[^HRK][^P][^R])(?=[FLWY][^P])|(?<=[^HRK][^P][FLWY])(?=.[^P]?)','\n', sequence)

seq = ""
header = None
for line in sys.stdin:
    if not line.startswith('>'):
        seq = seq + line.rstrip()
    else:
        if header:
            for idx, fragment in enumerate(digest(seq).split('\n')):
                sys.stdout.write("%s frag.%d\n%s\n" % (header, idx + 1, fragment))
            seq = ""
        header = line.rstrip()

# final pass
for idx, fragment in enumerate(digest(seq).split('\n')):
    sys.stdout.write("%s frag.%d\n%s\n" % (header, idx + 1, fragment))
$\endgroup$
3
  • $\begingroup$ Use BioPython for this with SeqIO.write $\endgroup$
    – Joe Healey
    Apr 2 '18 at 16:16
  • $\begingroup$ what do you mean? using for which step? $\endgroup$ Apr 3 '18 at 1:34
  • $\begingroup$ You can use it for both reading in amd writing out your sequences in a preformatted FASTA format. There is rarely a good reason to write your own fasta parser. $\endgroup$
    – Joe Healey
    Apr 3 '18 at 6:47
5
$\begingroup$

One way is to store the header as a separate string from your protein residues. Use a list comprehension to build a list of formatted header-fragment pairs, and then print them to standard output.

#!/usr/bin/env python                                                                                                                                                                                                                                                    

import sys
import re

myprotein = ">jgi|Cormi1|6|CCM_00006m.01\nMSSFTRAIRPALQGGRRVLLAQRLSTPRIAHPIAATALRSLSTTAPRRSVDLSELQPTPI\nTHLSEVETAMADAVSKFATEVVLPKAREMDEAEAMDPAVVEQLFEQGLMGIEIPEEYGGA\nGMNFTAAIIAIEELARADPSVSVLVDVHNTLCNTALMKWGSDALKKKYLPRLATNTVASF\nCLSEPVSGSDAFALATRATETPDGYTITGSKMWITNSMEAGFFIVFANLDPAKGYKGITA\nFVVDKDTPGFSIAKKEKKLGIRASSTCVLNFDDVAVPKENLLGKPGEGYKYAIGILNEGR\nIGIAAQMTGLALGAFENAVRYVWNDRKQFGTLVGEFQGMQHQIAQSYTEIAAARALVYNA\n"

# parse record
my_protein = []
for line in myprotein.split('\n'):
    if not line.startswith('>'):
        my_protein.append(line)
    else:
        header = line

# build sequence
my_pro = ''.join(my_protein)

# cleave sequence                                                                                                                                                                                                                                                        
peptides = re.sub(r'(?<=[^HRK][^P][^R])(?=[FLWY][^P])|(?<=[^HRK][^P][FLWY])(?=.[^P]?)','\n', my_pro)

# build a formatted list
records = ["%s frag.%d\n%s\n" % (header, idx + 1, fragment) for idx, fragment in enumerate(peptides.split('\n'))]

# print list
for record in records:
    sys.stdout.write("%s" % (record))

This gives:

>jgi|Cormi1|6|CCM_00006m.01 frag.1
MSS
>jgi|Cormi1|6|CCM_00006m.01 frag.2
F
>jgi|Cormi1|6|CCM_00006m.01 frag.3
TRAIRPAL
...
>jgi|Cormi1|6|CCM_00006m.01 frag.89
LV
>jgi|Cormi1|6|CCM_00006m.01 frag.90
Y
>jgi|Cormi1|6|CCM_00006m.01 frag.91
NA

If you have multiple records in one file called seqs.fa, then you could use standard input to this script (e.g., named digest.py) to process them all at once:

#!/usr/bin/env python                                                                                                                                                                                                                                                    

import sys
import re

def digest(sequence):
    return re.sub(r'(?<=[^HRK][^P][^R])(?=[FLWY][^P])|(?<=[^HRK][^P][FLWY])(?=.[^P]?)','\n', sequence)

seq = ""
header = None
for line in sys.stdin:
    if not line.startswith('>'):
        seq = seq + line.rstrip()
    else:
        if header:
            for idx, fragment in enumerate(digest(seq).split('\n')):
                sys.stdout.write("%s frag.%d\n%s\n" % (header, idx + 1, fragment))
            seq = ""
        header = line.rstrip()

# final pass
for idx, fragment in enumerate(digest(seq).split('\n')):
    sys.stdout.write("%s frag.%d\n%s\n" % (header, idx + 1, fragment))

Creating a function called digest lets you change the digestion rules in one place. It reduces code bloat and also reduces errors from changing things in one place and not another.

You could use this script like so:

$ ./digest.py < seqs.fa > seqs.digested.fa

The file seqs.digested.fa would look like:

$ cat seqs.digested.fa
>jgi|Cormi1|6|CCM_00006m.01 frag.1
MSS
>jgi|Cormi1|6|CCM_00006m.01 frag.2
F
>jgi|Cormi1|6|CCM_00006m.01 frag.3
TRAIRPAL
...
>jgi|Cormi1|100|CCM_00100m.01 frag.143
PTKTEVRERVRL
>jgi|Cormi1|100|CCM_00100m.01 frag.144
THMHKKEERRTRGDEHE
>jgi|Cormi1|100|CCM_00100m.01 frag.145
W*
$\endgroup$
11
  • $\begingroup$ Thanks Alex Reynolds but I need more function to my program that make it can read file (.fas) and run overall sequence in file (each sequence has different name on header) $\endgroup$ Mar 30 '18 at 10:47
  • $\begingroup$ See edited answer. $\endgroup$ Mar 30 '18 at 16:55
  • $\begingroup$ sorry for bother you again but I don't get how to make this work. So after creating the function "digest" where should I put the script to? It would be great if you explain step by step.( I am new for this) $\endgroup$ Mar 31 '18 at 2:08
  • $\begingroup$ Copy the script to a file called digest.py. Make the script executable via chmod +x digest.py. Say you have a file containing your sequences at seqs.fa. Run ./digest.py < seqs.fa > seqs.digested.fa to make a file in the format you want. $\endgroup$ Mar 31 '18 at 4:50
  • $\begingroup$ so I just upload the picture of the way I think you told me. Is it right or not sorry for my dumbness I really don't know how to make this work. :'( $\endgroup$ Mar 31 '18 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.