-
Notifications
You must be signed in to change notification settings - Fork 3
/
upload_viollier
executable file
·87 lines (69 loc) · 1.81 KB
/
upload_viollier
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
#!/bin/bash
configfile=viollier.conf
usage() { echo "Usage: $0 [-c <configfile>]" 1>&2; exit $1; }
while getopts "c:h" o; do
case "${o}" in
c) configfile=${OPTARG}
if [[ ! -r ${configfile} ]]; then
echo "Cannot read ${configfile}" 1>&2
usage 1
fi
;;
h) usage 0 ;;
*) usage 1 ;;
esac
done
shift $((OPTIND-1))
. ${configfile}
: ${lab:?}
: ${fileserver:?}
# ${srvport}
: ${expname:?}
: ${basedir:=$(pwd)}
: ${download:?}
: ${sampleset:?}
: ${working:=working}
target=consensus_sequences
[[ "${1}" == '-h' || "${1}" == '--help' ]] && usage 0
if [[ ! -d ${basedir}/${download}/ ]]; then
echo "missing directory ${download}" >&2
exit 1
elif [[ ! -d ${basedir}/${working}/ ]]; then
echo "missing working ${working}" >&2
exit 1
fi
lastmonth=$(date '+%Y%m' --date='-1 month')
month3ago=$(date '+%Y%m%d' --date='-3 month')
mkdir -p ${basedir}/${download}/${target}
cd ${basedir}
error=0
tsvs=( )
for byml in $(grep -l "lab: ${lab}" ${sampleset}/batch.*.yaml); do
if [[ ! $byml =~ batch\.(20[[:digit:]]{2}[01][[:digit:]][0-3][[:digit:]]_[[:alnum:]]{4,})\.yaml$ ]]; then
echo "cannot parse $byml name" >&2
error=1
continue
fi
batch=${BASH_REMATCH[1]}
if [[ ${lastmonth} > ${batch} ]]; then
echo "skipping ${batch}"
continue
fi
echo "batch: ${batch}"
tsv="${sampleset}/samples.${batch}.tsv"
if [[ ! -r ${tsv} ]]; then
echo "Cannot read ${tsv}"
error=1
continue
fi
tsvs+=( ${tsv} )
done
if (( ${#tsvs[@]} == 0 )); then
echo "Nothing to do"
exit $error
fi
cat "${tsvs[@]}" | while read sample batch len; do
cp --link -vrf ${working}/samples/${sample}/${batch}/references/ref_majority_dels.fasta ${download}/${target}/${sample}-${batch}.fasta || error=1
done
(( error )) && exit 0
./upload_sftp -c ${configfile} ${target} && exec ./purge_sftp_fasta -r ${month3ago} -c ${configfile} ${target}