django-to-galaxy 0.7.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- django_to_galaxy/__init__.py +1 -0
- django_to_galaxy/admin/__init__.py +13 -0
- django_to_galaxy/admin/galaxy_element.py +6 -0
- django_to_galaxy/admin/galaxy_instance.py +26 -0
- django_to_galaxy/admin/galaxy_output_file.py +79 -0
- django_to_galaxy/admin/galaxy_user.py +183 -0
- django_to_galaxy/admin/history.py +91 -0
- django_to_galaxy/admin/invocation.py +154 -0
- django_to_galaxy/admin/tag.py +17 -0
- django_to_galaxy/admin/utils.py +116 -0
- django_to_galaxy/admin/workflow.py +131 -0
- django_to_galaxy/api/__init__.py +0 -0
- django_to_galaxy/api/serializers/asymetricslugrelatedfield.py +31 -0
- django_to_galaxy/api/serializers/create_dataset_collection.py +118 -0
- django_to_galaxy/api/serializers/create_history.py +6 -0
- django_to_galaxy/api/serializers/galaxy_instance.py +10 -0
- django_to_galaxy/api/serializers/galaxy_output_file.py +17 -0
- django_to_galaxy/api/serializers/galaxy_user.py +20 -0
- django_to_galaxy/api/serializers/history.py +17 -0
- django_to_galaxy/api/serializers/invocation.py +22 -0
- django_to_galaxy/api/serializers/invoke_workflow.py +24 -0
- django_to_galaxy/api/serializers/upload_to_history.py +25 -0
- django_to_galaxy/api/serializers/workflow.py +41 -0
- django_to_galaxy/api/urls.py +53 -0
- django_to_galaxy/api/views/create_dataset_collection.py +461 -0
- django_to_galaxy/api/views/create_history.py +23 -0
- django_to_galaxy/api/views/galaxy_instance.py +13 -0
- django_to_galaxy/api/views/galaxy_output_file.py +15 -0
- django_to_galaxy/api/views/galaxy_user.py +13 -0
- django_to_galaxy/api/views/history.py +14 -0
- django_to_galaxy/api/views/invocation.py +45 -0
- django_to_galaxy/api/views/invoke_workflow.py +181 -0
- django_to_galaxy/api/views/upload_to_history.py +78 -0
- django_to_galaxy/api/views/workflow.py +14 -0
- django_to_galaxy/apps.py +6 -0
- django_to_galaxy/migrations/0001_new_initial.py +171 -0
- django_to_galaxy/migrations/0002_rename_state_history_galaxy_state_and_more.py +37 -0
- django_to_galaxy/migrations/0003_invocation_create_time.py +20 -0
- django_to_galaxy/migrations/0004_alter_galaxyuser_email_galaxyoutputfile.py +46 -0
- django_to_galaxy/migrations/0005_alter_galaxyoutputfile_invocation_and_more.py +37 -0
- django_to_galaxy/migrations/0006_tag_history_tags_workflow_tags.py +42 -0
- django_to_galaxy/migrations/0007_format_alter_history_tags_alter_workflow_tags_and_more.py +63 -0
- django_to_galaxy/migrations/0008_workflowinput_label.py +21 -0
- django_to_galaxy/migrations/0009_galaxyoutputfile_unique_galaxy_id_per_invocation.py +20 -0
- django_to_galaxy/migrations/0010_workflow__is_meta_workflow__step_jobs_count.py +23 -0
- django_to_galaxy/migrations/0011_rename__step_jobs_count_workflow__step_count_and_more.py +23 -0
- django_to_galaxy/migrations/0012_workflowinput_collection_type_and_more.py +136 -0
- django_to_galaxy/migrations/__init__.py +0 -0
- django_to_galaxy/models/__init__.py +8 -0
- django_to_galaxy/models/accepted_input.py +139 -0
- django_to_galaxy/models/galaxy_element.py +52 -0
- django_to_galaxy/models/galaxy_instance.py +29 -0
- django_to_galaxy/models/galaxy_output_file.py +53 -0
- django_to_galaxy/models/galaxy_user.py +94 -0
- django_to_galaxy/models/history.py +73 -0
- django_to_galaxy/models/invocation.py +251 -0
- django_to_galaxy/models/workflow.py +440 -0
- django_to_galaxy/schemas/__init__.py +0 -0
- django_to_galaxy/schemas/dataset.py +16 -0
- django_to_galaxy/settings.py +8 -0
- django_to_galaxy/templates/admin/import_workflows.html +89 -0
- django_to_galaxy/urls.py +3 -0
- django_to_galaxy/utils.py +61 -0
- django_to_galaxy/version.py +3 -0
- django_to_galaxy-0.7.0.0.dist-info/METADATA +17 -0
- django_to_galaxy-0.7.0.0.dist-info/RECORD +68 -0
- django_to_galaxy-0.7.0.0.dist-info/WHEEL +4 -0
- django_to_galaxy-0.7.0.0.dist-info/licenses/LICENSE +661 -0
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
from bioblend.galaxy.objects import wrappers
|
|
2
|
+
from django.db import models
|
|
3
|
+
from .history import History
|
|
4
|
+
from .invocation import Invocation
|
|
5
|
+
from .galaxy_element import GalaxyElement
|
|
6
|
+
|
|
7
|
+
from django_to_galaxy.utils import load_galaxy_invocation_time_to_datetime
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Workflow(GalaxyElement):
|
|
11
|
+
"""Table for Galaxy workflows."""
|
|
12
|
+
|
|
13
|
+
galaxy_owner = models.ForeignKey(
|
|
14
|
+
"GalaxyUser", null=False, on_delete=models.CASCADE, related_name="workflows"
|
|
15
|
+
)
|
|
16
|
+
"""Galaxy user that owns the workflow."""
|
|
17
|
+
_step_count = models.PositiveIntegerField(default=0)
|
|
18
|
+
"""Number of steps in the workflow."""
|
|
19
|
+
_is_meta = models.BooleanField(null=True, default=None, blank=True)
|
|
20
|
+
"""Indicates whether the workflow is a meta (i.e., has sub-workflows) or not."""
|
|
21
|
+
|
|
22
|
+
@property
|
|
23
|
+
def galaxy_workflow(self) -> wrappers.Workflow:
|
|
24
|
+
"""Galaxy object using bioblend."""
|
|
25
|
+
if getattr(self, "_galaxy_workflow", None) is None:
|
|
26
|
+
self._galaxy_workflow = self._get_galaxy_workflow()
|
|
27
|
+
return self._galaxy_workflow
|
|
28
|
+
|
|
29
|
+
def _get_galaxy_workflow(self) -> wrappers.Workflow:
|
|
30
|
+
"""Get galaxy object using bioblend."""
|
|
31
|
+
return self.galaxy_owner.obj_gi.workflows.get(self.galaxy_id)
|
|
32
|
+
|
|
33
|
+
def get_is_meta(self):
|
|
34
|
+
"""Sets / returns _is_meta value."""
|
|
35
|
+
if self._is_meta is None:
|
|
36
|
+
self._is_meta = False
|
|
37
|
+
for key, step_dict in self.galaxy_workflow.steps.items():
|
|
38
|
+
w = step_dict.wrapped
|
|
39
|
+
if "workflow_id" in w:
|
|
40
|
+
self._is_meta = True
|
|
41
|
+
break
|
|
42
|
+
self.save(update_fields=["_is_meta"])
|
|
43
|
+
return self._is_meta
|
|
44
|
+
|
|
45
|
+
def get_step_count(self):
|
|
46
|
+
"""Sets / returns _step_jobs_count value."""
|
|
47
|
+
if self._step_count == 0:
|
|
48
|
+
self._step_count = len(self.galaxy_workflow.steps)
|
|
49
|
+
self.save(update_fields=["_step_count"])
|
|
50
|
+
return self._step_count
|
|
51
|
+
|
|
52
|
+
def _get_tool_input(self, tool_label, tool):
|
|
53
|
+
"""
|
|
54
|
+
Retrieve a specific tool input dictionary from a Galaxy tool definition.
|
|
55
|
+
|
|
56
|
+
This method navigates the nested structure of a tool's inputs or conditional cases
|
|
57
|
+
to locate the input corresponding to `tool_label`. It supports labels that reference
|
|
58
|
+
nested inputs using a "|" separator.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
tool_label (str): The label of the input to retrieve. Can be a simple label
|
|
62
|
+
or a nested label separated by "|", e.g. "param_group|param_name".
|
|
63
|
+
tool (dict): The tool definition dictionary returned by Galaxy
|
|
64
|
+
(from gi.tools.show_tool),
|
|
65
|
+
which may contain:
|
|
66
|
+
- "inputs": a list of input dictionaries
|
|
67
|
+
- "cases": a list of conditional input cases
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
dict: The dictionary representing the requested input, including all its parameters.
|
|
71
|
+
If the input cannot be found, raises a ValueError or returns the original `tool`
|
|
72
|
+
if it has no matching inputs/cases.
|
|
73
|
+
|
|
74
|
+
Raises:
|
|
75
|
+
ValueError: If the target input cannot be found when navigating a nested label.
|
|
76
|
+
|
|
77
|
+
Notes:
|
|
78
|
+
- Nested labels separated by "|" are resolved recursively.
|
|
79
|
+
- Handles both regular "inputs" and conditional "cases".
|
|
80
|
+
- If no inputs or cases match the label, the original `tool` dictionary is returned
|
|
81
|
+
(for non-nested top-level tool access).
|
|
82
|
+
|
|
83
|
+
Example:
|
|
84
|
+
tool = {
|
|
85
|
+
"inputs": [{"name": "param1", "type": "text"},
|
|
86
|
+
{"name": "param2", "type": "integer"}]
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
_get_tool_input("param1", tool)
|
|
90
|
+
# Returns: {"name": "param1", "type": "text"}
|
|
91
|
+
|
|
92
|
+
tool = {
|
|
93
|
+
"cases": [{"inputs": [{"name": "choice1", "type": "text"}]}]
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
_get_tool_input("choice1", tool)
|
|
97
|
+
# Returns: {"name": "choice1", "type": "text"}
|
|
98
|
+
"""
|
|
99
|
+
if "|" in tool_label:
|
|
100
|
+
first, tool_label = tool_label.split("|", maxsplit=1)
|
|
101
|
+
if "inputs" in tool.keys():
|
|
102
|
+
for x in tool["inputs"]:
|
|
103
|
+
if x["name"] == first:
|
|
104
|
+
return self._get_tool_input(tool_label, x)
|
|
105
|
+
elif "cases" in tool.keys():
|
|
106
|
+
for x in tool["cases"]:
|
|
107
|
+
if x["inputs"]:
|
|
108
|
+
if x["inputs"][0]["name"] == first:
|
|
109
|
+
return self._get_tool_input(tool_label, x["inputs"][0])
|
|
110
|
+
else:
|
|
111
|
+
raise ValueError(
|
|
112
|
+
f"Cannot find the target tool from this tool label: {tool_label}."
|
|
113
|
+
)
|
|
114
|
+
else:
|
|
115
|
+
if "inputs" in tool.keys():
|
|
116
|
+
for x in tool["inputs"]:
|
|
117
|
+
if x["name"] == tool_label:
|
|
118
|
+
return x
|
|
119
|
+
elif "cases" in tool.keys():
|
|
120
|
+
for x in tool["cases"]:
|
|
121
|
+
if x["inputs"]:
|
|
122
|
+
if x["inputs"][0]["name"] == tool_label:
|
|
123
|
+
return x["inputs"][0]
|
|
124
|
+
else:
|
|
125
|
+
return tool
|
|
126
|
+
|
|
127
|
+
def _get_subworkflow_inputs(self, gi, input_mapping):
|
|
128
|
+
"""
|
|
129
|
+
Recursively retrieve input information from subworkflows linked to a parameter input.
|
|
130
|
+
|
|
131
|
+
This private method inspects the subworkflow referenced in `input_mapping["target_subwf"]`
|
|
132
|
+
and updates the mapping with tools or nested subworkflows that consume the input.
|
|
133
|
+
It handles multiple levels of nested subworkflows recursively.
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
gi (GalaxyInstance): The Galaxy instance object (typically
|
|
137
|
+
`self.galaxy_owner.obj_gi.gi`) used to query workflows and tool details.
|
|
138
|
+
input_mapping (dict): A dictionary representing a single parameter input.
|
|
139
|
+
It must contain:
|
|
140
|
+
- `has_subwf` (bool): True if the input is consumed by a subworkflow.
|
|
141
|
+
- `target_subwf` (dict): Information about the first subworkflow that consumes
|
|
142
|
+
the input:
|
|
143
|
+
- `workflow_id` (str): ID of the subworkflow
|
|
144
|
+
- `input_name` (str): Name of the input in the subworkflow
|
|
145
|
+
- `target_tools` (list): List of tools that consume the input (will be updated)
|
|
146
|
+
- `has_tool` (bool): Flag indicating whether a tool consumes the input (may be
|
|
147
|
+
updated)
|
|
148
|
+
|
|
149
|
+
Returns:
|
|
150
|
+
dict: The updated `input_mapping` with:
|
|
151
|
+
- `target_tools` populated with tools consuming the input from the subworkflow
|
|
152
|
+
- `target_subwf` updated if nested subworkflows exist
|
|
153
|
+
- `has_subwf` set to False once all subworkflow inputs have been resolved
|
|
154
|
+
|
|
155
|
+
Notes:
|
|
156
|
+
- This function uses recursion to traverse multiple levels of nested subworkflows.
|
|
157
|
+
- It only processes the first subworkflow consuming the input at each level.
|
|
158
|
+
- The function distinguishes between steps of type `"tool"` and `"subworkflow"`.
|
|
159
|
+
|
|
160
|
+
Example:
|
|
161
|
+
Before:
|
|
162
|
+
{
|
|
163
|
+
"label": "Parameter X",
|
|
164
|
+
"type": "parameter_input",
|
|
165
|
+
"target_tools": [],
|
|
166
|
+
"target_subwf": {"input_name": "sub_input", "workflow_id": "wf_123"},
|
|
167
|
+
"has_subwf": True
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
After:
|
|
171
|
+
{
|
|
172
|
+
"label": "Parameter X",
|
|
173
|
+
"type": "parameter_input",
|
|
174
|
+
"target_tools": [
|
|
175
|
+
{"input_name": "param1", "tool_id": "tool_456"}
|
|
176
|
+
],
|
|
177
|
+
"target_subwf": None,
|
|
178
|
+
"has_subwf": False
|
|
179
|
+
}
|
|
180
|
+
"""
|
|
181
|
+
|
|
182
|
+
if not input_mapping["has_subwf"]:
|
|
183
|
+
return input_mapping
|
|
184
|
+
|
|
185
|
+
subworkflow_id = input_mapping["target_subwf"]["workflow_id"]
|
|
186
|
+
input_label = input_mapping["target_subwf"]["input_name"]
|
|
187
|
+
|
|
188
|
+
# Get the subworkflow information
|
|
189
|
+
data = gi.workflows.show_workflow(subworkflow_id, instance=True)
|
|
190
|
+
|
|
191
|
+
input_keys = {v["label"]: k for k, v in data["inputs"].items()}
|
|
192
|
+
steps = data["steps"]
|
|
193
|
+
source_id = str(steps[input_keys[input_label]]["id"])
|
|
194
|
+
|
|
195
|
+
step_ids = list(steps.keys())
|
|
196
|
+
|
|
197
|
+
for step_id in step_ids:
|
|
198
|
+
input_steps = steps[step_id].get("input_steps", {})
|
|
199
|
+
for input_name, input_details in input_steps.items():
|
|
200
|
+
if str(input_details.get("source_step")) == source_id:
|
|
201
|
+
if steps[step_id].get("type") == "tool":
|
|
202
|
+
input_mapping["target_tools"].append(
|
|
203
|
+
{
|
|
204
|
+
"input_name": input_name,
|
|
205
|
+
"tool_id": steps[step_id]["tool_id"],
|
|
206
|
+
}
|
|
207
|
+
)
|
|
208
|
+
input_mapping["has_subwf"] = False
|
|
209
|
+
|
|
210
|
+
elif steps[step_id].get("type") == "subworkflow":
|
|
211
|
+
if not input_mapping["has_subwf"]:
|
|
212
|
+
input_mapping["target_subwf"] = {
|
|
213
|
+
"input_name": input_name,
|
|
214
|
+
"workflow_id": steps[step_id]["workflow_id"],
|
|
215
|
+
}
|
|
216
|
+
input_mapping["has_subwf"] = True
|
|
217
|
+
|
|
218
|
+
return self._get_subworkflow_inputs(gi, input_mapping)
|
|
219
|
+
|
|
220
|
+
def get_workflow_inputs(self):
|
|
221
|
+
"""
|
|
222
|
+
Retrieve detailed information about all inputs of a Galaxy workflow.
|
|
223
|
+
|
|
224
|
+
This method processes a `Workflow` instance from `django-to-galaxy` and returns
|
|
225
|
+
a dictionary describing each input, whether it is a `data_input` or a `parameter_input`.
|
|
226
|
+
|
|
227
|
+
For each input, the returned information includes:
|
|
228
|
+
- `label`: the human-readable label of the input
|
|
229
|
+
- `type`: the type of input (`data_input` or `parameter_input`)
|
|
230
|
+
- `tool_inputs`: the dictionary of tool inputs associated with the step
|
|
231
|
+
- `target_tools`: for parameter inputs, a list of tools that consume this input
|
|
232
|
+
- Each entry includes:
|
|
233
|
+
- `input_name`: the name of the input in the target tool
|
|
234
|
+
- `tool_id`: the Galaxy ID of the tool
|
|
235
|
+
- `tool_input`: the detailed tool input specification (retrieved later)
|
|
236
|
+
- `target_subwf`: for parameter inputs, the first subworkflow that consumes this input
|
|
237
|
+
- Includes:
|
|
238
|
+
- `input_name`: the name of the input in the subworkflow
|
|
239
|
+
- `workflow_id`: the ID of the subworkflow
|
|
240
|
+
- `has_tool`: boolean flag indicating if any tool consumes this input
|
|
241
|
+
- `has_subwf`: boolean flag indicating if any subworkflow consumes this input
|
|
242
|
+
|
|
243
|
+
The function also handles nested subworkflows and retrieves input information
|
|
244
|
+
for subworkflow parameters using `_get_subworkflow_inputs`. Tool-specific input
|
|
245
|
+
details are retrieved using `_get_tool_input`.
|
|
246
|
+
|
|
247
|
+
Args:
|
|
248
|
+
self: A workflow wrapper instance containing:
|
|
249
|
+
- `self.galaxy_workflow`: the Galaxy workflow object
|
|
250
|
+
- `self.galaxy_owner.obj_gi.gi`: Galaxy instance handle
|
|
251
|
+
|
|
252
|
+
Returns:
|
|
253
|
+
dict: A mapping of input IDs to detailed information, for example:
|
|
254
|
+
|
|
255
|
+
{
|
|
256
|
+
"0": {
|
|
257
|
+
"label": "Input dataset",
|
|
258
|
+
"type": "data_input",
|
|
259
|
+
"tool_inputs": {...},
|
|
260
|
+
},
|
|
261
|
+
"1": {
|
|
262
|
+
"label": "Threshold",
|
|
263
|
+
"type": "parameter_input",
|
|
264
|
+
"tool_inputs": {...},
|
|
265
|
+
"target_tools": [
|
|
266
|
+
{
|
|
267
|
+
"input_name": "param1",
|
|
268
|
+
"tool_id": "toolshed.g2.bx.psu.edu/repos/.../tool/1",
|
|
269
|
+
"tool_input": {...},
|
|
270
|
+
}
|
|
271
|
+
],
|
|
272
|
+
"target_subwf": {
|
|
273
|
+
"input_name": "subwf_input",
|
|
274
|
+
"workflow_id": "wf_123",
|
|
275
|
+
},
|
|
276
|
+
"has_tool": True,
|
|
277
|
+
"has_subwf": True,
|
|
278
|
+
},
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
Known caveats:
|
|
282
|
+
- Cannot retrieve the tool input if the tool has sections (e.g., `tooldistillator`
|
|
283
|
+
tool).
|
|
284
|
+
- Only the first subworkflow consuming a parameter input is inspected.
|
|
285
|
+
|
|
286
|
+
"""
|
|
287
|
+
gi = self.galaxy_owner.obj_gi.gi
|
|
288
|
+
|
|
289
|
+
inputs = self.galaxy_workflow.inputs
|
|
290
|
+
steps = self.galaxy_workflow.steps
|
|
291
|
+
steps = {k: v.wrapped for k, v in steps.items()}
|
|
292
|
+
steps_ids = list(steps.keys())
|
|
293
|
+
|
|
294
|
+
# Initialization
|
|
295
|
+
input_mapping = {}
|
|
296
|
+
parameter_input_ids = []
|
|
297
|
+
|
|
298
|
+
for input_id, input_dict in inputs.items():
|
|
299
|
+
input_mapping[input_id] = {}
|
|
300
|
+
input_mapping[input_id]["label"] = input_dict["label"]
|
|
301
|
+
input_mapping[input_id]["type"] = steps[input_id]["type"]
|
|
302
|
+
input_mapping[input_id]["tool_inputs"] = steps[input_id]["tool_inputs"]
|
|
303
|
+
|
|
304
|
+
if steps[input_id]["type"] == "parameter_input":
|
|
305
|
+
parameter_input_ids.append(input_id)
|
|
306
|
+
steps_ids.remove(input_id)
|
|
307
|
+
input_mapping[input_id]["target_tools"] = []
|
|
308
|
+
input_mapping[input_id]["target_subwf"] = None
|
|
309
|
+
input_mapping[input_id]["has_tool"] = False
|
|
310
|
+
input_mapping[input_id]["has_subwf"] = False
|
|
311
|
+
|
|
312
|
+
for target_id in parameter_input_ids:
|
|
313
|
+
for step_id in steps_ids:
|
|
314
|
+
input_steps = steps[step_id].get("input_steps", {})
|
|
315
|
+
for input_name, input_details in input_steps.items():
|
|
316
|
+
if input_details.get("source_step") == target_id:
|
|
317
|
+
if steps[step_id].get("type") == "tool":
|
|
318
|
+
input_mapping[target_id]["target_tools"].append(
|
|
319
|
+
{
|
|
320
|
+
"input_name": input_name,
|
|
321
|
+
"tool_id": steps[step_id]["tool_id"],
|
|
322
|
+
}
|
|
323
|
+
)
|
|
324
|
+
input_mapping[target_id]["has_tool"] = True
|
|
325
|
+
elif steps[step_id].get("type") == "subworkflow":
|
|
326
|
+
if not input_mapping[target_id]["has_subwf"]:
|
|
327
|
+
input_mapping[target_id]["target_subwf"] = {
|
|
328
|
+
"input_name": input_name,
|
|
329
|
+
"workflow_id": steps[step_id]["workflow_id"],
|
|
330
|
+
}
|
|
331
|
+
input_mapping[target_id]["has_subwf"] = True
|
|
332
|
+
|
|
333
|
+
# Then search for subworkflows
|
|
334
|
+
# For each input just search in the first subworkflow to get the parameters information
|
|
335
|
+
for k in input_mapping.keys():
|
|
336
|
+
if "target_subwf" in input_mapping[k].keys():
|
|
337
|
+
input_mapping[k] = self._get_subworkflow_inputs(gi, input_mapping[k])
|
|
338
|
+
|
|
339
|
+
# Then search input information in tools
|
|
340
|
+
for k in input_mapping.keys():
|
|
341
|
+
if "target_tools" in input_mapping[k].keys():
|
|
342
|
+
for kk in input_mapping[k]["target_tools"]:
|
|
343
|
+
tool_label = kk["input_name"]
|
|
344
|
+
tool = gi.tools.show_tool(
|
|
345
|
+
kk["tool_id"],
|
|
346
|
+
io_details=True,
|
|
347
|
+
link_details=True,
|
|
348
|
+
)
|
|
349
|
+
kk["tool_input"] = self._get_tool_input(tool_label, tool)
|
|
350
|
+
|
|
351
|
+
return input_mapping
|
|
352
|
+
|
|
353
|
+
def get_workflow_datamap_template(self):
|
|
354
|
+
"""
|
|
355
|
+
Generate a template of the datamap required to invoke a Galaxy workflow.
|
|
356
|
+
|
|
357
|
+
This method inspects the workflow's inputs and steps, and constructs:
|
|
358
|
+
1. `input_mapping`: a dictionary describing each input, including its label and type.
|
|
359
|
+
2. `datamap_template`: a dictionary with default placeholders for input values
|
|
360
|
+
suitable for workflow invocation.
|
|
361
|
+
|
|
362
|
+
Input types are handled as follows:
|
|
363
|
+
- "parameter_input": the parameter type from the tool inputs is returned as default.
|
|
364
|
+
- "data_input": a dictionary with {"id": "", "src": "hda"}.
|
|
365
|
+
- "data_collection_input": a dictionary with {"id": "", "src": "hdca"}.
|
|
366
|
+
|
|
367
|
+
Returns:
|
|
368
|
+
dict: A dictionary containing two keys:
|
|
369
|
+
- "input_mapping" (dict): maps input IDs to dictionaries with:
|
|
370
|
+
- "label": human-readable label of the input
|
|
371
|
+
- "type": type of input ("parameter_input", "data_input", or
|
|
372
|
+
"data_collection_input")
|
|
373
|
+
- "datamap_template" (dict): maps input IDs to default values/placeholders
|
|
374
|
+
appropriate for workflow invocation.
|
|
375
|
+
|
|
376
|
+
Example:
|
|
377
|
+
{
|
|
378
|
+
"input_mapping": {
|
|
379
|
+
"0": {"label": "Input dataset", "type": "data_input"},
|
|
380
|
+
"1": {"label": "Threshold", "type": "parameter_input"}
|
|
381
|
+
},
|
|
382
|
+
"datamap_template": {
|
|
383
|
+
"0": {"id": "", "src": "hda"},
|
|
384
|
+
"1": "integer"
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
"""
|
|
388
|
+
|
|
389
|
+
inputs = self.galaxy_workflow.inputs
|
|
390
|
+
steps = self.galaxy_workflow.steps
|
|
391
|
+
steps = {k: v.wrapped for k, v in steps.items()}
|
|
392
|
+
|
|
393
|
+
input_mapping = {}
|
|
394
|
+
datamap_template = {}
|
|
395
|
+
|
|
396
|
+
for input_id, input_dict in inputs.items():
|
|
397
|
+
input_mapping[input_id] = {}
|
|
398
|
+
input_mapping[input_id]["label"] = input_dict["label"]
|
|
399
|
+
input_mapping[input_id]["type"] = steps[input_id]["type"]
|
|
400
|
+
|
|
401
|
+
if steps[input_id]["type"] == "parameter_input":
|
|
402
|
+
datamap_template[input_id] = steps[input_id]["tool_inputs"][
|
|
403
|
+
"parameter_type"
|
|
404
|
+
]
|
|
405
|
+
elif steps[input_id]["type"] == "data_input":
|
|
406
|
+
datamap_template[input_id] = {"id": "", "src": "hda"}
|
|
407
|
+
elif steps[input_id]["type"] == "data_collection_input":
|
|
408
|
+
datamap_template[input_id] = {"id": "", "src": "hdca"}
|
|
409
|
+
|
|
410
|
+
return {"input_mapping": input_mapping, "datamap_template": datamap_template}
|
|
411
|
+
|
|
412
|
+
def invoke(self, datamap: dict, history: History) -> wrappers.Invocation:
|
|
413
|
+
"""
|
|
414
|
+
Invoke workflow using bioblend.
|
|
415
|
+
|
|
416
|
+
Args:
|
|
417
|
+
datamap: dictionnary to link dataset to workflow inputs
|
|
418
|
+
history: history obj the dataset(s) come from
|
|
419
|
+
|
|
420
|
+
Returns:
|
|
421
|
+
Invocation object from bioblend
|
|
422
|
+
"""
|
|
423
|
+
galaxy_inv = self.galaxy_workflow.invoke(
|
|
424
|
+
datamap, history=history.galaxy_history
|
|
425
|
+
)
|
|
426
|
+
# Create invocations
|
|
427
|
+
invocation = Invocation(
|
|
428
|
+
galaxy_id=galaxy_inv.id,
|
|
429
|
+
galaxy_state=galaxy_inv.state,
|
|
430
|
+
workflow=self,
|
|
431
|
+
history=history,
|
|
432
|
+
create_time=load_galaxy_invocation_time_to_datetime(galaxy_inv),
|
|
433
|
+
)
|
|
434
|
+
invocation.save()
|
|
435
|
+
# Create output files
|
|
436
|
+
invocation.create_output_files()
|
|
437
|
+
return invocation
|
|
438
|
+
|
|
439
|
+
def __repr__(self):
|
|
440
|
+
return f"Workflow: {super().__str__()}"
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
from pydantic import BaseModel
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SimpleDataset(BaseModel):
|
|
5
|
+
"""Simple model for dataset from history."""
|
|
6
|
+
|
|
7
|
+
id: str
|
|
8
|
+
"""ID of the dataset."""
|
|
9
|
+
name: str
|
|
10
|
+
"""Name of the dataset."""
|
|
11
|
+
data_type: str
|
|
12
|
+
"""Type of dataset."""
|
|
13
|
+
|
|
14
|
+
def generate_datamap(self, tool_id):
|
|
15
|
+
"""Generate datamap to invoke workflow."""
|
|
16
|
+
return {tool_id: {"id": self.id, "src": "hda"}}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{% extends "admin/base_site.html" %}
|
|
2
|
+
|
|
3
|
+
{% block title %}Import workflows{% endblock %}
|
|
4
|
+
|
|
5
|
+
{% block breadcrumbs %}
|
|
6
|
+
<div class="breadcrumbs">
|
|
7
|
+
<a href="/admin/">Home</a>
|
|
8
|
+
>
|
|
9
|
+
<a href="/admin/django_to_galaxy/">Django to Galaxy</a>
|
|
10
|
+
>
|
|
11
|
+
<a href="/admin/django_to_galaxy/galaxyuser/">Galaxy users</a>
|
|
12
|
+
> Import workflows
|
|
13
|
+
</div>
|
|
14
|
+
{% endblock %}
|
|
15
|
+
|
|
16
|
+
{% block content %}
|
|
17
|
+
|
|
18
|
+
<h1>Import workflows</h1>
|
|
19
|
+
<div>
|
|
20
|
+
<ul>
|
|
21
|
+
<li><b>User:</b> {{ galaxy_user.email }}</li>
|
|
22
|
+
<li><b>Galaxy Instance:</b> {{ galaxy_user.galaxy_instance.url }}</li>
|
|
23
|
+
</ul>
|
|
24
|
+
</div>
|
|
25
|
+
{% if existing_workflows %}
|
|
26
|
+
<div>
|
|
27
|
+
<h2>
|
|
28
|
+
Already present on the application:
|
|
29
|
+
</h2>
|
|
30
|
+
<table>
|
|
31
|
+
<tr>
|
|
32
|
+
<th>Name</th>
|
|
33
|
+
<th>Galaxy ID</th>
|
|
34
|
+
<th>Annotation</th>
|
|
35
|
+
<th>Published</th>
|
|
36
|
+
<th>Tags</th>
|
|
37
|
+
</tr>
|
|
38
|
+
{% for wf in existing_workflows %}
|
|
39
|
+
<tr>
|
|
40
|
+
<td> {{ wf.name }}</td>
|
|
41
|
+
<td> {{ wf.galaxy_id }}</td>
|
|
42
|
+
<td> {{ wf.annotation }}</td>
|
|
43
|
+
<td> {{ wf.published }}</td>
|
|
44
|
+
<td>
|
|
45
|
+
{% for tag in wf.tags.all %}
|
|
46
|
+
{{ tag.label }}
|
|
47
|
+
{% endfor %}
|
|
48
|
+
</td>
|
|
49
|
+
</tr>
|
|
50
|
+
{% endfor %}
|
|
51
|
+
</table>
|
|
52
|
+
</div>
|
|
53
|
+
{% endif %}
|
|
54
|
+
<div>
|
|
55
|
+
<h2>List of available workflow(s):</h2>
|
|
56
|
+
|
|
57
|
+
<p>Please select the workflow(s) you would like to add to the application from the following list:</p>
|
|
58
|
+
|
|
59
|
+
<form method="post">
|
|
60
|
+
{% csrf_token %}
|
|
61
|
+
<table>
|
|
62
|
+
<tr>
|
|
63
|
+
<th>Import</th>
|
|
64
|
+
<th>Name</th>
|
|
65
|
+
<th>Galaxy ID</th>
|
|
66
|
+
<th>Annotation</th>
|
|
67
|
+
<th>Published</th>
|
|
68
|
+
<th>Tags</th>
|
|
69
|
+
</tr>
|
|
70
|
+
{% for wf, tags in new_workflows %}
|
|
71
|
+
<tr>
|
|
72
|
+
<td> <input type="checkbox" name="save_to_app" value="{{wf.galaxy_id}}" /></td>
|
|
73
|
+
<td> {{ wf.name }}</td>
|
|
74
|
+
<td> {{ wf.galaxy_id }}</td>
|
|
75
|
+
<td> {{ wf.annotation }}</td>
|
|
76
|
+
<td> {{ wf.published }}</td>
|
|
77
|
+
<td>
|
|
78
|
+
{% for tag in tags %}
|
|
79
|
+
{{ tag }}
|
|
80
|
+
{% endfor %}
|
|
81
|
+
</td>
|
|
82
|
+
|
|
83
|
+
</tr>
|
|
84
|
+
{% endfor %}
|
|
85
|
+
</table>
|
|
86
|
+
<input type="submit" name="apply" value="Import selected workflow(s)" />
|
|
87
|
+
</form>
|
|
88
|
+
</div>
|
|
89
|
+
{% endblock %}
|
django_to_galaxy/urls.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from contextlib import contextmanager
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
|
|
4
|
+
from bioblend.galaxy.objects import wrappers
|
|
5
|
+
from requests_cache import install_cache, uninstall_cache
|
|
6
|
+
|
|
7
|
+
from django_to_galaxy.settings import settings
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def load_galaxy_time_to_datetime(galaxy_time: str) -> datetime:
|
|
11
|
+
"""
|
|
12
|
+
Parse str time from galaxy to datetime.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
galaxy_time: galaxy time
|
|
16
|
+
Returns:
|
|
17
|
+
datetime object of the parsed string
|
|
18
|
+
"""
|
|
19
|
+
return datetime.strptime(galaxy_time, settings.GALAXY_TIME_FORMAT)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def load_galaxy_history_time_to_datetime(galaxy_history: wrappers.History) -> datetime:
|
|
23
|
+
"""
|
|
24
|
+
Parse time from galaxy history object to datetime.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
galaxy_history: Galaxy history instance
|
|
28
|
+
Returns:
|
|
29
|
+
datetime object of the parsed string
|
|
30
|
+
"""
|
|
31
|
+
return load_galaxy_time_to_datetime(galaxy_history.wrapped["create_time"])
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def load_galaxy_invocation_time_to_datetime(
|
|
35
|
+
galaxy_invocation: wrappers.Invocation,
|
|
36
|
+
) -> datetime:
|
|
37
|
+
"""
|
|
38
|
+
Parse time from galaxy invocation object to datetime.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
galaxy_invocation: Galaxy invocation instance
|
|
42
|
+
Returns:
|
|
43
|
+
datetime object of the parsed string
|
|
44
|
+
"""
|
|
45
|
+
return load_galaxy_time_to_datetime(galaxy_invocation.wrapped["create_time"])
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@contextmanager
|
|
49
|
+
def enabled_cache():
|
|
50
|
+
"""
|
|
51
|
+
Context manager for temporarily enabling caching for all ``requests`` functions.
|
|
52
|
+
|
|
53
|
+
This aims to be the place to set parameters for requests_cache in the future.
|
|
54
|
+
|
|
55
|
+
Inspired from requests_cache.enabled context manager.
|
|
56
|
+
"""
|
|
57
|
+
install_cache()
|
|
58
|
+
try:
|
|
59
|
+
yield
|
|
60
|
+
finally:
|
|
61
|
+
uninstall_cache()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: django-to-galaxy
|
|
3
|
+
Version: 0.7.0.0
|
|
4
|
+
Summary: Django extension that eases communication with Galaxy instance to execute workflows.
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Author: Kenzo-Hugo Hillion
|
|
7
|
+
Author-email: hillion.kenzo@posteo.net
|
|
8
|
+
Requires-Python: ==3.11.*
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
+
Requires-Dist: Django (>=5.1.1,<6.0.0)
|
|
12
|
+
Requires-Dist: Markdown (>=3.3.6,<4.0.0)
|
|
13
|
+
Requires-Dist: bioblend (>=1.6.0,<2.0.0)
|
|
14
|
+
Requires-Dist: djangorestframework (>=3.13.1,<4.0.0)
|
|
15
|
+
Requires-Dist: pydantic (>=2.11.0,<3.0.0)
|
|
16
|
+
Requires-Dist: pydantic-settings (>=2.9.0,<3.0.0)
|
|
17
|
+
Requires-Dist: requests-cache (>=0.9.5,<0.10.0)
|