Skip to content

Commit

Permalink
Merge pull request #15971 from davelopez/23.0_fix_rocrate_invocation_…
Browse files Browse the repository at this point in the history
…export_collections

[23.0] Fix RO-crate invocation export with complex collections
  • Loading branch information
bgruening authored Apr 20, 2023
2 parents 3a90b83 + a9c8820 commit 102aed5
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions lib/galaxy/model/store/ro_crate_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import (
Any,
Dict,
Optional,
)

from rocrate.model.computationalworkflow import (
Expand Down Expand Up @@ -46,11 +47,6 @@ def __init__(self, model_store: Any):
self.model_store = model_store
self.invocation: WorkflowInvocation = model_store.included_invocations[0]
self.workflow: Workflow = self.invocation.workflow
self.collection_type_mapping = {
"list": "https://training.galaxyproject.org/training-material/faqs/galaxy/collections_build_list.html",
"paired": "https://training.galaxyproject.org/training-material/faqs/galaxy/collections_build_list_paired.html",
None: "https://training.galaxyproject.org/training-material/faqs/galaxy/collections_build_list.html",
}
self.param_type_mapping = {
"integer": "Integer",
"text": "Text",
Expand All @@ -72,7 +68,6 @@ def __init__(self, model_store: Any):
"rules": "Text",
"directory_uri": "URI",
"drill_down": "Text",
None: "Text",
}

self.ignored_parameter_type = [
Expand Down Expand Up @@ -157,7 +152,7 @@ def _add_collection(self, hdca: HistoryDatasetCollectionAssociation, crate: ROCr
collection_properties = {
"name": name,
"@type": "Collection",
"additionalType": self.collection_type_mapping[hdca.collection.collection_type],
"additionalType": self._get_collection_additional_type(hdca.collection.collection_type),
"hasPart": dataset_ids,
"exampleOfWork": {"@id": f"#{hdca.type_id}-param"},
}
Expand All @@ -174,6 +169,16 @@ def _add_collection(self, hdca: HistoryDatasetCollectionAssociation, crate: ROCr

return collection_entity

def _get_collection_additional_type(self, collection_type: Optional[str]) -> str:
if collection_type and "paired" in collection_type:
return "https://training.galaxyproject.org/training-material/faqs/galaxy/collections_build_list_paired.html"
return "https://training.galaxyproject.org/training-material/faqs/galaxy/collections_build_list.html"

def _get_parameter_additional_type(self, parameter_type: Optional[str]) -> str:
if parameter_type in self.param_type_mapping:
return self.param_type_mapping[parameter_type]
return "Text"

def _add_collections(self, crate: ROCrate):
for wfdca in self.invocation.input_dataset_collections:
collection_entity = self._add_collection(wfdca.dataset_collection, crate)
Expand Down Expand Up @@ -356,7 +361,7 @@ def _add_step_parameter_fp(self, step: WorkflowInvocationStep, crate: ROCrate):
f"{param_id}-param",
properties={
"@type": "FormalParameter",
"additionalType": self.param_type_mapping[param_type],
"additionalType": self._get_parameter_additional_type(param_type),
"description": self._get_association_description(step.workflow_step),
"name": f"{param_id}",
"valueRequired": str(not step.workflow_step.input_optional),
Expand Down Expand Up @@ -387,7 +392,7 @@ def _add_step_tool_fp(self, step: WorkflowInvocationStep, tool_input: str, crate
f"{param_id}-param",
properties={
"@type": "FormalParameter",
"additionalType": self.param_type_mapping[param_type],
"additionalType": self._get_parameter_additional_type(param_type),
"description": self._get_association_description(step.workflow_step),
"name": f"{step.workflow_step.label}",
"valueRequired": str(not step.workflow_step.input_optional),
Expand Down

0 comments on commit 102aed5

Please sign in to comment.