-
Notifications
You must be signed in to change notification settings - Fork 30
/
test_rdfgen.py
111 lines (102 loc) · 4.21 KB
/
test_rdfgen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""
Test Generate RDF from Assocs
"""
import rdflib
from rdflib.namespace import RDFS
from rdflib import compare
from ontobio.io.gafparser import GafParser
from ontobio.rdfgen.assoc_rdfgen import TurtleRdfWriter, CamRdfTransform
from ontobio.assoc_factory import AssociationSetFactory
from ontobio.ontol_factory import OntologyFactory
from ontobio.model import association
POMBASE = "tests/resources/truncated-pombase.gaf"
ONT = "tests/resources/go-truncated-pombase.json"
def test_parse():
ont = OntologyFactory().create(ONT)
p = GafParser()
assocs = p.parse(open(POMBASE, "r"), skipheader=True)
#gen(assocs,SimpleAssocRdfTransform(),'simple')
gen(assocs, CamRdfTransform(), 'cam')
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("2015", "03", "05", ""),
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 gene_product_class_query():
return """
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX NCBITaxon: <http://purl.obolibrary.org/obo/NCBITaxon_>
PREFIX RO: <http://purl.obolibrary.org/obo/RO_>
SELECT ?cls ?taxon
WHERE {
?cls rdfs:subClassOf [ a owl:Restriction ;
owl:onProperty RO:0002162 ;
owl:someValuesFrom ?taxon ] .
}
"""
def gen(assocs, tr, n):
fn = 'tests/resources/{}.rdf'.format(n)
tr.emit_header()
for a in assocs:
tr.translate(a)
tr.writer.serialize(destination=open(fn,'wb'))
#tr.writer.serialize(fn, 'ntriples')