'SyntaxError': 'return' outside function?
1
0
Entering edit mode
22 months ago
namck • 0

I have a super large file containing more than 1000 FASTA sequences merged. I want to extract the list of accession IDs from the file. But the following code got me an error. Can anybody tell me why and how to solve this? All my sequences contains a header file like this,

>NZ_QJRW01000001 (<'gap type:'>, <'description'>, 'gap start:', XXXXX, 'gap end:', XXXXX)**

Here is a snippet from the python script I have tried,

snippet from the code

biopython pattern python regex • 894 views
ADD COMMENT
0
Entering edit mode

if you want to stop the loop at the first time, there is no match use "break". if you want to skip the line with no match and continue use "continue"

ADD REPLY
0
Entering edit mode

Any particular reason you are doing this with python (other than perhaps learning python)? Or is there more to this script than just accession recovery. That can be done with a simple grep and cut otherwise.

$ cat your_file | grep "^>" | cut -f1 -d " " | sed 's/>//'
NZ_QJRW01000001
ADD REPLY
1
Entering edit mode
22 months ago

Because the return keyword is only allowed inside function definitions:

def biggerthanfive(x):
    if x > 5:
        return True
    else:
        return False

In your example, you are only using a loop that you can break, but not return from. You can also write it way more succinct.

ADD COMMENT

Login before adding your answer.

Traffic: 1968 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6