def to_bed12(f, db, child_type='exon', name_field='ID'):
    if isinstance(f, six.string_types):
        f = db[f]
    children = list(db.children(f, featuretype=child_type, order_by='start'))
    sizes = [len(i) for i in children]
    starts = [i.start - f.start for i in children]
    fields = [
        f.chrom,
        f.start - 1,  # GTF -> BED coord system
        f.stop,
        f.attributes.get(name_field, ['.'])[0],
        f.score,
        f.strand,
        f.start,
        f.stop,
        '0,0,0',
        len(children),
        ','.join(map(str, sizes)),
        ','.join(map(str, starts))
    ]
    return '\t'.join(map(str, fields)) + '\n'
Override to suppress rel="nofollow" on some anchors.
dataset/ETHPy150Open daler/gffutils/gffutils/convert.py/to_bed12--crossover with--dataset/ETHPy150Open cloudera/hue/desktop/core/ext-py/lxml-3.3.6/src/lxml/html/clean.py/Cleaner.allow_follow