def make_index(gff_file): """ Make a sqlite database for fast retrieval of features. """ import GFFutils db_file = gff_file + ".db" if need_update(gff_file, db_file): if op.exists(db_file): os.remove(db_file) GFFutils.create_gffdb(gff_file, db_file) return GFFutils.GFFDB(db_file)
def make_index(gff_file): """ Make a sqlite database for fast retrieval of features. """ import GFFutils db_file = gff_file + ".db" if need_update(gff_file, db_file): if op.exists(db_file): os.remove(db_file) GFFutils.create_gffdb(gff_file, db_file) return GFFutils.GFFDB(db_file)
def main(gff_file, fasta_file, parents, children): db_file = gff_file + ".db" if not op.exists(db_file): GFFutils.create_gffdb(gff_file, db_file) f = Fasta(fasta_file) g = GFFutils.GFFDB(db_file) parents = set(parents.split(',')) parents_iter = [g.features_of_type(x) for x in parents] parents_list = itertools.chain(*parents_iter) children_list = set(children.split(',')) for feat in parents_list: children = [] for c in g.children(feat.id, 1): if c.featuretype not in children_list: continue child = f.sequence(dict(chr=c.chrom, start=c.start, stop=c.stop, strand=c.strand)) children.append((child, c)) if not children: print >>sys.stderr, "[warning] %s has no children with type %s" \ % (feat.id, ','.join(children_list)) continue # sort children in incremental position children.sort(key=lambda x: x[1].start) # reverse children if negative strand if feat.strand=='-': children.reverse() feat_seq = ''.join(x[0] for x in children) print ">%s" % feat.id print feat_seq
def main(gff_file, fasta_file, parents, children): db_file = gff_file + ".db" if not op.exists(db_file): GFFutils.create_gffdb(gff_file, db_file) f = Fasta(fasta_file) g = GFFutils.GFFDB(db_file) parents = set(parents.split(',')) parents_iter = [g.features_of_type(x) for x in parents] parents_list = itertools.chain(*parents_iter) children_list = set(children.split(',')) for feat in parents_list: children = [] for c in g.children(feat.id, 1): if c.featuretype not in children_list: continue child = f.sequence( dict(chr=c.chrom, start=c.start, stop=c.stop, strand=c.strand)) children.append((child, c)) if not children: print >>sys.stderr, "[warning] %s has no children with type %s" \ % (feat.id, ','.join(children_list)) continue # sort children in incremental position children.sort(key=lambda x: x[1].start) # reverse children if negative strand if feat.strand == '-': children.reverse() feat_seq = ''.join(x[0] for x in children) print ">%s" % feat.id print feat_seq
#!/usr/bin/python usage = """ Create a GFF database from a GFF file, e.g., downloaded from FlyBase. Ryan Dale 2010 ([email protected]) """ import GFFutils import optparse import os import sys op = optparse.OptionParser(usage=usage) op.add_option('--gff',dest='gff',help='Input GFF file') op.add_option('--gffdb',dest='gffdb',help='Destination GFF database file') options,args = op.parse_args() if not options.gff or not options.gffdb: op.print_help() print '\nERROR: Please specify an input GFF file and an output GFF database file' sys.exit() if not os.path.exists(options.gff): print 'GFF file %s does not exist!' % options.gff sys.exit() GFFutils.create_gffdb(options.gff, options.gffdb)