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"
def make_keys_from_gaf(gaf: association.GoAssociation) -> List[AnnotationKey]: term = curie_util.expand_uri(str(gaf.object.id), cmaps=[prefix_context]) relation = curie_util.expand_uri(str(gaf.relation), cmaps=[prefix_context]) taxon = curie_util.expand_uri(str(gaf.object.taxon), cmaps=[prefix_context]) extensions = gaf.object_extensions # type: List[association.ConjunctiveSet] annotation_keys = [] # type: List[AnnotationKey] if extensions: for conjunction in extensions: # Each conjunction is a ConjunctiveSet # conjunction is foo(bar),hello(world) # Create a new ConjunctiveSet using a frozenset of the elements instead of a list frozen_conjunction = association.ConjunctiveSet( frozenset(conjunction.elements)) # Build the Key now annotation_keys.append( AnnotationKey(RelationTo(relation, term), taxon, frozen_conjunction)) else: annotation_keys.append( AnnotationKey(RelationTo(relation, term), taxon, association.ConjunctiveSet(frozenset([])))) return annotation_keys
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" a[13] = "20200303" 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 = [association.ConjunctiveSet(["PomBase:BLAH123"])] test_result = qc.GoRule46().test(assoc, config) assert test_result.result_type == qc.ResultType.WARNING assoc.evidence.with_support_from = [association.ConjunctiveSet(["PomBase:SPAC25B8.17"]), association.ConjunctiveSet(["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
def test_conjunctiveset_tostring(): c = association.ConjunctiveSet(["MGI:12345"]) assert str(c) == "MGI:12345" c = association.ConjunctiveSet(["MGI:12345", "MGI:12345"]) assert str(c) == "MGI:12345,MGI:12345" c = association.ConjunctiveSet([]) assert str(c) == ""
def make_conjunctions(extension: List) -> association.ConjunctiveSet: extension_units = [] # type: List[association.ExtensionUnit] for unit in extension: extension_units.append( association.ExtensionUnit(unit["relation"], unit["term"])) return association.ConjunctiveSet(frozenset(extension_units))
def test_object_extensions(): p = GafParser() assoc_result = p.parse_line("PomBase\tSPAC25B8.17\typf1\t\tGO:0000007\tGO_REF:0000024\tISO\tSGD:S000001583\tC\tintramembrane aspartyl protease of the perinuclear ER membrane Ypf1 (predicted)\tppp81\tprotein\ttaxon:4896\t20181024\tPomBase\tpart_of(X:1)\tUniProtKB:P12345") print(p.report.to_markdown()) assert len(assoc_result.associations[0].object_extensions) > 0 object_extensions = [ association.ConjunctiveSet([ association.ExtensionUnit(association.Curie("BFO", "0000050"), association.Curie("X", "1")) ]) ] assert assoc_result.associations[0].object_extensions == object_extensions
def test_conjunctive_set_str_to_conjunctions(): c = association.ConjunctiveSet.str_to_conjunctions("") assert c == [] c = association.ConjunctiveSet.str_to_conjunctions("MGI:12345") assert c == [association.ConjunctiveSet([Curie.from_str("MGI:12345")])] c = association.ConjunctiveSet.str_to_conjunctions("MGI:12345,MGI:12345") assert c == [ association.ConjunctiveSet( [Curie.from_str("MGI:12345"), Curie.from_str("MGI:12345")]) ] c = association.ConjunctiveSet.str_to_conjunctions("MGI:12345|MGI:12345") assert c == [ association.ConjunctiveSet([Curie.from_str("MGI:12345")]), association.ConjunctiveSet([Curie.from_str("MGI:12345")]) ] c = association.ConjunctiveSet.str_to_conjunctions( "MGI:12345,DOI:333|GO:987") assert c == [ association.ConjunctiveSet( [Curie.from_str("MGI:12345"), Curie.from_str("DOI:333")]), association.ConjunctiveSet([Curie.from_str("GO:987")]) ] c = association.ConjunctiveSet.str_to_conjunctions( "part_of(MGI:123),part_of(FOO:456)|has_direct_input(BAR:987)", conjunct_element_builder=lambda u: association.ExtensionUnit.from_str( u)) assert c == [ association.ConjunctiveSet([ association.ExtensionUnit(Curie.from_str("BFO:0000050"), Curie.from_str("MGI:123")), association.ExtensionUnit(Curie.from_str("BFO:0000050"), Curie.from_str("FOO:456")) ]), association.ConjunctiveSet([ association.ExtensionUnit(Curie.from_str("GOREL:0000752"), Curie.from_str("BAR:987")) ]) ] c = association.ConjunctiveSet.str_to_conjunctions( "HECK_NO,part_of(FOO:456)|has_direct_input(BAR:987)", conjunct_element_builder=lambda u: association.ExtensionUnit.from_str( u)) assert c == association.Error("HECK_NO")
def test_validate_pipe_with_additional_delims(): parser = gafparser.GafParser() ids = parser.validate_pipe_separated_ids("F:123,B:234|B:111", assocparser.SplitLine( "", [""] * 17, "taxon:foo"), extra_delims=",") assert set(ids) == set(["F:123", "B:234", "B:111"]) result = parser.parse_line( "PomBase\tSPAC25B8.17\typf1\t\tGO:1990578\tGO_REF:0000024\tISO\tUniProtKB:Q9CXD9|ensembl:ENSMUSP00000038569,PMID:11111\tC\tintramembrane aspartyl protease of the perinuclear ER membrane Ypf1 (predicted)\tppp81\tprotein\ttaxon:4896\t20150305\tPomBase\t\t" ) expected = [ association.ConjunctiveSet( elements=[association.Curie.from_str("UniProtKB:Q9CXD9")]), association.ConjunctiveSet(elements=[ association.Curie.from_str("ensembl:ENSMUSP00000038569"), association.Curie.from_str("PMID:11111") ]) ] assert result.associations[0].evidence.with_support_from == expected
def test_conjunctive_set_list_to_str(): c = association.ConjunctiveSet.list_to_str([]) assert c == "" c = association.ConjunctiveSet.list_to_str( [association.ConjunctiveSet([Curie.from_str("MGI:12345")])]) assert c == "MGI:12345" c = association.ConjunctiveSet.list_to_str([ association.ConjunctiveSet( [Curie.from_str("MGI:12345"), Curie.from_str("MGI:12345")]) ]) assert c == "MGI:12345,MGI:12345" c = association.ConjunctiveSet.list_to_str([ association.ConjunctiveSet([Curie.from_str("MGI:12345")]), association.ConjunctiveSet([Curie.from_str("MGI:12345")]) ]) assert c == "MGI:12345|MGI:12345" c = association.ConjunctiveSet.list_to_str([ association.ConjunctiveSet( [Curie.from_str("MGI:12345"), Curie.from_str("DOI:333")]), association.ConjunctiveSet([Curie.from_str("GO:987")]) ]) assert c == "MGI:12345,DOI:333|GO:987"
def test_go_rule_16(): # No GO term w/ID a = ["blah"] * 15 a[3] = "" a[4] = "GO:1234567" a[6] = "IC" a[7] = "BLAH:12345" a[8] = "P" a[13] = "20200303" assoc = gafparser.to_association(a).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(["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(["GO:0012345"]), association.ConjunctiveSet(["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 = "ECO:0000501" assoc.evidence.with_support_from = [association.ConjunctiveSet(["BLAH:5555555"]), association.ConjunctiveSet(["FOO:999999"])] test_result = qc.GoRule16().test(assoc, assocparser.AssocParserConfig()) assert test_result.result_type == qc.ResultType.PASS
def parse_with(f, p): p.config.ecomap = EcoMap() is_gaf = f == POMBASE ont = OntologyFactory().create(ONT) if is_gaf: # only do ontology checking on GAF parse; # this is because ontology is made from GAF p.config.ontology = ont else: p.config.ontology = None results = p.parse(open(f, "r"), skipheader=True) print(p.report.to_markdown()) r1 = results[0] # TODO: test datafile does not have ECOs yet!! assert ecomap.ecoclass_to_coderef(str( r1.evidence.type))[0] == 'ISO' or str( r1.evidence.type) == 'ECO:0000201' assert r1.evidence.with_support_from == [ association.ConjunctiveSet( [association.Curie.from_str('SGD:S000001583')]) ] assert r1.evidence.has_supporting_reference == [ association.Curie.from_str('GO_REF:0000024') ] if is_gaf: assert r1.subject.label == 'ypf1' assert association.ymd_str(r1.date, "") == '20150305' for r in results: #print(str(r)) sid = r.subject.id prov = r.provided_by assert prov == 'PomBase' or prov == 'UniProt' assert r.object.id.namespace == "GO" assert sid.namespace == 'PomBase' or (not is_gaf and sid.namespace == 'PR') if is_gaf: assert str(r.subject.taxon) == 'NCBITaxon:4896' # for m in p.report.messages: # print("MESSAGE: {}".format(m)) print("MESSAGES (sample): {}".format(p.report.messages[0:5])) # Messages that aren't about upgrading qualifiers in rule 59 should be 0 assert len([ msg for msg in p.report.messages if msg["rule"] != 59 and msg["rule"] != 27 ]) == 0
def test_conjunctive_set_list_to_str(): c = association.ConjunctiveSet.list_to_str([]) assert c == "" c = association.ConjunctiveSet.list_to_str( [association.ConjunctiveSet(["MGI:12345"])]) assert c == "MGI:12345" c = association.ConjunctiveSet.list_to_str( [association.ConjunctiveSet(["MGI:12345", "MGI:12345"])]) assert c == "MGI:12345,MGI:12345" c = association.ConjunctiveSet.list_to_str([ association.ConjunctiveSet(["MGI:12345"]), association.ConjunctiveSet(["MGI:12345"]) ]) assert c == "MGI:12345|MGI:12345" c = association.ConjunctiveSet.list_to_str([ association.ConjunctiveSet(["MGI:12345", "DOI:333"]), association.ConjunctiveSet(["GO:987"]) ]) assert c == "MGI:12345,DOI:333|GO:987"