-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmission-report
executable file
·195 lines (148 loc) · 4.87 KB
/
submission-report
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
#/bin/bash
# author Renzo Kottmann
declare -r DEBUG='true'
function log::debug () {
test -z "${DEBUG}" && { echo "ERROR: DEBUG variable not set"; exit 100; }
test -n "${DEBUG}" && echo "DEBUG ${1}" 1>&2;
}
function log::error () {
test -z "${DEBUG}" && { echo "ERROR: DEBUG variable not set"; exit 100; }
test -n "${DEBUG}" && echo "ERROR ${1}" 1>&2;
}
function check_empty_var() {
if [[ ! ${1} ]]; then
log::error "Variable is empty";
return 100
fi
return 0
}
function create_usage() {
cat <<EOF
Usage: ${0}
Options:
-s, --sequencing-center Provide a sequencing center name e.g. LGC_GENOMICS
-c, --campaign-name Provide a campaign name e.g. OSD2014 or MYOSD2016
-d, --data-set Provide the data set name e.g. 18S, 16S or shotgun
-p, --processing-status Provide a th (pre-) processing status of sequences e.g. RAW or WORKABLE
--primer Provide a primer pair name used for sequencing e.g. alma_alma or NONE in case of shotgun
EOF
}
function main() {
check_empty_var "${1}" || { log::debug 'Provide options'; create_usage; }
# expecting last argument to be the directory from where to gather the report
while [[ $# -gt 0 ]]; do
case ${1} in
-s|--sequencing-center)
shift;
check_empty_var "${1}" || {
log::error "Provide a sequencing center name e.g. LGC_GENOMICS";
exit 66
}
local -r SEQUENCING_CENTER="${1}"
shift;
;;
-c|--campaign-name)
shift;
check_empty_var "${1}" || {
log::error "Provide a campaign name e.g. OSD or MYOSD";
exit 66
}
local -r CAMPAIGN_NAME="${1}"
shift;
;;
-d|--data-set)
shift;
check_empty_var "${1}" || {
log::error "Provide the sequencing data category e.g. 16S or shotgun";
exit 66
}
local -r DATA_CAT="${1^^}"
shift;
;;
-p|--processing-status)
shift;
check_empty_var "${1}" || {
log::error "Provide a th (pre-) processing status of sequences e.g. RAW or WORKABLE";
exit 66
}
local -r PROCESSING_STATUS="${1,,}"
shift;
;;
--primer)
shift;
check_empty_var "${1}" || {
log::error "Provide a the primer pair used for sequencing e.g. alma_alma or NONE in case of shotgung";
exit 66
}
local -r PRIMER_PAIR="${1,,}"
shift;
;;
-h|--help)
create_usage ;
exit 0
;;
*)
log::error "Unknown option $1"
log::debug "Option $1 unknown"
declare -gr dir="${1}"
# now checking last argument
if [[ -d ${1} ]]; then
echo "dir=${dir} exists. Can proceed..."
else
log::error "dir=${dir} does not exist"
exit 1
fi
shift;
;;
esac
done
check_empty_var "${SEQUENCING_CENTER}" || {
log::error "SEQUENCING_CENTER missing but required"
exit 66
}
check_empty_var "${CAMPAIGN_NAME}" || {
log::error "CAMPAIGN_NAME missing but required"
exit 66
}
check_empty_var "${DATA_CAT}" || {
log::error "DATA SET name missing but required"
exit 66
}
check_empty_var "${PROCESSING_STATUS}" || {
log::error "PROCESSING_STATUS missing but required"
exit 66
}
check_empty_var "${PRIMER_PAIR}" || {
log::error "PRIMER_PAIR missing but required"
exit 66
}
log::debug "
SEQUENCING_CENTER=${SEQUENCING_CENTER}
CAMPAIGN_NAME=${CAMPAIGN_NAME}
DATA SET=${DATA_CAT}
PROCESSING_STATUS=${PROCESSING_STATUS}
PIMER PAIR=${PRIMER_PAIR}
"
local -r CUR_DATE=$(date --rfc-3339=date)
local md5_report="submission_md5_${CAMPAIGN_NAME}_${PROCESSING_STATUS}_${DATA_CAT}_report_${CUR_DATE}.txt"
local submission_report="submission_${CAMPAIGN_NAME}_${PROCESSING_STATUS}_${DATA_CAT}_files_report_${CUR_DATE}.csv"
rm --force --verbose "${submission_report}"
log::debug "dir=${dir}"
shopt -s extglob
cat "${dir}/"*.md5 > ${md5_report}
cat ${md5_report} | \
while read md5 filename; do
# if md5 is from binary file there is * at beginning, therefore replace with nothing in case
filename=${filename/#\*/}
filename=$(basename "${filename}")
pp_fullpath=$(readlink -f "${dir}/${filename}")
log::debug "
filename=${filename}
dir=${dir}
fullpath=${pp_fullpath}
"
echo "${CAMPAIGN_NAME},${SEQUENCING_CENTER},${DATA_CAT},${PROCESSING_STATUS},${PRIMER_PAIR},${md5},${filename},${pp_fullpath}" >> ${submission_report} ;
done
}
log::debug 'Hi Submission Reporter'
main "$@"