Reputation: 209
Novice here!!
I am trying to search through a FASTA for a specific DNA sequence, but I keep getting a sytax error. The if statements work outside of the for loop, so I think it is how I have put them in, can anybody see the syntax error here, I can't work it out:
#!/bin/python
#My Mimp_finder
import re
from Bio import SeqIO
for seq in SeqIO.parse("Focub_mimp12rm_Chang_mimps.faa", "fasta"):
print(seq.id)
print(len(seq)
if re.search(r"CAGTGGG..GCAA[TA]AA", seq):
result_start = re.search(r"CAGTGGG..GCAA[TA]AA", seq)
match_1_start = result_start.start()
elif re.search(r"TT[TA]TTGC..CCCACTG", seq):
result_end = re.search(r"TT[TA]TTGC..CCCACTG", seq)
match_2_end = result_end.end()
mimp_lenth = match_2_end - match_1_start
print('---------------------------\n\n')
if mimp_lenth < 400 :
print('Mimp found at postion ' + str(match_1_start) + ' and ' + str(match_2_end) + ' in the sequence: \n\n' + seq + '. \n\nThe $
print('\n\n---------------------------\n\n')
Returned:
File "./My_mimp_finder.py", line 16
if re.search(r"CAGTGGG..GCAA[TA]AA", seq):
^
SyntaxError: invalid syntax
Python version 3.8.3
Upvotes: 0
Views: 525
Reputation: 207
There are two issues in your code. One is already pointed out by @I like coding above.
The reason for your error is in line above the line 16 where error is reported . You are missing closing braces for print statement.
print(len(seq) -- > print(len(seq))
Upvotes: 1
Reputation: 118
Side Note, there is also an issue with indentation.
After your "if" statement:
if mimp_lenth < 400 :
There needs to be an indentation otherwise you'll get an indentation error.
#!/bin/python
#My Mimp_finder
import re
from Bio import SeqIO
for seq in SeqIO.parse("Focub_mimp12rm_Chang_mimps.faa", "fasta"):
print(seq.id)
print(len(seq)
if re.search(r"CAGTGGG..GCAA[TA]AA", seq):
result_start = re.search(r"CAGTGGG..GCAA[TA]AA", seq)
match_1_start = result_start.start()
elif re.search(r"TT[TA]TTGC..CCCACTG", seq):
result_end = re.search(r"TT[TA]TTGC..CCCACTG", seq)
match_2_end = result_end.end()
mimp_lenth = match_2_end - match_1_start
print('---------------------------\n\n')
if mimp_lenth < 400 :
print('Mimp found at postion ' + str(match_1_start) + ' and ' + str(match_2_end) + ' in the sequence: \n\n' + seq + '. \n\nThe $
print('\n\n---------------------------\n\n')
Upvotes: 0
Reputation: 1631
Parenthesis missing in the second print statement
print(len(seq)
should be
print(len(seq))
Upvotes: 3