コード例 #1
0
def test_rdfgen_includes_taxon_in_gp_class():
    assoc = association.GoAssociation(
        source_line=
        "PomBase\tSPAC25B8.17\typf1\t\tGO:1990578\tGO_REF:0000024\tISO\tSGD:S000001583\tC\tintramembrane aspartyl protease of the perinuclear ER membrane Ypf1 (predicted)\tppp81\tprotein\ttaxon:4896\t20150305\tPomBase\t\t",
        subject=association.Subject(
            id=association.Curie("PomBase", "SPAC25B8.17"),
            label="ypf1",
            type="protein",
            fullname=
            "intramembrane aspartyl protease of the perinuclear ER membrane Ypf1 (predicted)",
            synonyms=["ppp81"],
            taxon=association.Curie("NCBITaxon", "4896")),
        object=association.Term(id=association.Curie("GO", "0000006"),
                                taxon=association.Curie("NCBITaxon", "4896")),
        negated=False,
        qualifiers=[],
        aspect=association.Aspect("C"),
        relation=association.Curie("BFO", "0000050"),
        interacting_taxon=association.Curie("NCBITaxon", "555"),
        evidence=association.Evidence(
            type=association.Curie("ECO", "0000266"),
            has_supporting_reference=[association.Curie("GO_REF", "0000024")],
            with_support_from=[
                association.ConjunctiveSet(
                    elements=[association.Curie("SGD", "S000001583")])
            ]),
        provided_by=association.Provider("PomBase"),
        date=association.Date("20150305"),
        subject_extensions=[
            association.ExtensionUnit(
                relation=association.Curie("rdfs", "subClassOf"),
                term=association.Curie("UniProtKB", "P12345"))
        ],
        object_extensions=[
            association.ConjunctiveSet(elements=[
                association.ExtensionUnit(relation=association.Curie(
                    "BFO", "0000050"),
                                          term=association.Curie("X", "1")),
                association.ExtensionUnit(
                    relation=association.Curie("BFO", "0000066"),
                    term=association.Curie("GO", "0016020"))
            ]),
            association.ConjunctiveSet(elements=[
                association.ExtensionUnit(
                    relation=association.Curie("RO", "0002233"),
                    term=association.Curie("PomBase", "12345"))
            ])
        ],
        properties=dict())

    rdfWriter = TurtleRdfWriter(label="pombase_single.ttl")
    gaf_transformer = CamRdfTransform(writer=rdfWriter)
    gaf_transformer.translate(assoc)
    gaf_transformer.provenance()

    gp_res = rdfWriter.graph.query(gene_product_class_query())
    for row in gp_res:
        assert str(row["cls"]) == "http://identifiers.org/pombase/SPAC25B8.17"
        assert str(
            row["taxon"]) == "http://purl.obolibrary.org/obo/NCBITaxon_4896"
コード例 #2
0
ファイル: assocparser.py プロジェクト: deepakunni3/ontobio
def parse_date(date: str, report: Report,
               line: List) -> Optional[association.Date]:
    if date == "":
        report.error(line,
                     Report.INVALID_DATE,
                     "\'\'",
                     "GORULE:0000001: empty",
                     rule=1)
        return None

    d = None
    if len(date) == 8 and date.isdigit():
        # For GAF date, should be YYYYMMDD all as digits and
        # a well formed date string here will be exactly 8 characters long
        d = association.Date(year=date[0:4],
                             month=date[4:6],
                             day=date[6:8],
                             time="")
    else:
        report.warning(
            line,
            report.INVALID_DATE,
            date,
            "GORULE:0000001: Date field must be YYYYMMDD, got: {}".format(
                date),
            rule=1)
        parsed = None
        try:
            parsed = dateutil.parser.parse(date)
        except:
            report.error(
                line,
                Report.INVALID_DATE,
                date,
                "GORULE:0000001: Could not parse date '{}' at all".format(
                    date),
                rule=1)
            return None

        d = association.Date(year="{:02d}".format(parsed.year),
                             month="{:02d}".format(parsed.month),
                             day="{:02d}".format(parsed.day),
                             time="")

    return d
