Question: Biopython: Is It Possible To Update Only Sequence In A Seqrecord Object?
gravatar for sinanugur
7.0 years ago by
sinanugur10 wrote:

Well I know sequence objects are immutable, but why cant we assign a new sequence to a SeqRecord object without changing any other data.

biopython • 4.2k views
ADD COMMENTlink modified 7.0 years ago by David W4.8k • written 7.0 years ago by sinanugur10

If you are hitting an error relating to letter annotations (e.g. "You must empty the letter annotations first!"), you can copy them to a temporary dict object while you modify the seq, clear them, and then copy them back to the SeqRecord afterwards.

ADD REPLYlink written 6.7 years ago by Adam R20
gravatar for David W
7.0 years ago by
David W4.8k
New Zealand
David W4.8k wrote:


from Bio import Seq
from Bio import SeqRecord

rec = SeqRecord.SeqRecord(id='test', description='', seq=Seq.Seq('ATTGA'))
print rec.format('fasta')


rec.seq = Seq.Seq('ATTGG')
print rec.format('fasta')

ADD COMMENTlink written 7.0 years ago by David W4.8k

I just wanted to post something similar - it's important that the new sequence 'ATTGG' is an object of class Seq, not a string, because then you'll get (at least on my system with Python 2.7.5 and BioPython 1.62b)

SeqRecord (id=test) has an invalid sequence.
ADD REPLYlink modified 7.0 years ago • written 7.0 years ago by Philipp Bayer6.9k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1460 users visited in the last hour