[Biopython] Problems with SeqFeature

Chevreux, Bastien bastien.chevreux at dsm.com
Tue Nov 22 15:14:24 UTC 2016


Thank you, that worked like a charm. I left a comment on the BioStars page for the following generations to learn from it :-)

Best,
  Bastien

--
DSM Nutritional Products Microbia Inc | Bioinformatics
60 Westview Street | Lexington, MA 02421 | United States
Phone +1 781 259 7613 | Fax +1 781 259 0615

From: Kevin Bonham [mailto:kevbonham at gmail.com]
Sent: Tuesday, November 22, 2016 12:50 AM
To: Chevreux, Bastien <bastien.chevreux at dsm.com>; biopython at biopython.org
Subject: Re: [Biopython] Problems with SeqFeature

--- This mail has been sent from an external source ---

Hi Bastien,

Yeah, it looks like you're pulling from two different snippets and they're not using the same conventions. When you're doing `from Bio.SeqFeature import SeqFeature...`, you're overwriting what Python thinks `SeqFeature` means from when you did `from Bio import SeqFeature`. And, as you say, you're importing a bunch of stuff twice, which doesn't make much sense.

My recommendation would be to do:

    from Bio import SeqFeature as sf

    def myfun():
        spos = sf.BeforePosition(50);

        epos = sf.ExactPosition(100);

        l1 = sf.FeatureLocation(spos, epos, strand=+1)

        f1 = sf.SeqFeature(l1, strand=1, type="CDS", qualifiers={});

This way everything is nice and tidy, and you can see where those functions came from in your code. Plus you have access to everything in Bio.SeqFeature if you need it.

If you really only need those four things, and you want to reduce the overhead a bit, you could do

    from Bio.SeqFeature import BeforePosition, ExactPosition, FeatureLocation, SeqFeature

    ...

And then just use these unqualified. Hope this helps!

Kevin

PS I didn't actually try to run any of the above code and im typing on my phone, so don't be mad if there's a syntax error somewhere :-)

On Mon, Nov 21, 2016, 1:03 PM Chevreux, Bastien <bastien.chevreux at dsm.com<mailto:bastien.chevreux at dsm.com>> wrote:
Hi all,

I am basing my question on https://www.biostars.org/p/57549/ which gives a code snipped which shows on how to add SeqFeatures.

Adapted, that code looks like this:
---
from Bio import SeqFeature;
spos = SeqFeature.BeforePosition(50);
epos = SeqFeature.ExactPosition(100);
from Bio.SeqFeature import SeqFeature, FeatureLocation, CompoundLocation
l1 = FeatureLocation(spos, epos, strand=+1)
f1 = SeqFeature(l1, strand=1, type="CDS", qualifiers={});
---

And it does work, no problem.

However, I have some terrible issues with the above code: it imports SeqFeature twice. And I cannot write:
---
from Bio import SeqFeature;
from Bio.SeqFeature import SeqFeature, FeatureLocation, CompoundLocation
…
---

as this will bomb.

And therefore I cannot easily stick the above into a function without re-importing in the function every time I use the functionality. Like this:

---
def myfun():
    from Bio import SeqFeature;
    spos = SeqFeature.BeforePosition(50);
    epos = SeqFeature.ExactPosition(100);
    from Bio.SeqFeature import SeqFeature, FeatureLocation, CompoundLocation
    l 1 = FeatureLocation(spos, epos, strand=+1)
    f1 = SeqFeature(l1, strand=1, type="CDS", qualifiers={});
---

This seems so infinitely wrong to me. What’s the correct way to write a function like this:

---
from … import …
from … import …

def myfun(x,y):
    spos = SeqFeature.BeforePosition(x);
    epos = SeqFeature.ExactPosition(y);
    l 1 = FeatureLocation(spos, epos, strand=+1)
    f1 = SeqFeature(l1, strand=1, type="CDS", qualifiers={});
    return f1;
---

Best,
  Bastien


--
DSM Nutritional Products Microbia Inc | Bioinformatics
60 Westview Street | Lexington, MA 02421 | United States
Phone +1 781 259 7613 | Fax +1 781 259 0615


________________________________

DISCLAIMER:
This e-mail is for the intended recipient only.
If you have received it by mistake please let us know by reply and then delete it from your system; access, disclosure, copying, distribution or reliance on any of it by anyone else is prohibited.
If you as intended recipient have received this e-mail incorrectly, please notify the sender (via e-mail) immediately.
_______________________________________________
Biopython mailing list  -  Biopython at mailman.open-bio.org<mailto:Biopython at mailman.open-bio.org>
http://mailman.open-bio.org/mailman/listinfo/biopython
--
Lecturer, Harvard Medical School
617-432-2210
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biopython/attachments/20161122/9584651c/attachment-0001.html>


More information about the Biopython mailing list