diff --git a/bids_prov/merge.py b/bids_prov/merge.py index b5b6de3e..b9f80e37 100644 --- a/bids_prov/merge.py +++ b/bids_prov/merge.py @@ -33,7 +33,7 @@ def get_associated_sidecar(layout: BIDSLayout, data_file: BIDSFile) -> dict: return layout.get_file(sidecar_filename) def filter_provenance_group(files: list, group: str) -> list: - """ Filter a given BIDSFile list, returning the sub-list containig the BIDS + """ Filter a given BIDSFile list, returning the sub-list containing the BIDS `prov` entity equal to group """ return [f for f in files if f'prov-{group}' in f.filename] @@ -62,10 +62,15 @@ def get_described_datasets(layout: BIDSLayout) -> list: for file in files: metadata = file.get_dict() if 'GeneratedBy' in metadata: - for generated_by_obj in metadata['GeneratedBy']: - if 'Id' in generated_by_obj: - out_files.append(file) - break + # If GeneratedBy is either a list of objects or a list of activity ids + if isinstance(metadata['GeneratedBy'], list): + for generated_by_obj in metadata['GeneratedBy']: + if 'Name' not in generated_by_obj: + out_files.append(file) + break + # If GeneratedBy is an activity id + else: + out_files.append(file) return out_files @@ -98,9 +103,12 @@ def get_dataset_entity_record(description_file: BIDSJSONFile) -> dict: } # Get provenance-related metadata - for generated_by_obj in metadata['GeneratedBy']: - if 'Id' in generated_by_obj: - entity['GeneratedBy'].append(generated_by_obj['Id']) + if isinstance(metadata['GeneratedBy'], list): + for generated_by_obj in metadata['GeneratedBy']: + if 'Name' not in generated_by_obj: + entity['GeneratedBy'].append(generated_by_obj) + else: + entity['GeneratedBy'].append(metadata['GeneratedBy']) return entity diff --git a/context.json b/context.json index a7d596e5..43aa8f27 100644 --- a/context.json +++ b/context.json @@ -39,11 +39,16 @@ "@id": "prov:used", "@type": "@id" }, + "ActedOnBehalfOf" : { + "@id": "prov:actedOnBehalfOf", + "@type": "@id" + }, "Entities": "prov:Entity", "Entity": "prov:Entity", + "Environments": "prov:Entity", "Activities": "prov:Activity", "Activity": "prov:Activity", - "Software": "prov:Agent", + "Software": "prov:SoftwareAgent", "Atlocation": "prov:atLocation" } } diff --git a/dev-requirements.txt b/dev-requirements.txt index 04123e1b..d07346b9 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -12,4 +12,5 @@ pre-commit rdflib boutiques markdownify -rfc3986 \ No newline at end of file +rfc3986 +pybids diff --git a/examples/from_parsers/context_2025_07_11_14h40m18s.txt b/examples/from_parsers/context_2025_09_30_09h08m00s.txt similarity index 98% rename from examples/from_parsers/context_2025_07_11_14h40m18s.txt rename to examples/from_parsers/context_2025_09_30_09h08m00s.txt index d46a9bfd..93c29279 100644 --- a/examples/from_parsers/context_2025_07_11_14h40m18s.txt +++ b/examples/from_parsers/context_2025_09_30_09h08m00s.txt @@ -1,4 +1,4 @@ -Date : 2025_07_11_14h40m18s +Date : 2025_09_30_09h08m00s Processing files... file= nidmresults-examples/afni_alt_onesided_proc.sub_001 file= nidmresults-examples/afni_alt_onesided_proc.sub_001 @@ -69,4 +69,4 @@ Processing files... file= nidmresults-examples/spm_thr_voxelfdrp05_batch.m file= nidmresults-examples/spm_thr_voxelfwep05_batch.m file= nidmresults-examples/spm_thr_voxelunct4_batch.m -End of processed files. Results in dir : 'examples/from_parsers'. Time required: 0:00:02.016392 +End of processed files. Results in dir : 'examples/from_parsers'. Time required: 0:00:02.101514 diff --git a/pyproject.toml b/pyproject.toml index 9f6db35d..cf8ce573 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,7 @@ pydot = "^2.0.0" pyld = "^2.0.4" pyyaml = "^6.0.1" requests = "^2.32.3" +pybids = "^0.18.1" [tool.poetry.group.dev.dependencies] black = "^24.4.2"