FAA File Sequence
2
0
Entering edit mode
23 months ago

I used this sequence of codes to print the sequences with a header:

enter image description here

but now that I'm trying to print without a header (the lines with > in the start) using this other code, I'm not getting it

enter image description here

enter image description here

Is there any other code that can do this, a more direct one or using the same sequence with sth different?

faa python • 1.1k views
ADD COMMENT
1
Entering edit mode
23 months ago

I managed to solve it with this code:

openFile = open('genoma9.faa', 'r')
writeFile = open('updatedFile.txt', 'w')
for txtLine in openFile .readlines():
    if not (txtLine.startswith('>WP')):
        print(txtLine)
        writeFile.write(txtLine)
writeFile.close()

openFile.close()
ADD COMMENT
1
Entering edit mode
23 months ago

The read() method returns the specified number of bytes from the file. Default is -1 which means the whole file.

here you read the whole file. If the file is too large, it won't fit in memory.

Is there any other code that can do this

iterate over each line, fill the name and the sequence of the current sequence.

see Correct Way To Parse A Fasta File In Python

ADD COMMENT

Login before adding your answer.

Traffic: 1971 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