From 921fdbd14a431ebb131d2fc0a2636b41288f2612 Mon Sep 17 00:00:00 2001 From: pierre-nedelec Date: Tue, 12 Sep 2023 14:47:29 -0700 Subject: [PATCH] add "GeneratedBy"s in `dataset_description.json` Fixes #1018 --- AFQ/api/group.py | 4 +++- AFQ/data/fetch.py | 18 ++++++++++++------ AFQ/tests/test_api.py | 15 ++++++++++----- examples/tutorial_examples/plot_bids_layout.py | 3 ++- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/AFQ/api/group.py b/AFQ/api/group.py index ed0ae49ca..7cdd2f1fb 100644 --- a/AFQ/api/group.py +++ b/AFQ/api/group.py @@ -187,7 +187,9 @@ def __init__(self, "Name": bids_description["Name"], "BIDSVersion": bids_description["BIDSVersion"], "PipelineDescription": {"Name": "pyAFQ", - "Version": pyafq_version}} + "Version": pyafq_version}, + "GeneratedBy": [{"Name": op.basename(self.afq_path), + "Version": pyafq_version}]} pl_desc_file = op.join(self.afq_path, 'dataset_description.json') diff --git a/AFQ/data/fetch.py b/AFQ/data/fetch.py index 380498898..ac1b965c7 100644 --- a/AFQ/data/fetch.py +++ b/AFQ/data/fetch.py @@ -1020,7 +1020,8 @@ def organize_cfin_data(path=None): to_bids_description( dmriprep_folder, **{"Name": "CFIN", - "PipelineDescription": {"Name": "dipy"}}) + "PipelineDescription": {"Name": "dipy"}, + "GeneratedBy": [{"Name": "dipy"}]}) def organize_stanford_data(path=None, clear_previous_afq=None): @@ -1120,10 +1121,12 @@ def organize_stanford_data(path=None, clear_previous_afq=None): # And descriptions of the pipelines in the derivatives: to_bids_description(dmriprep_folder, **{"Name": "Stanford HARDI", - "PipelineDescription": {"Name": "vistasoft"}}) + "PipelineDescription": {"Name": "vistasoft"}, + "GeneratedBy": [{"Name": "vistasoft"}]}) to_bids_description(freesurfer_folder, **{"Name": "Stanford HARDI", - "PipelineDescription": {"Name": "freesurfer"}}) + "PipelineDescription": {"Name": "freesurfer"}, + "GeneratedBy": [{"Name": "freesurfer"}]}) fetch_stanford_hardi_lv1 = _make_reusable_fetcher( @@ -1750,7 +1753,8 @@ def fetch_hcp(subjects, to_bids_description(base_dir, **{"Name": study, "Acknowledgements": hcp_acknowledgements, - "PipelineDescription": {'Name': 'dmriprep'}}) + "PipelineDescription": {'Name': 'dmriprep'}, + "GeneratedBy": [{'Name': 'dmriprep'}]}) return data_files, op.join(my_path, study) @@ -1844,7 +1848,8 @@ def fetch_hbn_preproc(subjects, path=None): to_bids_description(base_dir, **{"Name": "HBN", "Acknowledgements": hbn_acknowledgements, - "PipelineDescription": {'Name': 'qsiprep'}}) + "PipelineDescription": {'Name': 'qsiprep'}, + "GeneratedBy": [{'Name': 'qsiprep'}]}) return data_files, op.join(my_path, "HBN") @@ -1941,6 +1946,7 @@ def fetch_hbn_afq(subjects, path=None): # Create the BIDS derivatives description file text to_bids_description(base_dir, **{"Name": "HBN", - "PipelineDescription": {'Name': 'afq'}}) + "PipelineDescription": {'Name': 'afq'}, + "GeneratedBy": [{'Name': 'afq'}]}) return data_files, op.join(my_path, "HBN") diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index 4537cd5e6..7888037d2 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -114,7 +114,8 @@ def create_dummy_bids_path(n_subjects, n_sessions, share_sessions=True): afd.to_bids_description( dmriprep_dir, **{"Name": "Dummy", - "PipelineDescription": {"Name": "synthetic"}}) + "PipelineDescription": {"Name": "synthetic"}, + "GeneratedBy": [{"Name": "synthetic"}]}) for subject in subjects: for session in sessions: @@ -140,7 +141,8 @@ def create_dummy_bids_path(n_subjects, n_sessions, share_sessions=True): afd.to_bids_description( dmriprep_dir, **{"Name": "Dummy", - "PipelineDescription": {"Name": "synthetic"}}) + "PipelineDescription": {"Name": "synthetic"}, + "GeneratedBy": [{"Name": "synthetic"}]}) for d in range(n_subjects): subject = subjects[d] @@ -163,7 +165,8 @@ def create_dummy_bids_path(n_subjects, n_sessions, share_sessions=True): afd.to_bids_description( dmriprep_dir, **{"Name": "Dummy", - "PipelineDescription": {"Name": "synthetic"}}) + "PipelineDescription": {"Name": "synthetic"}, + "GeneratedBy": [{"Name": "synthetic"}]}) for subject in subjects: for modality in ['anat', 'dwi']: @@ -205,7 +208,8 @@ def test_AFQ_missing_files(): "otherDeriv"), **{ "Name": "Missing", - "PipelineDescription": {"Name": "otherDeriv"}}) + "PipelineDescription": {"Name": "otherDeriv"}, + "GeneratedBy": [{"Name": "otherDeriv"}]}) touch(op.join(subses_folder, "sub-01_ses-01_dwi.nii.gz")) with pytest.raises( @@ -218,7 +222,8 @@ def test_AFQ_missing_files(): afd.to_bids_description( op.join(bids_path, "missingPipe"), **{ "Name": "Missing", - "PipelineDescription": {"Name": "missingPipe"}}) + "PipelineDescription": {"Name": "missingPipe"}, + "GeneratedBy": [{"Name": "missingPipe"}]}) with pytest.raises( ValueError, match="No non-json files recognized by pyBIDS" diff --git a/examples/tutorial_examples/plot_bids_layout.py b/examples/tutorial_examples/plot_bids_layout.py index 9e786b824..49003e912 100644 --- a/examples/tutorial_examples/plot_bids_layout.py +++ b/examples/tutorial_examples/plot_bids_layout.py @@ -107,7 +107,8 @@ afd.to_bids_description( tractography_path, **{"Name": "my_tractography", - "PipelineDescription": {"Name": "my_tractography"}}) + "PipelineDescription": {"Name": "my_tractography"}, + "GeneratedBy": [{"Name": "my_tractography"}]}) ###########################################################################