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