示例#1
0
def iterate(fin):
    buf = fin.next()
    x = buf.split("\t")[1:]
    qr = BED12._make(BED12._types(x))
    hits = []
    overlap = []
    i = 0
    for x in TableIO.parse(fin):
        if x[0] == "QR":
            if i % 100 == 0:
                logging.info("processing " + str(i) + "  genes")
            i += 1
            yield qr, hits, overlap
            qr = BED12._make(BED12._types(x[1:]))
            hits = []
            overlap = []
        elif x[0] == "HT":
            hits.append(BED12._make(BED12._types(x[1:])))
        elif x[0] == "OP":
            overlap.append(BED12._make(BED12._types(x[1:])))
    yield qr, hits, overlap
示例#2
0
def run(args):
    logging.basicConfig(level=logging.DEBUG)
    db_filename=args.translator
    t_name,t_ext=splitext(args.translator)
    '''
    test if it is db file
    generate db file if it doesn't exists.
    '''
    if t_ext!="db":
        #possible_db=args.translator.strip("\\.gz")+".db"
        possible_db=args.translator+".db"
        print(possible_db)
        if os.path.exists(possible_db):
            db_filename=possible_db
        else:
            _generate_db(args.translator,possible_db,args.table_name)
            db_filename=possible_db
    
    '''
    query db file
    '''
    out=IO.fopen(args.output,"w")
    with sqlite3.connect(db_filename) as conn:
        conn.row_factory=lambda conn,x: Bed12._make(Bed12._types(x[1:]))
        cursor=conn.cursor()
        for i in TableIO.parse(IO.fopen(args.input,"r"),"bed"):
            s=template.substitute({"table_name":args.table_name,"name":i.chr.strip()})
            print(s)
            cursor.execute(s)
            gene=None
            try:
                gene=cursor.fetchone()
                logging.debug(i)
                logging.debug(i.cdna_length())
                logging.debug(gene)
                logging.debug(gene.cdna_length())
            except:
                raise
                logging.warning("can't find gene %s"%i.chr)
                continue
            assert gene.cdna_length() > i.cdna_length()
            print(reverse_translate(gene,i),file=out) 
示例#3
0
文件: Templates.py 项目: HaoKuo/bam2x
                            """)
 

bed3_insert_template=string.Template("""insert into $table_name (chr,start,stop)
                            values (?,?,?)
                            """)
 

schema_templates={
    "bed12":bed12_schema_template,
    "bed6":bed6_schema_template,
    "bed3":bed3_schema_template,
}
insert_templates={   
    "bed12":bed12_insert_template,
    "bed6":bed6_insert_template,
    "bed3":bed3_insert_template,
}

factories = {
"bed12":lambda c,r:BED12._make(BED12._types(r[1:])),
"bed6":lambda c,r:BED6._make(BED6._types(r[1:])),
"bed3":lambda c,r:BED3._make(BED3._types(r[1:])),
}


select_template=string.Template("""select * from $table_name where name=\"$name\"""")