Mercurial > repos > davidvanzessen > shm_csr
comparison tests/test_shm_csr.py @ 98:d714f5ea83d7 draft default tip
planemo upload commit 1a01065a084a817382872154f779b94090a35ebf
author | rhpvorderman |
---|---|
date | Wed, 10 Jan 2024 12:32:47 +0000 |
parents | 84e9e5c8c101 |
children |
comparison
equal
deleted
inserted
replaced
97:fbc6307dd83b | 98:d714f5ea83d7 |
---|---|
47 "Ignore virtualenv and git directories to prevent massive tmp folders" | 47 "Ignore virtualenv and git directories to prevent massive tmp folders" |
48 if os.path.basename(src) in (".venv", ".git"): | 48 if os.path.basename(src) in (".venv", ".git"): |
49 return files | 49 return files |
50 return () | 50 return () |
51 | 51 |
52 @pytest.fixture(scope="module") | 52 |
53 def shm_csr_result(): | 53 def run_shm_csr( |
54 input=str(CONTROL_NWK377_PB_IGHC_MID1_40nt_2), | |
55 infile_name = "input_data", | |
56 functionality = "productive", | |
57 unique = "Sequence.ID", | |
58 naive_output = "no", | |
59 naive_output_ca = "None", | |
60 naive_output_cg = "None", | |
61 naive_output_cm = "None", | |
62 naive_output_ce = "None", | |
63 naive_output_all = "None", | |
64 naive_output_igm_naive = "None", | |
65 naive_output_igm_naive_memory = "None", | |
66 filter_unique = "remove", | |
67 filter_unique_count = '2', | |
68 class_filter = '70_70', | |
69 empty_region_filter = 'FR1', | |
70 # Skip baseline and changeo by default. These tools cannot be modified | |
71 # anyway and take most of the test time to execute. The environment | |
72 # variable can be set to "no" on the CI so the code path is tested | |
73 # at the time a PR is ready. | |
74 run_changeo = "yes" if os.environ.get("SHM_CSR_FAST") == "no" else "no", | |
75 run_baseline = "yes" if os.environ.get("SHM_CSR_FAST") == "no" else "no", | |
76 ): | |
54 temp_dir = Path(tempfile.mkdtemp()) | 77 temp_dir = Path(tempfile.mkdtemp()) |
55 tool_dir = temp_dir / "shm_csr" | 78 tool_dir = temp_dir / "shm_csr" |
56 shutil.copytree( | 79 shutil.copytree( |
57 GIT_ROOT, tool_dir, | 80 GIT_ROOT, tool_dir, |
58 # Ignore .venv and .git directories. | 81 # Ignore .venv and .git directories. |
60 working_dir = temp_dir / "working" | 83 working_dir = temp_dir / "working" |
61 working_dir.mkdir(parents=True) | 84 working_dir.mkdir(parents=True) |
62 output_dir = temp_dir / "outputs" | 85 output_dir = temp_dir / "outputs" |
63 output_dir.mkdir(parents=True) | 86 output_dir.mkdir(parents=True) |
64 wrapper = str(tool_dir / "wrapper.sh") | 87 wrapper = str(tool_dir / "wrapper.sh") |
65 input = str(CONTROL_NWK377_PB_IGHC_MID1_40nt_2) | |
66 out_files_path = output_dir / "results" | 88 out_files_path = output_dir / "results" |
67 out_file = out_files_path / "result.html" | 89 out_file = out_files_path / "result.html" |
68 infile_name = "input_data" | |
69 functionality = "productive" | |
70 unique = "Sequence.ID" | |
71 naive_output = "no" | |
72 naive_output_ca = "None" | |
73 naive_output_cg = "None" | |
74 naive_output_cm = "None" | |
75 naive_output_ce = "None" | |
76 naive_output_all = "None" | |
77 naive_output_igm_naive = "None" | |
78 naive_output_igm_naive_memory = "None" | |
79 filter_unique = "remove" | |
80 filter_unique_count = '2' | |
81 class_filter = '70_70' | |
82 empty_region_filter = 'FR1' | |
83 # Skip baseline and changeo by default. These tools cannot be modified | |
84 # anyway and take most of the test time to execute. The environment | |
85 # variable can be set to "no" on the CI so the code path is tested | |
86 # at the time a PR is ready. | |
87 fast = os.environ.get("SHM_CSR_FAST", "yes") | |
88 cmd = [ | 90 cmd = [ |
89 "bash", | 91 "bash", |
90 wrapper, | 92 wrapper, |
91 input, | 93 input, |
92 "custom", | 94 "custom", |
106 naive_output_igm_naive_memory, | 108 naive_output_igm_naive_memory, |
107 filter_unique, | 109 filter_unique, |
108 filter_unique_count, | 110 filter_unique_count, |
109 class_filter, | 111 class_filter, |
110 empty_region_filter, | 112 empty_region_filter, |
111 fast | 113 run_changeo, |
114 run_baseline | |
112 ] | 115 ] |
113 docker_cmd = ["docker", "run", "-v", f"{temp_dir}:{temp_dir}", | 116 docker_cmd = ["docker", "run", "-v", f"{temp_dir}:{temp_dir}", |
114 "--rm", # Remove container after running | 117 "--rm", # Remove container after running |
115 "-v", f"{input}:{input}", | 118 "-v", f"{input}:{input}", |
116 "-w", str(working_dir), | 119 "-w", str(working_dir), |
126 ] + cmd | 129 ] + cmd |
127 with open(temp_dir / "stderr", "wt") as stderr_file: | 130 with open(temp_dir / "stderr", "wt") as stderr_file: |
128 with open(temp_dir / "stdout", "wt") as stdout_file: | 131 with open(temp_dir / "stdout", "wt") as stdout_file: |
129 subprocess.run(docker_cmd, cwd=working_dir, stdout=stdout_file, | 132 subprocess.run(docker_cmd, cwd=working_dir, stdout=stdout_file, |
130 stderr=stderr_file, check=True) | 133 stderr=stderr_file, check=True) |
131 yield Path(out_files_path) | 134 return Path(out_files_path) |
135 | |
136 | |
137 @pytest.fixture(scope="module") | |
138 def shm_csr_result(): | |
139 yield run_shm_csr() | |
132 | 140 |
133 | 141 |
134 def test_check_output(shm_csr_result): | 142 def test_check_output(shm_csr_result): |
135 assert shm_csr_result.exists() | 143 assert shm_csr_result.exists() |
136 | 144 |
155 ) as result_h: | 163 ) as result_h: |
156 with open(Path(TEST_DIR, "sequence_overview", "ntoverview.txt") | 164 with open(Path(TEST_DIR, "sequence_overview", "ntoverview.txt") |
157 ) as validate_h: | 165 ) as validate_h: |
158 for line in result_h: | 166 for line in result_h: |
159 assert line == validate_h.readline() | 167 assert line == validate_h.readline() |
168 | |
169 | |
170 def test_baseline_succeeds(): | |
171 run_shm_csr( | |
172 functionality="unproductive", | |
173 empty_region_filter="None", | |
174 filter_unique="no", | |
175 unique="VGene,DGene,JGene,CDR3.IMGT.seq", | |
176 class_filter="101_101_IGA", | |
177 naive_output="yes", | |
178 run_baseline="yes", | |
179 run_changeo="yes", | |
180 ) |