datahipy.handlers
The datahipy.handlers
subpackage contains modules that define classes and functions that handle the reading and writing of BIDS data. The classes are also designed to be used with the datahipy
command line interface.
datahipy.handlers.dataset
Manage BIDS dataset using BIDS Manager.
- class datahipy.handlers.dataset.DatasetHandler(dataset_path=None)[source]
Bases:
object
Class to represent the handler of a dataset with utility functions.
- static add_keys_requirements(ds_obj=None, clin_keys=None)[source]
Update the requirements.json with new keys.
- static check_converters(ds_obj=None)[source]
Check if the converters are specified and (re)write the requirements.json if necessary.
- dataset_create(input_data=None)[source]
Create a new BIDS dataset.
- dataset_get_content(input_data=None, output_file=None)[source]
Extract dataset information indexed by the HIP platform.
- static dump_output_file(output_data=None, output_file=None)[source]
Dump output_data dict in a JSON file.
- static get_run(root_dir: str, bids_entities: dict, bids_modality: str)[source]
Parse the BIDS dataset to get the max run for a set of BIDS entities.
- static load_input_data(input_data)[source]
Return input_data JSON file in a dict.
- static make_safe_filename(s)[source]
Return a modified version of the string that contains only alphanumeric characters (letters and numbers).
Any other character in the original string is replaced by an underscore (
_
). The function also removes any trailing underscores from the end of the modified string.Parameters
- s: str
Input string
Return
String that contains only alphanumeric characters.
datahipy.handlers.participants
Manage BIDS participants using BIDS Manager.
- class datahipy.handlers.participants.ParticipantHandler(dataset_path=None, input_path=None)[source]
Bases:
object
Class to represent the handler of a dataset’s participant with utility functions.
- static create_data2import(ds_obj=None, input_data=None)[source]
Create a data2import object.
This object will be used to import data in the BIDS dataset.
Parameters
- ds_objBIDS Manager BidsDataset object
The BIDS Manager object representing a BIDS dataset.
- input_datadict
The input_data dictionary containing the data to import in the BIDS dataset.
Returns
- data2importBIDS Manager Data2Import object
The BIDS Manager object representing the data to import in the BIDS dataset.
- static dump_output_file(output_data=None, output_file=None)[source]
Dump output_data dict in a JSON file.
- static find_subject_dict(ds_obj=None, subject=None)[source]
Find the subject dict in the parsed BIDS dataset object.
- static load_input_data(input_data)[source]
Load the input_data JSON file.
- sub_delete(input_data=None)[source]
Delete a subject from an already existing BIDS dataset.
- sub_delete_file(input_data=None)[source]
Delete data files from /raw and /source.
- sub_edit_clinical(input_data=None)[source]
Update subject clinical info in BIDS dataset.
- sub_get(input_data=None, output_file=None)[source]
Get info of a subject.
- sub_import(input_data=None)[source]
Import subject(s) data into a BIDS dataset.
datahipy.handlers.project
Methods supporting the Collaborative Space of the HIP.
- datahipy.handlers.project.create_project(input_data: str, output_file: str)[source]
Create a new Collaborative Project on the HIP initialized with directory/file structure.
Parameters
- input_datastr
Path to input data JSON file sent by the HIP that contains all information about Project and corresponding BIDS dataset in the form:
{ "path": "/path/to/project/directory", "title": "Project Title", "description": "Project Description that would be put in the README.md file", "datasetDescription": { "Name": "BIDS Dataset Title", "BIDSVersion": "1.6.0", "License": "CC-BY-4.0", "Authors": ["Author 1", "Author 2"], "Acknowledgements": "Acknowledgement 1", "Funding": ["Funding 1"], "ReferencesAndLinks": ["Reference 1", "Reference 2"], "DatasetDOI": "10.18112/openneuro.ds000000.v1.0.0" } }
- output_filestr
Path to output file that will contain the JSON summary of the BIDS dataset of the project.
- datahipy.handlers.project.import_document(input_data: str)[source]
Import a new supporting document to the
documents/
folder of the HIP Collaborative Project.Parameters
- input_datastr
Path to input data JSON file sent by the HIP that contains all information about the document to import in the form:
{ "sourceDocumentAbsPath": "/path/to/source/document/file", "targetProjectAbsPath": "/path/to/target/project/directory", "sourceDocumentRelPath": "/project/relative/path/to/target/document/file", }
- datahipy.handlers.project.import_subject(input_data: str, output_file: str)[source]
Import a new subject from a BIDS dataset of the HIP Center space to the BIDS dataset of the HIP Collaborative Project.
Parameters
- input_datastr
Path to input data JSON file sent by the HIP that contains all information about the subject and files to import in the form:
{ "sourceDatasetPath": "/path/to/source/bids/dataset/directory", "participantId": "sub-01", "targetDatasetPath": "/path/to/target/bids/dataset/directory", }
- output_filestr
Path to output file that will contain the JSON summary of the BIDS dataset of the project.
- datahipy.handlers.project.initialize_project_structure(project_dir: Path, project_title: str, project_description: str)[source]
Initialize the directory structure of a Collaborative Project on the HIP.
Parameters
- project_dirpathlib.Path
Path to the project directory.
- project_titlestr
Title of the project.
- project_descriptionstr
Description of the project.
- datahipy.handlers.project.manage_project_with_datalad(project_dir: str)[source]
Create a Datalad dataset out of an existing project not Datalad-managed yet.
Parameters
- project_dirstr
Path to the project directory.
- datahipy.handlers.project.transfer_subject_participants_tsv_row(participant_id: str, source_participant_tsv: str, target_participants_tsv: str)[source]
Transfer subject row from the participants.tsv file of the source to the participants.tsv file of the target BIDS dataset.
Parameters
- participant_idstr
ID of the participant to transfer (e.g. “sub-01”).
- source_participant_tsvstr
Path to the participants.tsv file of the source BIDS dataset.
- target_participants_tsvstr
Path to the participants.tsv file of the target BIDS dataset.