[Biopython] Adding a SeqFeature to a SeqRecord
Peter Cock
p.j.a.cock at googlemail.com
Wed Apr 17 21:53:57 UTC 2013
Hi Mark,
On Wed, Apr 17, 2013 at 10:24 PM, Mark Budde <markbudde at gmail.com> wrote:
> Hi, I have a simple question. The cookbook shows many examples using
> SeqFeatures, I can't find any information on adding features to a
> SeqRecord.
The "Tutorial and Cookbook" does have examples of creating a
SeqFeature - if this was not obvious to you how might we make
it clearer?
http://biopython.org/DIST/docs/tutorial/Tutorial.html
http://biopython.org/DIST/docs/tutorial/Tutorial.pdf
See also the docstrings,
>>> from Bio.SeqFeature import SeqFeature, FeatureLocation
>>> help(SeqFeature)
>>> help(FeatureLocation)
Online here (for the current release):
http://biopython.org/DIST/docs/api/Bio.SeqFeature.SeqFeature-class.html
http://biopython.org/DIST/docs/api/Bio.SeqFeature.FeatureLocation-class.html
> Say I wanted to add a Feature to an existing SeqRecord. Lets say it spans
> nucleotides 10..100, is called "Gene1" and is on the reverse strand. How
> would I add this to my SeqRecord?
>
> Thanks,
> Mark
Which version of Biopython do you have? The strand is moving
from the SeqFeature to the FeatureLocation, but this will work
on old and new:
from Bio.SeqFeature import SeqFeature, FeatureLocation
loc = FeatureLocation(9, 100)
f = SeqFeature(loc, strand=-1, qualifiers={"locus_tag":"Gene1"})
This is preferred for future-proofing:
from Bio.SeqFeature import SeqFeature, FeatureLocation
loc = FeatureLocation(9, 100, strand=-1)
f = SeqFeature(loc, qualifiers={"locus_tag":"Gene1"})
Exactly where you put the gene name depends on what you'll be
doing with the record - for GenBank or EMBL output, using a
locus_tag key would be a sensible option.
Then if you have a SeqRecord, use my_record.features.append(f)
or similar (and for GenBank/EMBL output pay attention to the
order).
Is that clear?
Regards,
Peter
More information about the Biopython
mailing list