-
Notifications
You must be signed in to change notification settings - Fork 0
/
unwarp_bupbdown_report.sh
110 lines (77 loc) · 3.52 KB
/
unwarp_bupbdown_report.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
#! /bin/sh
# example usage
# unwarp_bupbdown_report.sh -t temp-unwarp_fieldmap -r report-unwarp_fieldmap [-n 6]
#---------variables---------#
tmpdir=temp-unwarp_bupbdown # name of directory for intermediate files
reportdir=report-unwarp_bupbdown # report dir
logfile_name=unwarp_bupbdown_report.log # Log file
scriptdir=`dirname $0`
#----------- Utility Functions ----------#
usage_exit() {
cat <<EOF
Generates report for correction of B0 inhomogeneity distortion using blip-up, blip-down images
Usage:
$CMD -t <directory with intermediade files from unwarp_bupbdown> -r <directory to put the generated reports>
EOF
exit 1;
}
T () {
E=0
if [ "$1" = "-e" ] ; then # just outputting and logging a message with T -e
E=1; shift
fi
cmd="$*"
echo $* | tee -a $LF # read the command into the console, and the log file
if [ "$E" != "1" ] ; then
$cmd 2>&1 | tee -a $LF # run the command. read the output into a the log file. Stderr is not directed to the logfile
fi
echo | tee -a $LF # write an empty line to the console and log file
}
error_exit (){
echo "$1" >&2 # Send message to stderr
echo "$1" >> $LF # send message to log file
exit "${2:-1}" # Return a code specified by $2 or 1 by default.
}
#------------- Parse Parameters --------------------#
while getopts t:r:s:o:n: OPT
do
case "$OPT" in
"t" ) tmpdir="$OPTARG";;
"r" ) reportdir="$OPTARG";;
"o" ) outdir="$OPTARG";;
* ) usage_exit;;
esac
done;
#------------- Setting things up --------------------#
LF=$reportdir/$logfile_name
RF=$reportdir/unwarp_bupbdown_report
if [ -e $reportdir ]; then /bin/rm -Rf $reportdir;fi
mkdir -p $reportdir
#------------- Check dependencies ----------------#
command -v fsl > /dev/null 2>&1 || { error_exit "ERROR: FSL required for report, but not found (http://fsl.fmrib.ox.ac.uk/fsl). Aborting."; }
command -v whirlgif > /dev/null 2>&1 || command -v gifsicle > /dev/null 2>&1 || { error_exit "ERROR: either whirlgif or gifsicle required for report, but neither found. Aborting."; }
command -v pandoc > /dev/null 2>&1 || { error_exit "ERROR: pandoc required for report, but not found (http://pandoc.org/). Aborting."; }
command -v R > /dev/null 2>&1 || { error_exit "ERROR: R required for report, but not found (https://www.r-project.org). Aborting."; }
rmarkdown_test=`R -q -e "\"rmarkdown\" %in% rownames(installed.packages())" | grep 1`
if [ "$rmarkdown_test" != "[1] TRUE" ]; then error_exit "ERROR: R package 'rmarkdown' required for report, but not found.
Try running this command in R:
install.packages(\"rmarkdown\") " ;fi
#------------- Begin report --------------------#
echo "---" > ${RF}.Rmd
echo "title: QA report for correction of inhomogeneous magnetic suceptibility-induced distortions using a pair of blip-up, blip-down images " >> ${RF}.Rmd
echo "output:" >> ${RF}.Rmd
echo " html_document:" >> ${RF}.Rmd
echo " keep_md: yes" >> ${RF}.Rmd
echo " toc: yes" >> ${RF}.Rmd
echo " force_captions: TRUE" >> ${RF}.Rmd
echo "---" >> ${RF}.Rmd
# warped S0s gif
T $scriptdir/image_to_movie.sh $tmpdir/S0_images.nii.gz $reportdir/native_S0s.gif
echo "## Native, warped S0 image " >> ${RF}.Rmd
echo "![](native_S0s.gif) \n" >> ${RF}.Rmd
# unwarped B0s gif
T $scriptdir/image_to_movie.sh $tmpdir/unwarped_S0_images.nii.gz $reportdir/unwarped_S0s.gif
echo "## Unwarped S0 image " >> ${RF}.Rmd
echo "![](unwarped_S0s.gif) \n" >> ${RF}.Rmd
# TODO: show fieldmap
T R -e library\(rmarkdown\)\;rmarkdown::render\(\"${RF}.Rmd\"\)