-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathshort_read_connector_linker.sh
More file actions
executable file
·377 lines (290 loc) · 11 KB
/
short_read_connector_linker.sh
File metadata and controls
executable file
·377 lines (290 loc) · 11 KB
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
#!/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_linker.sh - Compare reads from two read sets (distinct or not)"
echo "Version "$version
echo "Usage: sh short_read_connector_linker.sh [index/query]"
}
function help_index {
echo "short_read_connector_linker.sh index - Index a read file"
echo "Usage: sh short_read_connector_linker.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_linker.sh query -i indexed_file -q read_file_of_files [OPTIONS]"
echo "MANDATORY:"
echo " -i index created by short_read_connector_linker.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 2 reads as similar. "
echo " The kmer span is the number of bases from the read query covered by a kmer shared with the target read."
echo " If a read of length 80 has a kmer-span of 60 with another read (of unkonwn size) from the bank, 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 position covered by shared kmers, the read couple is output."
echo " TRICK: with kmer_threshold<=0 a single kmer is sufficient in the linker mode to link two reads. "
echo " -l Keep low complexity regions (default false)"
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)"
# echo " -A index kmers present at least 'kmer_abundance_min' times in the bank AND in the queries."
echo " -r do not output precision about pair of similar reads. Only ids of reads from queries similar to at least one read from bank are output."
}
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
# in case of linker, we cannot apply to multiple sequences
if [ ! $commet_like_option ]; then
# Check that the bank file is NOT a file of file. If its gzipped: consider its ok, else check that the first line contains something that is not a file
gunzip -t ${bank_set} 2>/dev/null
if [ $? -ne 0 ] # IN CASE THIS IS NOT A GZIPPED FILE
then
line=`head -n 1 ${bank_set} | cut -f 1 -d ' '`
if [ -f $line ]; then
echo "With SRC linker (without the -r option), the bank must not be composed of a file of file. It must be a fasta or fastq file gzipped or not"
exit 1
fi
fi
fi
out_dsk="solid_kmers_k"${kmer_size}".h5"
# echo $abundanceMode
# exit
# 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_linker -make_index -dumped_quasi_dict ${index_name} -graph ${out_dsk} -bank ${bank_set} -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: pierre.peterlongo@inria.fr"
echo "***********************************"
fi # END INDEXATION
# #####
# QUERY
# #####
if [ "$feature" == "query" ]; then
commet_like_option=""
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:rw: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
;;
r)
echo "Output only ids of read shared (no complete links)">&2
commet_like_option="-no_sharing_detail"
;;
\?)
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_linker -dumped_quasi_dict ${index_name} -query ${query_set} -out ${result_file} -kmer_threshold ${kmer_threshold} -core ${core_used} ${commet_like_option} ${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: pierre.peterlongo@inria.fr"
echo "***********************************"
fi