-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_create_case_lists.py
175 lines (149 loc) · 6.04 KB
/
test_create_case_lists.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import os
import pytest
from genie import create_case_lists
study_id = "test"
clinical_file_map = {"": ["FOOBAR", "NEED"]}
clinical_file_map["Testing2"] = ["test1"]
clinical_file_map["Test1 Now, Please/foo"] = ["wow"]
expected_change_text = (
"cancer_study_identifier: test\n"
"stable_id: test_Test1_Now_Please_foo\n"
"case_list_name: Tumor Type: Test1 Now, Please/foo\n"
"case_list_description: All tumors with cancer type "
"Test1 Now, Please/foo\n"
"case_list_ids: wow"
)
expected_same_text = (
"cancer_study_identifier: test\n"
"stable_id: test_Testing2\n"
"case_list_name: Tumor Type: Testing2\n"
"case_list_description: All tumors with cancer type Testing2\n"
"case_list_ids: test1"
)
expected_nocode_text = (
"cancer_study_identifier: test\n"
"stable_id: test_no_oncotree_code\n"
"case_list_name: Tumor Type: NA\n"
"case_list_description: All tumors with cancer type NA\n"
"case_list_ids: FOOBAR\tNEED"
)
@pytest.fixture(
params=[
# tuple with (input, expectedOutput)
("", clinical_file_map[""], expected_nocode_text),
("Testing2", clinical_file_map["Testing2"], expected_same_text),
(
"Test1 Now, Please/foo",
clinical_file_map["Test1 Now, Please/foo"],
expected_change_text,
),
]
)
def oncotree_write_params(request):
return request.param
def test_filenames_write_case_list_files():
case_list_files = create_case_lists.write_case_list_files(
clinical_file_map, "./", study_id
)
required_files = [
"cases_Test1_Now_Please_foo.txt",
"cases_no_oncotree_code.txt",
"cases_Testing2.txt",
]
basenames = [os.path.basename(case_file) for case_file in case_list_files]
assert all([req_file in basenames for req_file in required_files])
def test__write_single_oncotree_case_list(oncotree_write_params):
(cancer_type, ids, expected_text) = oncotree_write_params
caselist_path = create_case_lists._write_single_oncotree_case_list(
cancer_type, ids, study_id, "./"
)
with open(caselist_path, "r") as case_list:
caselist_text = case_list.read()
assert caselist_text == expected_text
os.remove(caselist_path)
class TestCreateCaseList:
def setup_method(self):
self.sequenced_case_list_files = create_case_lists.write_case_list_sequenced(
["test1", "test2"], "./", study_id
)
self.case_list_cna_path = create_case_lists.write_case_list_cna(
["test1", "test2"], "./", study_id
)
self.case_list_cnaseq_path = create_case_lists.write_case_list_cnaseq(
["test1", "test2"], "./", study_id
)
self.case_list_sv_path = create_case_lists.write_case_list_sv(
["test1", "test2"], "./", study_id
)
def teardown_method(self):
os.remove(self.sequenced_case_list_files[0])
os.remove(self.sequenced_case_list_files[1])
os.remove(self.case_list_cna_path)
os.remove(self.case_list_cnaseq_path)
os.remove(self.case_list_sv_path)
def test_filenames_write_case_list_sequenced(self):
first = os.path.basename(self.sequenced_case_list_files[0])
assert first == "cases_sequenced.txt"
second = os.path.basename(self.sequenced_case_list_files[1])
assert second == "cases_all.txt"
def test_sequencetext_write_case_list_sequenced(self):
expected_text = (
"cancer_study_identifier: test\n"
"stable_id: test_sequenced\n"
"case_list_name: Sequenced Tumors\n"
"case_list_description: All sequenced samples\n"
"case_list_ids: test1\ttest2"
)
with open(self.sequenced_case_list_files[0], "r") as case_list:
caselist_text = case_list.read()
assert caselist_text == expected_text
def test_all_write_case_list_sequenced(self):
expected_text = (
"cancer_study_identifier: test\n"
"stable_id: test_all\n"
"case_list_name: All samples\n"
"case_list_description: All samples\n"
"case_list_ids: test1\ttest2"
)
with open(self.sequenced_case_list_files[1], "r") as case_list:
caselist_text = case_list.read()
assert caselist_text == expected_text
def test_filename_write_case_list_cna(self):
assert os.path.basename(self.case_list_cna_path) == "cases_cna.txt"
def test_filename_write_case_list_cnaseq(self):
assert os.path.basename(self.case_list_cnaseq_path) == "cases_cnaseq.txt"
def test_cnatext_write_case_list_cna(self):
expected_text = (
"cancer_study_identifier: test\n"
"stable_id: test_cna\n"
"case_list_name: Samples with CNA\n"
"case_list_description: Samples with CNA\n"
"case_list_ids: test1\ttest2"
)
with open(self.case_list_cna_path, "r") as case_list:
caselist_text = case_list.read()
assert caselist_text == expected_text
def test_cnaseq_write_case_list_cnaseq(self):
expected_text = (
"cancer_study_identifier: test\n"
"stable_id: test_cnaseq\n"
"case_list_name: Samples with CNA and mutation\n"
"case_list_description: Samples with CNA and mutation\n"
"case_list_ids: test1\ttest2"
)
with open(self.case_list_cnaseq_path, "r") as case_list:
caselist_text = case_list.read()
assert caselist_text == expected_text
def test_cnaseq_write_case_list_sv(self):
expected_text = (
"cancer_study_identifier: test\n"
"stable_id: test_sv\n"
"case_list_name: Samples with Structural Variants\n"
"case_list_description: Samples with Structural Variants\n"
"case_list_ids: test1\ttest2"
)
with open(self.case_list_sv_path, "r") as case_list:
caselist_text = case_list.read()
assert (
caselist_text == expected_text
), "The case list text doesn't match the expected output"