[Biopython] Adding a SeqFeature to a SeqRecord

Mark Budde markbudde at gmail.com
Wed Apr 17 22:52:31 UTC 2013


On Wed, Apr 17, 2013 at 2:53 PM, Peter Cock <p.j.a.cock at googlemail.com>wrote:

> 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
>
> I am coming at this from the perspective of generating a plasmid with
features on it. I guess most people would be using this for mining data
from pubmed or something, so maybe I'm just not the targeted user. I spent
a lot of time looking for how to name a feature, like you would in a vector
editing program. I now see that I can generate a feature as shown in the
first example in 4.3.3 - is this what you are referring to? I was confused
earlier because I could never figure out how to name the feature, nor how
to add it to the SeqRecord. I can see how to do this from you example below
(using qualifiers to name the feature, and append to add the feature). I
think the cookbook would benefit from adding a line such as

>>> len(MyRecord.features)
0
>>> example_feature.qualifiers['locus_tag'] = 'Gene1'
>>> MyRecord.features.append(example_feature)
>>> len(MyRecord.features)
1


> 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:
>
> I have v1.59

> 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?

Yes. Your example provided here is clear and I think it should be added to
the cookbook.

>
>
Regards,
>
> Peter
>
Thanks for your help Peter, and pardon my ignorance.
-Mark



More information about the Biopython mailing list