Biopython: Is It Possible To Update Only Sequence In A Seqrecord Object?
1
1
Entering edit mode
10.1 years ago
sinanugur ▴ 10

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 • 6.1k views
ADD COMMENT
1
Entering edit mode

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 REPLY
4
Entering edit mode
10.1 years ago
David W 4.9k

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 COMMENT
1
Entering edit mode

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 REPLY

Login before adding your answer.

Traffic: 2898 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6