Hi, community!
I am trying to find a motif in a DNA sequence. This is my code:
#!/usr/bin/env python3
from sys import argv
import re
#Functions
def find_motif(seq_dna, motif):
results = re.finditer(motif, seq_dna)
r = []
for result in results:
r.append(result.span()[0] + 1)
print(" ".join(map(str, r)))
if __name__=='__main__':
seq_dna = argv[1]
motif = argv[2]
find_motif(seq_dna, motif)
By running my code as python finding_motif.py "GATATATGCATATACTT" "ATAT", this is the stdout:
2 10
However, there is another motif in index 3 that is not counted. Could somebody help me with a way how to tackle this? The real output is:
2 4 10
Thank you for your help in advance
btw., you can do
print(*r)
instead of the print-join-map business, which is equivalent toprint(r[0], r[1],
etc.)
.Wow! I did not know about that. Thank you!! It worked.