# Filtering fasta files by ID

I have this code to filter some IDs from a fasta file:

for line in file_open:
line=line.rstrip()
if '16S' in line:
seq=seq.strip()


however, this code doesn't get me all content of each ID sequence. I get this result:

>ID1
AGTTTTGCCGAATTCCTTTAGGATTTTGTGAGGAACATTGTGTTAAATGTATTTATAGTTCTACTAATTC


When I should get this:

>ID1
AGTTTTGCCGAATTCCTTTAGGATTTTGTGAGGAACATTGTGTTAAATGTATTTATAGTTCTACTAATTC
TGCGAAGGTAGCATAATCATTAGCCTTTTGATTTGAGGCTGGAATGAATGGTTTGACGAGAGATGGTCTG
GGGCCGTGGTATACTGACCATGCGAAGGTAGCATAATCATTAGCCTCTTGATTTGAGGCTGGAATGAATG
GGGCCGTGGTATAC


Thanks

• Does this answer your question? Remove/delete sequences by ID from multifasta Sep 24 '20 at 15:27
• Well, the code you wrote prints the seq on a single line (and without any newline afterwards), are you sure that's not the only problem? Sep 26 '20 at 19:25
• @KonradRudolph I think the question is more about writing the fasta file well formated. Sep 26 '20 at 19:25
• @KamilSJaron No, the question isn’t about formatting. Check the output in the question again. It isn’t all on one line, it’s truncated (as in, only the first line is read and written, subsequent lines are omitted). Sep 28 '20 at 8:07
• I thought that the truncated line could be due to copypasting. Now I see, it's not about the formatting of output, but expected formatting of the input. Sep 28 '20 at 9:06

from Bio import SeqIO