Skip to content
Snippets Groups Projects
Commit e976a6dd authored by Carolyn McNabb's avatar Carolyn McNabb
Browse files

adding scripts for dcm2bids

parent 0c06ab2f
Branches
No related tags found
No related merge requests found
#!/bin/bash
#SBATCH --mail-user=mcnabbc1@cardiff.ac.uk
#SBATCH --mail-type=END
#SBATCH --job-name=SW2_dcm2bids
#SBATCH --partition=cubric-centos7
#SBATCH -o /home/sapcm15/sbatch_reports/SW2_dcm2bids_%j.out
#SBATCH -e /home/sapcm15/sbatch_reports/SW2_dcm2bids_%j.err
#SBATCH --array=1-1
export PATH=$PATH:/home/sapcm15/gitlab/brainandgenomicshub/DownloadData
# use the SLURM_ARRAY_TASK_ID to define the subject ID (sub) from the subject_list.txt file
sub=$(sed -n ${SLURM_ARRAY_TASK_ID}p /home/sapcm15/gitlab/brainandgenomicshub/DownloadData/subject_list.txt)
# run the analysis - note that the first argument is the participant ID - they will get their own SLURM job
batch_dcm2bids.sh ${sub}
# Analysis scripts for downloading data and storing in BIDS format
**Carolyn McNabb**</br>
Last updated: September 2024
## Downloading MRI data from XNAT
First, you'll need to download the MRI data from XNAT.
## DICOM to dicomBIDS conversion
Once data are downloaded, you can convert the DICOM files to NifTI format and arrange these according to the Brain Imaging Data Structure ([BIDS](https://bids-specification.readthedocs.io/en/stable/)).
#### Initial environment setup
To use dcm2bids, you need to be in a python environment. First you'll need to set this up and then you can download dcm2bids.
2.1. Set up environment for dcm2bids
```
gedit environment.yml
```
Paste in the following:
```
name: dcm2bids
channels:
- conda-forge
dependencies:
- dcm2niix
- dcm2bids
- pip
```
Create conda environment and activate:
```
conda env create -f environment.yml --prefix ~/dcm2bids_env
source activate ~/dcm2bids_env
cd /cubric/scratch/sapcm15/BioBank_forCarolyn/sourcedata
```
2.2. Install dcm2bids
In terminal, type:
```
pip install dcm2bids
```
#### If environment has already been setup
2.2. activate environment
```
source activate ~/dcm2bids_env
cd /cubric/scratch/sapcm15/BioBank_forCarolyn/sourcedata
```
2.3. Convert raw data to BIDS format with dcm2bids
First, test that dcm2bids is working by typing
```
dcm2bids --help
```
Use the dcm2bids helper function to look at your json files (associated with each of your nifti files - these will be in the tmp_dcm2bids folder).
```
dcm2bids_helper -d /cubric/scratch/sapcm15/BioBank_forCarolyn/scans
```
### Run dcm2bids
To run dcm2bids, you need to have a configuration file set up. For the SW2 project, this is stored in `~/gitlab/UKBiobank_CUBRIC/DownloadData/dcm2bids_config.SW2.json`
You'll also need a subject list of all the subjects you want to convert from DICOM to NifTI. This should be stored in the brainandgenomicshub gitlab folder and called `subject_list.txt`.
Now, open `0.1_dcm2bids_SLURM.sh` and update the `#SBATCH --array=1-1` line to include all the subjects in your list that you want to convert, e.g. `#SBATCH --array=3-15`. You'll also need to update the paths in `batch_dcm2bids` to match the paths where you've downloaded the data from XNAT and the path where you keep this gitlab repository.
You should now be ready to run dcm2bids. In the linux terminal, type:
```
sbatch 0.1_dcm2bids_SLURM.sh
```
This will send the command to the cluster and each subject will get it's own job id. You can check the progress of the jobs by typing:
```
squeue -u <youruserid>
```
You can cancel all the jobs you just sent by typing:
```
scancel -u <youuserid>
```
You can cancel individual jobs too, by typing:
```
scancel <jobid>
```
Once the job has finished, you can check whether there were any errors by looking in the reports folder you specified in `0.1_dcm2bids_SLURM.sh`. The job will create two files, one ending `.err` and one ending `.out`. You will need to check both of them to make sure the job ran okay.
\ No newline at end of file
# Carolyn McNabb - dcm2bids script for WAND data
#!/bin/bash
#Define subject - $1 represents the first input argument from the SLURM file (in this case, the subject ID)
# id=$1
# sub=${id//$"314_"/}
sub=$1
#Set up paths
bids_dir=/cubric/scratch/sapcm15/BioBank_forCarolyn/sourcedata
home_dir=/home/sapcm15
dicom_dir=/cubric/scratch/sapcm15/BioBank_forCarolyn/XNATDownloads
json_dir=${home_dir}/gitlab/brainandgenomicshub/DownloadData
echo "running dcm2bids for ${sub}"
#use dcm2bids environment
source activate ${home_dir}/dcm2bids_env
#run dcm2bids analysis
dcm2bids -d ${dicom_dir}/${sub}/scans -p ${sub} -s 01 -c ${json_dir}/dcm2bids_config_SW2.json -o ${bids_dir} #for collab bids
\ No newline at end of file
{
"dcm2niixOptions": "-b y -ba y -z y -f '%n_%3s_%f_%p'",
"descriptions": [
{
"dataType": "anat",
"modalityLabel": "T1w",
"criteria": {
"ImageType": ["ORIGINAL", "PRIMARY", "M", "ND", "NORM"],
"SeriesDescription": "T1_p2_1mm_fov256_sag_TI_880"
}
},
{
"dataType": "func",
"modalityLabel": "sbref",
"criteria": {
"ImageType": ["ORIGINAL", "PRIMARY", "M", "ND", "MOSAIC"],
"SeriesDescription": "MB8_FMRI_fov210_2.4mm_resting_SBRef"
}
},
{
"dataType": "func",
"modalityLabel": "bold",
"criteria": {
"ImageType": ["ORIGINAL", "PRIMARY", "M", "MB", "ND", "MOSAIC"],
"SeriesDescription": "MB8_FMRI_fov210_2.4mm_resting"
},
"sidecarChanges": {
"TaskName": "rest"
}
},
{
"dataType": "anat",
"modalityLabel": "FLAIR",
"criteria": {
"ImageType": ["ORIGINAL", "PRIMARY", "M", "ND", "NORM"],
"SeriesDescription": "t2_flair_sag_p2_1mm_FS_ellip_pf78"
}
},
{
"dataType": "dwi",
"modalityLabel": "dwi",
"customLabels": "dir-PA_part-mag",
"criteria": {
"ImageType": ["ORIGINAL", "PRIMARY", "DIFFUSION", "NONE", "MB", "ND"],
"SeriesDescription": "diff_PA_MPopt_MB3_3b0_lowflip",
"PhaseEncodingDirection": "j"
}
},
{
"dataType": "dwi",
"modalityLabel": "dwi",
"customLabels": "dir-AP_part-mag",
"criteria": {
"ImageType": ["ORIGINAL", "PRIMARY", "DIFFUSION", "NONE", "MB", "ND", "MOSAIC"],
"SeriesDescription": "diff_AP_MPopt_MB3_50b1000_50b2000_8b0_lowflip",
"PhaseEncodingDirection": "j-"
}
},
{
"dataType": "swi",
"modalityLabel": "GRE",
"customLabels": "echo-1",
"criteria": {
"ImageType": ["ORIGINAL", "PRIMARY", "M", "ND", "NORM", "FM", "FIL"],
"SeriesDescription": "SWI_3mm_Updated_v1.1",
"EchoNumber": 1
}
},
{
"dataType": "swi",
"modalityLabel": "GRE",
"customLabels": "echo-2",
"criteria": {
"ImageType": ["ORIGINAL", "PRIMARY", "M", "ND", "NORM", "FM", "FIL"],
"SeriesDescription": "SWI_3mm_Updated_v1.1",
"EchoNumber": 2
}
}
]
}
sub-01
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment