I am trying to use Bio and SeqIO to open a FASTA file that contains multiple sequences, edit the names of the sequences to remove a '.seq' on the end of all the names, (>SeqID20.seq should become >SeqID20), then write all the sequences to a new FASTA file, But i get the following error
AttributeError: 'str' object has no attribute 'id'
This is what I started with :
with open ('lots_of_fasta_in_file.fasta') as f:
for seq_record in SeqIO.parse(f, 'fasta'):
name, sequence = seq_record.id, str(seq_record.seq)
pair = [name.replace('.seq',''), sequence]
SeqIO.write(pair, "new.fasta", "fasta")
but i have also tried this and get the same error:
file_in ='lots_of_fasta_in_file.fasta'
file_out='new.fasta'
with open(file_out, 'w') as f_out:
with open(file_in, 'r') as f_in:
for seq_record in SeqIO.parse(f_in, 'fasta'):
name, sequence = seq_record.id, str(seq_record.seq)
# remove .seq from ID and add features
pair = [name.replace('.seq',''), sequence]
SeqIO.write(pair, file_out, 'fasta')
I assume I'm making some error in going from my list 'pair' to writing to a new file, but I'm not sure what to change. Any help would be appreciated!