<div dir="ltr"><div>Dear Peter,<br><br>Thank you very much, this seems to be exactly what I was looking for.<br><br></div>Best,<br>Ilya<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-07-28 11:09 GMT+02:00 Peter Cock <span dir="ltr">&lt;<a href="mailto:p.j.a.cock@googlemail.com" target="_blank">p.j.a.cock@googlemail.com</a>&gt;</span>:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Fri, Jul 25, 2014 at 1:55 PM, Ilya Flyamer &lt;<a href="mailto:flyamer@gmail.com">flyamer@gmail.com</a>&gt; wrote:<br>


&gt; Hi,<br>
&gt;<br>
&gt; is there a way to either change SeqFeature&#39;s location in place or create a<br>
&gt; copy with a different location? Assigning to feature.location.start raises<br>
&gt; an AttributeError.<br>
<br>
</div>The FeatureLocation properties are (currently at least) read only<br>
attributes. You could replace the current SeqFeature&#39;s location<br>
with a new FeatureLocation instead:<br>
<br>
Example to get a SeqFeature,<br>
<br>
&gt;&gt;&gt; from Bio import SeqIO<br>
&gt;&gt;&gt; record = SeqIO.read(&quot;NC_000932.g&quot;, &quot;genbank&quot;)<br>
&gt;&gt;&gt; f = record.features[10]<br>
&gt;&gt;&gt; f<br>
SeqFeature(FeatureLocation(ExactPosition(2055), ExactPosition(3570),<br>
strand=-1), type=&#39;CDS&#39;)<br>
&gt;&gt;&gt; print f<br>
type: CDS<br>
location: [2055:3570](-)<br>
qualifiers:<br>
    Key: codon_start, Value: [&#39;1&#39;]<br>
    Key: db_xref, Value: [&#39;GI:126022795&#39;, &#39;GeneID:844797&#39;]<br>
    Key: gene, Value: [&#39;matK&#39;]<br>
    Key: locus_tag, Value: [&#39;ArthCp003&#39;]<br>
    Key: product, Value: [&#39;maturase K&#39;]<br>
    Key: protein_id, Value: [&#39;NP_051040.2&#39;]<br>
    Key: transl_table, Value: [&#39;11&#39;]<br>
    Key: translation, Value:<br>
[&#39;MDKFQGYLEFDGARQQSFLYPLFFREYIYVLAYDHGLNRLNRNRYIFLENADYDKKYSSLITKRLILRMYEQNRLIIPTKDVNQNSFLGHTSLFYYQMISVLFAVIVEIPFSLRLGSSFQGKQLKKSYNLQSIHSIFPFLEDKLGHFNYVLDVLIPYPIHLEILVQTLRYRVKDASSLHFFRFCLYEYCNWKNFYIKKKSILNPRFFLFLYNSHVCEYESIFFFLRKRSSHLRSTSYEVLFERIVFYGKIHHFFKVFVNNFPAILGLLKDPFIHYVRYHGRCILATKDTPLLMNKWKYYFVNLWQCYFSVWFQSQKVNINQLSKDNLEFLGYLSSLRLNPLVVRSQMLENSFLIDNVRIKLDSKIPISSIIGSLAKDKFCNVLGHPISKATWTDSSDSDILNRFVRICRNISHYYSGSSKKKNLYRIKYILRLCCVKTLARKHKSTVRTFLKRLGSGLLEEFLTGEDQVLSLIFPRSYYASKRLYRVRIWYLDILYLNDLVNHE&#39;]<br>


&gt;&gt;&gt; f.location<br>
FeatureLocation(ExactPosition(2055), ExactPosition(3570), strand=-1)<br>
&gt;&gt;&gt; print f.location<br>
[2055:3570](-)<br>
<br>
Now let&#39;s change the location:<br>
<br>
&gt;&gt;&gt; from Bio.SeqFeature import FeatureLocation<br>
&gt;&gt;&gt; f.location = FeatureLocation(2049, 3570, strand=-1)<br>
&gt;&gt;&gt; f.location<br>
FeatureLocation(ExactPosition(2049), ExactPosition(3570), strand=-1)<br>
&gt;&gt;&gt; print f.location<br>
[2049:3570](-)<br>
<div class=""><br>
&gt; My ultimate goal is to move all features in a genbank file by some specific<br>
&gt; number of nucleotides (for example, add 1000 to all coordinates). If someone<br>
&gt; can help me and tell about an easier way, I will appreciate it.<br>
<br>
</div>The easy way is just to add 1000 to the feature location, which will give<br>
you a new FeatureLocation with shifted coordinates:<br>
<br>
&gt;&gt;&gt; loc = FeatureLocation(2049, 3564, strand=-1)<br>
&gt;&gt;&gt; loc<br>
FeatureLocation(ExactPosition(2049), ExactPosition(3564), strand=-1)<br>
&gt;&gt;&gt; loc + 6<br>
FeatureLocation(ExactPosition(2055), ExactPosition(3570), strand=-1)<br>
<br>
On in situ, replacing the old FeatureLocation object:<br>
<br>
&gt;&gt;&gt; loc += 6<br>
&gt;&gt;&gt; loc<br>
FeatureLocation(ExactPosition(2055), ExactPosition(3570), strand=-1)<br>
<br>
Also, you might have missed this kind of thing in the tutorial - adding<br>
to a SeqRecord will adjust the feature locations accordingly:<br>
<br>
&gt;&gt;&gt; from Bio import SeqIO<br>
&gt;&gt;&gt; record = SeqIO.read(&quot;NC_000932.gb&quot;, &quot;genbank&quot;)<br>
&gt;&gt;&gt; record.features[10].location<br>
FeatureLocation(ExactPosition(2055), ExactPosition(3570), strand=-1)<br>
&gt;&gt;&gt; new = &quot;N&quot;*1000 + record<br>
&gt;&gt;&gt; new.features[10].location<br>
FeatureLocation(ExactPosition(3055), ExactPosition(4570), strand=-1)<br>
<br>
See also &quot;Adding SeqRecord objects&quot; in the Tutorial:<br>
<a href="http://biopython.org/DIST/docs/tutorial/Tutorial.html" target="_blank">http://biopython.org/DIST/docs/tutorial/Tutorial.html</a><br>
<span class="HOEnZb"><font color="#888888"><br>
Peter<br>
</font></span></blockquote></div><br></div>