-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_run_hpc_playground.py
208 lines (177 loc) · 7.31 KB
/
test_run_hpc_playground.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import requests
#import jwt
import os
from keycloak import KeycloakOpenID
import pytest
def pytest_namespace():
return {'plan_id': 0 ,"dar_id": None , "analysis_type_id":0, "pipeline_id":-1}
api_host="https://playground.gpapdev.cnag.eu/analysis_service/"
username='test'#os.environ['username']
password= os.environ['password']
keycloak_openid = KeycloakOpenID(server_url="https://sso.gpapdev.cnag.eu/",
client_id="genomed4all",
realm_name="playground",
client_secret_key="ac1ae8c6-d525-472e-ab59-7631399cdc29",
verify=False)
import requests,json
token = keycloak_openid.token(username,password )
headers={"Content-Type": "application/json","Authorization":f"Bearer {token['access_token']}", "host":"playground.gpapdev.cnag.eu"}
#dataload
#first step generate a csv file out of something,pipeline,query,etc and then link the data id to the training plan
def test_get_analysis_type():
resp=requests.get(api_host+"/analysis_type/", headers=headers)
for analysis in resp.json()['data']:
if analysis['name']=='germline':
pytest.analysis_type_id= analysis['id']
assert True
def test_get_resource():
resp=requests.get(api_host+"/resources/", headers=headers)
for resource in resp.json()['data']:
if resource['name']=='dry':
pytest.resource_id= resource['id']
assert True
def test_put_pipeline():
pipeline_def={
"analysis_type": "germline",
"analysis_type_id": pytest.analysis_type_id,
"name": "dry_germline_plus",
"data": {
"repo": "bag-cnag/sarek_plus_germline_dry",
"step": "mapping",
"steps": [
{
"step": "File availability and integrity",
"step_type": "process",
"description": ""
},
{
"step": "Sequencing data quality check",
"step_type": "qc",
"description": ""
},
{
"step": "Mapping to the reference genome",
"step_type": "process",
"description": ""
},
{
"step": "Mapping quality check",
"step_type": "qc",
"description": ""
},
{
"step": "Variant calling (SNV, CNV/SV) + Biomarkers/Pharmacogenomics",
"step_type": "process",
"description": ""
},
{
"step": "Variant calling quality check",
"step_type": "qc",
"description": ""
},
{
"step": "Annotations",
"step_type": "process",
"description": ""
},
{
"step": "Annotations Quality Check",
"step_type": "qc",
"description": ""
},
{
"step": "Upload to Elastic Quality",
"step_type": "process",
"description": ""
},
{
"step": "Upload to Elastic Quality Check",
"step_type": "qc",
"description": ""
},
{
"step": "Pipeline completion check",
"step_type": "process",
"description": ""
}
],
"tools": "cnvkit,manta,haplotypecaller,strelka,expansionhunter,stripy,fullmetrics",
"release": "v0.1",
"pipelines": "sarek,pcgx,annotatesvs,gatk_mt,qualitycontrols",
"output_format": {
"snvs": [{"type": "file",
"path": "{wd}/results/variant_calling/haplotypecaller/{experiment}/{experiment}.haplotypecaller.filtered.vcf.gz"},
{"type": "index", "index": "cnag_{task_id}"}],
"cnvs": [{"type": "file", "path": "{wd}/results/annotsv/cnvkit/{experiment}/{experiment}.tsv"},
{"type": "index", "index": "cnag_{task_id}"}],
"svs": [{"type": "file", "path": "{wd}/results/annotsv/manta/{experiment}/{experiment}.tsv"},
{"type": "index", "index": "cnag_{task_id}"}],
"pharmacogenomics": [
{"type": "file", "path": "{wd}/results/pharmacogenomics/{experiment}/results_gathered_alleles.tsv"},
{"type": "index", "index": "cnag_{task_id}"}],
"multiqc": [{"type": "file", "path": "{wd}/results/multiqc/multiqc_report.html"},
{"type": "index", "index": "cnag_{task_id}"}],
"cram": [{"type": "file", "path": "{wd}/results/preprocessing/recalibrated/{experiment}/{experiment}.recal.cram"},
{"type": "index", "index": "cnag_{task_id}"}],
"qc_checks": [{"type": "file", "path": "{wd}/annotations.json"},
{"type": "index", "index": "cnag_{task_id}"},
{"type": "file", "path": "{wd}/elastic.json"},
{"type": "index", "index": "cnag_{task_id}"},
{"type": "file", "path": "{wd}/sequencing_data_quality_check.json"},
{"type": "index", "index": "cnag_{task_id}"},
{"type": "file", "path": "{wd}/mapping_qc.json"},
{"type": "index", "index": "cnag_{task_id}"},
{"type": "file", "path": "{wd}/variant.json"},
{"type": "index", "index": "cnag_{task_id}"},
{"type": "file", "path": "{wd}/workflow_complete.json"},
{"type": "index", "index": "cnag_{task_id}"}]
}
},
}
#only run whn needed we can not delete it via API
pytest.pipeline_id = -1
resp=requests.get(api_host+"/pipelines/", headers=headers)
for pipeline in resp.json():
if pipeline['name']=='dry_germline_plus':
pytest.pipeline_id = pipeline['id']
if pytest.pipeline_id == -1:
resp=requests.put(api_host+"/pipelines/",json=pipeline_def, headers=headers)
pytest.pipeline_id = resp.json()['id']
assert (resp.status_code == 200 or resp.status_code == 201)
def test_create_dar():
dar_data1 = {"analysis_type":"germline",
"analysis_type_id":pytest.analysis_type_id,
"description":"","clinical_referrer":"",
"clinical_referrer_contact":"","hospital_name":"",
"priority":"medium","deadline":"2024-09-04",
"resource_id":pytest.resource_id,"pipeline_id":pytest.pipeline_id,
"tumor_experiment_id":"",
"control_experiment_id":"HG002"}
resp=requests.put(api_host+"/dars/",json=dar_data1, headers=headers)
pytest.dar_id=resp.json()['dar_id']
print(pytest.dar_id)
assert resp.status_code == 201
def test_run_task():
resp=requests.post(f"{api_host}/dars/run/{pytest.dar_id}",json={"resource_id":pytest.resource_id}, headers=headers)
pytest.task_id=resp.json()['task_id']
print(pytest.task_id)
assert resp.status_code == 200
def test_run_execution():
import time
while True:
time.sleep(3)
resp= requests.get(f"{api_host}/tasks/{pytest.task_id}", headers=headers)
status=resp.json()['data'][0]['status']
if status=='completed':
assert 1==1
break
if status=='failed':
assert 1==0
break
def test_check_status_dar():
resp=requests.get(f"{api_host}/dars/{pytest.dar_id}", headers=headers)
assert resp.json()['status']=='review'
assert resp.status_code == 200
def test_delete_dar():
resp=requests.delete(f"{api_host}/dars/{pytest.dar_id}", headers=headers)
assert resp.status_code == 200