1
- import os , sys
1
+ import os
2
2
from os .path import dirname , abspath
3
- from etltools import sparqlmap
4
- from etltools .utils import get_jena_home , sparql_ask
3
+ from etltools .utils import sparql_ask , DEFAULT_NAMESPACES
5
4
import rdflib
6
5
import unittest
6
+ from zipfile import bz2
7
7
8
8
graph = None
9
9
@@ -16,23 +16,33 @@ def run_mappings ():
16
16
os .chdir ( mydir )
17
17
18
18
print ( "Running mapping workflow" )
19
- if os .system ( "snakemake --snakefile sample-data-build.snakefile --configfile ../../snake-config.yaml --cores all" ) != 0 :
19
+ if os .system ( "snakemake --verbose -- snakefile sample-data-build.snakefile --cores all" ) != 0 :
20
20
raise ChildProcessError ( "Mapping workflow execution failed" )
21
21
22
22
ETL_OUT = os .getenv ( "ETL_OUT" )
23
23
DFW_ETL = os .getenv ( "DFW_ETL" )
24
24
25
+ """
26
+ the bz2 can be used for verifications that need the original data, however, the tests
27
+ below are written against the output only, since these loadings are slow.
28
+ """
25
29
out_names = [
26
- "knetminer-mapping-test-out.nt " ,
27
- "knetminer-sample.ttl "
30
+ # "knetminer-sample.ttl.bz2 ",
31
+ "knetminer-mapping-test-out.nt "
28
32
]
29
33
for oname in out_names :
30
34
out_path = ETL_OUT + "/test/" + oname
31
35
print ( "--- Loading result from '%s'" % out_path )
36
+ if oname .endswith ( ".bz2" ):
37
+ with bz2 .open ( out_path , mode = "rt" ) as fh :
38
+ graph .parse ( source = fh )
39
+ continue
32
40
graph .parse ( out_path , format = "turtle" )
33
41
34
42
graph .parse ( DFW_ETL + "/../agri-schema.ttl" , format = "turtle" )
35
43
44
+
45
+
36
46
print ( "----- Test Initialised -----\n \n " )
37
47
38
48
@@ -43,18 +53,18 @@ def __init__ ( self, methodName ):
43
53
super ().__init__ ( methodName )
44
54
45
55
def assert_sparql ( self , ask_query , msg ):
46
- self .assertTrue ( sparql_ask ( graph , ask_query ), msg )
56
+ self .assertTrue ( sparql_ask ( graph , ask_query , DEFAULT_NAMESPACES ), msg )
47
57
48
58
def test_pref_name ( self ):
49
59
for p in [ "rdfs:label" , "schema:name" , "skos:prefLabel" ]:
50
60
self .assert_sparql (
51
- "ASK { bkr:to_0002682 %s 'plant cell shape '}" % p ,
61
+ "ASK { bkr:trait_to_0006001 %s 'salt tolerance '}" % p ,
52
62
"%s not inferred!" % p
53
63
)
54
64
55
65
def test_name ( self ):
56
- s = "bkr:to_0000387 "
57
- l = "plant phenotype "
66
+ s = "bkr:gene_at1g71100_locus_2026296 "
67
+ l = "ribose 5-phosphate isomerase "
58
68
for p in [ "rdfs:label" , "skos:altLabel" ]:
59
69
self .assert_sparql (
60
70
"ASK { %s %s '%s'}" % (s , p , l ),
@@ -68,19 +78,19 @@ def test_name ( self ):
68
78
69
79
def test_bioschema_Protein ( self ):
70
80
self .assert_sparql (
71
- "ASK { bkr:protein_q0d6f4 a bioschema:Protein }" ,
81
+ "ASK { bkr:protein_p07519 a bioschema:Protein }" ,
72
82
"bioschema:Protein not inferred!"
73
83
)
74
84
75
85
def test_bioschema_Publication ( self ):
76
- pmid = "18089549 "
86
+ pmid = "3558409 "
77
87
78
88
for po in [
79
89
"a agri:ScholarlyPublication" ,
80
- "dcterms:title 'The Rice Annotation Project Database (RAP-DB): 2008 update.' " ,
81
- "dcterms:identifier '%s'" % pmid ,
82
- "dcterms:issued 2008 " ,
83
- "schema:datePublished 2008 "
90
+ "dcterms:title ?title " ,
91
+ # "dcterms:identifier '%s'" % pmid, # TODO not in the sample dataset
92
+ "dcterms:issued 1987 " ,
93
+ "schema:datePublished 1987 "
84
94
]:
85
95
self .assert_sparql (
86
96
"ASK { bkr:publication_%s %s }" % (pmid , po ),
@@ -89,15 +99,13 @@ def test_bioschema_Publication ( self ):
89
99
90
100
self .assert_sparql (
91
101
"""ASK { bkr:publication_%s
92
- bka:Abstract ?abs;
93
102
schema:abstract ?abs;
94
103
dcterms:description ?abs
95
104
}""" % pmid ,
96
105
"abstract properties not inferred!"
97
106
)
98
107
self .assert_sparql (
99
108
"""ASK { bkr:publication_%s
100
- bka:AUTHORS ?authors;
101
109
dcterms:creator ?authors;
102
110
agri:authorsList ?authors
103
111
}""" % pmid ,
@@ -116,26 +124,26 @@ def test_name_is_not_title ( self ):
116
124
117
125
def test_bioschema_isPartOf ( self ):
118
126
self .assert_sparql (
119
- "ASK { bkr:to_0000804 schema:isPartOf bkr:to_0006031 }" ,
127
+ "ASK { bkr:gene_6652998 schema:isPartOf bkr:path_6645240 }" ,
120
128
"schema:isPartOf not inferred!"
121
129
)
122
130
123
131
def test_agri_evidence ( self ):
124
132
self .assert_sparql (
125
- "ASK { bkr:publication_16240171 agri:evidence bk:IMPD }" ,
133
+ "ASK { bkr:publication_28380544 agri:evidence bk:IMPD }" ,
126
134
"agri:evidence not inferred!"
127
135
)
128
136
129
137
def test_dc_source ( self ):
130
138
self .assert_sparql (
131
- "ASK { bkr:publication_16240171 dc:source bk:NLM_UNIPROTKB }" ,
139
+ "ASK { bkr:publication_12472693 dc:source bk:NLM_UNIPROTKB }" ,
132
140
"dc:source not inferred!"
133
141
)
134
142
135
143
def test_mentions ( self ):
136
144
self .assert_sparql (
137
- """ASK { bkr:publication_26473199
138
- schema:mentions bkr:protein_q6h5l4 , bkr:protein_q0ddi1
145
+ """ASK { bkr:publication_22399647
146
+ schema:mentions bkr:gene_bradi_3g39910v3 , bkr:gene_horvu6hr1g085710
139
147
}""" ,
140
148
"schema:mentions not inferred!"
141
149
)
0 commit comments