Chapter 13 DWI Preprocessing with Vistasoft
Unfortunately, the VistaSoft code is riddled with problems. Because the lab that originally has written the code is still running MATLAB r2012, newer versions or even different versions of MATLAB are going to have issues. Here are the changes you will need to make to your code in order for it to run correctly on helix:
vi ~/apps/matlab/vistasoft/mrDiffusion/dtiInit/dtiInit.m
Starting on line 163 (or maybe 170), we need to comment out one line of code. To comment out code in MATLAB, add a percent sign at the beginning of the command line:
% dtiCheckMotion(dwDir.ecFile,'off');
13.1 Job Script
On the remote computer create job script.
vi ~/scripts/ACAP/dtiVistaSoft-job.sh
Copy and paste.
#!/bin/bash
#SBATCH --time=04:00:00 # walltime
#SBATCH --ntasks=1 # number of processor cores (i.e. tasks)
#SBATCH --nodes=1 # number of nodes
#SBATCH --mem-per-cpu=16G # memory per CPU core
# LOAD MODULES, INSERT CODE, AND RUN YOUR PROGRAMS HERE
cd ~/scripts/ACAP/
module load matlab
module load lib/openblas/0.2.20-gnu
module load fsl/6.0.0
matlab -nodisplay -nojvm -nosplash -r "dtiVistaSoft('$1', '$2')"
13.2 Batch Script
First check that your subjid
and ses
are correct.
for i in $(find /work/ashley.ware/BIDS/ACAP/ -name "*b900_dwi.nii.gz"); do
subjid=`echo $i | cut -d "/" -f6`
ses=`echo $i | cut -d "/" -f7`
echo $subjid
echo $ses
done
If everything is correct then you can create your batch file.
Create script.
vi ~/scripts/ACAP/dtiVistaSoft-batch.sh
Copy and paste.
#!/bin/bash
curTime=`date +"%Y%m%d-%H%M%S"`
username=`id -un`
mkdir -p ~/logfiles/ACAP/${curTime}
for i in $(find /work/${username}/BIDS/ACAP/ -name "*b900_dwi.nii.gz"); do
subjid=`echo $i | cut -d "/" -f6`
ses=`echo $i | cut -d "/" -f7`
mkdir -p /work/${username}/data/ACAP/dtiInit/${subjid}_${ses}
sbatch \
-o ~/logfiles/ACAP/${curTime}/output-${subjid}_${ses}.txt \
-e ~/logfiles/ACAP/${curTime}/error-${subjid}_${ses}.txt \
~/scripts/ACAP/dtiVistaSoft-job.sh \
${subjid} \
${ses}
sleep 1
done
13.3 MATLAB Function
The reason we are creating a function versus a script, is so we can pass a variable, namely the participant ID, into the script.
vi ~/scripts/ACAP/dtiVistaSoft.m
Copy and paste.
%%%%%%%
function dtiVistaSoft(subjid, ses)
% Display participant ID:
display(subjid);
display(ses);
% Get home directory:
var = getenv('HOME');
% Add modules to MATLAB. Do not change the order of these programs:
SPM8Path = [var, '/apps/matlab/spm8'];
addpath(genpath(SPM8Path));
vistaPath = [var, '/apps/matlab/vistasoft'];
addpath(genpath(vistaPath));
AFQPath = [var, '/apps/matlab/AFQ'];
addpath(genpath(AFQPath));
% Set file names:
subjDir = ['/work/ashley.ware/BIDS/ACAP/', subjid, '/', ses, '/dwi/'];
dtiFile = [subjDir, subjid, '_', ses, '_acq-b900_dwi.nii.gz'];
cd(subjDir);
% Don't change the following code:
ni = readFileNifti(dtiFile);
ni = niftiSetQto(ni, ni.sto_xyz);
writeFileNifti(ni, dtiFile);
dwParams = dtiInitParams();
dwParams.rotateBvecsWithCanXform = 1;
dwParams.phaseEncodeDir = 2;
dwParams.clobber = -1;
dwParams.outDir = ['/work/ashley.ware/data/ACAP/dtiInit/', subjid, '_', ses, '/'];
dwParams.dt6BaseName = 'dt';
% Here's the one line of code to do the DTI preprocessing:
dtiInit(dtiFile, 'MNI', dwParams);
exit;
13.4 Submit Jobs with Batch Script
Finally, submit the whole process by submitting the batch script.
sh ~/scripts/ACAP/dtiVistaSoft-batch.sh
You can check the status of your jobs by checking if it is running or pending.
squeue
You can check the outputs.
tail -n 5 ~/logfiles/ACAP/<date>/output*
13.5 Download Directory / Sync Directory with Helix
Back on your local computer make sure you have the directory already.
mkdir -p /Volumes/bobo/data/ACAP/dtiInit
Then sync the data from the remote computer to your local computer.
rsync -rauv \
ashley.ware@arc.ucalgary.ca:/work/ashley.ware/data/ACAP/dtiInit/ \
/Volumes/bobo/data/ACAP/dtiInit/