-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoAchabParall.sh
198 lines (162 loc) · 6.79 KB
/
autoAchabParall.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
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
#!/bin/sh
###########################################################################
######### ###########
######### AutoAchab ###########
######### @uthor : D Baux david.baux<at>inserm.fr ###########
######### Date : 22/08/2018 ###########
######### ###########
###########################################################################
###########################################################################
###########
########### Script to automate captainAchab WDL workflow
########### to annotate VCFs
########### see https://github.com/mobidic/MobiDL
###########
###########################################################################
#### This script is meant to be croned
#### must check the Todo directory
#### and launch captainAchab
#### This version treats all folders in parallel
#### therefore be careful
#### either use a job scheduler with cromwell or singularity
#### or ensure you won't break your server with too many samples
############## If any option is given, print help message ##################################
VERSION=1.0
USAGE="
Program: AutoAchab
Version: ${VERSION}
Contact: Baux David <[email protected]>
Usage: This script is meant to be croned
Should be executed once per minute
"
if [ $# -ne 0 ]; then
echo "${USAGE}"
echo "Error Message : Arguments provided"
echo ""
exit 1
fi
# -- Log functions got from cww.sh -- simplified here
error() { log "[error]" "$1" ; }
warning() { log "[warn]" "$1" ; }
info() { log "[info]" "$1" ; }
debug() { log "[debug]" "$1" ; }
# -- Print log
echoerr() { echo -e "$@" 1>&2 ; }
log() {
echoerr "[`date +'%Y-%m-%d %H:%M:%S'`] $1 - autoAchab version : ${VERSION} - $2"
}
############### Get options from conf file ##################################
CONFIG_FILE='./autoAchabParall.conf'
#we check params against regexp
UNKNOWN=$(cat ${CONFIG_FILE} | grep -Evi "^(#.*|[A-Z0-9_]*=[a-z0-9_ \.\/\$\{\}]*)$")
if [ -n "${UNKNOWN}" ]; then
error "Error in config file. Not allowed lines:"
echo ${UNKNOWN}
exit 1
fi
source ${CONFIG_FILE}
############### 1st check whether another instance of the script is running ##################
RESULT=$(ps x | grep -v grep | grep -c ${SERVICE})
#echo `ps x | grep -v grep |grep ${SERVICE} `
#echo "Result: ${RESULT}"
if [ "${RESULT}" -gt 3 ]; then
exit 0
fi
############### functions for admin tasks
admin() {
#if sample_dir ne json sampleid
SAMPLE_OUT=$(awk -F"[ ,\"]" '/captainAchab.sampleID/{print $7}' "$4")
ADMIN_DIR="${DONE_DIR}/${SAMPLE_OUT}/$1"
mkdir "${ADMIN_DIR}"
"${RSYNC}" -az --exclude '*.vcf' "$2" "${ADMIN_DIR}"
#cp "$2" "${ADMIN_DIR}"
#cp "$3" "${ADMIN_DIR}"
#cp "$4" "${ADMIN_DIR}"
#rm -r "${DONE_DIR}/${SAMPLE_OUT}/CaptainAchab/disease/"
chmod -R 777 "${DONE_DIR}/$3"
}
success() {
#OLDOLDOLDOLDsuccess exit code -"${DONE_DIR}/$1/CaptainAchab/admin" - "${TODO_DIR}/$1/captainAchab_inputs.json" - "${TODO_DIR}/$1/disease.txt" - ${LOG_FILE} - (Genuine|Relaunched) - ${SAMPLE}
#success exit code -"${DONE_DIR}/$1/CaptainAchab/admin" - (Genuine|Relaunched) - ${SAMPLE}
if [ "$1" -eq 0 ];then
info "$3 Job finished for $4"
#admin "$2" "$3" "$4" "$5" "$7"
admin "$2" "${TODO_DIR}/${SAMPLE}/" "$4" "$5"
#admin "CaptainAchab/admin" "${TODO_DIR}/${SAMPLE}/captainAchab_inputs.json" "${TODO_DIR}/${SAMPLE}/disease.txt" "${LOG_FILE}" "${SAMPLE}"
exec 1>>"${ERROR_DIR}/autoAchabError.log" 2>&1
rm -rf "${TODO_DIR}/$4"
else
error "$4 was not treated correctly - Please contact an Admin to check log file at ${ERROR_DIR}/$4/autoAchab.log"
"${RSYNC}" -az "${TODO_DIR}/$4" "${ERROR_DIR}"
exec 1>>"${ERROR_DIR}/autoAchabError.log" 2>&1
if [ "$?" -eq 0 ];then
rm -rf "${TODO_DIR}/$4"
fi
"${RSYNC}" -az "${DONE_DIR}/$4" "${ERROR_DIR}/$4"
chmod -R 777 "${ERROR_DIR}/$4"
rm -rf "${DONE_DIR}/$4"
exit 1
fi
}
launch() {
#launch $SAMPLE - conf - $LOG_FILE - (Genuine|Relaunched)
if [ "${ACHABILARITY}" -eq 0 ];then
"${NOHUP}" "${SH}" "${CWW}" -e "${CROMWELL_JAR}" -o "${OPTIONS_JSON}" -c "$2" -w "${CAPTAINACHAB_WDL}" -i "${TODO_DIR}/$1/captainAchab_inputs.json" >>"$3" 2>&1
#success "$?" "CaptainAchab/admin" "${TODO_DIR}/$1/captainAchab_inputs.json" "${TODO_DIR}/$1/disease.txt" "$3" "$4" "$1"
#success exit code - selfexpl - selfexpl - selfexpl - ${LOG_FILE} - (Genuine|Relaunched) - ${SAMPLE}
success "$?" "CaptainAchab/admin" "$4" "$1" "${TODO_DIR}/$1/captainAchab_inputs.json"
#success exit code - selfexpl - (Genuine|Relaunched) - ${SAMPLE} - selfexpl
else
"${NOHUP}" "${SINGULARITY}" run -B "${ANNOVAR_PATH}:/media" -B "${DATA_MOUNT_POINT}:/mnt" ${ACHABILARITY_SIMG} -o "${OPTIONS_JSON}" -c "$2" -i "${TODO_DIR}/$1/captainAchab_inputs.json" >>"$3" 2>&1
success "$?" "CaptainAchab/admin" "$4" "$1" "${TODO_DIR}/$1/captainAchab_inputs.json"
fi
}
treat_sample() {
#${SAMPLE}
############## log file
LOG_FILE="${TODO_DIR}/${SAMPLE}/autoAchab.log"
touch ${LOG_FILE}
#exec &>${LOG_FILE}
exec 1>>${LOG_FILE} 2>&1
VCF=$(ls -l --time-style="long-iso" "${TODO_DIR}/${SAMPLE}" | egrep '^-' | awk '{print $8}' | egrep '*.vcf')
if [ -f "${TODO_DIR}/${SAMPLE}/${VCF}" ] && [ -f "${TODO_DIR}/${SAMPLE}/captainAchab_inputs.json" ] && [ -f "${TODO_DIR}/${SAMPLE}/disease.txt" ];then
echo ""
info "Launching captainAchab workflow for ${SAMPLE}, to follow check:"
info "tail -f ${LOG_FILE}"
launch "${SAMPLE}" "${CROMWELL_CONF_NODB_NOCACHE}" "${LOG_FILE}" "Genuine"
else
error "Folder incomplete or error in file names for sample ${SAMPLE}"
#exec 1 >> "${ERROR_DIR}/autoAchabError.log" 2>&1
#mv "${TODO_DIR}/${SAMPLE}" "${ERROR_DIR}"
${RSYNC} -az "${TODO_DIR}/${SAMPLE}" "${ERROR_DIR}"
if [ "$?" -eq 0 ];then
exec 1>>"${ERROR_DIR}/autoAchabError.log" 2>&1
rm -r "${TODO_DIR}/${SAMPLE}"
fi
fi
}
############### Now we'll have a look at the content of the directories #####################
#http://moinne.com/blog/ronald/bash/list-directory-names-in-bash-shell
#--time-style is used here to ensure awk $8 will return the right thing (dir name)
SAMPLES=$(ls -l --time-style="long-iso" ${TODO_DIR} | egrep '^d' | awk '{print $8}')
#debug "Samples: --${SAMPLES}--"
if [ "${SAMPLES}" != '' ];then
for SAMPLE in ${SAMPLES}
do
treat_sample "${SAMPLE}" &
############## log file
#LOG_FILE="${TODO_DIR}/${SAMPLE}/autoAchab.log"
#touch ${LOG_FILE}
#exec &>${LOG_FILE}
#VCF=$(ls -l --time-style="long-iso" "${TODO_DIR}/${SAMPLE}" | egrep '^-' | awk '{print $8}' | egrep '*.vcf')
#if [ -f "${TODO_DIR}/${SAMPLE}/${VCF}" ] && [ -f "${TODO_DIR}/${SAMPLE}/captainAchab_inputs.json" ] && [ -f "${TODO_DIR}/${SAMPLE}/disease.txt" ];then
# echo ""
# info "Launching captainAchab workflow for ${SAMPLE}, to follow check:"
# info "tail -f ${LOG_FILE}"
# launch "${SAMPLE}" "${CROMWELL_CONF}" "${LOG_FILE}" "Genuine"
#else
# error "Folder incomplete or error in file names for sample ${SAMPLE}"
# mv "${TODO_DIR}/${SAMPLE}" "${ERROR_DIR}"
#fi
done
fi