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RWNRDAVKHTLQNINSVQLKELEEEWVKLPTGAPKPSRFLRSQQELEA
KLEQQQSAGGDAEGGGDDGDEVPQVDAYELLDAVEILSKLPKDFYDKIEAKKWQERKEAL
EAVEVLVKNPKLEAGDYADLVKALKKVVGKDTNVMLVALAAKCLTGLAVGLRKKFGQYAG
HVVPTILEKFKEKKPQVVQALQEAIDAIFLTTTLQNISEDVLAVMDNKNPTIKQQTSLFI
ARSFRHCTSSTLPKSLLKPFCAALLKHINDSAPEVRDAAFEALGTALKVVGEKSVNPFLA
...
in total 100 sequences In these sequences i searched a motif of interest using python script as follows
import re
infile=open("seq.fasta",'r')
out=open("results.csv",'w')
pattern=re.compile(r"(P[A-Z]{2}P)")
for line in infile:
line = line.strip("\n")
if line.startswith('>'):
name=line
else:
s = re.findall(pattern,line)
print '%s:%s' %(name,s)
out.write('%s:\t%s\n' %(name,s))
This script perfectly worked it gave me desired motif i wanted...now i wanted to count motif of interest in each seqeunce present out put of the script is as follows
>p1:
PGCP
>p1:
PHCP,
PKCP
and so on
but I want out put as follows
>p1:
1
>p1:
2
Can anybody tell me how to do this using python?
Thanks in Advance
Ni