-
Notifications
You must be signed in to change notification settings - Fork 2
/
s1_preprocess_data.sh
executable file
·140 lines (114 loc) · 4.43 KB
/
s1_preprocess_data.sh
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
## PREPROCESS DATA, including:
# 1. conversion to BIDS
# 2. Defacing
# 3. MRIQC
# 4. FMRIPrep
# Exit upon any error
set -euo pipefail
## Change lines for Study/subject/system. Also add lines for stim files, TSV fles, and eye tracking files. Then try running it on our sample data.
DIRN=`dirname $0`
source $DIRN/setup.sh ${1-}
source "$CODE_DIR"/Subroutines/utils.sh
# Go!
# Sample data from subject wlsubj042, acquired on DATE!?!?!?!
#
### Global variables: ###
# Study/subject specific #
dcmFolder="$SAMPLE_DATA_DIR/dicoms"
logFolder=${LOG_DIR}/s1
mkdir -p $logFolder
fsLicense=$(fsLicensePath)
# we'll be running the Docker containers as yourself, not as root:
userID=$(id -u):$(id -g)
### Get conatiner images: ###
container_pull cbinyu/heudiconv:v3.7.0
container_pull bids/validator:v1.7.2
container_pull cbinyu/bids_pydeface:v2.0.3
container_pull poldracklab/mriqc:0.16.1
container_pull nipreps/fmriprep:20.2.3
# Set up some derived variables that we'll use later:
fsLicenseBasename=$(basename $fsLicense)
fsLicenseFolder=${fsLicense%$fsLicenseBasename}
### Extract DICOMs into BIDS: ###
# The images were extracted and organized in BIDS format:
# --name heudiconv_container \
container_run \
$dcmFolder:/dataIn:ro \
$STUDY_DIR:/dataOut \
cbinyu/heudiconv:v3.7.0 \
${SINGULARITY_PULLFOLDER}/heudiconv_v3.7.0.sif \
"-d /dataIn/{subject}/*/*.dcm \
-f cbi_heuristic_simple \
-s ${SUBJECT_ID} \
-ss ${SESSION_ID} \
-c dcm2niix \
-b \
-o /dataOut \
--overwrite" \
> ${logFolder}/sub-${SUBJECT_ID}_extraction.log 2>&1
# heudiconv makes files read only
# We need some files to be writable, eg for defacing
chmod -R u+wr,g+wr ${STUDY_DIR}
## We run the BIDS-validator:
container_run \
$STUDY_DIR:/data:ro \
$STUDY_DIR:/ignore:ro \
bids/validator:v1.7.2 \
${SINGULARITY_PULLFOLDER}/validator_v1.7.2.sif \
"/data" \
> ${logFolder}/bids-validator_report.txt 2>&1
# For BIDS compliance, we want the validator report to go to the top level of derivatives. But for debugging, we want all logs from a given script to go to a script-specific folder
#> ${STUDY_DIR}/derivatives/bids-validator_report.txt 2>&1
### Deface: ###
# The anatomical images were defaced using PyDeface:
container_run \
$STUDY_DIR:/data \
$STUDY_DIR:/ignore:ro \
cbinyu/bids_pydeface:v2.0.3 \
${SINGULARITY_PULLFOLDER}/bids_pydeface_v2.0.3.sif \
"/data \
/data/derivatives \
participant \
--participant_label ${SUBJECT_ID} \
--skip_bids_validator" \
> ${logFolder}/sub-${SUBJECT_ID}_pydeface.log 2>&1
### MRIQC: ###
# mriqc_reports folder contains the reports generated by 'mriqc'
container_run \
$STUDY_DIR:/data \
$STUDY_DIR:/ignore:ro \
cbinyu/mriqc:0.15.0 \
${SINGULARITY_PULLFOLDER}/mriqc_0.16.1.sif \
"/data \
/data/derivatives/mriqc_reports \
participant \
--ica \
--verbose-reports \
--fft-spikes-detector \
--participant_label ${SUBJECT_ID}" \
> ${logFolder}/sub-${SUBJECT_ID}_mriqc_participant.log 2>&1
container_run \
$STUDY_DIR:/data \
$STUDY_DIR:/ignore:ro \
cbinyu/mriqc:0.15.0 \
${SINGULARITY_PULLFOLDER}/mriqc_0.16.1.sif \
"/data \
/data/derivatives/mriqc_reports \
group" \
> ${logFolder}/sub-${SUBJECT_ID}_mriqc_group.log 2>&1
### fMRIPrep: ###
# fmriprep folder contains the reports and results of 'fmriprep'
container_run \
$STUDY_DIR:/data \
${fsLicenseFolder}:/FSLicenseFolder:ro \
nipreps/fmriprep:20.2.1 \
${SINGULARITY_PULLFOLDER}/fmriprep_20.2.1.sif \
"/data \
/data/derivatives \
participant \
--fs-license-file /FSLicenseFolder/$fsLicenseBasename \
--output-space T1w:res-native fsnative:res-native \
--participant_label ${SUBJECT_ID} \
--skip_bids_validation \
--no-submm-recon" \
> ${logFolder}/sub-${SUBJECT_ID}_fMRIPrep.log 2>&1