This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Add gene feature into genebank file

Hi, I would like to add some new features into genebank file in order to visulize them in some software like Snapgene.

I have create a dict with the position information and sequnce, like:

{Seq('TTCAGAGAAGCCTGAACTATTGGAGTGCTCGGCGGCT'): (129576, 129612), Seq('TTCAACGGACCCGGCTGTTCCCGACAGCTCCAGACGG'): (130899, 130607),Seq('TTCGAGTCTCTGCCGCAGCCGCTGGTTCTCCAAGGTG'): (129652, 129688)}

And I want to merge these sequences into gbk file and name them as "feature1, feature2 ... ..."

caution: sometimes the sequence is reverse, like second sequence (130899, 130607)

How can I do it by using biopython or other methods? I want everything to be sorted by position

Thanks a lot, good man.

feature genebank biopython

1 answer

What you need to build is a SeqRecord object that has SeqFeatures and FeatureLocation instances.

Note that you can't just add sequences as features, the features are relative to the sequence that the GenBank record describes, here is an example of how to create objects that can be saved as GenBank

from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio.SeqFeature import SeqFeature, FeatureLocation
from Bio import SeqIO

ann = dict(molecule_type="DNA")

seq = Seq('ATGC')
rec = SeqRecord(seq, id="test", annotations=ann)
feat = SeqFeature(FeatureLocation(1, 2), type='CDS')
rec.features.append(feat)

SeqIO.write(rec, 'output.gb', 'genbank')

Log in to answer this question.