-
Notifications
You must be signed in to change notification settings - Fork 6
/
bnxsubsample.sh
executable file
·111 lines (97 loc) · 2.52 KB
/
bnxsubsample.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
#!/bin/bash
# BioNanoGenomics BNX subsample and filter at CLI
#
# script name: bnx_subsample.sh
# Requirements:
# run on a unix computer installed with working bionano code
# Stephane Plaisance (VIB-NC+BITS) 2016/09/09; v1.0
#
# visit our Git: https://github.com/Nucleomics-VIB
# check parameters for your system
TOOLS=$BNGTOOLS
version="1.0, 2016_09_09"
usage='# Usage: bnx_subsample.sh -i <molecules.bnx>
# script version '${version}'
# [optional: -o <output_prefix|bnx_subset>]
# [optional: -l <minlen|100>]
# [optional: -x <maxlen|2500>]
# [optional: -f <minlabels|5>]
# [optional: -g <maxlabels|200>]
# [optional: -a <maxai|0.6>]
# [optional: -s <minSNR|3.5>]
# [optional: -t <max-threads|24>]
# [optional: -m <max-ram|64>]
# [optional: -n <sample N molecules>]'
while getopts "i:o:l:x:f:g:a:s:t:m:n:h" opt; do
case $opt in
i) bnxdata=${OPTARG} ;;
o) outprefix=${OPTARG} ;;
l) minimumlen=${OPTARG} ;;
x) maximumlen=${OPTARG} ;;
f) minimumlabels=${OPTARG} ;;
g) maximumlabels=${OPTARG} ;;
a) maxaverageint=${OPTARG} ;;
s) minmumsnr=${OPTARG} ;;
t) maxthreads=${OPTARG} ;;
m) maxmemory=${OPTARG} ;;
n) molnumber=${OPTARG} ;;
h) echo "${usage}" >&2; exit 0 ;;
\?) echo "Invalid option: -${OPTARG}" >&2; exit 1 ;;
*) echo "this command requires arguments, try -h" >&2; exit 1 ;;
esac
done
# defaults
timestamp=$(date +%s)
# defaults
startts=$(date +%s)
# user-provided variables or defaults
minlen=${minimumlen:-100}
maxlen=${maximumlen:-2500}
minsites=${minimumlabels:-5}
maxsites=${maximumlabels:-200}
maxai=${maxaverageint:-0.6}
minsnr=${minmumsnr:-3.5}
maxthr=${maxthreads:-24}
maxmem=${maxmemory:-64}
# test if minimal arguments were provided
if [ -z "${bnxdata}" ]
then
echo "# no bnx provided!"
echo "${usage}"s
exit 1
fi
if [ ! -f "${bnxdata}" ]; then
echo "${bnxdata} file not found!"
exit 1
fi
if [ -z "${molnumber}" ]
then
lim=''
outfile=${outprefix:-bnx_subset}
else
lim="-randomize 1 -subset 1 ${molnumber}"
outfile=${outprefix:-${molnumber}_bnx_subset}
fi
# build command and quote weird chars
echo "# creating subset from ${bnxdata}"
cmd="${TOOLS}/RefAligner \
-i $(printf '%q' "${bnxdata}") \
-o $(printf '%q' "${outfile}") \
-merge \
-bnx \
-minlen ${minlen} \
-maxlen ${maxlen} \
-minsites ${minsites} \
-maxsites ${maxsites} \
-minSNR ${minsnr} \
-MaxIntensity ${maxai} \
-maxmem ${maxmem} \
-maxthreads ${maxthr} \
-stdout \
-stderr \
${lim}"
echo "# ${cmd}"
eval ${cmd}
endts=$(date +%s)
dur=$(echo "${endts}-${startts}" | bc)
echo "Done in ${dur} sec"