<p dir="ltr">Hi Bastien,</p>
<p dir="ltr">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.</p>
<p dir="ltr">My recommendation would be to do:<br>
<br>
from Bio import SeqFeature as sf<br>
<br>
def myfun():<br>
spos = sf.BeforePosition(50);</p>
<p dir="ltr"> epos = sf.ExactPosition(100);</p>
<p dir="ltr"> l1 = sf.FeatureLocation(spos, epos, strand=+1)</p>
<p dir="ltr"> f1 = sf.SeqFeature(l1, strand=1, type="CDS", qualifiers={});</p>
<p dir="ltr">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.</p>
<p dir="ltr">If you really only need those four things, and you want to reduce the overhead a bit, you could do</p>
<p dir="ltr"> from Bio.SeqFeature import BeforePosition, ExactPosition, FeatureLocation, SeqFeature</p>
<p dir="ltr"> ...</p>
<p dir="ltr">And then just use these unqualified. Hope this helps!</p>
<p dir="ltr">Kevin</p>
<p dir="ltr">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 :-)</p>
<br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 21, 2016, 1:03 PM Chevreux, Bastien <<a href="mailto:bastien.chevreux@dsm.com">bastien.chevreux@dsm.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-GB" link="#0563C1" vlink="#954F72" class="gmail_msg">
<div class="m_-7174191323466886599WordSection1 gmail_msg">
<p class="MsoNormal gmail_msg">Hi all,<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">I am basing my question on <a href="https://www.biostars.org/p/57549/" class="gmail_msg" target="_blank">
https://www.biostars.org/p/57549/</a> which gives a code snipped which shows on how to add SeqFeatures.<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">Adapted, that code looks like this:<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">---<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">from Bio import SeqFeature;<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">spos = SeqFeature.BeforePosition(50);<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">epos = SeqFeature.ExactPosition(100);<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">from Bio.SeqFeature import SeqFeature, FeatureLocation, CompoundLocation<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><span lang="FR" class="gmail_msg">l1 = FeatureLocation(spos, epos, strand=+1)<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg">f1 = SeqFeature(l1, strand=1, type="CDS", qualifiers={});<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">---<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">And it does work, no problem.<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">However, I have some terrible issues with the above code: it imports SeqFeature twice. And I cannot write:<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">---<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">from Bio import SeqFeature;<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">from Bio.SeqFeature import SeqFeature, FeatureLocation, CompoundLocation<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">…<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">---<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">as this will bomb.<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">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:<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">---<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">def myfun():<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"> from Bio import SeqFeature;<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"> spos = SeqFeature.BeforePosition(50);<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"> epos = SeqFeature.ExactPosition(100);<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"> from Bio.SeqFeature import SeqFeature, FeatureLocation, CompoundLocation<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><span lang="FR" class="gmail_msg"> l 1 = FeatureLocation(spos, epos, strand=+1)<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg"> f1 = SeqFeature(l1, strand=1, type="CDS", qualifiers={});<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">---<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">This seems so infinitely wrong to me. What’s the correct way to write a function like this:<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">---<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">from … import …<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">from … import …<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">def myfun(x,y):<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"> spos = SeqFeature.BeforePosition(x);<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><span lang="FR" class="gmail_msg"> epos = SeqFeature.ExactPosition(y);<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg"><span lang="FR" class="gmail_msg"> l 1 = FeatureLocation(spos, epos, strand=+1)<u class="gmail_msg"></u><u class="gmail_msg"></u></span></p>
<p class="MsoNormal gmail_msg"><span lang="FR" class="gmail_msg"> </span>f1 = SeqFeature(l1, strand=1, type="CDS", qualifiers={});<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"> return f1;<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">---<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg">Best,<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"> Bastien<u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><span style="font-size:8.5pt;color:#008fd5" class="gmail_msg">-- <br class="gmail_msg">
DSM Nutritional Products Microbia Inc | Bioinformatics<br class="gmail_msg">
60 Westview Street | Lexington, MA 02421 | United States<br class="gmail_msg">
Phone +1 781 259 7613 | Fax +1 781 259 0615</span><u class="gmail_msg"></u><u class="gmail_msg"></u></p>
<p class="MsoNormal gmail_msg"><u class="gmail_msg"></u> <u class="gmail_msg"></u></p>
</div>
<br class="gmail_msg">
<hr class="gmail_msg">
<font face="Arial" color="Gray" size="1" class="gmail_msg"><br class="gmail_msg">
DISCLAIMER:<br class="gmail_msg">
This e-mail is for the intended recipient only.<br class="gmail_msg">
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.<br class="gmail_msg">
If you as intended recipient have received this e-mail incorrectly, please notify the sender (via e-mail) immediately.<br class="gmail_msg">
</font>
</div>
_______________________________________________<br class="gmail_msg">
Biopython mailing list - <a href="mailto:Biopython@mailman.open-bio.org" class="gmail_msg" target="_blank">Biopython@mailman.open-bio.org</a><br class="gmail_msg">
<a href="http://mailman.open-bio.org/mailman/listinfo/biopython" rel="noreferrer" class="gmail_msg" target="_blank">http://mailman.open-bio.org/mailman/listinfo/biopython</a></blockquote></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><div>Lecturer, Harvard Medical School</div><div>617-432-2210</div></div></div>