Skip to content

Commit

Permalink
ATPP_CLI V2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
haililihai committed Dec 20, 2016
0 parents commit ae7105e
Show file tree
Hide file tree
Showing 130 changed files with 23,477 additions and 0 deletions.
51 changes: 51 additions & 0 deletions 0_gen_WD.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#! /bin/bash
# generate working directory for ATPP
#
# Directory structure:
# Working_dir
# |-- sub1
# | |-- T1_sub1.nii
# | `-- b0_sub1.nii
# |-- ...
# |-- subN
# | |-- T1_subN.nii
# | `-- b0_subN.nii
# |-- ROI
# | |-- ROI_L.nii
# | `-- ROI_R.nii
# `-- log
#
# !! Please modify the following codes to organzie these files according to the above structure


WD=$1
shift
DATA_DIR=$1
shift
ROI=$1
shift
SUB_LIST=$1
shift
ROI_DIR=$1

# generate ROI directory
mkdir -p ${WD}/ROI
mkdir -p ${WD}/log

# unzip ROIs if they are in gz format
gunzip ${ROI_DIR}/${ROI}_L.nii.gz
gunzip ${ROI_DIR}/${ROI}_R.nii.gz

# copy ROIs from ROI_DIR to ROI directory in working directory
cp -vrt ${WD}/ROI ${ROI_DIR}/${ROI}_L.nii ${ROI_DIR}/${ROI}_R.nii

# copy T1 and b0 files from DATA_DIR for each subject
for sub in `cat ${SUB_LIST}`
do
mkdir -p ${WD}/${sub}
cp -vrt ${WD}/${sub} ${DATA_DIR}/${sub}/T1_brain.nii.gz ${DATA_DIR}/${sub}/DTI/nodif_brain.nii.gz
gunzip ${WD}/${sub}/nodif_brain.nii.gz
gunzip ${WD}/${sub}/T1_brain.nii.gz
mv -v ${WD}/${sub}/T1_brain.nii ${WD}/${sub}/T1_${sub}.nii
mv -v ${WD}/${sub}/nodif_brain.nii ${WD}/${sub}/b0_${sub}.nii
done
24 changes: 24 additions & 0 deletions 10_postprocess_mpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! /bin/bash
# smooth the mpm image

PIPELINE=$1
shift
WD=$1
shift
ROI=$1
shift
SUB_LIST=$1
shift
MAX_CL_NUM=$1
shift
NIFTI=$1
shift
MPM_THRES=$1
shift
VOX_SIZE=$1
shift
LEFT=$1
shift
RIGHT=$1

${COMMAND_MATLAB} -nodisplay -nosplash -r "addpath('${PIPELINE}');addpath('${NIFTI}');postprocess_mpm_group_xmm('${WD}','${ROI}','${SUB_LIST}',${MAX_CL_NUM},${MPM_THRES},${VOX_SIZE},${LEFT},${RIGHT});exit"
46 changes: 46 additions & 0 deletions 11_validation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#! /bin/bash
# produce various validity indices

pipeline=$1
shift
WD=$1
shift
ROI=$1
shift
SUB=$1
shift
METHOD=$1
shift
VOX_SIZE=$1
shift
MAX_CL_NUM=$1
shift
N_ITER=$1
shift
POOLSIZE=$1
shift
GROUP_THRES=$1
shift
MPM_THRES=$1
shift
LEFT=$1
shift
RIGHT=$1
shift
split_half=$1
shift
pairwise=$1
shift
leave_one_out=$1
shift
cont=$1
shift
hi_vi=$1
shift
silhouette=$1
shift
tpd=$1


${COMMAND_MATLAB} -nodisplay -nosplash -r "addpath('${pipeline}');validation('${WD}','${ROI}','${SUB}','${METHOD}',${VOX_SIZE},${MAX_CL_NUM},${N_ITER},${POOLSIZE},${GROUP_THRES},${MPM_THRES},${LEFT},${RIGHT},${split_half},${pairwise},${leave_one_out},${cont},${hi_vi},${silhouette},${tpd});exit"

35 changes: 35 additions & 0 deletions 12_indices_plot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#! /bin/bash
# plot indices

