Skip to content

Commit d35c7d4

Browse files
authored
Merge pull request #7578 from RZ9082/swissmodel_modelling_api
SWISS-MODEL API tool - Use credentials instead of parameter for tokens
2 parents 431830f + bb117e3 commit d35c7d4

File tree

2 files changed

+23
-66
lines changed

2 files changed

+23
-66
lines changed

tools/swissmodel_modelling_api/sm_api_wrapper.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,7 @@ def _parse_args():
286286
metas = {
287287
"outdir": "<OUTPUT DIRECTORY>",
288288
"target_sequences": "<SEQUENCE[S]>",
289-
"token": "<TOKEN>",
290289
}
291-
parser.add_argument(
292-
"token",
293-
help="Authentication token for SWISS-MODEL",
294-
metavar=metas["token"],
295-
)
296290
parser.add_argument(
297291
"outdir",
298292
help="Directory to store results in",
@@ -377,20 +371,27 @@ def _main():
377371
"""Run as script."""
378372
opts = _parse_args()
379373

374+
token = os.getenv("SWISSMODEL_API_TOKEN")
375+
if not token:
376+
print(
377+
"SWISS-MODEL token is not provided in credentials!",
378+
file=sys.stderr,
379+
)
380+
sys.exit(1)
380381
target_sequences = _defastarise_targets(opts.target_sequences)
381382
# determine class
382383
whsprr = None
383384
if opts.project_type.lower() == "automodel":
384385
whsprr = _AutoModelWhisperer(
385-
target_sequences, opts.token, project_title=opts.project_title
386+
target_sequences, token, project_title=opts.project_title
386387
)
387388
elif opts.project_type.lower() == "alignment":
388389
template_sequence = _defastarise_targets([opts.template_sequence])
389390
assert len(template_sequence) == 1
390391
template_sequence = template_sequence[0]
391392
whsprr = _AlignmentWhisperer(
392393
target_sequences,
393-
opts.token,
394+
token,
394395
template_sequence,
395396
opts.template_seqres_offset,
396397
opts.pdb_id,
@@ -401,7 +402,7 @@ def _main():
401402
elif opts.project_type.lower() == "usertemplate":
402403
whsprr = _UserTemplateWhisperer(
403404
target_sequences,
404-
opts.token,
405+
token,
405406
opts.template_file,
406407
project_title=opts.project_title,
407408
)

tools/swissmodel_modelling_api/swissmodel_api.xml

Lines changed: 13 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
<tool name="SWISS-MODEL Modelling API" id="swissmodel_modelling_api" profile="21.05" version="2.0.0">
1+
<tool name="SWISS-MODEL Modelling API" id="swissmodel_modelling_api" profile="25.1" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@">
22
<description>
33
Fully automated protein structure homology-modelling
44
</description>
5+
<macros>
6+
<token name="@TOOL_VERSION@">2.0.0</token>
7+
<token name="@VERSION_SUFFIX@">0</token>
8+
</macros>
59
<xrefs>
610
<xref type="bio.tools">swiss_model</xref>
711
</xrefs>
812
<requirements>
913
<requirement type="package" version="3.11">python</requirement>
1014
<requirement type="package" version="2.32.5">requests</requirement>
15+
<credentials name="swissmodel_api_credentials" version="1.0" label="SWISS-MODEL API Credentials" description="Credentials for accessing SWISS-MODEL API">
16+
<secret name="swissmodel_api_token" inject_as_env="SWISSMODEL_API_TOKEN" optional="false" label="SWISS-MODEL API token" description="Token to authenticate to the SWISS-MODEL API. Can be managed on your https://swissmodel.expasy.org/login_page"/>
17+
</credentials>
1118
</requirements>
1219
<command detect_errors="aggressive"><![CDATA[
1320
mkdir -p 'output_dir/'
@@ -27,7 +34,7 @@ mkdir -p 'output_dir/'
2734
--template-file '${template_file}'
2835
#end if
2936
'${project.project_type}'
30-
'${token}' output_dir
37+
output_dir
3138
#if $project_type == 'alignment'
3239
'${target_sequence}'
3340
#else
@@ -39,12 +46,6 @@ mkdir -p 'output_dir/'
3946
]]>
4047
</command>
4148
<inputs>
42-
<param name="token" type="text" optional="false" label="API token">
43-
<help><![CDATA[
44-
Token to authenticate to the SWISS-MODEL API. Can be managed on your
45-
<a href="https://swissmodel.expasy.org/login_page" target="_blank"> SWISS-MODEL account</a> page.
46-
]]></help>
47-
</param>
4849
<param name="project_title" type="text" value="Untitled project" optional="true" label="Project title"/>
4950
<conditional name="project">
5051
<param name="project_type" type="select" value="automodel" optional="false" label="Modelling setup" display="radio">
@@ -140,7 +141,7 @@ sequence.
140141
</assert_stderr>
141142
</test>
142143
<!-- with sequences, everything else empty, fail -->
143-
<test expect_exit_code="2" expect_failure="true">
144+
<test expect_exit_code="1" expect_failure="true">
144145
<conditional name="project">
145146
<repeat name="target_list">
146147
<param name="sequence" value="MVVKAVCVINGDAKGTVFFEQESSGTPVKVSGEVCGL"/>
@@ -150,19 +151,7 @@ sequence.
150151
</repeat>
151152
</conditional>
152153
<assert_stderr>
153-
<has_line line="Argument of '&lt;TOKEN&gt;' can not be an empty string"/>
154-
</assert_stderr>
155-
</test>
156-
<!-- sequence and token (complete automodel job), fail (no real token) -->
157-
<test expect_exit_code="1" expect_failure="true">
158-
<conditional name="project">
159-
<repeat name="target_list">
160-
<param name="sequence" value="MVVKAVCVINGDAKGTVFFEQESSGTPVKVSGEVCGL"/>
161-
</repeat>
162-
</conditional>
163-
<param name="token" value="NOTAVALIDTOKEN"/>
164-
<assert_stderr>
165-
<has_line line="RuntimeError: Submitting modelling job failed (401)"/>
154+
<has_line line="SWISS-MODEL token is not provided in credentials!"/>
166155
</assert_stderr>
167156
</test>
168157
<!-- alignment mode tests, as few params as possible, fail -->
@@ -216,21 +205,6 @@ sequence.
216205
</assert_stderr>
217206
</test>
218207
<!-- alignment mode tests, with sequence, fail -->
219-
<test expect_exit_code="2" expect_failure="true">
220-
<conditional name="project">
221-
<param name="assembly_id" value="0"/>
222-
<param name="auth_asym_id" value="A"/>
223-
<param name="pdb_id" value="1AKE"/>
224-
<param name="project_type" value="alignment"/>
225-
<param name="target_sequence" value="MVVKAVCVINGDAKGTVFFEQESSGTPVKVSG"/>
226-
<param name="template_seqres_offset" value="0"/>
227-
<param name="template_sequence" value="MVVKAVCVINGDAKGTVFFEQESSGTPV"/>
228-
</conditional>
229-
<assert_stderr>
230-
<has_line line="Argument of '&lt;TOKEN&gt;' can not be an empty string"/>
231-
</assert_stderr>
232-
</test>
233-
<!-- alignment mode tests, with token, fail -->
234208
<test expect_exit_code="1" expect_failure="true">
235209
<conditional name="project">
236210
<param name="assembly_id" value="0"/>
@@ -241,9 +215,8 @@ sequence.
241215
<param name="template_seqres_offset" value="0"/>
242216
<param name="template_sequence" value="MVVKAVCVINGDAKGTVFFEQESSGTPV"/>
243217
</conditional>
244-
<param name="token" value="NOTAVALIDTOKEN"/>
245218
<assert_stderr>
246-
<has_line line="RuntimeError: Submitting modelling job failed (401)"/>
219+
<has_line line="SWISS-MODEL token is not provided in credentials!"/>
247220
</assert_stderr>
248221
</test>
249222
<!-- usertemplate mode tests, as few params as possible, fail -->
@@ -257,22 +230,6 @@ sequence.
257230
</assert_stderr>
258231
</test>
259232
<!-- usertemplate mode tests, with sequence, fail -->
260-
<test expect_exit_code="2" expect_failure="true">
261-
<conditional name="project">
262-
<param name="project_type" value="usertemplate"/>
263-
<param name="template_file" value="model_01.pdb"/>
264-
<repeat name="target_list">
265-
<param name="sequence" value="MVVKAVCVINGDAKGTVFFEQESSGTPVKVSGEVCGL"/>
266-
</repeat>
267-
<repeat name="target_list">
268-
<param name="sequence" value="AKGLHGFHVHEFGDNTNGCMSSGPHFNPYGKE"/>
269-
</repeat>
270-
</conditional>
271-
<assert_stderr>
272-
<has_line line="Argument of '&lt;TOKEN&gt;' can not be an empty string"/>
273-
</assert_stderr>
274-
</test>
275-
<!-- usertemplate mode tests, with token, fail -->
276233
<test expect_exit_code="1" expect_failure="true">
277234
<conditional name="project">
278235
<param name="project_type" value="usertemplate"/>
@@ -284,9 +241,8 @@ sequence.
284241
<param name="sequence" value="AKGLHGFHVHEFGDNTNGCMSSGPHFNPYGKE"/>
285242
</repeat>
286243
</conditional>
287-
<param name="token" value="NOTAVALIDTOKEN"/>
288244
<assert_stderr>
289-
<has_line line="RuntimeError: Submitting modelling job failed (401)"/>
245+
<has_line line="SWISS-MODEL token is not provided in credentials!"/>
290246
</assert_stderr>
291247
</test>
292248
</tests>

0 commit comments

Comments
 (0)