[Biopython] gff3 writting

Mic mictadlo at gmail.com
Tue Jul 2 05:22:02 UTC 2013


Hi,
I found here (
http://biopython.org/wiki/GFF_Parsing#Writing_GFF3_from_scratch ) an
example how to write GFF3 from scratch.

I modified it in order to add one more features and sub_features, but the
second sub_features are not visible:
##gff-version 3
##sequence-region ID1 1 40
ID1     prediction      gene    1       20      10.0    +       .
other=Some,annotations;ID=gene1
ID1     prediction      exon    1       5       .       +       .
Parent=gene1
ID1     prediction      exon    16      20      .       +       .
Parent=gene1
ID1     prediction      gene    31      40      10.0    +       .
other=Some,annotations;ID=gene2

with the following code:
from BCBio import GFF
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio.SeqFeature import SeqFeature, FeatureLocation

out_file = "gff3.gff"
seq = Seq("GATCGATCGATCGATCGATCGATCGATCGATCGATCGATC")
rec = SeqRecord(seq, "ID1")
qualifiers = {"source": "prediction", "score": 10.0, "other": ["Some",
"annotations"],
              "ID": "gene1"}
sub_qualifiers = {"source": "prediction"}
top_feature = SeqFeature(FeatureLocation(0, 20), type="gene", strand=1,
                         qualifiers=qualifiers)
top_feature.sub_features = [SeqFeature(FeatureLocation(0, 5), type="exon",
strand=1,
                                       qualifiers=sub_qualifiers),
                            SeqFeature(FeatureLocation(15, 20),
type="exon", strand=1,
                                       qualifiers=sub_qualifiers)]
rec.features = [top_feature]

qualifiers2 = {"source": "prediction", "score": 10.0, "other": ["Some",
"annotations"],
              "ID": "gene2"}
sub_qualifiers2 = {"source": "prediction"}
top_feature2 = SeqFeature(FeatureLocation(30, 40), type="gene", strand=1,
                         qualifiers=qualifiers2)
top_feature2.sub_features2 = [SeqFeature(FeatureLocation(30, 35),
type="exon", strand=1,
                                       qualifiers=sub_qualifiers2),
                            SeqFeature(FeatureLocation(37, 40),
type="exon", strand=1,
                                       qualifiers=sub_qualifiers2)]
rec.features.append(top_feature2)

with open(out_file, "w") as out_handle:
    GFF.write([rec], out_handle)

Thank you in advance.

Mic



More information about the Biopython mailing list