Mercurial > repos > davidvanzessen > argalaxy_tools
comparison tests/test_imgt.py @ 56:7ae6b6b5d890 draft
"planemo upload commit 2d4cb6757e8eff095295550bbde6fd9e2ee0b73d"
author | rhpvorderman |
---|---|
date | Tue, 14 Dec 2021 12:45:47 +0000 |
parents | |
children | 33412e85e669 |
comparison
equal
deleted
inserted
replaced
55:2a7dc86d8f85 | 56:7ae6b6b5d890 |
---|---|
1 # Copyright (c) 2021 Leiden University Medical Center | |
2 # | |
3 # Permission is hereby granted, free of charge, to any person obtaining a copy | |
4 # of this software and associated documentation files (the "Software"), to deal | |
5 # in the Software without restriction, including without limitation the rights | |
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
7 # copies of the Software, and to permit persons to whom the Software is | |
8 # furnished to do so, subject to the following conditions: | |
9 # | |
10 # The above copyright notice and this permission notice shall be included in | |
11 # all copies or substantial portions of the Software. | |
12 # | |
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
19 # SOFTWARE. | |
20 | |
21 import os | |
22 import shutil | |
23 import subprocess | |
24 import tempfile | |
25 from pathlib import Path | |
26 from xml.etree import ElementTree | |
27 from xml.etree.ElementTree import Element | |
28 | |
29 import pytest | |
30 | |
31 GIT_ROOT = Path(__file__).parent.parent.absolute() | |
32 TEST_DIR = Path(__file__).parent | |
33 TEST_DATA_DIR = TEST_DIR / "data" | |
34 VALIDATION_DATA_DIR = TEST_DIR / "validation_data" | |
35 CONTROL_NWK377_PB_IGHC_MID1_40nt_2 = TEST_DATA_DIR / "CONTROL_NWK377_PB_IGHC_MID1_40nt_2.txz" | |
36 | |
37 | |
38 def get_container(): | |
39 tool = ElementTree.parse(GIT_ROOT / "complete_immunerepertoire.xml").getroot() | |
40 requirements: Element = tool.find("requirements") | |
41 container = requirements.find("container") | |
42 return container.text | |
43 | |
44 | |
45 @pytest.fixture(scope="module") | |
46 def imgt_result(): | |
47 temp_dir = Path(tempfile.mkdtemp()) | |
48 tool_dir = temp_dir / "imgt" | |
49 shutil.copytree(GIT_ROOT, tool_dir) | |
50 working_dir = temp_dir / "working" | |
51 working_dir.mkdir(parents=True) | |
52 output_dir = temp_dir / "outputs" | |
53 output_dir.mkdir(parents=True) | |
54 wrapper = str(tool_dir / "complete.sh") | |
55 sample = CONTROL_NWK377_PB_IGHC_MID1_40nt_2 | |
56 input = f"\"ID1\" {sample} {sample} \"ID2\" {sample}" | |
57 out_files_path = output_dir / "results" | |
58 out_files_path.mkdir(parents=True) | |
59 out_file = out_files_path / "result.html" | |
60 clonaltype = "none" | |
61 gene_selection = dict(species="Homo sapiens functional", | |
62 locus="TRA") | |
63 filterproductive = "yes" | |
64 clonality_method = "none" | |
65 cmd = [ | |
66 "bash", | |
67 wrapper, | |
68 input, | |
69 str(out_file), | |
70 str(out_files_path), | |
71 clonaltype, | |
72 gene_selection["species"], | |
73 gene_selection["locus"], | |
74 filterproductive, | |
75 clonality_method | |
76 ] | |
77 docker_cmd = ["docker", "run", "-v", f"{temp_dir}:{temp_dir}", | |
78 "-v", f"{sample}:{sample}", | |
79 "-w", str(working_dir), | |
80 get_container()] + cmd | |
81 with open(temp_dir / "stderr", "wt") as stderr_file: | |
82 with open(temp_dir / "stdout", "wt") as stdout_file: | |
83 subprocess.run(docker_cmd, cwd=working_dir, stdout=stdout_file, | |
84 stderr=stderr_file, check=True) | |
85 yield Path(out_files_path) | |
86 | |
87 | |
88 def test_check_output(imgt_result): | |
89 assert imgt_result.exists() |