pipeline=$1
shift
WD=$1
shift
ROI=$1
shift
SUB_LIST=$1
shift
VOX_SIZE=$1
shift
MAX_CL_NUM=$1
shift
LEFT=$1
shift
RIGHT=$1
shift
split_half=$1
shift
pairwise=$1
shift
leave_one_out=$1
shift
cont=$1
shift
hi_vi=$1
shift
silhouette=$1
shift
tpd=$1


${COMMAND_MATLAB} -nodisplay -nosplash -r "addpath('${pipeline}');addpath('${pipeline}/export_fig');indices_plot('${WD}','${ROI}','${SUB_LIST}',${VOX_SIZE},${MAX_CL_NUM},${LEFT},${RIGHT},${split_half},${pairwise},${leave_one_out},${cont},${hi_vi},${silhouette},${tpd});exit"
41 changes: 41 additions & 0 deletions 1_ROI_registration_spm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#! /bin/bash
# ROI registration, from MNI space to DTI space, using spm batch

PIPELINE=$1
shift
WD=$1
shift
ROI=$1
shift
SUB_LIST=$1
shift
POOLSIZE=$1
shift
SPM=$1
shift
NIFTI=$1
shift
TEMPLATE=$1
shift
LEFT=$1
shift
RIGHT=$1

source ${PIPELINE}/config.sh

${COMMAND_MATLAB} -nodisplay -nosplash -r "addpath('${PIPELINE}');addpath('${SPM}');addpath('${NIFTI}');ROI_registration_spm('${WD}','${ROI}','${SUB_LIST}',${POOLSIZE},'${TEMPLATE}',${LEFT},${RIGHT});exit"


for sub in `cat ${SUB_LIST}`
do
if [ "${LEFT}" == "1" ]; then
mv ${WD}/${sub}/w${ROI}_L.nii ${WD}/${sub}/${sub}_${ROI}_L_DTI.nii
gzip ${WD}/${sub}/${sub}_${ROI}_L_DTI.nii
fi
if [ "${RIGHT}" == "1" ]; then
mv ${WD}/${sub}/w${ROI}_R.nii ${WD}/${sub}/${sub}_${ROI}_R_DTI.nii
gzip ${WD}/${sub}/${sub}_${ROI}_R_DTI.nii
fi
done


20 changes: 20 additions & 0 deletions 2_ROI_calc_coord.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#! /bin/bash
# calculate ROI coordinates in DTI space

PIPELINE=$1
shift
WD=$1
shift
ROI=$1
shift
SUB_LIST=$1
shift
POOLSIZE=$1
shift
NIFTI=$1
shift
LEFT=$1
shift
RIGHT=$1

${COMMAND_MATLAB} -nodisplay -nosplash -r "addpath('${PIPELINE}');addpath('${NIFTI}');ROI_calc_coord('${WD}','${ROI}','${SUB_LIST}','${POOLSIZE}',${LEFT},${RIGHT});exit"
80 changes: 80 additions & 0 deletions 3_ROI_probtrackx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#! /bin/bash
# generate probabilistic tractography for each voxel in ROI

WD=$1
shift
DATA_DIR=$1
shift
ROI=$1
shift
SUB_LIST=$1
shift
N_SAMPLES=$1
shift
DIS_COR=$1
shift
LEN_STEP=$1
shift
N_STEPS=$1
shift
CUR_THRES=$1
shift
LEFT=$1
shift
RIGHT=$1

# create a directory to check the status
if [ -d ${WD}/qsub_jobdone ]
then
rm -rf ${WD}/qsub_jobdone
mkdir -p ${WD}/qsub_jobdone
else
mkdir -p ${WD}/qsub_jobdone
fi


