0

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

2
  • Could you please reduce your code to minimum needed to reproduce the issue? Commented Aug 7, 2020 at 16:46
  • 2
    Hint: A syntax error is often above the place pointed to. Commented Aug 7, 2020 at 16:47

3 Answers 3

3

Parenthesis missing in the second print statement

print(len(seq)

should be

print(len(seq))
Sign up to request clarification or add additional context in comments.

Comments

1

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))

Comments

0

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')

2 Comments

No, indentation errors produce an IndentationError (or semantic errors).
@MichaelButscher Oh good point, my fault. I will edit my answer once I figure out the syntax error, but there is an indentation error as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.