forked from AG-Boerries/MIRACUM-Pipe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_tumorOnly_report.sh
executable file
·94 lines (74 loc) · 2.72 KB
/
make_tumorOnly_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
#!/usr/bin/env bash
readonly DIR_SCRIPT=$(
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
pwd -P
)
## load settings
# shellcheck source=common.cfg.sh
. "${DIR_SCRIPT}"/common.cfg.sh
function usage() {
echo "usage: miracum_pipe.sh -d dir [-h]"
echo " -d dir specify relative folder of patient"
echo " -h show this help screen"
exit 1
}
while getopts d:h option; do
case "${option}" in
d) readonly PARAM_DIR_PATIENT=$OPTARG ;;
h) usage ;;
\?)
echo "Unknown option: -$OPTARG" >&2
exit 1
;;
:)
echo "Missing option argument for -$OPTARG" >&2
exit 1
;;
*)
echo "Unimplemented option: -$OPTARG" >&2
exit 1
;;
esac
done
# if no patient is defined
if [[ -z "${PARAM_DIR_PATIENT}" ]]; then
echo "no patient defined."
echo "--"
usage
fi
# load patient yaml
readonly CFG_SEX=$(get_config_value sex "${PARAM_DIR_PATIENT}")
if [[ "$(get_config_value common.protocol "${PARAM_DIR_PATIENT}")" = "tumorOnly" ]]; then
readonly CFG_CASE=tumorOnly
fi
# check inputs
readonly VALID_SEXES=("XX XY")
if [[ ! " ${VALID_SEXES[@]} " =~ " ${CFG_SEX} " ]]; then
echo "unknown sex: ${CFG_SEX}"
echo "use one of the following values: $(join_by ' ' ${VALID_SEXES})"
exit 1
fi
##################################################################################################################
## load programs
# shellcheck source=programs.cfg.sh
. "${DIR_SCRIPT}/programs.cfg.sh"
##################################################################################################################
cd "${DIR_ANALYSES}" || exit 1
# execute Main.R, i.e. complete analyses in R
${BIN_RSCRIPT} "${DIR_RSCRIPT}/Main.R" "${PARAM_DIR_PATIENT}"
# translate to tex
${BIN_RSCRIPT} -e "load('${DIR_ANALYSES}/Report.RData'); library(knitr); knit('${DIR_RSCRIPT}/Report_tumorOnly.Rnw');"
# fix possible knitr syntax issues
sed -i 's/\\textbf{.\\textbf{.}/\\textbf{.}/' ${DIR_ANALYSES}/Report_tumorOnly.tex
# PDF report
mv "${DIR_ANALYSES}/Report_tumorOnly.tex" "${DIR_ANALYSES}/${CFG_CASE}_${PARAM_DIR_PATIENT}_Report_tumorOnly.tex"
pdflatex -interaction=nonstopmode "${DIR_ANALYSES}/${CFG_CASE}_${PARAM_DIR_PATIENT}_Report_tumorOnly.tex" \
--output-directory="${DIR_ANALYSES}"
pdflatex -interaction=nonstopmode "${DIR_ANALYSES}/${CFG_CASE}_${PARAM_DIR_PATIENT}_Report_tumorOnly.tex" \
--output-directory="${DIR_ANALYSES}"
# clean up
# remove aux files which are created while pdflatex
rm -f "${DIR_ANALYSES}/${CFG_CASE}_${PARAM_DIR_PATIENT}_Report_tumorOnly.aux" \
"${DIR_ANALYSES}/${CFG_CASE}_${PARAM_DIR_PATIENT}_Report_tumorOnly.toc" \
"${DIR_ANALYSES}/${CFG_CASE}_${PARAM_DIR_PATIENT}_Report_tumorOnly.log" \
"${DIR_ANALYSES}/${CFG_CASE}_${PARAM_DIR_PATIENT}_Report_tumorOnly.out"