Example #1
0
                        setattr(txt, field, value)

                txts[txt_name].exons.append([int(start), int(end)])

    for txt in txts.values():
        txt.exons.sort(lambda x,y: int(x[0])-int(y[0]))
        txt.txStart = int(txt.exons[0][0])
        txt.txEnd = int(txt.exons[-1][1])

    return txts.values()

def get_attrs(text):
    """Extracts attributes(gene, transcript, etc) from attribute string in GTF file"""
    attrs = {}
    for pair in text.rstrip(';').split(';'):
        name, value = pair.rstrip().lstrip().split(' ')
        value = value.strip('"')
        attrs[name] = value
    return attrs

if __name__ == '__main__':
    usage = "Usage: %prog gtf-file outfile"
    parser = OptionParser(usage=usage)
    parser.add_option("-i", "--index", dest="index", help="index output file")

    (options, args) = parser.parse_args()

    if len(args) == 2:
        output(parse(args[0]), args[1])

Example #2
0
                    txts[pp].exons.append([int(start), int(end)])

    for txt in txts.values():
        txt.exons.sort(lambda x,y: int(x[0])-int(y[0]))
        if not txt.cdsStart:
            txt.cdsStart = txt.exons[0][0]
        if not txt.cdsEnd:
            txt.cdsEnd = txt.exons[-1][1]

    return txts.values()

def get_attrs(text):
    """Extracts attributes(gene, transcript, etc) from attribute string in GFF file"""
    attrs = {}
    for pair in text.split(';'):
        if '=' in pair:
            name, value = pair.split('=')
            attrs[name] = value
    return attrs

if __name__ == '__main__':
    usage = "Usage: %prog gff-file outfile"
    parser = OptionParser(usage=usage)
    parser.add_option("-i", "--index", dest="index", help="index output file")
    parser.add_option("-c", "--use_cds", dest="use_cds", help="use CDS as exon", action="store_true", default=False)

    (options, args) = parser.parse_args()

    if len(args) == 2:
        output(parse(args[0], use_cds=options.use_cds), args[1])