예제 #1
0
def write_gff(
    gff: GFF,
    outfile: TextIO,
) -> None:
    print("#gff-version 3", file=outfile)
    for feature in gff.traverse_children(sort=True, breadth=True):
        print(feature, file=outfile)
    return
예제 #2
0
def split_gffs(gff: GFF, group_level: str) -> Tuple[GFF, GFF]:
    keep: Set[GFF3Record] = set()
    drop: Set[GFF3Record] = set()

    for mrna in gff.select_type(group_level):
        if mrna.attributes is None:
            should_keep = True
        elif "should_exclude" in mrna.attributes.custom:
            should_keep = False
        else:
            should_keep = True

        if should_keep:
            keep.update(gff.traverse_children([mrna]))
            keep.update(gff.traverse_parents([mrna]))
        else:
            drop.update(gff.traverse_children([mrna]))
            drop.update(gff.traverse_parents([mrna]))

    kept = prune_gff(keep)
    dropped = prune_gff(drop)
    return kept, dropped
예제 #3
0
def shift_gff(gff: GFF, seqid: str, start: int) -> GFF:
    out = list()

    for feature in gff.traverse_children(sort=True):
        f = deepcopy(feature)
        f.start -= start
        f.end -= start
        f.seqid = seqid
        if f.attributes is not None:
            if f.attributes.id is not None:
                f.attributes.id = seqid + "_" + f.attributes.id

            new_parents = []
            for parent in f.attributes.parent:
                new_parent = seqid + "_" + parent
                new_parents.append(new_parent)

            f.attributes.parent = new_parents

        out.append(f)

    return GFF(out)