4 from unittest import TestCase, TestSuite, defaultTestLoader
6 from rdflib import Graph, Namespace
8 from htsworkflow.util.rdfhelp import \
11 from htsworkflow.submission.submission import list_submissions, Submission
12 from htsworkflow.submission.results import ResultMap
13 from .submission_test_common import (
14 generate_sample_results_tree,
23 #logging.basicConfig(level=logging.DEBUG)
25 class TestSubmissionModule(TestCase):
26 def test_empty_list_submission(self):
28 self.assertEqual(len(list(list_submissions(model))), 0)
30 def test_one_submission(self):
33 @prefix subns: <http://jumpgate.caltech.edu/wiki/UcscSubmissionOntology#> .
34 @prefix test: <http://jumpgate.caltech.edu/wiki/SubmissionsLog/test#> .
36 <http://jumpgate.caltech.edu/wiki/SubmissionsLog/test#>
37 subns:has_submission test:lib1 ;
38 subns:has_submission test:lib2.
40 submissions = list(list_submissions(model))
41 self.assertEqual(len(submissions), 1)
42 self.assertEqual(submissions[0], "test")
44 def test_two_submission(self):
47 @prefix subns: <http://jumpgate.caltech.edu/wiki/UcscSubmissionOntology#> .
48 @prefix test: <http://jumpgate.caltech.edu/wiki/SubmissionsLog/test#> .
50 <http://jumpgate.caltech.edu/wiki/SubmissionsLog/test1#>
51 subns:has_submission test:lib1 .
52 <http://jumpgate.caltech.edu/wiki/SubmissionsLog/test2#>
53 subns:has_submission test:lib2 .
55 submissions = list(list_submissions(model))
56 self.assertEqual(len(submissions), 2)
57 truth = set(["test1", "test2"])
59 for name in submissions:
61 self.assertEqual(testset, truth)
63 class TestSubmission(TestCase):
65 generate_sample_results_tree(self, 'submission_test')
69 shutil.rmtree(self.tempdir)
71 def test_create_submission(self):
72 s = Submission('foo', self.model, 'http://localhost')
73 self.assertEqual(str(s.submissionSet),
74 "http://jumpgate.caltech.edu/wiki/SubmissionsLog/foo")
75 self.assertEqual(str(s.submissionSetNS['']),
76 str(Namespace(str(s.submissionSet) + '#')['']))
77 self.assertEqual(str(s.libraryNS['']),
78 str(Namespace('http://localhost/library/')['']))
80 def test_scan_submission_dirs(self):
81 turtle = get_turtle_header() + r"""
82 @prefix thisView: <http://jumpgate.caltech.edu/wiki/SubmissionsLog/test/view/> .
83 thisView:Fastq ucscDaf:filename_re ".*[^12]\\.fastq$" ;
85 geoSoft:fileTypeLabel "fastq" ;
86 ucscDaf:output_type "read" .
87 thisView:FastqRead1 ucscDaf:filename_re ".*r1\\.fastq$" ;
89 geoSoft:fileTypeLabel "fastq" ;
90 ucscDaf:output_type "read1" .
91 thisView:FastqRead2 ucscDaf:filename_re ".*r2\\.fastq$" ;
93 geoSoft:fileTypeLabel "fastq" ;
94 ucscDaf:output_type "read2" .
95 thisView:alignments ucscDaf:filename_re ".*\\.bam$" ;
96 a geoSoft:supplemental ;
97 geoSoft:fileTypeLabel "bam" ;
98 ucscDaf:output_type "alignments" .
101 resultmap = ResultMap()
102 resultmap['1000'] = os.path.join(self.sourcedir, S1_NAME)
103 resultmap['2000'] = os.path.join(self.sourcedir, S2_NAME)
105 s = Submission('foo', self.model, 'http://localhost')
106 mock = MockAddDetails(self.model, turtle)
107 mock.add_turtle(S1_TURTLE)
108 mock.add_turtle(S2_TURTLE)
109 #s._add_library_details_to_model(mock)
110 s.scan_submission_dirs(resultmap)
112 nodes = list(s.analysis_nodes(resultmap))
113 self.assertEqual(len(nodes), 2)
115 'http://jumpgate.caltech.edu/wiki/SubmissionsLog/foo#1000-sample',
116 'http://jumpgate.caltech.edu/wiki/SubmissionsLog/foo#2000-sample',
118 got = set((str(nodes[0]), str(nodes[1])))
119 self.assertEqual(expected, got)
121 def test_find_best_match(self):
122 turtle = get_turtle_header() + r"""
123 @prefix thisView: <http://jumpgate.caltech.edu/wiki/SubmissionsLog/test/view/> .
124 thisView:Fastq ucscDaf:filename_re ".*[^12]\\.fastq\\.bz2$" ;
126 geoSoft:fileTypeLabel "fastq" ;
127 ucscDaf:output_type "read" .
128 thisView:FastqRead1 ucscDaf:filename_re ".*r1\\.fastq\\.bz2$" ;
130 geoSoft:fileTypeLabel "fastq" ;
131 ucscDaf:output_type "read1" .
132 thisView:FastqRead2 ucscDaf:filename_re ".*r2\\.fastq\\.bz2$" ;
134 geoSoft:fileTypeLabel "fastq" ;
135 ucscDaf:output_type "read2" .
136 thisView:alignments ucscDaf:filename_re ".*\\.bam$" ;
137 a geoSoft:supplemental ;
138 geoSoft:fileTypeLabel "bam" ;
139 ucscDaf:output_type "alignments" .
142 self.model.parse(data=turtle, format='turtle')
143 s = Submission('foo', self.model, 'http://localhost')
144 q = (None, dafTermOntology['filename_re'], None)
145 view_map = s._get_filename_view_map()
146 self.assertEqual(len(view_map), 4)
148 fastq = s.find_best_match("asdf.fastq.bz2")
151 "http://jumpgate.caltech.edu/wiki/SubmissionsLog/test/view/Fastq")
153 fastq = s.find_best_match("asdf.r2.fastq.bz2")
156 "http://jumpgate.caltech.edu/wiki/SubmissionsLog/test/view/FastqRead2")
161 defaultTestLoader.loadTestsFromTestCase(TestSubmissionModule))
163 defaultTestLoader.loadTestsFromTestCase(TestSubmission))
166 if __name__ == "__main__":
167 from unittest import main
168 main(defaultTest='suite')