Ejemplo n.º 1
0
def rnammer2gff(args: argparse.Namespace) -> None:
    records: List[GFF3Record] = []

    for line in args.infile:
        if line.startswith("#"):
            continue

        sline = line.strip().split("\t")
        rrna_type = sline[8]
        new_type = TYPE_MAP[args.kingdom][rrna_type.lower()]
        sline[1] = args.source
        sline[2] = new_type
        sline[8] = "."

        rna_record = cast(GFF3Record, GFF3Record.parse("\t".join(sline)))
        gene_record = deepcopy(rna_record)
        gene_record.type = "rRNA_gene"
        gene_record.add_child(rna_record)

        records.append(gene_record)
        records.append(rna_record)

    num = 0
    for record in GFF(records).traverse_children(sort=True):
        if record.attributes is None:
            attr = GFF3Attributes()
            record.attributes = attr
        else:
            attr = record.attributes

        if record.type == "rRNA_gene":
            num += 1
            attr.id = f"rRNA_gene{num}"
        else:
            attr.id = f"rRNA{num}"
            attr.parent = [
                p.attributes.id for p in record.parents
                if (p.attributes is not None and p.attributes.id is not None)
            ]

        print(record, file=args.outfile)

    return
Ejemplo n.º 2
0
def add_antifam(args: argparse.Namespace) -> None:

    antifam_records: Dict[str, List[DomTbl]] = defaultdict(list)
    for rec in DomTbl.from_file(args.antifam):
        antifam_records[rec.target_name].append(rec)

    for line in args.infile:
        sline = line.strip()
        if sline.startswith("#") or sline == "":
            args.outfile.write(line)
            continue

        record = GFF3Record.parse(sline)
        if record.attributes is None:
            print(record, file=args.outfile)
            continue

        field = record.attributes.get(args.field, None)
        if field is None:
            print(record, file=args.outfile)
            continue

        if str(field) not in antifam_records:
            print(record, file=args.outfile)
            continue

        dbxrefs = []
        matches = []
        for antifam_record in antifam_records[str(field)]:
            dbxrefs.append(f"AntiFam:{antifam_record.query_acc}")
            matches.append(
                f"{antifam_record.query_acc} {antifam_record.full_evalue} "
                f"{antifam_record.full_score} {antifam_record.domain_score} "
                f"{antifam_record.hmm_from} {antifam_record.hmm_to} "
                f"{antifam_record.ali_from} {antifam_record.ali_to}")

        record.attributes.dbxref.extend(dbxrefs)
        record.attributes.custom["antifam_match"] = ",".join(matches)
        print(record, file=args.outfile)

    return