knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = FALSE
)
library(BIDSconvertR)

Setup

You need to install the library "papayaWidget" by John Mushelli (@muschellij2). This implements the NIfTI viewer to inspect the images visually.

install.packages("devtools")
devtools::install_github("muschellij2/papayaWidget")

First steps

Choose a folder, where you want to store your "user settings" file. The function create_user_settings("path") creates a template file at the desired folder.

create_user_settings("/media/niklas/BIDS_data/BIDSconvertR/output/") # Linux
create_user_settings("C:/Science/bidirect_bids/") # Windows

Edit the file "user_settings.R" to your needs.

+----------------------+------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+ | Variable | Example | Description | +======================+========================================================================================================================+=================================================================================================================================================+ | path_input_dicom | "/media/niklas/BIDS_data/dicom/" | Input path, where your DICOM folders are inside of session folders | +----------------------+------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+ | path_output | "/media/niklas/BIDS_data/BIDSconvertR" | A path, where all the output of the converter should be written to. | +----------------------+------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+ | study_name | "BiDirect Study" | Your study name, only needed for the dashboard rendering. | +----------------------+------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+ | regex_subject_id | "[:digit:]{5}" | Regex defining your unique subject ID's. | +----------------------+------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+ | regex_group_id | "[:digit:]{1}(?=[:digit:]{4})" | Regex defining the group ID (if present). | +----------------------+------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+ | regex_remove_pattern | "[:punct:]{1}\|[:blank:]{1}\|((b\|d)i(d\|b)i\|bid\|bd\|bdi)(ect\|rect)(\$\|(rs\|T2TSE\|inclDIRSequenz\|neu\|abbruch))" | These regex will be removed from the file names. | +----------------------+------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+ | sessions_id_old | c("Baseline", "FollowUp", "FollowUp2", "FollowUp3") | The folder (and session) names before conversion | +----------------------+------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+ | sessions_id_new | c("0", "2", "4", "6") | The folder (and session) names after conversion. These can be identical to "sessions_id_old". But note, that in BIDS a number is the way to go. | +----------------------+------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+ | mri_sequences | "T1\|T2\|DTI\|fmr\|rest\|rs\|func\|FLAIR\|smartbrain\|survey\|smart\|ffe\|tse" | These are regular expressions, which should be matched to your MRI sequence ID's. | +----------------------+------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+

: Information in the user settings file

Now you have edited your "user_settings.R" file.

The next step is to prepare your environment with the function "prepare_environment('/path/to/user_settings.R)"

# settings_file <- "/media/niklas/BIDS_data/BIDSconvertR/output/user_settings.R"
settings_file <- "C:/Science/bidirect_bids/user_settings.R"

prepare_environment(settings_file)

Then you need to install dcm2niix. The function automatically uses the tested "v1.0.20211006" of dcm2niix, other versions can be installed by changing the version number.

https://github.com/rordenlab/dcm2niix/releases

install_dcm2niix()

install_dcm2niix("v1.0.20181125") # installs v1.0.20181125

How to run the main script

The convert_to_BIDS function takes two arguments: the user_settings_file and a switch to select, if you want to see the sequence_table everytime ("on") or only, if something is not plausible ("off").

"On" is useful to inspect the sequence mapping again. "Off" shows the sequence mapper only, if some unplausible data is identified, e.g. new sequences, which are not mapped.

convert_to_BIDS(user_settings_file = settings_file,
                sequence_table = "off")

Alternatively to main script: You can also run each step manually

user_settings_file = settings_file

# dcm2niix - niftis
dcm2nii_converter_anon()

# dcm2niix - jsons
dcm2nii_converter_json()

# read all metadata from JSON files
read_json_headers(json_path = path_output_converter_temp_json, suffix = "")

read_json_headers(json_path = path_output_converter_temp_nii, suffix = "_anon")


sequence_mapper(edit_table = sequence_table)

check_sequence_map()

copy2BIDS()

create_dashboard_internal()


wulms/bidsconvertr documentation built on Sept. 17, 2023, 11:22 p.m.