示例#1
0
def test_go_rule08():

    assoc = make_annotation(goid="GO:0006810", evidence="IEA").associations[0]

    test_result = qc.GoRule08().test(assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.WARNING

    assoc.evidence.type = Curie.from_str("ECO:0000305")
    test_result = qc.GoRule08().test(assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.WARNING

    assoc.object.id = Curie.from_str("GO:0007049")  # do not manually annotate
    # evidence is IC, non IEA
    test_result = qc.GoRule08().test(assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.WARNING

    assoc.evidence.type = Curie.from_str("ECO:0000501") #IEA
    # IEA, but on not manual, so should pass
    test_result = qc.GoRule08().test(assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.PASS

    assoc.object.id = Curie.from_str("GO:0034655")  # neither
    assoc.evidence.type = Curie.from_str("ECO:0000305")
    test_result = qc.GoRule08().test(assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.PASS
示例#2
0
def produce_ttl(dataset, target_dir, gaf_path, ontology_graph):
    gafparser = GafParser()
    gafparser.config = assocparser.AssocParserConfig(ontology=ontology_graph)

    with open(gaf_path) as sg:
        lines = sum(1 for line in sg)

    ttl_path = os.path.join(
        os.path.split(gaf_path)[0], "{}_cam.ttl".format(dataset))
    click.echo("Producing ttl: {}".format(ttl_path))
    rdf_writer = assoc_rdfgen.TurtleRdfWriter()
    transformer = assoc_rdfgen.CamRdfTransform(writer=rdf_writer)
    parser_config = assocparser.AssocParserConfig(ontology=ontology_graph)

    with open(gaf_path) as gf:
        with click.progressbar(
                iterable=gafparser.association_generator(file=gf),
                length=lines) as associations:
            for association in associations:
                if "header" not in association or not association["header"]:
                    transformer.provenance()
                    transformer.translate(association)

    with open(ttl_path, "wb") as ttl:
        click.echo("Writing ttl to disk")
        rdf_writer.serialize(destination=ttl)

    return ttl_path
示例#3
0
def test_go_rule29():
    a = ["blah"] * 15
    a[3] = ""
    a[6] = "IEA"
    a[8] = "P"
    a[13] = "19901111" # Nov 11, 1990, more than a year old
    assoc = gafparser.to_association(a).associations[0]

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

    ## Pass if not IEA
    assoc.evidence.type = "ECO:0000305" #Not IEA
    test_result = qc.GoRule29().test(assoc, assocparser.AssocParserConfig())
    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 = six_months_ago.strftime("%Y%m%d")
    assoc.evidence.type = "ECO:0000501"
    test_result = qc.GoRule29().test(assoc, assocparser.AssocParserConfig())
    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 = eighteen_months_ago.strftime("%Y%m%d")
    test_result = qc.GoRule29().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.WARNING
示例#4
0
def test_gorule55():
    a = ["blah"] * 15
    a[0] = "HELLO"
    a[1] = "123"
    a[3] = ""
    a[5] = "GO:0012345|PMID:1234567"
    a[6] = "ISS"
    a[7] = "HELLO:123"
    a[8] = "P"
    a[12] = "taxon:12345"
    a[13] = "20200303"
    assoc = make_annotation(db="HELLO",
                            db_id="123",
                            references="GO:0012345|PMID:1234567",
                            evidence="ISS",
                            withfrom="HELLO:123").associations[0]

    test_result = qc.GoRule55().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS

    assoc.evidence.has_supporting_reference = [
        association.Curie.from_str("GO:0001234"),
        association.Curie.from_str("GO:123456")
    ]
    test_result = qc.GoRule55().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.WARNING
示例#5
0
def test_go_rule26():

    config = assocparser.AssocParserConfig(ontology=ontology, paint=True)
    a = make_annotation("GO:BLAHBLAH", "IBA")
    a[8] = "P"
    a[3] = ""
    assoc = gafparser.to_association(a).associations[0]
    # Pass due to IBA in paint
    test_result = qc.GoRule26().test(assoc, config)
    assert test_result.result_type == qc.ResultType.PASS

    config = assocparser.AssocParserConfig(ontology=ontology, paint=False)
    a = make_annotation("GO:BLAHBLAH", "IPI")
    a[8] = "P"
    a[3] = ""
    assoc = gafparser.to_association(a).associations[0]
    # Pass due to non IBA
    test_result = qc.GoRule26().test(assoc, config)
    assert test_result.result_type == qc.ResultType.PASS

    config = assocparser.AssocParserConfig(ontology=ontology, paint=False)
    a = make_annotation("GO:BLAHBLAH", "IBA")
    a[8] = "P"
    a[3] = ""
    assoc = gafparser.to_association(a).associations[0]
    # Pass due to non IBA
    test_result = qc.GoRule26().test(assoc, config)
    assert test_result.result_type == qc.ResultType.ERROR
示例#6
0
def test_go_rules_15():

    a = ["blah"] * 15
    a[3] = ""
    a[4] = "GO:0044419"
    a[6] = "IEA"
    a[8] = "P"
    a[12] = "taxon:123|taxon:456"
    assoc = gafparser.to_association(a).associations[0]

    test_result = qc.GoRule15().test(
        assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.PASS

    assoc.object.id = "GO:1234567"
    test_result = qc.GoRule15().test(
        assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.WARNING

    assoc.object.id = "GO:0044215"
    assoc.object.id = "NCBITaxon:123"
    assoc.interacting_taxon = None  # This is the important part, no interacting taxon
    test_result = qc.GoRule15().test(
        assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.PASS
示例#7
0
def test_gorule46():
    config = assocparser.AssocParserConfig(ontology=ontology)
    # Self-binding, yes
    assoc = make_annotation(db="PomBase", db_id="SPAC25B8.17", goid="GO:0051260", withfrom="PomBase:SPAC25B8.17").associations[0]

    test_result = qc.GoRule46().test(assoc, config)
    assert test_result.result_type == qc.ResultType.PASS

    assoc.evidence.with_support_from = association.ConjunctiveSet.str_to_conjunctions("PomBase:BLAH123")
    test_result = qc.GoRule46().test(assoc, config)
    assert test_result.result_type == qc.ResultType.WARNING

    assoc.evidence.with_support_from = association.ConjunctiveSet.str_to_conjunctions("PomBase:SPAC25B8.17|PomBase:BLAH123")
    test_result = qc.GoRule46().test(assoc, config)
    assert test_result.result_type == qc.ResultType.PASS

    assoc.object.id = Curie.from_str("GO:0000123")
    # Not in a self-binding mode
    test_result = qc.GoRule46().test(assoc, config)
    assert test_result.result_type == qc.ResultType.PASS

    # Test no ontology should just pass
    assoc.object.id = Curie.from_str("GO:0051260")
    test_result = qc.GoRule46().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS
示例#8
0
def test_gorule37():
    a = ["blah"] * 15
    a[3] = ""
    a[6] = "IBA"
    a[5] = "PMID:21873635"
    a[8] = "P"
    a[14] = "GO_Central"
    assoc = gafparser.to_association(a).associations[0]

    test_result = qc.GoRule37().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS

    assoc.evidence.type = "ECO:0000305"  # Rule doesn't apply, not IBA
    test_result = qc.GoRule37().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS

    assoc.evidence.type = "ECO:0000318"
    assoc.evidence.has_supporting_reference = ["GO_REF:123"
                                               ]  # IBA, but wrong ref
    test_result = qc.GoRule37().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.ERROR

    assoc.evidence.has_supporting_reference = ["PMID:21873635"]
    assoc.provided_by = "Pascale"  # IBA, but wrong assigned_by
    test_result = qc.GoRule37().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.ERROR
示例#9
0
def test_go_rule08():
    a = ["blah"] * 16
    a[4] = "GO:0006810"  # do not annotate
    a[6] = "IEA"

    test_result = qc.GoRule08().test(
        a, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.WARNING

    a[6] = "IC"
    test_result = qc.GoRule08().test(
        a, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.WARNING

    a[4] = "GO:0007049"  # do not manually annotate
    # evidence is IC, non IEA
    test_result = qc.GoRule08().test(
        a, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.WARNING

    a[6] = "IEA"
    # IEA, but on not manual, so should pass
    test_result = qc.GoRule08().test(
        a, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.PASS

    a[4] = "GO:0034655"  # neither
    a[6] = "IC"
    test_result = qc.GoRule08().test(
        a, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.PASS
示例#10
0
def test_gorule46():
    config = assocparser.AssocParserConfig(ontology=ontology)

    a = ["blah"] * 15
    a[0] = "PomBase"
    a[1] = "SPAC25B8.17"
    a[3] = ""
    a[4] = "GO:0051260"  # Self-binding, yes
    a[7] = "PomBase:SPAC25B8.17"
    a[8] = "P"
    assoc = gafparser.to_association(a).associations[0]

    test_result = qc.GoRule46().test(assoc, config)
    assert test_result.result_type == qc.ResultType.PASS

    assoc.evidence.with_support_from = ["PomBase:BLAH123"]
    test_result = qc.GoRule46().test(assoc, config)
    assert test_result.result_type == qc.ResultType.WARNING

    assoc.evidence.with_support_from = [
        "PomBase:SPAC25B8.17", "PomBase:BLAH123"
    ]
    test_result = qc.GoRule46().test(assoc, config)
    assert test_result.result_type == qc.ResultType.PASS

    assoc.object.id = "GO:0000123"
    # Not in a self-binding mode
    test_result = qc.GoRule46().test(assoc, config)
    assert test_result.result_type == qc.ResultType.PASS

    # Test no ontology should just pass
    assoc.object.id = "GO:0051260"
    test_result = qc.GoRule46().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS
示例#11
0
def test_go_rule26():

    config = assocparser.AssocParserConfig(ontology=ontology,
                                           paint=True,
                                           rule_set=assocparser.RuleSet.ALL)
    assoc = make_annotation(goid="GO:1234567", evidence="IBA").associations[0]
    # Pass due to IBA in paint
    test_result = qc.GoRule26().test(assoc, config)
    assert test_result.result_type == qc.ResultType.PASS

    config = assocparser.AssocParserConfig(ontology=ontology,
                                           paint=False,
                                           rule_set=assocparser.RuleSet.ALL)
    assoc = make_annotation(goid="GO:1234567", evidence="IPI").associations[0]
    # Pass due to non IBA
    test_result = qc.GoRule26().test(assoc, config)
    assert test_result.result_type == qc.ResultType.PASS

    config = assocparser.AssocParserConfig(ontology=ontology,
                                           paint=False,
                                           rule_set=assocparser.RuleSet.ALL)
    assoc = make_annotation(goid="GO:1234567", evidence="IBA").associations[0]
    # Fail  due to non paint
    test_result = qc.GoRule26().test(assoc, config)
    assert test_result.result_type == qc.ResultType.ERROR
示例#12
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, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.ERROR

    ## Pass if not IEA
    assoc.evidence.type = Curie.from_str("ECO:0000305")  # Not IEA
    test_result = qc.GoRule29().test(assoc, assocparser.AssocParserConfig())
    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 = six_months_ago.strftime("%Y%m%d")
    assoc.evidence.type = Curie.from_str("ECO:0000501")
    test_result = qc.GoRule29().test(assoc, assocparser.AssocParserConfig())
    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 = eighteen_months_ago.strftime("%Y%m%d")
    test_result = qc.GoRule29().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.WARNING
示例#13
0
def test_go_rule_16():
    # No GO term w/ID
    assoc = make_annotation(evidence="IC", withfrom="BLAH:12345").associations[0]

    test_result = qc.GoRule16().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.ERROR

    # withfrom has GO term
    assoc.evidence.with_support_from = association.ConjunctiveSet.str_to_conjunctions("GO:0023456")

    test_result = qc.GoRule16().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS

    # Pipe
    assoc.evidence.with_support_from = association.ConjunctiveSet.str_to_conjunctions("GO:0012345|BLAH:54321")

    test_result = qc.GoRule16().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS

    # Empty withfrom
    assoc.evidence.with_support_from = []

    test_result = qc.GoRule16().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.ERROR

    # Not IC
    assoc.evidence.type = Curie.from_str("ECO:0000501")
    assoc.evidence.with_support_from = association.ConjunctiveSet.str_to_conjunctions("BLAH:5555555|FOO:999999")

    test_result = qc.GoRule16().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS
示例#14
0
def test_go_rules_13():

    a = ["PomBase", "SPBC11B10.09", "cdc2", "", "GO:0007275", "PMID:21873635", "IBA", "PANTHER:PTN000623979|TAIR:locus:2099478", "P", "Cyclin-dependent kinase 1", "UniProtKB:P04551|PTN000624043", "protein", "taxon:284812", "20170228", "GO_Central", "", ""]
    assoc = gafparser.to_association(a).associations[0]
    gaferences = gaference.load_gaferencer_inferences_from_file("tests/resources/test.inferences.json")
    test_result = qc.GoRule13().test(assoc, assocparser.AssocParserConfig(annotation_inferences=gaferences))
    assert test_result.result_type == qc.ResultType.ERROR

    a = ["PomBase", "SPBC11B10.09", "cdc2", "", "GO:0007275", "PMID:21873635", "EXP", "PANTHER:PTN000623979|TAIR:locus:2099478", "P", "Cyclin-dependent kinase 1", "UniProtKB:P04551|PTN000624043", "protein", "taxon:284812", "20170228", "GO_Central", "", ""]
    assoc = gafparser.to_association(a).associations[0]
    gaferences = gaference.load_gaferencer_inferences_from_file("tests/resources/test.inferences.json")
    test_result = qc.GoRule13().test(assoc, assocparser.AssocParserConfig(annotation_inferences=gaferences))
    assert test_result.result_type == qc.ResultType.WARNING

    a = ["PomBase", "SPBC11B10.09", "cdc2", "NOT", "GO:0007275", "PMID:21873635", "EXP", "PANTHER:PTN000623979|TAIR:locus:2099478", "P", "Cyclin-dependent kinase 1", "UniProtKB:P04551|PTN000624043", "protein", "taxon:284812", "20170228", "GO_Central", "", ""]
    assoc = gafparser.to_association(a).associations[0]
    gaferences = gaference.load_gaferencer_inferences_from_file("tests/resources/test.inferences.json")
    test_result = qc.GoRule13().test(assoc, assocparser.AssocParserConfig(annotation_inferences=gaferences))
    assert test_result.result_type == qc.ResultType.PASS

    a = ["AspGD", "ASPL0000059928", "AN0127", "", "GO:0032258", "AspGD_REF:ASPL0000000005", "IEA", "SGD:S000001917", "P", "", "AN0127|ANID_00127|ANIA_00127", "gene_product", "taxon:227321", "20200201", "AspGD", "", ""]
    assoc = gafparser.to_association(a).associations[0]
    gaferences = gaference.load_gaferencer_inferences_from_file("tests/resources/test.inferences.json")
    test_result = qc.GoRule13().test(assoc, assocparser.AssocParserConfig(annotation_inferences=gaferences))
    assert test_result.result_type == qc.ResultType.ERROR
示例#15
0
def test_gaf_2_1_simple_terms():
    line = ["SGD", "S000000819", "AFG3", "", "GO:0006259", "PMID:8681382|SGD_REF:S000055187", "IMP", "", "P", "Mitochondrial inner membrane m-AAA protease component", "YER017C|AAA family ATPase AFG3|YTA10", "gene", "taxon:559292", "20170428", "SGD"]
    ontology = OntologyFactory().create("tests/resources/goslim_generic.json")
    p = GafParser(config=assocparser.AssocParserConfig(ontology=ontology))
    p.make_internal_cell_component_closure()

    parsed = gafparser.to_association(line)
    assoc = p.upgrade_empty_qualifier(parsed.associations[0])
    assert assoc.qualifiers[0] == association.Curie(namespace="RO", identity="0002264")

    line = ["SGD", "S000000819", "AFG3", "", "GO:0042393", "PMID:8681382|SGD_REF:S000055187", "IMP", "", "P",
            "Mitochondrial inner membrane m-AAA protease component", "YER017C|AAA family ATPase AFG3|YTA10", "gene",
            "taxon:559292", "20170428", "SGD"]
    ontology = OntologyFactory().create("tests/resources/goslim_generic.json")
    p = GafParser(config=assocparser.AssocParserConfig(ontology=ontology))
    p.make_internal_cell_component_closure()

    parsed = gafparser.to_association(line)
    assoc = p.upgrade_empty_qualifier(parsed.associations[0])
    assert assoc.qualifiers[0] == association.Curie(namespace="RO", identity="0002327")

    line = ["SGD", "S000000819", "AFG3", "", "GO:0005773", "PMID:8681382|SGD_REF:S000055187", "IMP", "", "P",
            "Mitochondrial inner membrane m-AAA protease component", "YER017C|AAA family ATPase AFG3|YTA10", "gene",
            "taxon:559292", "20170428", "SGD"]
    ontology = OntologyFactory().create("tests/resources/goslim_generic.json")
    p = GafParser(config=assocparser.AssocParserConfig(ontology=ontology))
    p.make_internal_cell_component_closure()

    parsed = gafparser.to_association(line)
    assoc = p.upgrade_empty_qualifier(parsed.associations[0])
    assert assoc.qualifiers[0] == association.Curie(namespace="RO", identity="0001025")
示例#16
0
def test_go_rule08():
    a = ["blah"] * 15
    a[3] = ""
    a[4] = "GO:0006810"  # do not annotate
    a[6] = "IEA"
    a[8] = "P"
    assoc = gafparser.to_association(a).associations[0]

    test_result = qc.GoRule08().test(
        assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.WARNING

    assoc.evidence.type = "ECO:0000305"
    test_result = qc.GoRule08().test(
        assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.WARNING

    assoc.object.id = "GO:0007049"  # do not manually annotate
    # evidence is IC, non IEA
    test_result = qc.GoRule08().test(
        assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.WARNING

    assoc.evidence.type = "ECO:0000501"  #IEA
    # IEA, but on not manual, so should pass
    test_result = qc.GoRule08().test(
        assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.PASS

    assoc.object.id = "GO:0034655"  # neither
    assoc.evidence.type = "ECO:0000305"
    test_result = qc.GoRule08().test(
        assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.PASS
示例#17
0
def test_go_rule11():
    a = ["blah"] * 16
    a[4] = "GO:0003674"
    a[6] = "ND"

    test_result = qc.GoRule11().test(a, assocparser.AssocParserConfig())
    print("first test, we have {}".format(test_result))
    assert test_result.result_type == qc.ResultType.PASS

    # Bad GO ID
    a = ["blah"] * 16
    a[4] = "GO:1234567"
    a[6] = "ND"

    test_result = qc.GoRule11().test(a, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.ERROR

    # Not ND and not Root
    a = ["blah"] * 16
    a[4] = "GO:1234567"
    a[6] = "FOO"

    test_result = qc.GoRule11().test(a, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS

    # Root, but not ND
    a = ["blah"] * 16
    a[4] = "GO:0003674"
    a[6] = "FOO"
    test_result = qc.GoRule11().test(a, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.ERROR
示例#18
0
def test_create_parser_gpad():
    parser = collections.create_parser_from_header(
        "!gpa-version: 1.2", assocparser.AssocParserConfig())
    assert isinstance(parser, gpadparser.GpadParser)
    assert parser.version == "1.2"

    parser = collections.create_parser_from_header(
        "!gpad-version: 2.0", assocparser.AssocParserConfig())
    assert isinstance(parser, gpadparser.GpadParser)
    assert parser.version == "2.0"
示例#19
0
def test_create_parser_gaf():
    parser = collections.create_parser_from_header(
        "!gaf-version: 2.1", assocparser.AssocParserConfig())
    assert isinstance(parser, gafparser.GafParser)
    assert parser.version == "2.1"

    parser = collections.create_parser_from_header(
        "!gaf-version: 2.2", assocparser.AssocParserConfig())
    assert isinstance(parser, gafparser.GafParser)
    assert parser.version == "2.2"
示例#20
0
def test_go_rule_17():
    # IDA with anything in withfrom
    assoc = make_annotation(evidence="IDA", withfrom="BLAH:12345").associations[0]

    test_result = qc.GoRule17().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.WARNING

    # Nothing in withfrom, passes
    assoc.evidence.with_support_from = []
    test_result = qc.GoRule17().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS
示例#21
0
def make_products(dataset, target_dir, gaf_path, products, ontology_graph):
    gafparser = GafParser()
    gafparser.config = assocparser.AssocParserConfig(
        ontology=ontology_graph,
        paint=True
    )

    with open(gaf_path) as sg:
        lines = sum(1 for line in sg)

    product_files = {
        "gpad": open(os.path.join(os.path.split(gaf_path)[0], "{}.gpad".format(dataset)), "w"),
        "ttl": open(os.path.join(os.path.split(gaf_path)[0], "{}_cam.ttl".format(dataset)), "wb")
    }
    
    if not products["gpad"] and not products["ttl"]:
        # Bail if we have no products
        return []

    # def write_gpi_entity(association, bridge, gpiwriter):
    with open(gaf_path) as gf:
        # gpi info:
        click.echo("Using {} as the gaf to build data products with".format(gaf_path))
        if products["ttl"]:
            click.echo("Setting up {}".format(product_files["ttl"].name))
            rdf_writer = assoc_rdfgen.TurtleRdfWriter(label=os.path.split(product_files["ttl"].name)[1] )
            transformer = assoc_rdfgen.CamRdfTransform(writer=rdf_writer)
            parser_config = assocparser.AssocParserConfig(ontology=ontology_graph)

        if products["gpad"]:
            click.echo("Setting up {}".format(product_files["gpad"].name))
            gpadwriter = GpadWriter(file=product_files["gpad"])

        click.echo("Making products...")
        with click.progressbar(iterable=gafparser.association_generator(file=gf), length=lines) as associations:
            for association in associations:
                if products["ttl"]:
                    if "header" not in association or not association["header"]:
                        transformer.provenance()
                        transformer.translate(association)

                if products["gpad"]:
                    gpadwriter.write_assoc(association)

        # post ttl steps
        if products["ttl"]:
            click.echo("Writing ttl to disk")
            rdf_writer.serialize(destination=product_files["ttl"])

        # After we run through associations
        for f in product_files.values():
            f.close()

    return [product_files[prod].name for prod in sorted(product_files.keys()) if products[prod]]
示例#22
0
def test_go_rule_18():
    # IDA with nothing in withfrom
    a = ["blah"] * 16
    a[6] = "IPI"
    a[7] = ""

    test_result = qc.GoRule18().test(a, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.WARNING

    # Something in withfrom, passes
    a[7] = "BLAH:12345"
    test_result = qc.GoRule18().test(a, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS
示例#23
0
def test_gorule39():
    assoc = make_annotation(db="ComplexPortal", goid="GO:0032991").associations[0]

    test_result = qc.GoRule39().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.ERROR

    assoc.subject.id = association.Curie("FB", "1234")
    test_result = qc.GoRule39().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS

    assoc.subject.id = association.Curie("ComplexPortal", "12345")
    assoc.object.id = association.Curie("GO", "0000023")
    test_result = qc.GoRule39().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS
示例#24
0
def test_gorule42():
    assoc = make_annotation(qualifier="NOT", evidence="IKR").associations[0]

    test_result = qc.GoRule42().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS

    assoc.evidence.type = "ECO:0000305" # Not IKR so this rule is fine
    test_result = qc.GoRule42().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS

    assoc.evidence.type = "ECO:0000320"
    assoc.negated = False  # Not negated, so wrong
    test_result = qc.GoRule42().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.ERROR
示例#25
0
def test_go_rule02():

    assoc = make_annotation(qualifier="NOT", goid="GO:0005515").associations[0]

    test_result = qc.GoRule02().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.WARNING

    assoc.negated = False
    test_result = qc.GoRule02().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS

    assoc.negated = True
    assoc.object.id = Curie.from_str("GO:0003674")
    test_result = qc.GoRule02().test(assoc, assocparser.AssocParserConfig())
    assert test_result.result_type == qc.ResultType.PASS
示例#26
0
def test_go_rule_06():

    assoc = make_annotation(goid="GO:0005575", evidence="HEP", aspect="C").associations[0]

    test_result = qc.GoRule06().test(assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.ERROR

    assoc.aspect = "P"
    assoc.object.id = Curie.from_str("GO:0008150")
    test_result = qc.GoRule06().test(assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.PASS

    assoc.evidence.type = Curie.from_str("ECO:0000501")
    test_result = qc.GoRule06().test(assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.PASS
示例#27
0
def test_go_rule_07():

    assoc = make_annotation(goid="GO:0003824", evidence="IPI").associations[0]

    test_result = qc.GoRule07().test(assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.WARNING

    assoc.object.id = Curie.from_str("GO:1234567")
    test_result = qc.GoRule07().test(assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.PASS

    assoc.object.id = Curie.from_str("GO:0003824")
    assoc.evidence.type = "ECO:0000501" # Not IPI
    test_result = qc.GoRule07().test(assoc, assocparser.AssocParserConfig(ontology=ontology))
    assert test_result.result_type == qc.ResultType.PASS
示例#28
0
def produce_gpi(dataset, target_dir, gaf_path, ontology_graph):
    gafparser = GafParser()
    gafparser.config = assocparser.AssocParserConfig(ontology=ontology_graph)
    with open(gaf_path) as sg:
        lines = sum(1 for line in sg)

    gpi_path = os.path.join(
        os.path.split(gaf_path)[0], "{}.gpi".format(dataset))
    with open(gaf_path) as gf, open(gpi_path, "w") as gpi:
        click.echo("Using {} as the gaf to build gpi with".format(gaf_path))
        bridge = gafgpibridge.GafGpiBridge()
        gpiwriter = entitywriter.GpiWriter(file=gpi)
        gpi_cache = set()

        with click.progressbar(
                iterable=gafparser.association_generator(file=gf),
                length=lines) as associations:
            for association in associations:
                entity = bridge.convert_association(association)
                if entity not in gpi_cache and entity is not None:
                    # If the entity is not in the cache, add it and write it out
                    gpi_cache.add(entity)
                    gpiwriter.write_entity(entity)

    return gpi_path
示例#29
0
    def __init__(self, config=None, group="unknown", dataset="unknown"):
        """
        Arguments:
        ---------

        config : a AssocParserConfig object
        """
        if config is None:
            config = assocparser.AssocParserConfig()
        self.config = config
        self.report = assocparser.Report(group=group, dataset=dataset)
        self.gpi = None
        if self.config.gpi_authority_path is not None:
            self.gpi = dict()
            parser = entityparser.GpiParser()
            with open(self.config.gpi_authority_path) as gpi_f:
                entities = parser.parse(file=gpi_f)
                for entity in entities:
                    self.gpi[entity["id"]] = {
                        "symbol": entity["label"],
                        "name": entity["full_name"],
                        "synonyms": entitywriter.stringify(entity["synonyms"]),
                        "type": entity["type"]
                    }

                print("Loaded {} entities from {}".format(len(self.gpi.keys()), self.config.gpi_authority_path))
示例#30
0
def test_errors_gaf():
    config = assocparser.AssocParserConfig(ecomap=EcoMap())
    p = GafParser(config=config)
    assocs = p.parse(open("tests/resources/errors.gaf", "r"), skipheader=True)
    msgs = p.report.messages
    print(json.dumps(p.report.to_report_json(), indent=4))
    # print("MESSAGES: {}".format(len(msgs)))
    n_invalid_idspace = 0
    for m in msgs:
        print("MESSAGE: {}".format(m))
        if m['type'] == assocparser.Report.INVALID_IDSPACE:
            n_invalid_idspace += 1
    assert len(msgs) == 13
    assert n_invalid_idspace == 1
    assert len(assocs) == 2

    w = GafWriter()
    w.write(assocs)
    for a in assocs:
        if a.object_extensions != []:
            # our test file has no ORs, so in DNF this is always the first
            xs = a.object_extensions[0].elements
            print(xs)
            for x in xs:

                print('X: {}'.format(x))
                # ensure that invalid expressions have been eliminated
                assert x.relation == association.Curie("BFO", "0000050")
                assert x.term == association.Curie.from_str('X:1')
            assert len(xs) == 1