-
Notifications
You must be signed in to change notification settings - Fork 5
/
short_read_connector_counter.sh
executable file
·354 lines (268 loc) · 9.69 KB
/
short_read_connector_counter.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
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/bin/bash
version="1.2.0"
EDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd -P )
platform='mac'
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
platform='linux'
fi
dsk_bin=$EDIR/thirdparty/dsk/bin/macosx/dsk
if [[ $platform == 'linux' ]]; then
dsk_bin=$EDIR/thirdparty/dsk/bin/linux/dsk
fi
chmod a+x ${dsk_bin}
#BIN DIR:
if [ -d "$EDIR/build/" ] ; then # VERSION SOURCE COMPILED
BIN_DIR=$EDIR/build/bin
else # VERSION BINARY
BIN_DIR=$EDIR/bin
fi
function help {
echo "short_read_connector_counter.sh - Compare reads from two read sets (distinct or not)"
echo "Version "$version
echo "Usage: sh short_read_connector_counter.sh [index/query]"
}
function help_index {
echo "short_read_connector_counter.sh index - Index a read file"
echo "Usage: sh short_read_connector_counter.sh index -b read_file -i dumped_index_name [OPTIONS]"
echo " -b read_file for bank (fasta or fastq, gzipped or not)"
echo " Example: -b data/c1.fasta.gz"
echo " -i <string>. File of the index file to be created. Example \"my_index.dumped\""
echo " -k <int> value (<32). Set the length of used kmers. Must fit the compiled value. Default=31"
echo " -f <int> value. Fingerprint size. Size of the key associated to each indexed value, limiting false positives. Default=12"
echo " -G <int> value. gamma value. MPHF expert users parameter - Default=2"
echo " -a <int> kmer_abundance_min (kmer from bank seen less than this value both in the bank are not indexed). Default=2"
echo " -l Keep low complexity regions (default false)"
echo " -t <int> number of thread used. Default=0 (all)"
}
function help_query {
echo "Usage: sh short_read_connector_counter.sh query -i indexed_file -q read_file_of_files [OPTIONS]"
echo "MANDATORY:"
echo " -i index created by short_read_connector_counter.sh index (read only)"
echo " Example: -i my_index.dumped"
echo " -q read_file_of_files for query"
echo " Example: -q data/fof.txt (with fof being a file of file descriptor)"
echo "OPTIONS:"
echo " -w <int> window_size. See option -s. If the windows size is zero (default value), then the full read is considered. Default=0"
echo " -s <int> kmer_threshold: Minimal percentage of shared kmer span for considering a query read as similar to a data set. "
echo " The kmer span is the number of bases from the read query covered by a kmer shared with the bank."
echo " -l Keep low complexity regions (default false)"
echo " If a read of length 80 has a kmer-span of 60, then the percentage of shared kmer span is 75%. If a least a windows (of size \"windows_size\") contains at least kmer_threshold percent of positions covered by shared kmers, the read is output."
echo " -p <string> prefix. All out files will start with this prefix. Default=\"short_read_connector_res\""
echo " -t <int> number of thread used. Default=0 (all)"
}
if [ "$1" != "index" ] && [ "$1" != "query" ]; then
help
exit 1
fi
feature=$1
shift
# #####
# INDEX
# #####
if [ "$feature" == "index" ]; then
bank_set=""
index_name=""
kmer_size=31
abundance_min=2
gamma=2
fingerprint_size=12
core_used=0
keep_low_complexity_option=""
remove=1
#######################################################################
#################### GET INDEX OPTIONS #######################
#######################################################################
while getopts ":hG:i:f:b:lk:a:t:" opt; do
case $opt in
h)
help_index
exit
;;
G)
echo "use gamma: $OPTARG" >&2
gamma=$OPTARG
;;
i)
echo "create index $OPTARG" >&2
index_name=$OPTARG
;;
f)
echo "use fingerprint size: $OPTARG" >&2
fingerprint_size=$OPTARG
;;
b)
echo "use bank read set: $OPTARG" >&2
bank_set=$OPTARG
;;
l)
echo "keep low complexity sequences"
keep_low_complexity_option="-keep_low_complexity"
;;
k)
kmer_size=$OPTARG
if [ $kmer_size -gt 31 ]; then
echo "ERROR, kmer size must be <32. Please choose a lower k value"
exit 1
fi
echo "use k=$OPTARG" >&2
;;
a)
echo "use abundance_min=$OPTARG" >&2
abundance_min=$OPTARG
;;
t)
echo "use $OPTARG threads">&2
core_used=$OPTARG
;;
#
# u)
# echo "use at most $OPTARG cores" >&2
# option_cores_gatb="-nb-cores $OPTARG"
# option_cores_post_analysis="-t $OPTARG"
# ;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
#######################################################################
#################### END GET INDEX OPTIONS #######################
#######################################################################
if [ -z "${bank_set}" ]; then
echo "You must provide a bank read set (-b)"
help_index
exit 1
fi
if [ -z "${index_name}" ]; then
echo "You must provide an index name (-i)"
help_index
exit 1
fi
out_dsk="solid_kmers_k"${kmer_size}".h5"
# echo $abundanceMode
# if [ "$abundanceMode" -eq 1 ]; then
# ls ${bank_set} ${query_set} > FOF_FOR_DSK_REMOVE_ME_PLEASE.txt
# cmd="${dsk_bin} -file FOF_FOR_DSK_REMOVE_ME_PLEASE.txt -kmer-size ${kmer_size} -abundance-min ${abundance_min} -out ${out_dsk} -nb-cores ${core_used} -solidity-kind all"
# else
cmd="${dsk_bin} -file ${bank_set} -kmer-size ${kmer_size} -abundance-min ${abundance_min} -out ${out_dsk} -nb-cores ${core_used} -solidity-kind one"
# fi
echo ${cmd}
${cmd}
if [ $? -ne 0 ]
then
echo "there was a problem with the kmer counting."
exit 1
fi
# create the index
cmd="${BIN_DIR}/SRC_counter -make_index -dumped_quasi_dict ${index_name} -graph ${out_dsk} -fingerprint_size ${fingerprint_size} -core ${core_used} -gamma ${gamma} ${keep_low_complexity_option}"
echo ${cmd}
${cmd}
if [ $? -ne 0 ]
then
echo "there was a problem with the index creation."
exit 1
fi
# rm -f ${out_dsk}
echo "***********************************"
echo "Short read connector indexation finished"
echo "index in:"
echo " "${index_name}
echo "Contact: [email protected]"
echo "***********************************"
fi # END INDEXATION
# #####
# QUERY
# #####
if [ "$feature" == "query" ]; then
query_set=""
kmer_size=31
kmer_threshold=75
core_used=0
prefix="short_read_connector_res"
keep_low_complexity_option=""
windows_size=0
#######################################################################
#################### GET QUERY OPTIONS #######################
#######################################################################
while getopts "hi:w:q:p:ls:t:" opt; do
case $opt in
h)
help_query
exit
;;
i)
echo "Use index $OPTARG" >&2
index_name=$OPTARG
;;
q)
echo "use query read set: $OPTARG" >&2
query_set=$OPTARG
;;
w)
echo "use windows size: $OPTARG" >&2
windows_size=$OPTARG
;;
p)
echo "use prefix=$OPTARG" >&2
prefix=$OPTARG
;;
l)
echo "keep low complexity sequences"
keep_low_complexity_option="-keep_low_complexity"
;;
t)
echo "use $OPTARG threads">&2
core_used=$OPTARG
;;
s)
echo "use kmer_threshold=$OPTARG" >&2
kmer_threshold=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
#######################################################################
#################### END GET QUERY OPTION #######################
#######################################################################
if [ -z "${index_name}" ]; then
echo "You must provide the index name (-i)"
help_query
exit 1
fi
if [ -z "${query_set}" ]; then
echo "You must provide a query read set (-q)"
help_query
exit 1
fi
result_file=${prefix}".txt"
# Using a non-zero high density window: uncomment this line:
# zerod_option="-zero_density_windows_size 50 -zero_density_threshold 20"
# Creating the command
cmd="${BIN_DIR}/SRC_counter -dumped_quasi_dict ${index_name} -query ${query_set} -out ${result_file} -coverage_threshold ${kmer_threshold} -core ${core_used} ${zerod_option} ${keep_low_complexity_option} -windows_size ${windows_size}"
echo ${cmd}
${cmd}
if [ $? -ne 0 ]
then
echo "there was a problem with short read connector."
exit 1
fi
echo "***********************************"
echo "Short read connector finished"
echo "results in:"
echo " "${result_file}
echo "Contact: [email protected]"
echo "***********************************"
fi