I'm new trying to prgramming and I would like to separate from a multifasta, only specific sequences depending on their accession number, and create two different files, the first one with the sequences which their id is in the accession number list and the second one with the rest of files. I don't have any error after run the code but the output 1 is empty and it has to have the three sequences corresponding the accession number list.
Any comment is really welcome, and thanks in advance!
Here is my not working python code:
from Bio import SeqIO
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
accession_numbers = ["BA000007", "AL513382", "BX936398"]
infile = open("sequences.fasta")
my_file_1 = open("output_1.fasta", "w")
for seq_record in SeqIO.parse(infile, "fasta"):
my_file_1.write(">" + str(seq_record.id) + "\n" + str(seq_record.seq) +"\n")
He is not getting any errors so I think that's probably just a typo in the post.
But otherwise it works. May be the problem is with exact string match. I updated my post.
I actually wrote
strseq_record.id)
but don't know why the screen doesnt show it.thanks