2 from datetime import datetime
4 from unittest2 import TestCase
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]
16 class TestEncodeFind(TestCase):
18 self.model = get_model()
19 add_default_schemas(self.model)
20 self.inference = Infer(self.model)
22 def test_create_status_node_with_uri(self):
23 subURL = submission_view_url('5136')
24 submissionUri = RDF.Uri(subURL)
25 timestamp = '2011-12-19T12:42:53.048956'
26 manualUri = subURL + '/' + timestamp
27 nodeUri = encode_find.create_status_node(submissionUri, timestamp)
28 self.assertEqual(str(nodeUri.uri), manualUri)
30 def test_create_status_node_with_str(self):
31 subURL = submission_view_url('5136')
32 timestamp = '2011-12-19T12:42:53.048956'
33 manualUri = subURL + '/' + timestamp
34 nodeUri = encode_find.create_status_node(subURL, timestamp)
35 self.assertEqual(str(nodeUri.uri), manualUri)
37 def test_parse_submission_page(self):
38 timestamp = '2011-12-19T12:42:53.048956'
39 subURL = submission_view_url('5136')
40 subNode = encode_find.create_status_node(subURL, timestamp)
41 test_file = os.path.join(SOURCE_PATH, 'testdata', '5136SubDetail.html')
42 from lxml.html import parse
43 tree = parse(test_file)
44 dates = encode_find.get_creation_dates(self.model, subNode)
45 self.assertEqual(len(dates), 0)
46 encode_find.parse_submission_page(self.model, tree, subNode)
47 dates = encode_find.get_creation_dates(self.model, subNode)
48 self.assertEqual(len(dates), 1)
49 object_date = fromTypedNode(dates[0].object)
50 self.assertEqual(object_date, datetime(2011,12,7,15,23,0))
52 def test_delete_simple_lane(self):
54 parser = RDF.Parser(name='turtle')
55 parser.parse_string_into_model(model, '''@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
56 @prefix : <http://www.w3.org/1999/xhtml> .
57 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
58 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
59 @prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#> .
61 <http://jumpgate.caltech.edu/lane/1232>
62 libns:flowcell <http://jumpgate.caltech.edu/flowcell/42JV5AAXX/> ;
63 libns:total_unique_locations 5789938 .
65 ''', 'http://jumpgate.caltech.edu/library/')
66 errmsgs = list(self.inference.run_validation())
67 self.assertEqual(len(errmsgs), 0)
68 urn = RDF.Node(RDF.Uri('http://jumpgate.caltech.edu/lane/1232'))
69 encode_find.delete_lane(model, urn)
70 self.failUnlessEqual(len(model), 0)
72 def test_delete_lane_with_mapping(self):
73 ontology_size = len(self.model)
74 parser = RDF.Parser(name='turtle')
75 parser.parse_string_into_model(self.model, '''@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
76 @prefix : <http://www.w3.org/1999/xhtml> .
77 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
78 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
79 @prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#> .
81 <http://jumpgate.caltech.edu/flowcell/42JV5AAXX/> a libns:IlluminaFlowcell .
82 <http://jumpgate.caltech.edu/lane/1232>
83 libns:flowcell <http://jumpgate.caltech.edu/flowcell/42JV5AAXX/> ;
84 libns:has_mappings _:bnode110110 ;
85 libns:total_unique_locations 5789938 ;
86 a libns:IlluminaLane .
90 libns:mapped_to "newcontam_UK.fa"@en ;
92 ''', 'http://jumpgate.caltech.edu/library/')
93 errmsgs = list(self.inference.run_validation())
94 self.assertEqual(len(errmsgs), 0)
95 self.failUnlessEqual(len(self.model), 8 + ontology_size)
96 urn = RDF.Node(RDF.Uri('http://jumpgate.caltech.edu/lane/1232'))
97 encode_find.delete_lane(self.model, urn)
98 self.failUnlessEqual(len(self.model), 1 + ontology_size)
99 # the flowcell triple wasn't deleted.
101 def test_delete_library(self):
102 parser = RDF.Parser(name='turtle')
103 parser.parse_string_into_model(self.model, '''@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
104 @prefix : <http://www.w3.org/1999/xhtml> .
105 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
106 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
107 @prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#> .
109 <http://jumpgate.caltech.edu/flowcell/42JV5AAXX/> a libns:IlluminaFlowcell .
110 <http://jumpgate.caltech.edu/flowcell/62WCKAAXX/> a libns:IlluminaFlowcell .
112 <http://jumpgate.caltech.edu/lane/1232>
113 a libns:IlluminaLane ;
114 libns:flowcell <http://jumpgate.caltech.edu/flowcell/42JV5AAXX/> ;
115 libns:has_mappings _:bnode110110 ;
116 libns:total_unique_locations 5789938 .
118 <http://jumpgate.caltech.edu/library/11011/>
119 libns:affiliation "ENCODE"@en, "ENCODE_Tier1"@en, "Georgi Marinov"@en ;
120 libns:has_lane <http://jumpgate.caltech.edu/lane/1232> ;
121 libns:library_id "11011"@en ;
122 libns:library_type "None"@en ;
124 <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> .
127 a libns:MappedCount ;
128 libns:mapped_to "newcontam_UK.fa"@en ;
131 <http://jumpgate.caltech.edu/lane/1903>
132 a libns:IlluminaLane ;
133 libns:flowcell <http://jumpgate.caltech.edu/flowcell/62WCKAAXX/> ;
134 libns:has_mappings _:bnode120970 ;
135 libns:total_unique_locations 39172114 .
137 <http://jumpgate.caltech.edu/library/12097/>
138 libns:has_lane <http://jumpgate.caltech.edu/lane/1903> ;
139 libns:library_id "12097"@en ;
140 libns:library_type "Paired End (non-multiplexed)"@en ;
144 a libns:MappedCount ;
145 libns:mapped_to "newcontam_UK.fa"@en ;
147 ''', 'http://jumpgate.caltech.edu/library')
148 errmsgs = list(self.inference.run_validation())
149 self.assertEqual(len(errmsgs), 0)
150 urn = RDF.Node(RDF.Uri('http://jumpgate.caltech.edu/library/11011/'))
151 encode_find.delete_library(self.model, urn)
152 q = RDF.Statement(None, encode_find.libraryOntology['reads'], None)
153 stmts = list(self.model.find_statements(q))
154 self.failUnlessEqual(len(stmts), 1)
155 self.failUnlessEqual(fromTypedNode(stmts[0].object),
158 q = RDF.Statement(None, encode_find.libraryOntology['library_id'], None)
159 stmts = list(self.model.find_statements(q))
160 self.failUnlessEqual(len(stmts), 1)
161 self.failUnlessEqual(fromTypedNode(stmts[0].object),
165 from unittest2 import TestSuite, defaultTestLoader
167 suite.addTests(defaultTestLoader.loadTestsFromTestCase(TestEncodeFind))
171 if __name__ == "__main__":
172 from unittest2 import main