Skip to content

bruker2nifti conversion

Gabriel A. Devenyi edited this page Jun 17, 2024 · 26 revisions

DEPRECATED

Please just module load brkraw to use the latest version

Best practice as of now is using brkraw for both structural and functional scans. https://brkraw.github.io/

Installation

Directions for installation here: https://brkraw.github.io/docs/gs_inst.html

Here are some instructions for working with python environments: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands

First, load the anaconda module:
module load anaconda

Create an environment named brkraw with python installed:
conda create -n brkraw python=3.7.9

Activate your environments:
conda activate brkraw

Install brkraw:
pip install git+https://github.com/brkraw/bruker

Access file information

Then you can read information about your files as follows:

brkraw info 20201202_MCH_NEO_DEV_003.5q1/

Convert from bruker to nifti (BIDS format)

This is the recommended approach for all studies.

Brkraw can help you automatically format all your niftis into the standardized BIDS format. This is convenient for running RABIES, as RABIES requires your data to be in BIDS. Otherwise, it is also good practice to use BIDS.

First generate a BIDS datasheet (.xlsx):

brkraw bids_helper <input directory with your bruker files> <name of xlsx file>

In that file you will find a column for the filename of each scan (RawData), the id for each subject (SubjID), the session or timepoint for that scan (SessID), and the scan number (ScanID) and its type of scan (DataType). An example of this is shown in the next figure:

Screenshot 2024-02-09 at 3 48 36 PM

You may wish to modify the spreadsheet. For example, you can change the SubjID from '1' to 'KET001' if that fits better with your naming scheme. You should double check the 'DataType' column to make sure that each scan is properly classified as 'anat', 'func' or 'fmap' (aka fieldmap - applies to B0 and B1 maps), since bids_helper is prone to making mistakes in that column. It is also recommended to add the sequence type in the 'acq' column (e.g. EPI, FLASH, RARE etc.) as well as the modality in the 'modality' column (e.g. bold, T1w, T2w etc). If you have functional data, add the task to the 'task' column (e.g. rest). Finally, if you have multiple copies of the same sequence type ('acq') for the same subject and session, you will need to either: a) delete the rows corresponding to unnecessary scans (i.e. if one didn't turn out good so you had to reacquire it), or b) if you wish to use both, you need to specify a unique run number in the 'run' column (e.g. the first scan is run 1 and the second scan is run 2).

Now you can convert your scans using:

brkraw bids_convert <path to bruker scans> <path to xlsx file> -o <path to directory for converted scans>

Convert from bruker to nifti using 'brkraw tonii' (Quick and dirty way)

Only use this approach if you want to convert one subject or one scan quickly to check the output. The newer version of BRKRAW will generate parentheses in the output file name, so this function is not recommended for use on an entire dataset.

You can convert all scans in one folder as follows:

brkraw tonii 20201202_MCH_NEO_DEV_003.5q1/

If you know your FLASH is the 4th scan, for example, and only want to convert that, you can do as follows:

brkraw tonii 20201202_MCH_NEO_DEV_003.5q1/ -s 4

For anatomical data only (additional, retired method):

Install bruker2nifti on conda environment from https://github.com/SebastianoF/bruker2nifti:

  1. create a new conda environment: conda create -n bruker2nifti_1.0.4 python=3.7
  2. activate environment: source activate bruker2nifti_1.0.4
  3. install dependencies: conda install setuptools numpy nibabel
  4. install bruker2nifti: pip install bruker2nifti==1.0.4

Recommended bruker2nifti execution:

bruker2nifti -i raw_data/20190807_MCH_MFC_054.UE1 -o raw_nii -qform_code 1 -sform_code 1 -correct_slope -correct_offset -verbose 1

Further corrections on the bruker2nifti outputs are recommended, as the left-right orientation is inverted in the anatomical image, and the XYZ axis of the images may not be consistently representing the same anatomical axes. You can run the following script to re-orient the anatomical image and convert the axes to a consistent RAS orientation, where X=right-left, Y=Anterior-Posterior and Z=Superior-Inferior axes:

python /data/chamal/projects/Gabriel_DG/utils_scripts/process_bru2nii_outputs.py functional_image.nii.gz anatomical_image.nii.gz output_folder
Clone this wiki locally