def print_table(seqs, id2name, name):
    """
    print table of results
    # seqs[id] = [gene, model, [[i-gene_pos, i-model_pos, i-length, iseq, [orfs], [introns], orfs?, introns?], ...]]
    """
    itable = open('%s.itable' % (name.rsplit('.', 1)[0]), 'w')
    print('\t'.join(['#sequence', 'gene', 'model', 'insertion', 'gene position', 'model position', 'length', 'orf?', 'intron?', 'orf?intron?', 'insertion', 'orf', 'intron']), file=itable)
    for seq, info in list(seqs.items()):
        gene, model, insertions = info
        name = id2name[seq]
        for i, ins in enumerate(insertions, 1):
            gene_pos, model_pos, length, iseq, \
                    orfs, introns, orfs_b, introns_b, orf_annotations = ins
            # append annotation to orf header
            for orf in orfs:
                parts = orf[0].split()
                annotation = orf_annotations[parts[0].split('>')[1]]
                orf[0] = '%s %s %s' % (parts[0], annotation, ' '.join(parts[1:]))
            # get orf position
            gene_pos = '-'.join([str(j) for j in gene_pos])
            # check if orf, intron is present
            if orfs_b is True or introns_b is True:
                orfs_introns_b = True
            else:
                orfs_introns_b = False
            out = [name, gene, model, i, gene_pos, model_pos, length, orfs_b, introns_b, orfs_introns_b]
            out.append('|'.join(iseq))
            out.append('|'.join(['|'.join(orf) for orf in orfs]))
            out.append('|'.join(['|'.join(intron) for intron in introns]))
            print('\t'.join([str(i) for i in out]), file=itable)
    itable.close()
def print_table ( seqs , id2name , name ) : itable = open ( '%s.itable' % ( name . rsplit ( '.' , 1 ) [ 0 ] ) , 'w' ) print ( '\t' . join ( [ '#sequence' , 'gene' , 'model' , 'insertion' , 'gene position' , 'model position' , 'length' , 'orf?' , 'intron?' , 'orf?intron?' , 'insertion' , 'orf' , 'intron' ] ) , file = itable ) for seq , info in list ( seqs . items ( ) ) : gene , model , insertions = info name = id2name [ seq ] for i , ins in enumerate ( insertions , 1 ) : gene_pos , model_pos , length , iseq , orfs , introns , orfs_b , introns_b , orf_annotations = ins for orf in orfs : parts = orf [ 0 ] . split ( ) annotation = orf_annotations [ parts [ 0 ] . split ( '>' ) [ 1 ] ] orf [ 0 ] = '%s %s %s' % ( parts [ 0 ] , annotation , ' ' . join ( parts [ 1 : ] ) ) gene_pos = '-' . join ( [ str ( j ) for j in gene_pos ] ) if orfs_b is True or introns_b is True : orfs_introns_b = True else : orfs_introns_b = False out = [ name , gene , model , i , gene_pos , model_pos , length , orfs_b , introns_b , orfs_introns_b ] out . append ( '|' . join ( iseq ) ) out . append ( '|' . join ( [ '|' . join ( orf ) for orf in orfs ] ) ) out . append ( '|' . join ( [ '|' . join ( intron ) for intron in introns ] ) ) print ( '\t' . join ( [ str ( i ) for i in out ] ) , file = itable ) itable . close ( )
print table of results
    # seqs[id] = [gene, model, [[i-gene_pos, i-model_pos, i-length, iseq, [orfs], [introns], orfs?, introns?], ...]]