Question: Biopython: Is It Possible To Update Only Sequence In A Seqrecord Object?
1
gravatar for sinanugur
5.3 years ago by
sinanugur10
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 • 3.3k views
ADD COMMENTlink modified 5.3 years ago by David W4.7k • written 5.3 years ago by sinanugur10
1

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 5.0 years ago by Adam R20
4
gravatar for David W
5.3 years ago by
David W4.7k
New Zealand
David W4.7k wrote:

Yep:

from Bio import Seq
from Bio import SeqRecord

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

#>test
#ATTGA

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

#>test
#ATTGG
ADD COMMENTlink written 5.3 years ago by David W4.7k
1

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 5.3 years ago • written 5.3 years ago by Philipp Bayer6.2k
Please log in to add an answer.

Help
Access

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