diff --git a/lib/galaxy/model/store/ro_crate_utils.py b/lib/galaxy/model/store/ro_crate_utils.py index b6b583a57a77..33072d27baa1 100644 --- a/lib/galaxy/model/store/ro_crate_utils.py +++ b/lib/galaxy/model/store/ro_crate_utils.py @@ -123,25 +123,27 @@ def _add_file(self, dataset: HistoryDatasetAssociation, properties: Dict[Any, An def _add_files(self, crate: ROCrate): for wfda in self.invocation.input_datasets: if not self.file_entities.get(wfda.dataset.dataset.id): + dataset_formal_param = self._add_dataset_formal_parameter(wfda.dataset, crate) + crate.mainEntity.append_to("input", dataset_formal_param) properties = { - "exampleOfWork": {"@id": f"#{wfda.dataset.dataset.uuid}"}, + "exampleOfWork": {"@id": dataset_formal_param.id}, } file_entity = self._add_file(wfda.dataset, properties, crate) - dataset_formal_param = self._add_dataset_formal_parameter(wfda.dataset, crate) - crate.mainEntity.append_to("input", dataset_formal_param) self.create_action.append_to("object", file_entity) for wfda in self.invocation.output_datasets: if not self.file_entities.get(wfda.dataset.dataset.id): + dataset_formal_param = self._add_dataset_formal_parameter(wfda.dataset, crate) + crate.mainEntity.append_to("output", dataset_formal_param) properties = { - "exampleOfWork": {"@id": f"#{wfda.dataset.dataset.uuid}"}, + "exampleOfWork": {"@id": dataset_formal_param.id}, } file_entity = self._add_file(wfda.dataset, properties, crate) - dataset_formal_param = self._add_dataset_formal_parameter(wfda.dataset, crate) - crate.mainEntity.append_to("output", dataset_formal_param) self.create_action.append_to("result", file_entity) - def _add_collection(self, hdca: HistoryDatasetCollectionAssociation, crate: ROCrate) -> ContextEntity: + def _add_collection( + self, hdca: HistoryDatasetCollectionAssociation, crate: ROCrate, collection_formal_param: ContextEntity + ) -> ContextEntity: name = hdca.name dataset_ids = [] for hda in hdca.dataset_instances: @@ -158,7 +160,7 @@ def _add_collection(self, hdca: HistoryDatasetCollectionAssociation, crate: ROCr "@type": "Collection", "additionalType": self._get_collection_additional_type(hdca.collection.collection_type), "hasPart": dataset_ids, - "exampleOfWork": {"@id": f"#{hdca.type_id}-param"}, + "exampleOfWork": {"@id": collection_formal_param.id}, } collection_entity = crate.add( ContextEntity( @@ -185,14 +187,14 @@ def _get_parameter_additional_type(self, parameter_type: Optional[str]) -> str: def _add_collections(self, crate: ROCrate): for wfdca in self.invocation.input_dataset_collections: - collection_entity = self._add_collection(wfdca.dataset_collection, crate) collection_formal_param = self._add_collection_formal_parameter(wfdca.dataset_collection, crate) + collection_entity = self._add_collection(wfdca.dataset_collection, crate, collection_formal_param) crate.mainEntity.append_to("input", collection_formal_param) self.create_action.append_to("object", collection_entity) for wfdca in self.invocation.output_dataset_collections: - collection_entity = self._add_collection(wfdca.dataset_collection, crate) collection_formal_param = self._add_collection_formal_parameter(wfdca.dataset_collection, crate) + collection_entity = self._add_collection(wfdca.dataset_collection, crate, collection_formal_param) crate.mainEntity.append_to("output", collection_formal_param) self.create_action.append_to("result", collection_entity) @@ -336,31 +338,14 @@ def _add_profiles(self, crate: ROCrate): def _add_parameters(self, crate: ROCrate): for step in self.invocation.steps: if step.workflow_step.type == "parameter_input": - property_value = self._add_step_parameter_pv(step, crate) - formal_param = self._add_step_parameter_fp(step, crate) - crate.mainEntity.append_to("input", formal_param) + property_value = self._add_step_parameter(step, crate) self.create_action.append_to("object", property_value) - def _add_step_parameter_pv(self, step: WorkflowInvocationStep, crate: ROCrate): - param_id = step.workflow_step.label - return crate.add( - ContextEntity( - crate, - f"{param_id}-pv", - properties={ - "@type": "PropertyValue", - "name": f"{param_id}", - "value": step.output_value.value, - "exampleOfWork": {"@id": f"#{param_id}-param"}, - }, - ) - ) - - def _add_step_parameter_fp(self, step: WorkflowInvocationStep, crate: ROCrate): + def _add_step_parameter(self, step: WorkflowInvocationStep, crate: ROCrate) -> ContextEntity: param_id = step.workflow_step.label assert step.workflow_step.tool_inputs param_type = step.workflow_step.tool_inputs["parameter_type"] - return crate.add( + formal_param = crate.add( ContextEntity( crate, f"{param_id}-param", @@ -373,19 +358,16 @@ def _add_step_parameter_fp(self, step: WorkflowInvocationStep, crate: ROCrate): }, ) ) - - def _add_step_tool_pv(self, step: WorkflowInvocationStep, tool_input: str, crate: ROCrate): - param_id = tool_input - assert step.workflow_step.tool_inputs + crate.mainEntity.append_to("input", formal_param) return crate.add( ContextEntity( crate, f"{param_id}-pv", properties={ "@type": "PropertyValue", - "name": f"{step.workflow_step.label}", - "value": step.workflow_step.tool_inputs[tool_input], - "exampleOfWork": {"@id": f"#{param_id}-param"}, + "name": f"{param_id}", + "value": step.output_value.value, + "exampleOfWork": {"@id": formal_param.id}, }, ) ) @@ -419,7 +401,9 @@ def _add_dataset_formal_parameter(self, hda: HistoryDatasetAssociation, crate: R ) ) - def _add_collection_formal_parameter(self, hdca: HistoryDatasetCollectionAssociation, crate: ROCrate): + def _add_collection_formal_parameter( + self, hdca: HistoryDatasetCollectionAssociation, crate: ROCrate + ) -> ContextEntity: return crate.add( ContextEntity( crate,