I'm attempting to add features using BioPython to a multi-entry Genbank. Each entry in the genbank is a contig, and I'd like to annotate some BLAST hits.
I've performed a BLAST of my query against a multi-entry fasta, so I know which hits belong to which contig and what the contig is called. I'm able to parse my Genbank and find which contig I'd like to add the feature to. I then append the feature, but I'm problems at the final stage where I attempt to then write out the entire Genbank with the new feature added to one of the entries.
This is my code so far:
After this for loop, SeqIO.write() writes 0 features to the new file I specify.
If I do this - SeqIO.write(genbank, "D13_multi_edited.gbk", "genbank"), it writes out all the entries after the the contig that I've just append a feature to.
I've also tried this:
In this case it misses the first entry (there should be 110 entries) and writes out the entry that I've added a feature to but without the feature being added.
What am I doing wrong?
I've performed a BLAST of my query against a multi-entry fasta, so I know which hits belong to which contig and what the contig is called. I'm able to parse my Genbank and find which contig I'd like to add the feature to. I then append the feature, but I'm problems at the final stage where I attempt to then write out the entire Genbank with the new feature added to one of the entries.
This is my code so far:
Code:
>>> handle = open("D13_multi.gbk", "rU") >>> genbank = SeqIO.parse(handle, "genbank") >>> for record in genbank: ... if record.id == node: record.features.append(SeqFeature.SeqFeature(SeqFeature.FeatureLocation(start, end), type = "misc_feature")) ... print record.features ... [SeqFeature(FeatureLocation(ExactPosition(0), ExactPosition(35), strand=1), type='misc_feature'), SeqFeature(FeatureLocation(ExactPosition(652), ExactPosition(145)), type='misc_feature')]
If I do this - SeqIO.write(genbank, "D13_multi_edited.gbk", "genbank"), it writes out all the entries after the the contig that I've just append a feature to.
I've also tried this:
Code:
>>> for record in genbank: ... if record.id != node: ... SeqIO.write(genbank, "D13_test.gbk", "genbank") ... if record.id == node: ... record.features.append(SeqFeature.SeqFeature(SeqFeature.FeatureLocation(start, end), type = "misc_feature")) ... SeqIO.write(record, "D13_test.gbk", "genbank") ... 109
What am I doing wrong?
Comment