forked from AG-Boerries/MIRACUM-Pipe
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_panel_cnv.sh
executable file
·155 lines (124 loc) · 4.15 KB
/
make_panel_cnv.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/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 " -p computing as parallel process"
echo " -h show this help screen"
exit 1
}
while getopts d:ph option; do
case "${option}" in
d) readonly PARAM_DIR_PATIENT=$OPTARG ;;
p) readonly PARALLEL_PROCESSES=2 ;;
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}")" = "panel" ]]; then
readonly CFG_CASE=panelTumor
fi
echo ${CFG_CASE}
# 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"
##################################################################################################################
# CNV Calling with ControlFREEC
readonly DIR_CNV_OUTPUT="${DIR_WES}/CNV"
[[ -d "${DIR_CNV_OUTPUT}" ]] || mkdir -p "${DIR_CNV_OUTPUT}"
# names
readonly NameTD=${CFG_CASE}_${PARAM_DIR_PATIENT}_td
readonly NameD=${CFG_CASE}_${PARAM_DIR_PATIENT}
# keep
readonly bam=${DIR_WES}/${NameTD}_output.sort.rmdup.realigned.fixed.recal.bam
readonly HRD_OUTPUT=${DIR_WES}/${NameD}.seqz.gz
readonly HRD_OUTPUT_SMALL=${DIR_WES}/${NameD}.small.seqz.gz
readonly HRD_MODEL=${DIR_WES}/${NameD}_sequenza/${NameD}_alternative_solutions.txt
# HRD
if [ ! -f "${HRD_REF_WIG}" ]; then
echo "${HRD_REF_WIG} does not exist. Generating ..."
${SEQUENZA_UTILS} gc_wiggle --fasta "${FILE_GENOME}" -w "${SEQUENZA_WINDOW}" -o "${HRD_REF_WIG}"
fi
${SEQUENZA_UTILS} bam2seqz -S "${BIN_SAMTOOLS}" -gc "${HRD_REF_WIG}" --fasta "${FILE_GENOME}" -n "${bam}" --tumor "${bam}" --normal2 "${SEQUENZA_NON_MATCHING_NORMAL}" \
-C ${SEQUENZA_CHROMOSOMES} -o "${HRD_OUTPUT}"
${SEQUENZA_UTILS} seqz_binning -s "${HRD_OUTPUT}" -w "${SEQUENZA_WINDOW}" -o "${HRD_OUTPUT_SMALL}"
${BIN_RSCRIPT} "${DIR_RSCRIPT}/HRD.R" "${NameD}" "${DIR_WES}"
# Extract ploidy and purity from sequenza
PLOIDY=$(${BIN_RSCRIPT} "--vanilla" "-e" "ploidy <- round(read.delim('${HRD_MODEL}', header = T)[1, 2]); cat(ifelse(round(ploidy) < 2, 2, round(ploidy)))")
CONTAMINATION=$(${BIN_RSCRIPT} "--vanilla" "-e" "cat(1-read.delim('${HRD_MODEL}', header = T)[1, 1])")
# build config file
cat >"${DIR_WES}"/CNV_config.txt <<EOI
[general]
chrFiles = ${DIR_CHROMOSOMES}
chrLenFile = ${CFG_REFERENCE_LENGTH}
breakPointType = 4
breakPointThreshold = 1.2
forceGCcontentNormalization = 1
gemMappabilityFile = ${FILE_REFERENCE_MAPPABILITY}
intercept = 1
minCNAlength = 3
maxThreads = ${CFG_COMMON_CPUCORES}
noisyData = TRUE
outputDir = ${DIR_CNV_OUTPUT}
ploidy = ${PLOIDY}
contamination = ${CONTAMINATION}
contaminationAdjustment = TRUE
printNA = FALSE
readCountThreshold = 50
samtools = ${BIN_SAMTOOLS}
bedtools = ${DIR_TOOLS}/bedtools2/bin/bedtools
sex = ${CFG_SEX}
step = 0
window = 0
uniqueMatch = TRUE
BedGraphOutput = TRUE
[sample]
mateFile = ${bam}
inputFormat = BAM
mateOrientation = FR
[BAF]
makePileup = ${CFG_REFERENCE_DBSNP}
fastaFile = ${FILE_GENOME}
minimalCoveragePerPosition = ${CFG_PANEL_MUTECT_CALLABLEDEPTH}
minimalQualityPerPosition = ${CFG_GENERAL_MINBASEQUAL}
SNPfile = ${CFG_REFERENCE_DBSNP}
[target]
captureRegions = ${CFG_REFERENCE_CAPTUREREGIONS}
EOI
# run CNV calling
export PATH="${BIN_SAMTOOLS}:${PATH}"
${BIN_FREEC} -conf "${DIR_WES}"/CNV_config.txt
rm ${DIR_CNV_OUTPUT}/*.pileup