forked from pegeler/MethylMallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresume_join.sh
executable file
·76 lines (62 loc) · 1.77 KB
/
resume_join.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
#!/bin/bash
echo "resuming..." >&2
progname=$(basename $0)
CHECKPOINT=$SECONDS
set -e
# Usage -----------------------------------------------------------------------
function usage {
cat << EOF >&2
usage: $progname [-h] -d DIR -o OUT_FILE
Do a full outer join of tab-separated methylation files.
This resumes the file append process if for some reason
the script was prematurely terminated.
required arguments:
-d DIR working directory from previous call
-o OUT_FILE file name to be output to
optional arguments:
-h show this help message and exit
EOF
exit 1
}
# Options ---------------------------------------------------------------------
while getopts ":d:o:h" opt; do
case $opt in
d)
work_dir=$OPTARG
;;
o)
out_file=$OPTARG
;;
h)
usage
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
;;
esac
done
if [[ -z "$work_dir" || -z "$out_file" ]]; then
echo "ERROR: Missing option(s)"
usage
fi
mkdir -p "$work_dir"
# APPEND ----------------------------------------------------------------------
echo "$progname: Resuming appending columns..." >&2
i=1
for f in "${work_dir}/sorted_"*; do
echo -n "$progname: $(printf '% 5i' $i)/unknown: $(basename $f)" >&2
test -f "bin/do_join" && bin/do_join "$f" || python3 python/do_join.py "$f"
rm "$f"
echo " ($((SECONDS - CHECKPOINT)) seconds)" >&2
CHECKPOINT=$SECONDS
((i++))
done
# DONE ------------------------------------------------------------------------
mv "${work_dir}/out.csv" "$out_file"
echo "$progname: Success! All files joined. ($SECONDS seconds since resume)" >&2
echo "$progname: Combined comma-separated file saved in '$out_file'" >&2