Package: gff3
Manipulate genomic features and validate the syntax and reference sequence of yourGFF3files.Free software: BSD licenseDocumentation:https://gff3-py.readthedocs.org.FeaturesSimple data structures: Parses aGFF3file into a structure composed of simple pythondictandlist.Validation: Validates theGFF3syntax on parse, and saves the error messages in the parsed structure.Best effort parsing: Despite any detected errors, continue to parse the whole file and make as much sense to it as possible.Uses the pythonlogginglibrary to log error messages with support for custom loggers.Parses embeded or externalFASTAsequences to check bounds and number ofNs.Check and correct the phase forCDSfeatures.Tree traversal methodsancestorsanddescendantsreturns a simplelistin Breadth-first search order.Transfer children and parents using theadoptandadoptedmethods.Test for overlapping features using theoverlapmethod.Remove a feature and its associated features using theremovemethod.Write the modified structure to a GFF3 file using thewritemthod.Quick StartAn example that just parses a GFF3 file namedannotations.gffand validates it
using an external FASTA file namedannotations.falooks like:# validate.py# ============fromgff3importGff3# initialize a Gff3 objectgff=Gff3()# parse GFF3 file and do syntax checking, this populates gff.lines and gff.features# if an embedded ##FASTA directive is found, parse the sequences into gff.fasta_embeddedgff.parse('annotations.gff')# parse the external FASTA file into gff.fasta_externalgff.parse_fasta_external('annotations.fa')# Check seqid, bounds and the number of Ns in each feature using one or more reference sourcesgff.check_reference(allowed_num_of_n=0,feature_types=['CDS'])# Checks whether child features are within the coordinate boundaries of parent featuresgff.check_parent_boundary()# Calculates the correct phase and checks if it matches the given phase for CDS featuresgff.check_phase()A more feature complete GFF3 validator with a command line interface which also generates validation
report in MarkDown is available underexamples/gff_valid.pyThe following example demonstrates how to filter, tranverse, and modify the parsed gff3lineslist.Change features with typeexontopseudogenic_exonand typetranscripttopseudogenic_transcriptif the feature has an ancestor of typepseudogeneIf apseudogenefeature overlaps with agenefeature, move all of the children from thepseudogenefeature to thegenefeature, and remove thepseudogenefeature.# fix_pseudogene.py# =================fromgff3importGff3gff=Gff3('annotations.gff')type_map={'exon':'pseudogenic_exon','transcript':'pseudogenic_transcript'}pseudogenes=[lineforlineingff.linesifline['line_type']=='feature'andline['type']=='pseudogene']forpseudogeneinpseudogenes:# convert typesforlineingff.descendants(pseudogene):ifline['type']intype_map:line['type']=type_map[line['type']]# find overlapping geneoverlapping_genes=[lineforlineingff.linesifline['line_type']=='feature'andline['type']=='gene'andgff.overlap(line,pseudogene)]ifoverlapping_genes:# move pseudogene children to overlapping genegff.adopt(pseudogene,overlapping_genes[0])# remove pseudogenegff.remove(pseudogene)gff.write('annotations_fixed.gff')History1.0.0 (2018-12-01)Fix Python3 issuesAdded sequence functions: complement(seq) and translate(seq)Added fasta write function: fasta_dict_to_file(fasta_dict, fasta_file, line_char_limit=None)Added Gff method to return the sequence of line_data: sequence(self, line_data, child_type=None, reference=None)Gff.write no longer prints redundent ‘###’ when the whole gene is marked as removed0.3.0 (2015-03-10)Fixed phase checking.0.2.0 (2015-01-28)Supports python 2.6, 2.7, 3.3, 3.4, pypy.Don’t report empty attributes as errors.Improved documentation.0.1.0 (2014-12-11)First release on PyPI.