2 from datetime import datetime
9 from htsworkflow.submission.ucsc import submission_view_url
10 from htsworkflow.util.rdfhelp import add_default_schemas, \
11 dump_model, get_model, fromTypedNode
12 from htsworkflow.util.rdfinfer import Infer
14 SOURCE_PATH = os.path.split(os.path.abspath(__file__))[0]
17 class TestEncodeFind(unittest.TestCase):
19 self.model = get_model()
20 add_default_schemas(self.model)
21 self.inference = Infer(self.model)
23 def test_create_status_node_with_uri(self):
24 subURL = submission_view_url('5136')
25 submissionUri = RDF.Uri(subURL)
26 timestamp = '2011-12-19T12:42:53.048956'
27 manualUri = subURL + '/' + timestamp
28 nodeUri = encode_find.create_status_node(submissionUri, timestamp)
29 self.assertEqual(str(nodeUri.uri), manualUri)
31 def test_create_status_node_with_str(self):
32 subURL = submission_view_url('5136')
33 timestamp = '2011-12-19T12:42:53.048956'
34 manualUri = subURL + '/' + timestamp
35 nodeUri = encode_find.create_status_node(subURL, timestamp)
36 self.assertEqual(str(nodeUri.uri), manualUri)
38 def test_parse_submission_page(self):
39 timestamp = '2011-12-19T12:42:53.048956'
40 subURL = submission_view_url('5136')
41 subNode = encode_find.create_status_node(subURL, timestamp)
42 test_file = os.path.join(SOURCE_PATH, 'testdata', '5136SubDetail.html')
43 from lxml.html import parse
44 tree = parse(test_file)
45 dates = encode_find.get_creation_dates(self.model, subNode)
46 self.assertEqual(len(dates), 0)
47 encode_find.parse_submission_page(self.model, tree, subNode)
48 dates = encode_find.get_creation_dates(self.model, subNode)
49 self.assertEqual(len(dates), 1)
50 object_date = fromTypedNode(dates[0].object)
51 self.assertEqual(object_date, datetime(2011,12,7,15,23,0))
53 def test_delete_simple_lane(self):
55 parser = RDF.Parser(name='turtle')
56 parser.parse_string_into_model(model, '''@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
57 @prefix : <http://www.w3.org/1999/xhtml> .
58 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
59 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
60 @prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#> .
62 <http://jumpgate.caltech.edu/lane/1232>
63 libns:flowcell <http://jumpgate.caltech.edu/flowcell/42JV5AAXX/> ;
64 libns:total_unique_locations 5789938 .
66 ''', 'http://jumpgate.caltech.edu/library/')
67 errmsgs = list(self.inference.run_validation())
68 self.assertEqual(len(errmsgs), 0)
69 urn = RDF.Node(RDF.Uri('http://jumpgate.caltech.edu/lane/1232'))
70 encode_find.delete_lane(model, urn)
71 self.failUnlessEqual(len(model), 0)
73 def test_delete_lane_with_mapping(self):
74 ontology_size = len(self.model)
75 parser = RDF.Parser(name='turtle')
76 parser.parse_string_into_model(self.model, '''@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
77 @prefix : <http://www.w3.org/1999/xhtml> .
78 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
79 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
80 @prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#> .
82 <http://jumpgate.caltech.edu/flowcell/42JV5AAXX/> a libns:IlluminaFlowcell .
83 <http://jumpgate.caltech.edu/lane/1232>
84 libns:flowcell <http://jumpgate.caltech.edu/flowcell/42JV5AAXX/> ;
85 libns:has_mappings _:bnode110110 ;
86 libns:total_unique_locations 5789938 ;
87 a libns:IlluminaLane .
91 libns:mapped_to "newcontam_UK.fa"@en ;
93 ''', 'http://jumpgate.caltech.edu/library/')
94 errmsgs = list(self.inference.run_validation())
95 self.assertEqual(len(errmsgs), 0)
96 self.failUnlessEqual(len(self.model), 8 + ontology_size)
97 urn = RDF.Node(RDF.Uri('http://jumpgate.caltech.edu/lane/1232'))
98 encode_find.delete_lane(self.model, urn)
99 self.failUnlessEqual(len(self.model), 1 + ontology_size)
100 # the flowcell triple wasn't deleted.
102 def test_delete_library(self):
103 parser = RDF.Parser(name='turtle')
104 parser.parse_string_into_model(self.model, '''@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
105 @prefix : <http://www.w3.org/1999/xhtml> .
106 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
107 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
108 @prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#> .
110 <http://jumpgate.caltech.edu/flowcell/42JV5AAXX/> a libns:IlluminaFlowcell .
111 <http://jumpgate.caltech.edu/flowcell/62WCKAAXX/> a libns:IlluminaFlowcell .
113 <http://jumpgate.caltech.edu/lane/1232>
114 a libns:IlluminaLane ;
115 libns:flowcell <http://jumpgate.caltech.edu/flowcell/42JV5AAXX/> ;
116 libns:has_mappings _:bnode110110 ;
117 libns:total_unique_locations 5789938 .
119 <http://jumpgate.caltech.edu/library/11011/>
120 libns:affiliation "ENCODE"@en, "ENCODE_Tier1"@en, "Georgi Marinov"@en ;
121 libns:has_lane <http://jumpgate.caltech.edu/lane/1232> ;
122 libns:library_id "11011"@en ;
123 libns:library_type "None"@en ;
125 <http://www.w3.org/1999/xhtml/vocab#stylesheet> <http://jumpgate.caltech.edu/static/css/app.css>, <http://jumpgate.caltech.edu/static/css/data-browse-index.css> .
128 a libns:MappedCount ;
129 libns:mapped_to "newcontam_UK.fa"@en ;
132 <http://jumpgate.caltech.edu/lane/1903>
133 a libns:IlluminaLane ;
134 libns:flowcell <http://jumpgate.caltech.edu/flowcell/62WCKAAXX/> ;
135 libns:has_mappings _:bnode120970 ;
136 libns:total_unique_locations 39172114 .
138 <http://jumpgate.caltech.edu/library/12097/>
139 libns:has_lane <http://jumpgate.caltech.edu/lane/1903> ;
140 libns:library_id "12097"@en ;
141 libns:library_type "Paired End (non-multiplexed)"@en ;
145 a libns:MappedCount ;
146 libns:mapped_to "newcontam_UK.fa"@en ;
148 ''', 'http://jumpgate.caltech.edu/library')
149 errmsgs = list(self.inference.run_validation())
150 self.assertEqual(len(errmsgs), 0)
151 urn = RDF.Node(RDF.Uri('http://jumpgate.caltech.edu/library/11011/'))
152 encode_find.delete_library(self.model, urn)
153 q = RDF.Statement(None, encode_find.libraryOntology['reads'], None)
154 stmts = list(self.model.find_statements(q))
155 self.failUnlessEqual(len(stmts), 1)
156 self.failUnlessEqual(fromTypedNode(stmts[0].object),
159 q = RDF.Statement(None, encode_find.libraryOntology['library_id'], None)
160 stmts = list(self.model.find_statements(q))
161 self.failUnlessEqual(len(stmts), 1)
162 self.failUnlessEqual(fromTypedNode(stmts[0].object),
166 return unittest.makeSuite(TestEncodeFind, "test")
168 if __name__ == "__main__":
169 unittest.main(defaultTest="suite")