Repository navigation
Expand file tree
/
Copy pathsubmission-prepare-files
More file actions
executable file
·323 lines (243 loc) · 7.65 KB
/
Copy pathsubmission-prepare-files
File metadata and controls
executable file
·323 lines (243 loc) · 7.65 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#/bin/bash
# author Renzo Kottmann 2018-02-01
# This script creates symbolic links and md5 to the raw datafiles for
# 16S and 18 raw and workable datasets
# current dir (CWD) has to be sequence-data
#declare -r CWD=$(basename ${PWD})
#declare -r OSD_DIR='/bioinf/projects/osd/main/2015/06'
# from LGC
#declare -r LGC_RAW_18S_DATA_DIR=${OSD_DIR}'/pre-processing/18S/primer-clipping/lgc'
#declare -r LGC_WORKABLE_18S_DATA_DIR=${OSD_DIR}'/pre-processing/18S/quality-trimming/lgc'
#declare -r LGC_RAW_16S_DATA_DIR=${OSD_DIR}'/pre-processing/16S/primer-clipping/lgc'
#declare -r LGC_WORKABLE_16S_DATA_DIR=${OSD_DIR}'/pre-processing/16S/quality-trimming/lgc'
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 _check_required_programs() {
# Required program(s)
#req_progs=(readlink date md5)
for p in ${@}; do
hash "${p}" 2>&- || \
{ echo >&2 " Required program \"${p}\" not installed or in search PATH.";
exit 1;
}
done
}
function create_dir_structure {
echo "Current base dirname=${CWD}"
check_empty_var "${1}" || exit 999
local -r SUBMISSION_DIR="${1}"
mkdir -pv "${SUBMISSION_DIR}"
}
function blacklist() {
#
# delete blacklist: OSD_R[12]-_16S
#
echo "Deleting: ${BLACKLIST}"
rm ${BLACKLIST}
}
function calc_md5() {
## doing all md5 for 18S or 16S
echo 'creating md5s'
for i in *.fasta.gz ; do
echo "md5 for ${i}"
md5sum ${i} > ${i}.md5;
done
chmod 664 *.md5
}
function create_usage() {
cat <<EOF
Usage: ${BASH_SOURCE} [Options] directory
Options:
-n, --subsmission-name Give of a submission to be done e.g. myosd or osd
-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() {
local SUBMISSION_NAME='unknown'
log::debug "Num options=$#"
log::debug "first option=${1}="
declare -r RUN="${@}"
check_empty_var "${1}" || { log::debug 'Provide options'; create_usage; }
_check_required_programs md5sum readlink
while [[ $# -gt 0 ]]; do
case ${1} in
-n|--submission-name)
shift;
check_empty_var "${1}" || {
log::error "Provide a submission name";
exit 66
}
local -r SUBMISSION_NAME="${1}"
shift;
;;
-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. RRNA or shotgun";
exit 66
}
local -r DATA_SET="${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;
;;
-o|--output-dir)
shift;
check_empty_var "${1}" || {
log::error "Provide a output directory where files get created in";
exit 66
}
local -r OUTPUT_BASE_DIR='/OSD2015_*/fasta/*'
shift;
;;
--file-pattern)
shift;
check_empty_var "${1}" || {
log::error "Provide a bash compatible pattern for files to be included in submission preparation. This should be relative to directory provided as last argument. Without leading slash";
exit 66
}
local -r DIR_PATTERN=${1}
shift;
;;
-h|--help)
create_usage ;
exit 0
;;
*)
log::debug "Rest is source directory"
#create_usage ;
# now checking last argument
if [[ -d ${1} ]]; then
echo "directory=${1} exists. Can proceed..."
#TODO check more about source dir, like does it have readable files etc.
# need absolute path to source dit
local -r SOURCE_DIR=$(readlink -f "${1}")
log::debug "Source dir=${SOURCE_DIR}"
else
log::error "directory=${1} does not exist"
exit 1
fi
shift;
;;
esac
done
check_empty_var "${SUBMISSION_NAME}" || {
log::error "SEQUENCING_CENTER missing but required"
exit 66
}
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_SET}" || {
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
}
check_empty_var "${DIR_PATTERN}" || {
log::error "FILE PATTERN is missing but required"
exit 66
}
local -r FILE_TAG="${CAMPAIGN_NAME}-${DATA_SET}-${PRIMER_PAIR}-${PROCESSING_STATUS}"
local -r DESTINATION_DIR="${FILE_TAG}-${SUBMISSION_NAME}"
create_dir_structure "${DESTINATION_DIR}"
#cd "${SUBMISSION_NAME}"/workable
shopt -s nullglob
# TODO also add 2016-01-26
#local -r TEST_PATTERN='OSD2015_*/fasta/*'
for FILE in "${SOURCE_DIR}/"${DIR_PATTERN} ; do
if [ -e "${FILE}" ] ; then
fname="${DESTINATION_DIR}/"$(basename ${FILE});
log::debug "new link name=${fname} of ${FILE}"
ln -sf "${FILE}" "${fname}" || exit 1000;
else
echo "${FILE} does not exist"
fi
done
# becaause of md5sum writing filepath in report need to do it local to file
$( cd "${DESTINATION_DIR}";
for FILE in * ; do
log::debug "file=${FILE}";
md5sum "./${FILE}" > "${FILE}.md5" || {
log::error "Can not create md5sum" && exit 1000;
};
done
) || exit 9999
local -r CUR_DATE=$(date)
# ADDING README
cat > "${DESTINATION_DIR}/README.md" <<EOF
# Submission Perparation
This directory contains files from the submission preparation run with
Script: ${BASH_SOURCE}
Script Parameters: ${RUN}
Called from direcotry: ${PWD}
User: ${USER}
Time: ${CUR_DATE}
EOF
echo "Done :)"
}
log::debug 'Hi script'
main "$@"