2 from datetime import datetime
9 from htsworkflow.submission.ucsc import submission_view_url
10 from htsworkflow.util.rdfhelp import dump_model, get_model, fromTypedNode
12 SOURCE_PATH = os.path.split(os.path.abspath(__file__))[0]
15 class TestEncodeFind(unittest.TestCase):
16 def test_create_status_node_with_uri(self):
17 subURL = submission_view_url('5136')
18 submissionUri = RDF.Uri(subURL)
19 timestamp = '2011-12-19T12:42:53.048956'
20 manualUri = subURL + '/' + timestamp
21 nodeUri = encode_find.create_status_node(submissionUri, timestamp)
22 self.assertEqual(str(nodeUri.uri), manualUri)
24 def test_create_status_node_with_str(self):
25 subURL = submission_view_url('5136')
26 timestamp = '2011-12-19T12:42:53.048956'
27 manualUri = subURL + '/' + timestamp
28 nodeUri = encode_find.create_status_node(subURL, timestamp)
29 self.assertEqual(str(nodeUri.uri), manualUri)
31 def test_parse_submission_page(self):
32 timestamp = '2011-12-19T12:42:53.048956'
33 subURL = submission_view_url('5136')
34 subNode = encode_find.create_status_node(subURL, timestamp)
35 test_file = os.path.join(SOURCE_PATH, 'testdata', '5136SubDetail.html')
36 from lxml.html import parse
37 tree = parse(test_file)
39 dates = encode_find.get_creation_dates(model, subNode)
40 self.assertEqual(len(dates), 0)
41 encode_find.parse_submission_page(model, tree, subNode)
42 dates = encode_find.get_creation_dates(model, subNode)
43 self.assertEqual(len(dates), 1)
44 object_date = fromTypedNode(dates[0].object)
45 self.assertEqual(object_date, datetime(2011,12,7,15,23,0))
47 def test_delete_simple_lane(self):
49 parser = RDF.Parser(name='turtle')
50 parser.parse_string_into_model(model, '''@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
51 @prefix : <http://www.w3.org/1999/xhtml> .
52 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
53 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
54 @prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#> .
56 <http://jumpgate.caltech.edu/lane/1232>
57 libns:flowcell <http://jumpgate.caltech.edu/flowcell/42JV5AAXX/> ;
58 libns:total_unique_locations 5789938 .
60 ''', 'http://jumpgate.caltech.edu/library/')
61 urn = RDF.Node(RDF.Uri('http://jumpgate.caltech.edu/lane/1232'))
62 encode_find.delete_lane(model, urn)
63 self.failUnlessEqual(len(model), 0)
65 def test_delete_lane_with_mapping(self):
67 parser = RDF.Parser(name='turtle')
68 parser.parse_string_into_model(model, '''@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
69 @prefix : <http://www.w3.org/1999/xhtml> .
70 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
71 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
72 @prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#> .
74 <http://jumpgate.caltech.edu/lane/1232>
75 libns:flowcell <http://jumpgate.caltech.edu/flowcell/42JV5AAXX/> ;
76 libns:has_mappings _:bnode110110 ;
77 libns:total_unique_locations 5789938 .
80 libns:mapped_to "newcontam_UK.fa"@en ;
82 ''', 'http://jumpgate.caltech.edu/library/')
83 self.failUnlessEqual(len(model), 5)
84 urn = RDF.Node(RDF.Uri('http://jumpgate.caltech.edu/lane/1232'))
85 encode_find.delete_lane(model, urn)
86 self.failUnlessEqual(len(model), 0)
88 def test_delete_library(self):
90 parser = RDF.Parser(name='turtle')
91 parser.parse_string_into_model(model, '''@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
92 @prefix : <http://www.w3.org/1999/xhtml> .
93 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
94 @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
95 @prefix libns: <http://jumpgate.caltech.edu/wiki/LibraryOntology#> .
97 <http://jumpgate.caltech.edu/lane/1232>
98 libns:flowcell <http://jumpgate.caltech.edu/flowcell/42JV5AAXX/> ;
99 libns:has_mappings _:bnode110110 ;
100 libns:total_unique_locations 5789938 .
102 <http://jumpgate.caltech.edu/library/11011/>
103 libns:affiliation "ENCODE"@en, "ENCODE_Tier1"@en, "Georgi Marinov"@en ;
104 libns:has_lane <http://jumpgate.caltech.edu/lane/1232> ;
105 libns:library_id "11011"@en ;
106 libns:library_type "None"@en ;
107 a "libns:library"@en ;
108 <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> .
111 libns:mapped_to "newcontam_UK.fa"@en ;
114 <http://jumpgate.caltech.edu/lane/1903>
115 libns:flowcell <http://jumpgate.caltech.edu/flowcell/62WCKAAXX/> ;
116 libns:has_mappings _:bnode120970 ;
117 libns:total_unique_locations 39172114 .
119 <http://jumpgate.caltech.edu/library/12097/>
120 libns:has_lane <http://jumpgate.caltech.edu/lane/1903> ;
121 libns:library_id "12097"@en ;
122 libns:library_type "Paired End (non-multiplexed)"@en ;
123 a "libns:library"@en .
126 libns:mapped_to "newcontam_UK.fa"@en ;
128 ''', 'http://jumpgate.caltech.edu/library')
129 urn = RDF.Node(RDF.Uri('http://jumpgate.caltech.edu/library/11011/'))
130 encode_find.delete_library(model, urn)
131 q = RDF.Statement(None, encode_find.libraryOntology['reads'], None)
132 stmts = list(model.find_statements(q))
133 self.failUnlessEqual(len(stmts), 1)
134 self.failUnlessEqual(fromTypedNode(stmts[0].object),
137 q = RDF.Statement(None, encode_find.libraryOntology['library_id'], None)
138 stmts = list(model.find_statements(q))
139 self.failUnlessEqual(len(stmts), 1)
140 self.failUnlessEqual(fromTypedNode(stmts[0].object),
144 return unittest.makeSuite(TestEncodeFind, "test")
146 if __name__ == "__main__":
147 unittest.main(defaultTest="suite")