forked from HBClab/RestingState
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessRestingState.sh
More file actions
executable file
·1440 lines (1121 loc) · 47.6 KB
/
processRestingState.sh
File metadata and controls
executable file
·1440 lines (1121 loc) · 47.6 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
########################################################################
# Two main processing pipelines: "Classic" and "Melodic"
#
# Classic:
# -P 1:
# dataPrep
# qualityCheck
# -P 2a:
# restingStatePreprocess
# removeNuisanceRegressor
# motionScrub
# seedVoxelCorrelation
#
#
# Melodic:
# -P 1:
# dataPrep
# qualityCheck
# -P 2:
# restingStateMelodic
# -P 3:
# ICA_denoise
# removeNuisanceRegressor
# motionScrub
# seedVoxelCorrelation
########################################################################
scriptPath=`perl -e 'use Cwd "abs_path";print abs_path(shift)' $0`
scriptDir=`dirname $scriptPath`
roiDir=$scriptDir/ROIs
function printCommandLine {
echo ""
echo "Usage: processRestingState.sh -i datafile -r ROI -n nuisanceROI -t tr -T te -s smooth -P 1"
echo ""
echo " -OR-"
echo ""
echo " processRestingState.sh -i datafile -R datafile -N nuisanceDatafile -t tr -T te -s smooth -P 1"
echo ""
echo " where:"
echo ""
echo " Input Data (and related flags)"
echo " -------------------"
echo " -i Data file having a space-separated list of anatomical and epi images"
echo " *Text file with five possible entries:"
echo " 1) T1 (with skull)"
echo " 2) T1 (skull-stripped)"
echo " 3) EPI image"
echo " 4) FieldMap: Phase image"
echo " 5) FieldMap: Magnitude image"
echo ""
echo " A few notes:"
echo " *If FieldMap correction is to be run, you must ALSO run the '-f' flag"
echo " *The T1 files MUST be in NIFTI format"
echo " ** The skull-stripped file will be renamed T1_MNI_brain. The image with skull will be renamed T1_MNI."
echo " *If EPI is in DICOM format, it will be converted to NIFTI. If already NIFTI, it will be checked"
echo " for naming convention and orientation."
echo " -s spatial smoothing (mm) (default to 6mm)"
echo " -L lowpass filter frequency (Hz)"
echo " -H highpass filter frequency (Hz)"
echo " *default is set to NOT pass any low/highpass filter settings and to use restingStatePreprocess"
echo " script defaults (.008 < f < .08 Hz)"
echo " -o output directory (will create /anat for T1 data, /func for EPI data) (default is to write to EPI directory)"
echo " -c clobber/overwrite previous results"
echo " -m MotionScrubb the EPI: O,1 or 2 (default is 0/no)"
echo " 0 = use non-motionscrubbed EPI only (default)"
echo " 1 = use motionscrubbed EPI only"
echo " 2 = use motionscrubbed and non-motionscrubbed EPI (parallel output)"
echo " -V Review SeedCorrelation Results (default is to NOT view results). Setting of this flag will spit out time-series plot"
echo " of seed/ROI"
echo " *If selected, results seed Maps will be registered to subject's T1 and the MNI 2mm atlas"
echo ""
echo ""
echo ""
echo " EPI Data"
echo " -------------------"
echo " -t TR (seconds) (default to 2 s)"
echo " -T TE (milliseconds) (default to 30 ms)"
echo ""
echo ""
echo ""
echo " FieldMap Data"
echo " -------------------"
echo " -f Use FieldMap Correction with BBR (EPI to T1 registration)"
echo " *This is only applicable for data acquired on a Siemens scanner"
echo " -D dwell time (in seconds)"
echo " *dwell time is from the EPI but is only set if FieldMap correction ('-f') is chosen."
echo " *If not set and FieldMap correction is flagged ('-f'), default is 0.00056"
echo " **If DICOM is used for FieldMap input, dwellTime will be read from the header."
echo " -d Phase Encoding Direction"
echo " *peDir is from the EPI but is only set if FieldMap correction ('-f') is chosen."
echo " *If not set and FieldMap correction is flagged ('-f'), default is -y"
echo " **If DICOM is used for FieldMap input, peDir will be read from the header."
echo " -F deltaTE of the FieldMap (in mS)"
echo " *This scan be obtained from the difference in TE between the Phase and Magnitude images"
echo " *If FieldMap correction is called ('-f') and deltaTE is not specified, 2.46 mS is default."
echo " *Common TE values are 12.46 for the Magnitude, 10.00 for the Phase."
echo ""
echo ""
echo ""
echo " Seed Data"
echo " -------------------"
echo " -r ROI for seed voxel (can be used multiple times)"
echo " -R Data file with seed list, one seed per line"
echo " **Use ONLY one option, -r or -R, NOT both"
echo ""
echo ""
echo ""
echo " Nuisance Regressors"
echo " -------------------"
echo " -n nuisance ROI for regression (can be used multiple times)"
echo " -N Data file with nuisance ROI list, one ROI per line"
echo " **Use ONLY one option, -n or -N, NOT both"
echo ""
echo ""
echo ""
echo " Data Streams"
echo " -------------------"
echo " -P multi-part processing (possibly involving MELODIC**)"
echo " 1 = Data setup, quality control"
echo " 2 = MELODIC IC creation, signal/noise determination"
echo " 2a = High/Lowpass filtering, Nuisance Regression, Motion scrubbing (if chosen with '-m' flag), Network creation"
echo " * If this option is chosen, MELODIC/denoising will NOT be performed and step '-P 3' will NOT need to be run"
echo " 3 = Denoise, Nuisance Regression, Motion scrubbing (if chosen with '-m' flag), Network creation"
echo " -I List (comma-separated) of noise IC's from MELODIC ('-P 2)"
echo " -l Binary lesion mask"
echo " *This is only to be provided for T1 to MNI registration. The mask MUST be in the anatomical space."
echo " -p rsParams file (will be created after Initial '-P 1' run"
echo " *With initial run ('-P 1'), ALL further processing flags can be set ('-m, -r, etc.'). These input"
echo " flags will be stored in a text file, rsParams (in the EPI output directory). Further"
echo " processing ('-P 2, -P 3') can just point at this text file and variables will be set."
echo " IF parameters aren't set initially (for MELODIC, etc.), they MUST be set with appropriate '-P' section"
echo ""
echo " e.g.:"
echo ""
echo " processRestingState.sh -i datafile -r ROI -t tr -T te -s smooth -m 1 -c -P 1"
echo ""
echo " would then require:"
echo ""
echo " processRestingState.sh -p pathToEPIDir/rsParams -P 2"
echo " processRestingState.sh -p pathToEPIDir/rsParams -P 3"
echo ""
echo ""
echo " **Optionally, this script can be run in a three part process (that will require manual intevention):"
echo " PartI: Data Preparation and Quality Control"
echo " *This will make sure EPI and T1 are properly oriented and named and give a base for how noisy/bad the"
echo " input data is. The user could stop at this point, evaluate the"
echo " data (check analysisResults.html in the EPI output directory) to determine if it's worth processing further"
echo " PartII: MELODIC IC output"
echo " *The user will need to examine all outputs of MELODIC to evaluate ICs as noise or signal."
echo " PartIII: Denoising data, Nuisance regression, Motion Scrubbing (if set) and Network creation"
echo " *After determining signal ICs from PartII, this step will finish up the processing, first"
echo " removing nuisnace regressors further from the signal (Global, WM and CSF signal),"
echo " Motion scrubbing (eliminating TRs with too much motion) and creating network maps from input ROIs"
echo ""
echo " For a list of possible ROIs, see files in $roiDir"
echo ""
exit 1
}
# Parse Command line arguments
while getopts “hi:s:L:H:o:cm:Vt:T:fD:d:F:r:R:n:N:P:I:l:p:” OPTION
do
case $OPTION in
h)
printCommandLine
;;
i)
datafile=`perl -e 'use Cwd "abs_path";print abs_path(shift)' $OPTARG`
;;
s)
smooth=$OPTARG
;;
L)
lowpassArg=$OPTARG
;;
H)
highpassArg=$OPTARG
;;
o)
outDir=$OPTARG
outFlag=1
;;
c)
overwriteFlag=1
;;
m)
motionscrubFlag=$OPTARG
;;
V)
reviewResults=1
;;
t)
tr=$OPTARG
;;
T)
te=$OPTARG
;;
f)
fieldMapFlag=1
;;
D)
dwellTime=$OPTARG
;;
d)
peDir=$OPTARG
;;
F)
deltaTE=$OPTARG
;;
r)
roiList=`echo $roiList $OPTARG`
;;
R)
roiList=`cat $OPTARG`
;;
n)
nuisanceList=`echo $nuisanceList $OPTARG`
;;
N)
nuisanceList=`cat $OPTARG`
;;
P)
multiFlag=$OPTARG
;;
I)
noiseIC=$OPTARG
;;
l)
lesionMask=$OPTARG
lesionMaskFlag=1
;;
p)
rsParamFile=$OPTARG
rsParamFileSet=1
;;
?)
printCommandLine
;;
esac
done
#A few default parameters (if input not specified, these parameters are assumed)
if [[ $overwriteFlag == "" ]]; then
overwriteFlag=0
fi
if [[ $multiFlag == "" ]]; then
multiFlag=0
fi
if [[ $outFlag == "" ]]; then
outFlag=0
fi
if [[ $motionscrubFlag == "" ]]; then
motionscrubFlag=0
fi
if [[ $fieldMapFlag == "" ]]; then
fieldMapFlag=0
fi
if [[ $reviewResults == "" ]]; then
reviewResults=0
fi
if [[ $rsParamFileSet == "" ]]; then
rsParamFileSet=0
fi
if [[ $lesionMaskFlag == "" ]]; then
lesionMaskFlag=0
fi
#Check for multi-flag settings. One of them has to be used in order to run
if [[ $multiFlag != 1 ]] && [[ $multiFlag != 2 ]] && [[ $multiFlag != 2a ]] && [[ $multiFlag != 3 ]] ; then
echo "Error: One of the multi-flags must be used. Please run with either '-P (1, 2, 2a or 3)'"
exit 1
fi
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #
###### dataPrep and qualityCheck ############################################################
if [[ $multiFlag == 1 ]]; then
###### Basic Input/variables ########################################
#Directory to dump output paramaters to (where rsParams will reside)
epi=`sed -n "1p" $datafile | awk '{print $3}'`
epiDir=`dirname $epi`
#Set up directories for T1,EPI & FieldMap (if $outDir is specified)
if [[ $outDir != "" ]]; then
outDirOption="-o $outDir"
#EPI directory
if [[ ! -e $outDir/func ]]; then
mkdir -p $outDir/func
fi
#T1 directory
if [[ ! -e $outDir/anat ]]; then
mkdir -p $outDir/anat
fi
#FieldMap directory
if [[ $fieldMapFlag == 1 ]]; then
if [[ ! -e $outDir/fieldMap ]]; then
mkdir -p $outDir/fieldMap
fi
fi
else
outDirOption=""
fi
#rsParams log file setup
if [[ $outDir != "" ]]; then
rsParamDir=$outDir/func
else
rsParamDir=$epiDir
fi
#Variable for output text file
rsParamFile=$rsParamDir/rsParams
###############################################
##### Misc variables ######################
#If user set ROI seedlist from beginning, echo out list to rsParams (can be sourced later)
if [[ $roiList != "" ]]; then
for i in $roiList
do
seeds="$seeds -r $i"
done
echo "seeds=$seeds" >> $rsParamFile
fi
#If user set nuisance ROI list from beginning, echo out list to rsParams (can be sourced later)
if [[ $nuisanceList != "" ]]; then
for i in $nuisanceList
do
nuisanceROI="$nuisanceROI -n $i"
done
echo "nuisanceROI=$nuisanceROI" >> $rsParamFile
fi
#If Lowpass filter is set from the beginning
if [[ $lowpassArg != "" ]]; then
echo "lowpassFilt=$lowpassArg" >> $rsParamFile
fi
#If Highpass filter is set from the beginning
if [[ $highpassArg != "" ]]; then
echo "highpassFilt=$highpassArg" >> $rsParamFile
fi
#If motionScrub flag is set from the beginning
if [[ $motionscrubFlag == 1 || $motionscrubFlag == 2 ]]; then
echo "motionScrub=$motionscrubFlag" >> $rsParamFile
fi
#If reviewResults flag is set from the beginning
if [[ $reviewResults == 1 ]]; then
echo "reviewResultsFlag=$reviewResults" >> $rsParamFile
fi
#If TR is set from the beginning
if [[ $tr != "" ]]; then
echo "epiTR=$tr" >> $rsParamFile
fi
#If TE is set from the beginning
if [[ $te != "" ]]; then
echo "epiTE=$te" >> $rsParamFile
fi
#If smoothing kernel is set from the beginning
if [[ $smooth != "" ]]; then
echo "epiSmooth=$smooth" >> $rsParamFile
fi
#If Phase Encoding direction is set from the beginning
if [[ $peDir != "" ]]; then
echo "peDir=$peDir" >> $rsParamFile
fi
#If Dwell Time is set from the beginning
if [[ $dwellTime != "" ]]; then
echo "epiDwell=$dwellTime" >> $rsParamFile
fi
#If deltaTE is set from the beginning
if [[ $deltaTE != "" ]]; then
echo "deltaTE=$deltaTE" >> $rsParamFile
fi
###############################################
##### Initial processing check/clobber check ######################
#Check to see if Initial processing has been done
if [[ -e $rsParamFile ]]; then
baseProc=`cat $rsParamFile | grep "IsDone_PartI_" | tail -1`
fi
if [[ $overwriteFlag == 0 ]] && [[ $baseProc != "" ]]; then
echo "Base processing for EPI/T1, through qualityCheck, has already been run. Please set overwrite (-c) option to reprocess."
exit 1
fi
###############################################
##### -P 1 ######################
##Start PartI
#Set up text file to track info
echo "....Beginning Base processing of EPI/T1 data"
echo "_PartI_" >> $rsParamFile
echo "`date`" >> $rsParamFile
##### -P 1 (dataPrep) ######################
##### dataPrep variables ######################
#Initial datafile check and setup (need input files to work with)
if [[ $datafile == "" ]]; then
echo "Error: data file must be specified with the -i option"
exit 1
fi
##Flags that CAN be set but aren't required:
#-o output directory (will create func, anat, fieldMap (if chosen))
#-t TR (seconds)
#-T TE (ms)
#-f FieldMapFlag (preprocess FieldMap data)
#-F deltaTE (only if '-f' is set). This is optional and can be read from DICOM header
#-c overWriteFlag (clobber)
#TR
if [[ $tr != "" ]]; then
trOption="-t $tr"
else
trOption=""
fi
#TE
if [[ $te != "" ]]; then
teOption="-T $te"
else
teOption=""
fi
#fieldMapFlag
if [[ $fieldMapFlag == 1 ]]; then
fieldMapFlagOption="-f"
else
fieldMapFlagOption=""
fi
#deltaTe
deltaTECheck=`cat $rsParamFile | grep "deltaTE=" | tail -1`
if [[ $deltaTE != "" ]]; then
deltaTEOption="-F $deltaTE"
else
if [[ $deltaTECheck != "" ]]; then
deltaTEOption="-F $deltaTECheck"
else
deltaTEOption=""
fi
fi
#Overwrite flag
if [[ $overwriteFlag == 1 ]]; then
overwriteOption="-c"
else
overwriteOption=""
fi
###############################################
#Data Prep (Run EPI,T1 & FieldMap (if chosen) through processing stream to get correct name and orientation)
$scriptDir/dataPrep.sh -i $datafile $outDirOption $trOption $teOption $fieldMapFlagOption $deltaTEOption $overwriteOption
###############################################
##### -P 1 (qualityCheck) ######################
##### qualityCheck variables ######################
#Variables set from dataPrep script. Source from rsParams file
epiData=`cat $rsParamFile | grep "epiRaw=" | tail -1 | awk -F"=" '{print $2}'`
t1Data=`cat $rsParamFile | grep "t1=" | tail -1 | awk -F"=" '{print $2}'`
t1SkullData=`cat $rsParamFile | grep "t1Skull=" | tail -1 | awk -F"=" '{print $2}'`
##Flags that CAN be set but aren't required:
#l lesionMask (to be used with flirt/fnirt)
#-f FieldMapFlag (BBR registration with FieldMap data)
#-b FieldMap (prepped (combo of Phase and Magnitude)
#-v FieldMapMag
#-w FieldMapMag (skull-stripped)
#-D dwellTime (can be read from DICOM header)
#-d peDir (can be read from DICOM header
#-c overWriteFlag (clobber)
#FieldMap flag
fieldMapCheck=`cat $rsParamFile | grep "fieldMapCorrection=" | tail -1 | awk -F"=" '{print $2}'`
if [[ $fieldMapCheck == 1 ]]; then
#FieldMap images
fieldMapMag=`cat $rsParamFile | grep "fieldMapMag=" | tail -1 | awk -F"=" '{print $2}'`
fieldMapMagStripped=`cat $rsParamFile | grep "fieldMapMagStripped=" | tail -1 | awk -F"=" '{print $2}'`
fieldMapPrepped=`cat $rsParamFile | grep "fieldMapPrepped=" | tail -1 | awk -F"=" '{print $2}'`
#Dwell time
dwellTimeCheck=`cat $rsParamFile | grep "epiDwell=" | tail -1 | awk -F"=" '{print $2}'`
#Phase Encoding Direction
peDirCheck=`cat $rsParamFile | grep "peDir=" | tail -1 | awk -F"=" '{print $2}'`
#FieldMap options
fieldMapOption="-f -b $fieldMapPrepped -v $fieldMapMag -x $fieldMapMagStripped -D $dwellTimeCheck -d $peDirCheck"
else
fieldMapOption=""
fi
#Lesion mask flag (used in T1 to MNI registration)
if [[ $lesionMaskFlag == 1 ]]; then
lesionMaskOption="-l $lesionMask"
echo "lesionMask=$lesionMask" >> $rsParamFile
else
lesionMaskOption=""
fi
#Overwrite flag
if [[ $overwriteFlag == 1 ]]; then
overwriteOption="-c"
else
overwriteOption=""
fi
###############################################
#Quality Control
$scriptDir/qualityCheck.sh -E $epiData -A $t1Data -a $t1SkullData $lesionMaskOption $fieldMapOption $overwriteOption
###############################################
echo "IsDone_PartI_" >> $rsParamFile
###############################################
#############################################################################################
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #
###### restingStateMelodic ##################################################################
elif [[ $multiFlag == 2 ]]; then
##### Initial processing check/clobber check ######################
#Check for rsParams file (needed to grep for appropriate information)
if [[ $rsParamFile == "" ]]; then
echo "User must set path to rsParams file (-p) for further processing"
exit 1
fi
#Check to see if Initial processing has been done
baseProc2=`cat $rsParamFile | grep "IsDone_PartII_" | tail -1`
if [[ $overwriteFlag == 0 ]] && [[ $baseProc2 != "" ]]; then
echo "Base processing for MELODIC, has already been run. Please set overwrite (-c) option to reprocess."
exit 1
fi
###############################################
##### -P 2 ######################
##Start PartII
echo "....Calculating ICA components of EPI data"
echo "_PartII_" >> $rsParamFile
echo "`date`" >> $rsParamFile
##### -P 2 (restingStateMelodic) ######################
##### restingStateMelodic variables ######################
#EPI data (motion-corrected and skull-stripped)
epiDataCheck=`cat $rsParamFile | grep "epiMC=" | tail -1`
if [[ $epiDataCheck != "" ]]; then
epiData=`cat $rsParamFile | grep "epiMC=" | tail -1 | awk -F"=" '{print $2}'`
else
echo "Motion-corrected EPI needs to be specified. Please run processRestingState.sh '-P 1' first"
exit 1
fi
#T1 (skull-stripped)
t1DataCheck=`cat $rsParamFile | grep "t1=" | tail -1`
if [[ $t1DataCheck != "" ]]; then
t1Data=`cat $rsParamFile | grep "t1=" | tail -1 | awk -F"=" '{print $2}'`
else
echo "T1 needs to be specified. Please run processRestingState.sh -P 1' first"
exit 1
fi
#TR (-t)
trCheck=`cat $rsParamFile | grep "epiTR=" | tail -1 | awk -F"=" '{print $2}'`
if [[ $tr != "" ]]; then
trOption="-t $tr"
else
if [[ $trCheck != "" ]]; then
trOption="-t $trCheck"
else
trOption=""
fi
fi
#TE (-T)
teCheck=`cat $rsParamFile | grep "epiTE=" | tail -1 | awk -F"=" '{print $2}'`
if [[ $te != "" ]]; then
teOption="-T $te"
else
if [[ $teCheck != "" ]]; then
teOption="-T $teCheck"
else
teOption=""
fi
fi
#Smooth (-s)
smoothCheck=`cat $rsParamFile | grep "epiSmooth=" | tail -1 | awk -F"=" '{print $2}'`
if [[ $smooth != "" ]]; then
smoothOption="-s $smooth"
if [[ $smoothCheck == "" ]]; then
echo "epiSmooth=${smooth}" >> $rsParamFile
fi
else
if [[ $smoothCheck != "" ]]; then
smoothOption="-s $smoothCheck"
else
smoothOption=""
fi
fi
##Flags that CAN be set but aren't required:
#-f FieldMapFlag (updatefeatreg using nonlinear transforms (EPItoT1)
#-H highpassArg (Highpass Filter)
#-c overWriteFlag (clobber)
#FieldMap flag
fieldMapCheck=`cat $rsParamFile | grep "fieldMapCorrection=" | tail -1 | awk -F"=" '{print $2}'`
if [[ $fieldMapCheck == 1 ]]; then
fieldMapOption="-f"
else
fieldMapOption=""
fi
#Highpass Filter (-H)
highpassCheck=`cat $rsParamFile | grep "highpassFilt=" | tail -1 | awk -F"=" '{print $2}'`
if [[ $highpassArg != "" ]]; then
highpassOption="-H $highpassArg"
else
if [[ $highpassCheck != "" ]]; then
highpassOption="-H $highpassCheck"
else
highpassOption=""
fi
fi
#Overwrite flag
if [[ $overwriteFlag == 1 ]]; then
overwriteOption="-c"
else
overwriteOption=""
fi
###############################################
#MELODIC ICA component creation
$scriptDir/restingStateMelodic.sh -E $epiData -A $t1Data $trOption $teOption $smoothOption $fieldMapOption $highpassOption $overwriteOption
###############################################
echo "IsDone_PartII_" >> $rsParamFile
###############################################
#############################################################################################
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #
###### restingStatePreprocess, removeNuisanceRegressor, MotionScrub, seedVoxelCorrelation ###
elif [[ $multiFlag == 2a ]]; then
##### Initial processing check/clobber check ######################
#Check for rsParams file (needed to grep for appropriate information)
if [[ $rsParamFile == "" ]]; then
echo "User must set path to rsParams file (-p) for further processing"
exit 1
fi
#Check to see if Initial processing has been done
baseProc2a=`cat $rsParamFile | grep "IsDone_PartIIa_" | tail -1`
if [[ $overwriteFlag == 0 ]] && [[ $baseProc2a != "" ]]; then
echo "Final processing has already been run. Please set overwrite (-c) option to reprocess."
exit 1
fi
###############################################
##### -P 2a ######################
##Start PartIIa
echo "....Filtering (through seeding steps) EPI data"
echo "_PartIIa_" >> $rsParamFile
echo "_NoMELODIC_" >> $rsParamFile
echo "`date`" >> $rsParamFile
##### -P 2a (restingStatePreprocess) ######################
##### restingStatePreprocess variables ######################
#EPI data (motion-corrected and skull-stripped)
epiDataCheck=`cat $rsParamFile | grep "epiMC=" | tail -1`
if [[ $epiDataCheck != "" ]]; then
epiData=`cat $rsParamFile | grep "epiMC=" | tail -1 | awk -F"=" '{print $2}'`
else
echo "Motion-corrected EPI needs to be specified. Please run processRestingState.sh '-P 1' first"
exit 1
fi
#T1 (skull-stripped)
t1DataCheck=`cat $rsParamFile | grep "t1=" | tail -1`
if [[ $t1DataCheck != "" ]]; then
t1Data=`cat $rsParamFile | grep "t1=" | tail -1 | awk -F"=" '{print $2}'`
else
echo "T1 needs to be specified. Please run processRestingState.sh -P 1' first"
exit 1
fi
#TR (-t)
trCheck=`cat $rsParamFile | grep "epiTR=" | tail -1 | awk -F"=" '{print $2}'`
if [[ $tr != "" ]]; then
trOption="-t $tr"
else
if [[ $trCheck != "" ]]; then
trOption="-t $trCheck"
else
trOption=""
fi
fi
#TE (-T)
teCheck=`cat $rsParamFile | grep "epiTE=" | tail -1 | awk -F"=" '{print $2}'`
if [[ $te != "" ]]; then
teOption="-T $te"
else
if [[ $teCheck != "" ]]; then
teOption="-T $teCheck"
else
teOption=""
fi
fi
#Smooth (-s)
smoothCheck=`cat $rsParamFile | grep "epiSmooth=" | tail -1 | awk -F"=" '{print $2}'`
if [[ $smooth != "" ]]; then
smoothOption="-s $smooth"
if [[ $smoothCheck == "" ]]; then
echo "epiSmooth=${smooth}" >> $rsParamFile
fi
else
if [[ $smoothCheck != "" ]]; then
smoothOption="-s $smoothCheck"
else
smoothOption=""
fi
fi
##Flags that CAN be set but aren't required:
#-f FieldMapFlag (updatefeatreg using nonlinear transforms (EPItoT1)
#-c overWriteFlag (clobber)
#FieldMap flag
fieldMapCheck=`cat $rsParamFile | grep "fieldMapCorrection=" | tail -1 | awk -F"=" '{print $2}'`
if [[ $fieldMapCheck == 1 ]]; then
fieldMapOption="-f"
else
fieldMapOption=""
fi
#Overwrite flag
if [[ $overwriteFlag == 1 ]]; then
overwriteOption="-c"
else
overwriteOption=""
fi
###############################################
#First level FEAT (preproc.feat)
$scriptDir/restingStatePreprocess.sh -E $epiData -A $t1Data $trOption $teOption $smoothOption $fieldMapOption $overwriteOption
###############################################
##### -P 2a (removeNuisanceRegressor) ######################
##### removeNuisanceRegressor variables ######################
#EPI data (smoothed)
epiDataCheck=`cat $rsParamFile | grep "epiNonfilt=" | tail -1`
if [[ $epiDataCheck != "" ]]; then
epiData=`cat $rsParamFile | grep "epiNonfilt=" | tail -1 | awk -F"=" '{print $2}'`
else
echo "Non-filtered (smoothed) EPI needs to be specified. Please run restingStatePreprocess.sh first"
exit 1
fi
#T1 (skull-stripped)
t1DataCheck=`cat $rsParamFile | grep "t1=" | tail -1`
if [[ $t1DataCheck != "" ]]; then
t1Data=`cat $rsParamFile | grep "t1=" | tail -1 | awk -F"=" '{print $2}'`
else
echo "T1 needs to be specified. Please run processRestingState.sh -P 1' first"
exit 1
fi
#TR (-t)
trCheck=`cat $rsParamFile | grep "epiTR=" | tail -1 | awk -F"=" '{print $2}'`
if [[ $tr != "" ]]; then
trOption="-t $tr"
else
if [[ $trCheck != "" ]]; then
trOption="-t $trCheck"
else
trOption=""
fi
fi
#TE (-T)
teCheck=`cat $rsParamFile | grep "epiTE=" | tail -1 | awk -F"=" '{print $2}'`
if [[ $te != "" ]]; then
teOption="-T $te"
else
if [[ $teCheck != "" ]]; then
teOption="-T $teCheck"
else
teOption=""
fi
fi
#Nuisance Regressor ROIs (-N/-n)
nuisanceROICheck=`cat $rsParamFile | grep "nuisanceROI=" | tail -1 | awk -F"=" '{print $2}'`
if [[ $nuisanceList != "" ]]; then
for i in $nuisanceList
do
nuisanceROI="$nuisanceROI -n $i"
done
nuisanceROIOption="$nuisanceROI"
else
if [[ $nuisanceROICheck != "" ]]; then
nuisanceROIOption="$nuisanceROICheck"
else
nuisanceROIOption=""
fi
fi
##Flags that CAN be set but aren't required:
#-L lowpassArg (Lowpass Filter)
#-H highpassArg (Highpass Filter)
#-c overWriteFlag (clobber)
#Lowpass Filter (-L)
lowpassCheck=`cat $rsParamFile | grep "lowpassFilt" | tail -1 | awk -F"=" '{print $2}'`
if [[ $lowpassArg != "" ]]; then
lowpassOption="-L $lowpassArg"
else
if [[ $lowpassCheck != "" ]]; then
lowpassOption="-L $lowpassCheck"
else
lowpassOption=""
fi
fi
#Highpass Filter (-H)
highpassCheck=`cat $rsParamFile | grep "highpassFilt=" | tail -1 | awk -F"=" '{print $2}'`
if [[ $highpassArg != "" ]]; then
highpassOption="-H $highpassArg"
else
if [[ $highpassCheck != "" ]]; then
highpassOption="-H $highpassCheck"
else
highpassOption=""
fi
fi
#Overwrite flag
if [[ $overwriteFlag == 1 ]]; then
overwriteOption="-c"
else
overwriteOption=""
fi
###############################################
#Nuisance Regression (nuisancereg.feat)
$scriptDir/removeNuisanceRegressor.sh -E $epiData -A $t1Data $trOption $teOption $nuisanceROIOption $lowpassOption $highpassOption $overwriteOption
###############################################
##### -P 2a (motionScrub) ######################
##### motionScrub variables ######################
#Check for motionScrub flag
motionScrubCheck=`cat $rsParamFile | grep "motionScrub=" | tail -1`
#EPI data (smoothed)
epiDataCheck=`cat $rsParamFile | grep "epiRaw=" | tail -1`
if [[ $epiDataCheck != "" ]]; then
epiData=`cat $rsParamFile | grep "epiRaw=" | tail -1 | awk -F"=" '{print $2}'`
else
echo "Raw EPI needs to be specified (-E)."