-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmetabomatching.sh
executable file
·158 lines (136 loc) · 3.94 KB
/
metabomatching.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
#!/bin/bash
# Constants
# ==============
NM_PROG=$(basename $0)
DR_PROG=$(dirname $0)
isabs=$(echo $DR_PROG | grep ^/)
if [ -z "$isabs" ] ; then
DR_PROG="$PWD/$DR_PROG"
fi
YES=yes
DEBUG=0
DR_WORK=
IF_PSS=
IF_PAR=
IF_COR=
OF_SCO=
OF_PDF=
VER="0.2.0"
function print_help {
echo "Usage: $NM_PROG [options] directory"
echo
echo "metabomatching"
echo
echo "Options:"
echo " -g, --debug Debug mode."
echo " -h, --help Print this help message."
echo " -i, --input-file Set input file."
echo " -c, --correlation-file Set correlation file."
echo " -s, --output-score-file Set score output file."
echo " -S, --output-svg-file Set SVG output file."
}
# Error {{{1
# ==========
function error {
local msg=$1
echo "ERROR: $msg" >&2
exit 1
}
# Print debug msg {{{1
# ====================
function print_debug_msg {
local dbglvl=$1
local dbgmsg=$2
[ $DEBUG -ge $dbglvl ] && echo "[DEBUG] $dbgmsg" >&2
}
# Get opt val {{{1
# ================
function get_opt_val {
[ -n "$2" ] || error "\"$1\" requires a non-empty option argument."
echo $2
}
# Read args {{{1
# ==============
function read_args {
local args="$*" # save arguments for debugging purpose
# Read options
while true ; do
shift_count=1
case $1 in
-g|--debug) DEBUG=$((DEBUG + 1)) ;;
-h|--help) print_help ; exit 0 ;;
-i|--input-file) IF_PSS=$(get_opt_val $1 $2) ; shift_count=2 ;;
-p|--input-file-parameters) IF_PAR=$(get_opt_val $1 $2) ; shift_count=2 ;;
-c|--correlation-file) IF_COR=$2 ; shift_count=2 ;;
-s|--output-file-scores) OF_SCO=$(get_opt_val $1 $2) ; shift_count=2 ;;
-S|--output-file-pdf) OF_PDF=$(get_opt_val $1 $2) ; shift_count=2 ;;
-) error "Illegal option $1." ;;
--) error "Illegal option $1." ;;
--*) error "Illegal option $1." ;;
-?) error "Unknown option $1." ;;
-[^-]*) split_opt=$(echo $1 | sed 's/^-//' | sed 's/\([a-zA-Z]\)/ -\1/g') ; set -- $1$split_opt "${@:2}" ;;
*) break
esac
shift $shift_count
done
shift $((OPTIND - 1))
echo $#
# Read remaining arguments
if [ -z "$IF_PSS" ] ; then
if [ $# -eq 1 ] ; then
[ -d "$DR_WORK" ] || error "\"$DR_WORK\" is not a directory."
DR_WORK="$1"
elif [ -d "/mm-ps" ] ; then
echo "metabomatching "$VER" : no directory provided."
echo "metabomatching "$VER" : using dockerfile directory."
DR_WORK="/mm-ps"
if [[ $(find /mm-ps -type d -name "ps.*" | wc -c) -eq 0 ]]; then
echo "/mm-ps is empty, copying default pseudospectrum."
cp -r $DR_PROG/test/ps.test $DR_WORK
fi
else
error "You must specify one, and only one, directory to process."
fi
else
[ $# -eq 0 ] || error "You cannot specify a directory when using the -i option."
[ -f "$IF_PSS" ] || error "\"$IF_PSS\" is not a file."
[ -n "$OF_SCO" ] || error "When using -i option, you must also set -s option."
[ -n "$OF_PDF" ] || error "When using -i option, you must also set -S option."
fi
# Debug
print_debug_msg 1 "Arguments are : $args"
print_debug_msg 1 "Directory to process is: $DR_WORK"
print_debug_msg 1 "Input file to process is: $IF_PSS"
}
# MAIN {{{1
# =========
read_args "$@"
echo "metabomatching "$VER" : bash passed; running octave."
echo ""
# Set working directory
if [ -n "$IF_PSS" ] ; then
DR_WORK=wd
rm -fr $DR_WORK
mkdir -p $DR_WORK/ps.study
cp $IF_PSS $DR_WORK/ps.study/tag.pseudospectrum.tsv
fi
if [ -n "$IF_PAR" ] ; then
cp $IF_PAR $DR_WORK/ps.study/parameters.in.tsv
fi
if [ -n "$IF_COR" ] ; then
cp $IF_COR $DR_WORK/ps.study/correlation.csv
fi
# Execute
cd "$DR_WORK"
export DR_METABOMATCHING=$DR_PROG
octave-cli $DR_PROG/metabomatching.m
find -name "*.svg" -type f | while read file; do inkscape "${file}" --export-pdf="${file%.svg}.pdf"; done
if [ -n "$IF_PSS" ] ; then
pdftk ps.study/*.pdf cat output ps.study/all.pdf
fi
cd -
# Move output files
if [ -n "$IF_PSS" ] ; then
mv $DR_WORK/ps.study/tag.scores.tsv $OF_SCO
mv $DR_WORK/ps.study/all.pdf $OF_PDF
fi