From c9a15fcea6df7e511d199d9f539cf4e45cc61f67 Mon Sep 17 00:00:00 2001 From: simleo Date: Wed, 8 Nov 2023 16:30:24 +0100 Subject: [PATCH] convert: add encodingFormat to files when available --- src/runcrate/convert.py | 13 +++++++++---- tests/test_cwlprov_crate_builder.py | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/runcrate/convert.py b/src/runcrate/convert.py index 6957b56..ff48935 100644 --- a/src/runcrate/convert.py +++ b/src/runcrate/convert.py @@ -742,9 +742,9 @@ def patch_workflow_input_collection(self, crate, wf=None): if "ComputationalWorkflow" in as_list(tool.type): self.patch_workflow_input_collection(crate, wf=tool) - def _map_input_data(self, data): + def _map_input_data(self, crate, data): if isinstance(data, list): - return [self._map_input_data(_) for _ in data] + return [self._map_input_data(crate, _) for _ in data] if isinstance(data, dict): rval = {} for k, v in data.items(): @@ -756,8 +756,13 @@ def _map_input_data(self, data): source_k = str(source) dest = self.file_map.get(source_k) rval[k] = str(dest) if dest else v + fmt = data.get("format") + if fmt: + entity = crate.get(str(dest)) + if entity: + entity["encodingFormat"] = fmt else: - rval[k] = self._map_input_data(v) + rval[k] = self._map_input_data(crate, v) return rval return data @@ -766,7 +771,7 @@ def add_inputs_file(self, crate): if path.is_file(): with open(path) as f: data = json.load(f) - data = self._map_input_data(data) + data = self._map_input_data(crate, data) source = StringIO(json.dumps(data, indent=4)) crate.add_file(source, path.name, properties={ "name": "input object document", diff --git a/tests/test_cwlprov_crate_builder.py b/tests/test_cwlprov_crate_builder.py index 2ec6f9c..0f6404d 100644 --- a/tests/test_cwlprov_crate_builder.py +++ b/tests/test_cwlprov_crate_builder.py @@ -96,6 +96,7 @@ def test_revsort(data_dir, tmpdir): assert entity["alternateName"] == "whale.txt" assert entity["sha1"] == entity.id.rsplit("/")[-1] assert entity["contentSize"] == "1111" + assert "encodingFormat" in entity wf_input_file = entity wf_output_file = wf_results[0] assert wf_output_file["alternateName"] == "output.txt"