Hi, I would like to overwrite a feature in a genbank file using BioPython, using ambiguous locations.
For example, I can set an ambiguous location:
from Bio import SeqFeature
start_pos = SeqFeature.AfterPosition(5)
end_pos = SeqFeature.BeforePosition(10)
my_location = SeqFeature.FeatureLocation(start_pos, end_pos)
print my_location
Result:
[>5:<10]
Which is correct.
What I can't work out how to do is to use this ambiguous location to add a new feature to a sequence.
I can read in a genbank file, assign the records to a SeqRecord, and assign the genbank features to SeqFeatures :
for record in SeqIO.parse(myinfile, "genbank"):
new_gb = SeqRecord(record.seq)
new_gb.features=record.features
Then I can overwrite a feature:
new_gb.features[0]=SeqFeature(FeatureLocation(5,10), type="random_feature_type")
which, when I print the SeqRecord out in genbank format (to stdout), correctly overwrites the first feature:
out_handle = StringIO()
SeqIO.write(new_gb, out_handle, "genbank")
new_gb_output = out_handle.getvalue()
print new_gb_output
What I am stuck on is :
1) How to I add a completely new feature to a SeqRecord?
2) How can I use ambiguous locations in the location of a feature in a SeqRecord?
I'm sure this is simple but I can't seem to work it out.
Thanks and I'm sorry if this is stupid, I'm learning.
*features
starts out as an empty list, you should be able to add to is with*features.append(x)
?Also: if you want to save some time on formatting the record to genbank you can use
print(record.format("gb"))
Thanks, yes, basically silly by me, staring at a screen too long and using a SeqRecord when I wanted a SeqFeature. Worked out the use of ambiguous locations too.
Cool -you should post your solutions as an answer so future googlers can see how do it
I'm working on an idiot's guide to creating and adding a new feature to a sequence, will post it as an answer to this post once it's done.