コード例 #3
0
def test_go_rule29():

    # Nov 11, 1990, more than a year old
    assoc = make_annotation(evidence="IEA", date="19901111").associations[0]

    ## Base test: old IEA.
    test_result = qc.GoRule29().test(assoc, all_rules_config())
    assert test_result.result_type == qc.ResultType.ERROR

    ## Pass if not IEA
    assoc.evidence.type = Curie.from_str(ic_eco)  # Not IEA
    test_result = qc.GoRule29().test(assoc, all_rules_config())
    assert test_result.result_type == qc.ResultType.PASS

    ## Pass if only a half year old.
    now = datetime.datetime.now()
    six_months_ago = now - datetime.timedelta(days=180)
    assoc.date = association.Date(six_months_ago.year, six_months_ago.month,
                                  six_months_ago.day, "")
    assoc.evidence.type = Curie.from_str(iea_eco)
    test_result = qc.GoRule29().test(assoc, all_rules_config())
    assert test_result.result_type == qc.ResultType.PASS

    ## Warning if a year and a half year old.
    eighteen_months_ago = now - datetime.timedelta(days=(30 * 18))
    assoc.date = association.Date(eighteen_months_ago.year,
                                  eighteen_months_ago.month,
                                  eighteen_months_ago.day, "")
    test_result = qc.GoRule29().test(assoc, all_rules_config())
    assert test_result.result_type == qc.ResultType.WARNING

    ## Confirm the test can parse a YYYY-MM-DD date format from GPAD 2.0
    gpad_2_0_vals = assoc.to_gpad_2_0_tsv(
    )  # Cheat to shortcut DB and DB_Object_ID concatenation
    gpad_2_0_vals[5] = iea_eco
    gpad_2_0_vals[8] = "1990-11-11"
    assoc = gpadparser.to_association(gpad_2_0_vals,
                                      version="2.0").associations[0]
    test_result = qc.GoRule29().test(assoc, all_rules_config())
    assert test_result.result_type == qc.ResultType.ERROR
コード例 #4
0
ファイル: assocparser.py プロジェクト: kshefchek/ontobio
    def parse_with_dateutil(date: str, repot: Report, line: List) -> Optional[association.Date]:
        parsed = None
        try:
            parsed = dateutil.parser.parse(date)
        except:
            report.error(line, Report.INVALID_DATE, date, "GORULE:0000001: Could not parse date '{}' at all".format(date), rule=1)
            return None

        return association.Date(
            year="{:02d}".format(parsed.year),
            month="{:02d}".format(parsed.month),
            day="{:02d}".format(parsed.day),
            time=parsed.time().isoformat())
コード例 #5
0
ファイル: assocparser.py プロジェクト: kshefchek/ontobio
def parse_iso_date(date: str, report: Report, line: List) -> Optional[association.Date]:

    def parse_with_dateutil(date: str, repot: Report, line: List) -> Optional[association.Date]:
        parsed = None
        try:
            parsed = dateutil.parser.parse(date)
        except:
            report.error(line, Report.INVALID_DATE, date, "GORULE:0000001: Could not parse date '{}' at all".format(date), rule=1)
            return None

        return association.Date(
            year="{:02d}".format(parsed.year),
            month="{:02d}".format(parsed.month),
            day="{:02d}".format(parsed.day),
            time=parsed.time().isoformat())


    if date == "":
        report.error(line, Report.INVALID_DATE, "\'\'", "GORULE:0000001: empty", rule=1)
        return None

    d = None
    if len(date) >= 10:
        # For ISO style date, should be YYYY-MM-DD all as digits and
        # a well formed date string here will be at least 10 characters long.
        # Optionally, there could be an appended THH:MM
        year = date[0:4]
        month = date[5:7]
        day = date[8:10]
        time = date[11:]
        if year.isdigit() and month.isdigit() and day.isdigit():
            d = association.Date(year=year, month=month, day=day, time=time)
        else:
            # If any of year, month, day are not made of digits, then try to parse with dateutil
            report.warning(line, report.INVALID_DATE, date, "GORULE:0000001: Date field must be YYYY-MM-DD, got: {}".format(date), rule=1)
            d = parse_with_dateutil(date, report, line)

    else:
        # If we got the wrong number characters in the date, then fallback to dateutil
        report.warning(line, report.INVALID_DATE, date, "GORULE:0000001: Date field must be YYYY-MM-DD, got: {}".format(date), rule=1)
        d = parse_with_dateutil(date, report, line)

    return d
コード例 #6
0
def test_date():
    date_str = "20210105"
    date = association.Date(date_str[0:4], date_str[4:6], date_str[6:8], "")
    assert association.ymd_str(date, "-") == "2021-01-05"