Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/prepare json yaml files #31

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

hjbockholt
Copy link

We have branched the forked repo and provided the following script. It currently delivers all but derivatives for the test ds004733 case.
Summary of the Script
The BIDStoNDAConfigGenerator is a Python script designed to automate the generation of JSON and YAML configuration files required for submitting neuroimaging data (specifically BIDS datasets) to the National Institute of Mental Health (NIMH) Data Archive (NDA). This script simplifies the process of converting BIDS-compliant datasets into NDA-compliant formats, focusing on PET and other neuroimaging modalities.
How the Script Works

  1. Initialization and Setup:
    o The script initializes by accepting the path to a BIDS dataset as a command-line argument.
    o It uses the BIDSLayout from the pybids library to organize and interact with the dataset.
    o The script defines mappings for scan types (e.g., anat, pet) and image modalities (e.g., MRI, PET).
  2. File Name Parsing:
    o The script uses a regular expression pattern to extract components (such as X, Y, Z) from the filenames within the BIDS dataset. These components are crucial for generating the correct NDA configuration files.
  3. Generating JSON Contents:
    o The prepare_json_contents method generates JSON files for each relevant scan in the dataset.
    o These JSON files contain placeholders ({SUBJECT}, {SESSION}) that will be filled in when the data is uploaded to the NDA.
  4. Fetching Scan Types:
    o The fetch_scan_type method identifies the appropriate scan type based on the Y and Z components extracted from the filename.
  5. Generating YAML Contents:
    o The prepare_yaml_contents method generates YAML files, which include metadata such as scan type, image modality, and file format.
  6. Determining Z Values:
    o The fetch_Z_value method extracts unique Z values from the dataset’s files, which are then used to generate the correct filenames for the JSON and YAML files.
  7. Running the Script:
    o The run method iterates through the dataset, generating and saving JSON and YAML files in specified directories.
    o The output directories are automatically created if they do not already exist.

Instructions for Use

  1. Prepare Your Environment:
    o Ensure you have the necessary dependencies installed, such as pybids.
  2. Running the Script:
    o Place yourself in the directory where the script is located and execute the following command:
    bash
    Copy code
    python3 prepare_files.py /path/to/bids/dataset
    o Replace /path/to/bids/dataset with the actual path to your BIDS dataset.
  3. Output:
    o The script generates JSON and YAML files in directories named prepared_jsons and prepared_yamls, respectively.
    o These directories are created in the parent directory of the BIDS dataset.
    Next Steps
    This script forms the basis of a tool aimed at automating the process of submitting datasets from OpenNeuro and OpenNeuroPET into the NIMH Data Archive. Future enhancements could include:
    • Customizable Output Directories: Allowing users to specify output directories for the generated files via command-line arguments.
    • Support for Additional Data Types: Extending support to other neuroimaging modalities beyond PET and MRI.
    • Integration with NDA Submission Tools: Automating the actual submission process to the NDA, including manifest file creation.
    Additional Notes
    This tool is part of a broader project aimed at streamlining the data submission process for neuroimaging studies, particularly for datasets in BIDS format. By automating the creation of necessary configuration files, this tool reduces the manual effort required and ensures compliance with NDA requirements.

pbbaba and others added 10 commits August 1, 2024 10:42
Added a small additional description to the ArgumentParser.
Implemented functionality to generate both JSON and YAML files for derivatives in a BIDS dataset, ensuring compatibility with multiple data types. (Pooja's script was missing this)
Fixed bugs in JSON file generation for input data, ensuring accurate file parsing and content preparation. (Pooja's script generated empty JSON files for inputs; I resolved this)
Completed the addition of -s (source) and -d (destination) command-line arguments to allow users to specify custom input and output paths. (Pooja's TODO—completed by me)
Refactored the script extensively to improve code readability and maintainability.
How to Run:
cd json_yaml_files
python3 prepare_file.py -s <path_to_bids_data> -d <desination_path_for_output_files>
Co-authored-by: Eric Earl <[email protected]>
Co-authored-by: Eric Earl <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants