<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"><<a href="mailto:p.j.a.cock@googlemail.com" target="_blank">p.j.a.cock@googlemail.com</a>></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 <<a href="mailto:flyamer@gmail.com">flyamer@gmail.com</a>> wrote:<br>
> Hi,<br>
><br>
> is there a way to either change SeqFeature's location in place or create a<br>
> copy with a different location? Assigning to feature.location.start raises<br>
> an AttributeError.<br>
<br>
</div>The FeatureLocation properties are (currently at least) read only<br>
attributes. You could replace the current SeqFeature's location<br>
with a new FeatureLocation instead:<br>
<br>
Example to get a SeqFeature,<br>
<br>
>>> from Bio import SeqIO<br>
>>> record = SeqIO.read("NC_000932.g", "genbank")<br>
>>> f = record.features[10]<br>
>>> f<br>
SeqFeature(FeatureLocation(ExactPosition(2055), ExactPosition(3570),<br>
strand=-1), type='CDS')<br>
>>> print f<br>
type: CDS<br>
location: [2055:3570](-)<br>
qualifiers:<br>
Key: codon_start, Value: ['1']<br>
Key: db_xref, Value: ['GI:126022795', 'GeneID:844797']<br>
Key: gene, Value: ['matK']<br>
Key: locus_tag, Value: ['ArthCp003']<br>
Key: product, Value: ['maturase K']<br>
Key: protein_id, Value: ['NP_051040.2']<br>
Key: transl_table, Value: ['11']<br>
Key: translation, Value:<br>
['MDKFQGYLEFDGARQQSFLYPLFFREYIYVLAYDHGLNRLNRNRYIFLENADYDKKYSSLITKRLILRMYEQNRLIIPTKDVNQNSFLGHTSLFYYQMISVLFAVIVEIPFSLRLGSSFQGKQLKKSYNLQSIHSIFPFLEDKLGHFNYVLDVLIPYPIHLEILVQTLRYRVKDASSLHFFRFCLYEYCNWKNFYIKKKSILNPRFFLFLYNSHVCEYESIFFFLRKRSSHLRSTSYEVLFERIVFYGKIHHFFKVFVNNFPAILGLLKDPFIHYVRYHGRCILATKDTPLLMNKWKYYFVNLWQCYFSVWFQSQKVNINQLSKDNLEFLGYLSSLRLNPLVVRSQMLENSFLIDNVRIKLDSKIPISSIIGSLAKDKFCNVLGHPISKATWTDSSDSDILNRFVRICRNISHYYSGSSKKKNLYRIKYILRLCCVKTLARKHKSTVRTFLKRLGSGLLEEFLTGEDQVLSLIFPRSYYASKRLYRVRIWYLDILYLNDLVNHE']<br>
>>> f.location<br>
FeatureLocation(ExactPosition(2055), ExactPosition(3570), strand=-1)<br>
>>> print f.location<br>
[2055:3570](-)<br>
<br>
Now let's change the location:<br>
<br>
>>> from Bio.SeqFeature import FeatureLocation<br>
>>> f.location = FeatureLocation(2049, 3570, strand=-1)<br>
>>> f.location<br>
FeatureLocation(ExactPosition(2049), ExactPosition(3570), strand=-1)<br>
>>> print f.location<br>
[2049:3570](-)<br>
<div class=""><br>
> My ultimate goal is to move all features in a genbank file by some specific<br>
> number of nucleotides (for example, add 1000 to all coordinates). If someone<br>
> 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>
>>> loc = FeatureLocation(2049, 3564, strand=-1)<br>
>>> loc<br>
FeatureLocation(ExactPosition(2049), ExactPosition(3564), strand=-1)<br>
>>> loc + 6<br>
FeatureLocation(ExactPosition(2055), ExactPosition(3570), strand=-1)<br>
<br>
On in situ, replacing the old FeatureLocation object:<br>
<br>
>>> loc += 6<br>
>>> 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>
>>> from Bio import SeqIO<br>
>>> record = SeqIO.read("NC_000932.gb", "genbank")<br>
>>> record.features[10].location<br>
FeatureLocation(ExactPosition(2055), ExactPosition(3570), strand=-1)<br>
>>> new = "N"*1000 + record<br>
>>> new.features[10].location<br>
FeatureLocation(ExactPosition(3055), ExactPosition(4570), strand=-1)<br>
<br>
See also "Adding SeqRecord objects" 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>