[Biopython] GFF parsing with biopython

Brad Chapman chapmanb at 50mail.com
Wed May 1 06:04:08 EDT 2013


Mic;
(moving to galaxy-dev list so folks there can follow, but future
questions are more appropriate for the Biopython list only since
this isn't a Galaxy question)

> I have the following GFF file from a SNAP
>
> X1       SNAP    Einit   2579    2712    -3.221  +       .       X1-snap.1
[...]
> With the code below I have tried to parse the above GFF file

The attributes you're missing are parts of the feature, not the
SeqRecord itself, which is why you're seeing attribute error. Here's a
full example that pulls all of the information from an example line:

from BCBio import GFF

in_file = "snap.gff"
with open(in_file) as in_handle:
    for rec in GFF.parse(in_handle):
        feature = rec.features[0]
        print rec.id
        print feature.qualifiers["source"][0]
        print feature.type
        print feature.location.start
        print feature.location.end
        print feature.qualifiers["score"][0]
        print feature.location.strand
        print feature.qualifiers.get("X1-snap.1", [None])[0]

which outputs:

X1
SNAP
Einit
2578
2712
-3.221
1
true

Hope this helps,
Brad


More information about the Biopython mailing list