bb_tbss_md_NAWM 2.33 KB
Newer Older
Ludovica Griffanti's avatar
Ludovica Griffanti committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
#
# Script name: bb_tbss_md_NAWM
#
# Description: Script to calculate MD values from WM tracts excluding WMH, i.e. normal appearing white matter (NAWM)
#  (adapted pipeline from dMRI sequence with 3 diffusion directions)
#
# Authors: Ludovica Griffanti, Fidel Alfaro-Almagro, Stephen M. Smith & Mark Jenkinson
#
# Copyright 2021 University of Oxford
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

. "$BB_BIN_DIR"/bb_pipeline_tools/bb_set_header 

direc="$PWD"/"$1"
TBSSDir="$direc"/dMRI/TBSS
biancaDIR="$direc"/T2_FLAIR/lesions/

################# Apply FNRIT warp to WMH to have WMH_to_MNI.nii.gz
cd "$biancaDIR"

$FSLDIR/bin/applywarp -i final_mask.nii.gz -o final_mask_to_MNI.nii.gz -r ${FSLDIR}/data/standard/MNI152_T1_1mm.nii.gz -w ../../T1/transforms/T1_to_MNI_warp.nii.gz

################# Calculating IDPs masking out WMH
cd "$TBSSDir"
cd stats

fslmaths ${biancaDIR}/final_mask_to_MNI.nii.gz -thr 0.2 -binv -mul all_MD all_MD_NAWM
fslmaths all_MD_NAWM -mas mean_FA_skeleton_mask all_MD_NAWM_skeletonised
fslstats -K ${FSLDIR}/data/atlases/JHU/JHU-ICBM-labels-1mm all_MD_NAWM_skeletonised.nii.gz -M >JHUrois_MD_NAWM.txt 

cd ../..
################# Saving IDPs in the main IDPs directory

#Setting the string of NaN in case there is a problem.
numVars="48"
nanResult="";
for i in $(seq 1 $numVars) ; do 
    nanResult="NaN $nanResult" ; 
done

result="" 

#for i in FA MD ; do
for i in MD_NAWM ; do
    if [ -f ${TBSSDir}/stats/JHUrois_${i}.txt ] ; then
        if [ `cat ${TBSSDir}/stats/JHUrois_${i}.txt | wc -w` = $numVars ] ; then
            miniResult=`cat ${TBSSDir}/stats/JHUrois_${i}.txt`
        else
            miniResult="$nanResult"
        fi
    else
        miniResult="$nanResult"
    fi
    result="$result $miniResult"
done

echo $result > ${direc}/IDP_files/bb_IDP_diff_TBSS_NAWM.txt
done

73
. "$BB_BIN_DIR"/bb_pipeline_tools/bb_set_footer