for sub in $(cat ${SUB_LIST})
do
# single voxel probtrackx
if [ "${LEFT}" == "1" ]; then
job_id=$(${COMMAND_FSLSUB} -l ${WD}/log ${COMMAND_PROBTRACKX} --mode=simple --seedref=${DATA_DIR}/${sub}/DTI.bedpostX/nodif_brain_mask -o ${ROI}_L -x ${WD}/${sub}/${sub}_${ROI}_L_coord.txt -l ${DIS_COR} -c ${CUR_THRES} -S ${N_STEPS} --steplength=${LEN_STEP} -P ${N_SAMPLES} --forcedir --opd -s ${DATA_DIR}/${sub}/DTI.bedpostX/merged -m ${DATA_DIR}/${sub}/DTI.bedpostX/nodif_brain_mask --dir=${WD}/${sub}/${sub}_${ROI}_L_probtrackx &)
echo "${sub}_L probtrackx is running...! job_ID is ${job_id}"
mute=$(${COMMAND_FSLSUB} -j ${job_id} -N running... -l ${WD}/log touch ${WD}/qsub_jobdone/${sub}_L.jobdone)
fi

if [ "${RIGHT}" == "1" ]; then
job_id=$(${COMMAND_FSLSUB} -l ${WD}/log ${COMMAND_PROBTRACKX} --mode=simple --seedref=${DATA_DIR}/${sub}/DTI.bedpostX/nodif_brain_mask -o ${ROI}_R -x ${WD}/${sub}/${sub}_${ROI}_R_coord.txt -l ${DIS_COR} -c ${CUR_THRES} -S ${N_STEPS} --steplength=${LEN_STEP} -P ${N_SAMPLES} --forcedir --opd -s ${DATA_DIR}/${sub}/DTI.bedpostX/merged -m ${DATA_DIR}/${sub}/DTI.bedpostX/nodif_brain_mask --dir=${WD}/${sub}/${sub}_${ROI}_R_probtrackx &)
echo "${sub}_R probtrackx is running...! job_ID is ${job_id}"
mute=$(${COMMAND_FSLSUB} -j ${job_id} -N running... -l ${WD}/log touch ${WD}/qsub_jobdone/${sub}_R.jobdone)
fi

done


# check whether the tasks are finished or not
N=$(cat ${SUB_LIST}|wc -l)
if [ "${LEFT}" == "1" -a "${RIGHT}" == "0" ]
then
while [ "$(ls ${WD}/qsub_jobdone|wc -l)" != "${N}" ]
do
sleep 30s
done
fi

if [ "${LEFT}" == "0" -a "${RIGHT}" == "1" ]
then
while [ "$(ls ${WD}/qsub_jobdone|wc -l)" != "${N}" ]
do
sleep 30s
done
fi

if [ "${LEFT}" == "1" -a "${RIGHT}" == "1" ]
then
while [ "$(ls ${WD}/qsub_jobdone|wc -l)" != "$((${N}*2))" ]
do
sleep 30s
done
fi

echo "=========== Finally Probtrackx All Done!! ==========="
26 changes: 26 additions & 0 deletions 4_ROI_calc_matrix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /bin/bash
# calculate connectivity matrix between each voxel in ROI and the remain voxels of whole brain
# and correlation matrix among voxels in ROI

PIPELINE=$1
shift
WD=$1
shift
ROI=$1
shift
SUB_LIST=$1
shift
POOLSIZE=$1
shift
NIFTI=$1
shift
VAL_THRES=$1
shift
DOWN_SIZE=$1
shift
LEFT=$1
shift
RIGHT=$1


${COMMAND_MATLAB} -nodisplay -nosplash -r "addpath('${PIPELINE}');addpath('${NIFTI}');ROI_calc_matrix('${WD}','${ROI}','${SUB_LIST}',${POOLSIZE},${VAL_THRES},${DOWN_SIZE},${LEFT},${RIGHT});exit"
22 changes: 22 additions & 0 deletions 5_ROI_parcellation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /bin/bash
# ROI parcellation using spectral clustering, to generate 2 to max cluster number subregion

PIPELINE=$1
shift
WD=$1
shift
ROI=$1
shift
SUB_LIST=$1
shift
MAX_CL_NUM=$1
shift
POOLSIZE=$1
shift
METHOD=$1
shift
LEFT=$1
shift
RIGHT=$1

${COMMAND_MATLAB} -nodisplay -nosplash -r "addpath('${PIPELINE}');ROI_parcellation('${WD}','${ROI}','${SUB_LIST}',${MAX_CL_NUM},${POOLSIZE},'${METHOD}',${LEFT},${RIGHT});exit"
Loading

0 comments on commit ae7105e

Please sign in to comment.