-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmiRPursuit.sh
executable file
·551 lines (496 loc) · 20.9 KB
/
miRPursuit.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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
#!/usr/bin/env bash
# sRNAworkFlow.sh
#
#
# Created by Bruno Costa on 25/05/2015.
# Copyright 2015 ITQB / UNL. All rights reserved.
# Executes the complete pipeline
# Call: miRPursuit.sh [LIB_FIRST] [LIB_LAST] [STEP]
set -e
#Gets the script directory
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
#Get OUTPUT-COLOURING {green,red,NC,etc..}
. $DIR/"config/term-colors.cfg"
noPrompt=FALSE
specificFiles=FALSE
err_report() {
>&2 echo -e "${red}==> Error${NC} on line $1 caused a code $2 exit - $3"
>&2 echo $(tail -1 ${log_file})
echo "Error - on line $1 caused a code $2 exit"
}
trap 'err_report $LINENO $? $(basename $0)' ERR
while [[ $# > 0 ]]
do
key="$1"
case $key in
-f|--lib-first)
LIB_FIRST="$2"
shift # past argument
;;
-l|--lib-last)
LIB_LAST="$2"
shift # past argument
;;
-s|--step)
step="$2"
shift # past argument
;;
--fastq)
fastq="$2"
shift #past argument
;;
--fasta)
fasta="$2"
shift #past argument
;;
--lib)
SPECIFIC_LIB="$2"
shift #past argument
;;
--trim)
TRIM=TRUE #Don't shift one argument
;;
--headless)
HEADLESS_MODE=TRUE
;;
--no-prompt)
noPrompt=TRUE
;;
--no-genome-filter)
IGNORE_GENOME=TRUE
;;
--lc)
LC="$2"
shift # past argument
;;
-h|--help)
echo -e "
${blue}-f|--lib-first
-l|--lib-last
-h|--help${NC}
---------------------
Optional args
---------------------
${blue}-s|--step${NC} Step is an optional argument used to jump steps to start the analysis from a different point
${green}Step 1${NC}: Adaptor trimming (If flagged) & Wbench Filter
${green}Step 2${NC}: Filter Genome & mirbase
${green}Step 3${NC}: Tasi
${green}Step 4${NC}: Mircat
${green}Step 5${NC}: Report
${blue}--lib${NC} lib is an optional argument used to specify the number to be attributed to the specified file.
${blue}--lc${NC} Set the program to begin in lcmode instead of fs mode. The preceding substring from the lib num. (Pattern) Template + Lib num, but identify only one file in the inserts_dir
${blue}--fasta${NC} Set the program to start using fasta files. As an argument supply the file name that identifies the series to be used. Ex: Lib_1.fa, Lib_2.fa, .. --> argument should be Lib_
${blue}--fastq${NC} Set the program to start using fastq files. As an argument supply the file name that identifies the series to be used. Ex: Lib_1.fq, Lib_2.fq, .. --> argument should be Lib_ , if no .fq file is present but instead a .fastq.gz file will additionally be extracted automatically.
${blue}--trim${NC} Set this flag to perform adaptor trimming. No argument should be given. The adaptor is in the workdirs.cfg config file in the variable ADAPTOR.
${blue}--headless${NC} Set this flag to run on headless server. Requires Xvfb be installed on your system. Along with libswt-gtk-3-java and gkt3.
sudo apt-get update
sudo apt-get install xvfb libswt-gtk-java gkt3
${blue}--no-prompt${NC} Set this flag to skip all prompts.
${blue}--no-genome-filter${NC} Set this flag ignore genome filtering
-------------------------
Specific file mode
-------------------------
${blue}--fasta${NC} (In specific mode. i.e. no -f and -l) Set the program to start using fasta files. If no sequence of libraries are given then the argument can be a specific fasta file (uncompressed for now).
${blue}--fasta${NC} (In specific mode. i.e. no -f and -l) Set the program to start using fasta files. If no sequence of libraries are given then the argument can be a specific fasta file (uncompressed for now).
${blue}--lib${NC} (Optional) (In specific mode. i.e. no -f and -l) Set the library number to be attributed to the file. Should be coupled with --fasta or --fastq.
"
exit 0
esac
shift # past argument or value
done
if [[ -z $LIB_FIRST && -z $LIB_LAST ]]; then
echo -e "${blue}:: Specific files${NC} - Running with listed files "
specificFiles=TRUE
if [[ -z $SPECIFIC_LIB ]]; then
#Default lib used
echo -e "\n\n\n${yellow}==> WARNING${NC}: Using specific files mode but no specific files were given First lib and Last Lib are going to be set to 1.\n\n"
echo -e "LIB_FIRST = ${green}1${NC}"
echo -e "LIB_LAST = ${green}1${NC}\n\n\n"
sleep 5
LIB_FIRST=1
LIB_LAST=1
######## TODO - Check if there is any file for these conditions
else
#Provided lib used
LIB_FIRST=$SPECIFIC_LIB
LIB_LAST=$SPECIFIC_LIB
fi
else
if [[ -z $LIB_FIRST || -z $LIB_LAST ]]; then
echo -e "${red}Invalid input${NC} - Missing mandatory parameters"
echo -e "use ${blue}-h|--help${NC} for list of commands"
exit 127
else
if [[ ! $LIB_FIRST =~ ^[0-9]+$ ]]; then
echo -e "${red}Invalid input${NC} - Missing mandatory parameters for -f|--first"
echo -e "use ${blue}-h|--help${NC} for list of commands"
exit 127
fi
if [[ ! $LIB_LAST =~ ^[0-9]+$ ]]; then
echo -e "${red}Invalid input${NC} - Missing mandatory parameters for -l|--last"
echo -e "use ${blue}-h|--help${NC} for list of commands"
exit 127
fi
fi
fi
##Should check if libraries exist
if [[ -z "${IGNORE_GENOME}" ]]; then
IGNORE_GENOME="FALSE"
fi
if [[ ! -z "$step" ]]; then
if [[ "$step" -gt 5 || "$step" -lt 1 ]]; then
>&2 echo -e "${red}==> Terminating${NC} - That step doen't exist please specify a lower step"
exit 127
fi
fi
#Test if the var step exists
if [[ -z "$step" ]]; then
step=0
fi
#Gets the script directory
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
#Get config settings
. $DIR/"config/workdirs.cfg"
SOFT_CFG=${DIR}"/config/software_dirs.cfg"
. $SOFT_CFG
if [[ -z $HEADLESS_MODE && $HEADLESS == "FALSE" ]]; then
if ! xset q &>/dev/null; then
echo -e "No X server at \$DISPLAY [$DISPLAY] - ${blue}You are probably running on a server${NC}, but didn't set the ${red}headless mode${NC}. \nCheck if the necessary dependencies are installed: https://mirpursuit.readthedocs.io/en/latest/install.html#for-headless-server-no-x-server-running" >&2
exit 1
fi
## TODO - Test if xvfb-run-safe is working
fi
####### Check for updates ##################################
if [[ "${GIT}" == "1" ]]; then
if [[ "$(which git | wc -w)" -gt "1" ]];then
## "git not found" other then /usr/bin/git
$GIT == 0
##TODO set permanent
else
echo -e "${blue}:: This is a git install${NC}"
cd ${DIR}
#currentBranch=$(git branch --show-current)
git remote update
if [[ $(git status -u no | head -2 | tail -1) == "Your branch is up to date with 'origin/master'." ]];then
echo -ne "Git repository up to date!\n\n\n"
else
git update-server-info
current_commit=$(git rev-list --max-count=1 HEAD)
pendingCommits=$(git rev-list ${current_commit}..origin/HEAD --oneline --graph | wc -l)
if [[ $pendingCommits -gt 0 ]]; then
>&2 echo -e " ${red}==> Attention!${NC} There are pending updates to miRPursuit."
echo -e " ${brown}List of pending commits (None if empty):${NC}\n"
git rev-list ${current_commit}..origin/HEAD --oneline --graph
echo -ne "\n\n\n"
unset $booleanYorN
while [[ "$booleanYorN" != [yYnN] ]]
do
read -n1 -p "Update? (Y/N)" booleanYorN
done
if [[ $booleanYorN == [nN] ]]; then
echo -ne "\nContinuing without update"
else
>&2 echo -ne "\n\n\n\n\n\n\n\n\n\n${blue}Updating!${NC}"
git pull origin master
>&2 echo -ne "\n\n\r"
fi
unset $booleanYorN
else
echo " No pending updates at the moment."
fi
fi
cd -
tput cuu1; tput el; echo -ne "\r \n"
fi
else
echo -ne "\n\t\t\t${red}This is not a GIT installation${NC}\n"
if [[ "${GIT}" == "0" ]]; then
echo "Update check disabled"
else
echo -ne "Install commit hash is ${green}${GIT}${NC}"
echo "Currently not listing pending updates for non-git installations."
echo "Consider changing this installation to a git clone repository."
echo "Choose location and run command:"
echo -e "${grey} git clone https://github.com/forestbiotech-lab/miRPursuit.git${grey}"
echo -ne "To get rid of this message change the value of ${grey}GIT${NC} var in ${green}[miRPursuit_dir]/conifg/software_dirs.ctg${NC} to ${green}0${NC} instead of the current hash there.\n\n\n\n\n\n\n\n"
fi
fi
############# END Update check ##################################
##Progress report starting and declaring variable
progress=${workdir}/PROGRESS
#Set this to use HEADLESS version
if [[ $HEADLESS_MODE == "TRUE" ]]; then
sed -ri "s:(HEADLESS=)(.*):\1${HEADLESS_MODE}:" ${SOFT_CFG}
fi
echo -ne "${blue}:: Checking install dependencies:${NC}\n"
############# Check for dependencies ############################
#Check programs are set up and can run (Java and Wbench).
if [[ "$(which patman 2>&1 | awk -F 'in' '{print $1}')" == "which: no patman " ]]; then
echo -e " Patman [${red}X${NC}] - Not installed"
exit 127
else
echo -e " Patman [${green}✓${NC}]"
fi
if [[ -z "$JAVA_DIR" ]]; then
echo -e "${red}==> Not set${NC}: Please set java var in ${blue}software_dirs.cfg${NC} config file or run install script"
exit 127
else
if [[ -x "$JAVA_DIR" && -e "${JAVA_DIR}" ]]; then
echo -e " Java set up: ${green}OK${NC}"
else
echo -e "${red}==> Failed${NC}: Java can't be run or invalid path"
exit 127
fi
fi
if [[ -z "$WBENCH_DIR" ]]; then
echo -e "${red}==> Not set${NC}: Please set workbench var in ${blue}software_dirs.cfg${NC} config file or run install script"
exit 127
else
if [[ -x "$WBENCH_DIR" && -e "$WBENCH_DIR" ]]; then
echo -e " Workbench set up ${green}OK${NC}"
else
echo -e "${red}==> Failed${NC}: Workbench can't be run or invalid path. Please check the workbench var in the ${blue}software_dirs.cfg${NC} config file."
exit 127
fi
fi
############### END Check dep ####################################
echo -e "\n\n\n${blue}:: Running pipeline with the following arguments:${NC}"
#Only print if running in lib number mode
if [[ $specificFiles == "FALSE" ]]; then
printf "First Library\t\t\t${brown}=${NC} ${green}${LIB_FIRST}${NC}\n"
printf "Last Library\t\t\t${brown}=${NC} ${green}${LIB_LAST}${NC}\n"
printf "${grey}Number of threads\t\t${brown}=${NC} ${green}${THREADS}${NC}\n"
fi
if [[ -e "${DIR}/config/filters/wbench_filter_${FILTER_SUF}.cfg" ]]; then
echo -e "Filter suffix \t${brown}=${NC} ${green}${FILTER_SUF}${NC}"
cp ${DIR}/config/filters/wbench_filter_${FILTER_SUF}.cfg ${DIR}/config/wbench_filter_in_use.cfg
else
>&2 echo -e "${red}==> Error${NC} - The given filter file doesn't exist please check the file exists. Correct the FILTER_SUF var in ${blue}workdirs.cfg${NC} config file."
exit 127
fi
if [[ -e "${GENOME}" ]]; then
echo -e "${grey}Genome \t${brown}=${NC} ${green}${GENOME}${NC}"
else
>&2 echo -e "${red}==> Error${NC} - The given genome file doesn't exist please check the file exists. Correct the GENOME var in ${blue}workdirs.cfg${NC} config file."
exit 127
fi
if [[ -e "${GENOME_MIRCAT}" ]]; then
echo -e "${grey}Genome mircat \t${brown}=${NC} ${green}${GENOME_MIRCAT}${NC}"
else
echo -e "${red}==> Error${NC} - The given genome file for mircat doesn't exist please check the file exists. Correct the GENOME_MIRCAT var in ${blue}workdirs.cfg${NC} config file."
fi
if [[ -e "${MIRBASE}" ]]; then
echo -e "${grey}miRBase \t${brown}=${NC} ${green}${MIRBASE}${NC}"
else
echo -e "${red}==> Error${NC} - The given miRBase file doesn't exist please check the file exists. Correct the MIRBASE var in ${blue}workdirs.cfg${NC} config file."
exit 127
fi
if [[ -z "${workdir}" ]]; then
echo -e "${red}==> Not set:${NC} No workdir hasn't been set please don't put a trailing /, see config workdirs.cfg."
exit 127
else
echo -e "${grey}Working directory (workdir) \t${brown}=${NC} ${green}${workdir}${NC}"
fi
##############STEP 0 ##############################################################
if [[ -d "${INSERTS_DIR}" && "${step}" == "0" ]]; then
echo -e "${grey}sRNA directory (INSERTS_DIR) \t${brown}=${NC} ${green}${INSERTS_DIR}${NC}"
#Not dealing files from multiple files with same pattern but different extensions
#Checking if any thing matches first then it will check if multiple files are being found in pipe_fast*
if [[ ! -z "$fasta" && $specificFiles == "FALSE" ]]; then
if [[ -f ${INSERTS_DIR}/$(ls ${INSERTS_DIR} | grep -E ".*${fasta}0*${LIB_FIRST}[^0-9].*(fa|fasta)+(\.gz)*$") ]]; then
testLib=$(ls ${INSERTS_DIR} | grep -E ".*${fasta}0*${LIB_FIRST}[^0-9].*(fa|fasta)+(\.gz)*$")
else
testLib="${red}NOT FOUND${NC}"
fi
fi
if [[ ! -z "$fasta" && $specificFiles == "FALSE" ]]; then
if [[ -f ${INSERTS_DIR}/$(ls ${INSERTS_DIR} | grep -E ".*${fasta}0*${LIB_LAST}[^0-9].*(fa|fasta)+(\.gz)*$") ]]; then
testLibLast=$(ls ${INSERTS_DIR} | grep -E ".*${fasta}0*${LIB_LAST}[^0-9].*(fa|fasta)+(\.gz)*$")
else
testLibLast="${red}NOT FOUND${NC}"
fi
fi
if [[ ! -z "$fasta" && $specificFiles == "TRUE" ]]; then
testLib=$(basename $fasta)
fi
if [[ ! -z "$fastq" && $specificFiles == "FALSE" ]]; then
if [[ -f ${INSERTS_DIR}/$(ls ${INSERTS_DIR} | grep -E ".*${fastq}0*${LIB_FIRST}[^0-9].*(fq|fastq)+(\.gz)*$") ]];then
testLib=$(ls ${INSERTS_DIR} | grep -E ".*${fastq}0*${LIB_FIRST}[^0-9].*(fq|fastq)+(\.gz)*$")
else
testLib="${red}NOT FOUND${NC}"
fi
fi
if [[ ! -z "$fastq" && $specificFiles == "FALSE" ]]; then
if [[ -f ${INSERTS_DIR}/$(ls ${INSERTS_DIR} | grep -E ".*${fastq}0*${LIB_LAST}[^0-9].*(fq|fastq)+(\.gz)*$") ]];then
testLibLast=$(ls ${INSERTS_DIR} | grep -E ".*${fastq}0*${LIB_LAST}[^0-9].*(fq|fastq)+(\.gz)*$")
else
testLibLast="${red}NOT FOUND${NC}"
fi
fi
if [[ ! -z "$fastq" && $specificFiles == "TRUE" ]]; then
testLib=$(basename $fastq)
fi
###DEPRECATED WILL SOON BE REMOVED
if [[ ! -z "$LC" ]]; then
testLib=$(echo ${INSERTS_DIR}/*${fasta}${fastq}${LC}${LIB_FIRST}*)
fi
if [[ ! -z "$testLib" ]]; then
echo -e "\n${grey}First lib to be processed \t${brown}=${NC} ${green}${testLib}${NC}"
echo -e "${grey}Last lib to be processed \t${brown}=${NC} ${green}${testLibLast}${NC}\n"
if [[ ${testLib} == "\e[0;31mNOT FOUND\e[0m" || ${testLibLast} == "\e[0;31mNOT FOUND\e[0m" ]];then
echo -e "${red}==> Common string${NC}: The string used to group the sRNAs hasn't produced a proper result, see ${blue}https://mirpursuit.readthedocs.io/en/latest/gettingstarted.html#how-to-run-the-program${NC} ."
exit 127
fi
else
>&2 echo -e "${red}==> Invalid pattern:${NC} - No file / multiple files found, in inserts dir that matches your input settings ${green}${fasta}${fastq}${LC}${NC} for lib ${LIB_FIRST}. Or perhaps you're starting lib ${LIB_FIRST} is to low."
exit 127
fi
else
if [[ -d "${INSERTS_DIR}" ]]; then
echo -e "${grey}sRNA directory (INSERTS_DIR)${brown}=${NC} ${green}${INSERTS_DIR}${NC}"
else
echo -e "${red}==> Invalid dir${NC}: The inserts directory hasn't been configured properly, see config file ${blue}workdirs.cfg${NC}."
exit 127
fi
fi
#nonempty string bigger than 0 (Can't remember purpose of this!)
if [[ -n $1 ]]; then
echo "Last line of file specified as non-opt/last argument:"
tail -1 $1
fi
if [[ -d "$workdir" && "${noPrompt}" == "FALSE" ]]; then
unset $booleanYorN
>&2 echo -e "\n\n${red}==> Attention!${NC}\nworkdir ${brown}=>${NC} ${green}$workdir${NC} \nData already that exists in this folder might be overwritten."
while [[ "$booleanYorN" != [yYnN] ]]
do
read -n1 -p "Continue? (Y/N)" booleanYorN
done
if [[ $booleanYorN == [nN] ]]; then
echo $(date +"%y|%m|%d-%H:%M:%S")" - Terminated prematurely due to possibility of workdir being overwritten."
>&2 printf "\nTerminating prematurely\n"
exit 1
else
>&2 echo -ne "\n\n\r"
fi
fi
mkdir -p $workdir"/log/"
printf "0\tStarted\t0" >$progress
runDate=$(date +"%y|%m|%d-%H:%M:%S")
log_file="${workdir}/log/${runDate}:$$:Global:${LIB_FIRST}-${LIB_LAST}.log"
#Make dir to store all logs generated by subscripts.
mkdir -p $workdir"/log/$runDate"
exec >&1 > ${log_file}
echo $(date +"%y/%m/%d-%H:%M:%S")" - "$(basename ${log_file})
printf "\nRan with these vars:\n###################\n#software_dirs.cfg#\n###################\n"
cat $SOFT_CFG
printf "\nRan with these vars:\n##############\n#workdirs.cfg#\n##############\n"
cat $DIR/"config/workdirs.cfg"
printf "\n\n"
SCRIPTS_DIR=$DIR"/scripts"
if [[ ! -z "$LC" ]]; then
>&2 echo -e "${purple}==> Running in LC mode.${NC}"
${DIR}/extract_lcscience_inserts.sh $LIB_FIRST $LIB_LAST $LC
step=1
fi
if [[ ! -z "$fastq" ]]; then
>&2 echo -e "${purple}==> Running in fastq mode.${NC} - Copying fastq files..."
if [[ $specificFiles == "TRUE" ]]; then
########## Convert to absolute path? #################
${DIR}/pipe_fastq.sh $LIB_FIRST $fastq
else
${DIR}/pipe_fastq.sh $LIB_FIRST $LIB_LAST $fastq
fi
step=1
fi
if [[ ! -z "$fasta" ]]; then
>&2 echo -e "${purple}==> Running in fasta mode.${NC} - Copying fasta files..."
if [[ $specificFiles == "TRUE" ]]; then
########## Convert to absolute path? #################
${DIR}/pipe_fasta.sh $LIB_FIRST $fasta
else
${DIR}/pipe_fasta.sh $LIB_FIRST $LIB_LAST $fasta
fi
##Make profile
step=1
fi
if [[ "$step" -eq 0 ]]; then
#Concatenate and convert to fasta
>&2 echo -ne "${blue}:::: Step 0${NC} - Concatenating libs and converting to fasta [ ] 0%\r"
printf "0\tConverting\t0" > $progress
${DIR}/extract_fasteris_inserts.sh $LIB_FIRST $LIB_LAST
step=1
fi
if [[ "$step" -eq 1 ]]; then
if [[ $TRIM ]]; then
if [[ -z "$ADAPTOR" ]]; then
echo -e "${red}Invalid Adaptor${NC}: - The adaptor variable hasn't been configured properly, see config file ${blue}workdirs.cfg${NC}."
exit 127
else
>&2 printf "Adaptor sequence = ${ADAPTOR} \n\n"
>&2 echo -ne "${blue}:::: Step 1${NC} - Adaptor removal [## ] 10%\r"
printf "10\tAdaptor\t1" >$progress
${DIR}/pipe_trim_adaptors.sh $LIB_FIRST $LIB_LAST
fi
else
if [[ ! -z "$fastq" ]]; then
echo -e "${red}Attention!${NC}: - Not performing adaptor trimming"
fi
fi
#Filter size, t/rRNA, abundance.
>&2 echo -ne "${blue}:::: Step 1${NC} - Filtering libs with workbench Filter [##### ] 20%\r"
printf "20\tFiltering\t1" >$progress
${DIR}/pipe_filter_wbench.sh $LIB_FIRST $LIB_LAST
step=2
fi
if [[ "$step" -eq 2 ]]; then
#Filter genome and mirbase
>&2 echo -ne "${blue}:::: Step 2${NC} - Filtering libs against genome and mirbase [########## ] 40%\r"
printf "40\tGenome miRBase\t2" >$progress
${DIR}/pipe_filter_genome_mirbase.sh $LIB_FIRST $LIB_LAST ${IGNORE_GENOME}
step=3
fi
if [[ "$step" -eq 3 ]]; then
#tasiRNA
>&2 echo -ne "${blue}:::: Step 3${NC} - Running tasi, searching for tasi reads [############### ] 60%\r"
printf "60\tTasi\t3" >$progress
${DIR}/pipe_tasi.sh $LIB_FIRST $LIB_LAST
step=4
fi
if [[ "$step" -eq 4 ]]; then
#mircat
>&2 echo -ne "${blue}:::: Step 4${NC} - Running miRCat (Be patient, slow step) [#################### ] 80%\r"
printf "80\tmiRCat\t4" >$progress
${DIR}/pipe_mircat.sh $LIB_FIRST $LIB_LAST
step=5
fi
if [[ "$step" -eq 5 ]]; then
>&2 echo -ne "${blue} Step 5${NC} - Counting sequences to produces matrix [###################### ] 90%\r"
printf "90\tCounting\t5" >$progress
${DIR}/counts_merge.sh
>&2 echo -ne "${blue}:::: Step 5${NC} - Running report [######################## ] 95%\r"
printf "95\tReporting\t5" >$progress
$SCRIPTS_DIR/report.sh $LIB_FIRST $LIB_LAST ${DIR}
${DIR}/write_report.sh $LIB_FIRST $LIB_LAST complete
fi
>&2 echo -e "${blue}:::: Step 5${NC} - Done, files are in workdir [#########################] 100%"
printf "100\tFinished\t5" >$progress
sleep 4
>&2 echo " "
>&2 echo "This workflow was created by Forest Biotech Lab - iBET, Portugal "
sleep 2
>&2 echo "Build around the UEA srna-workbench. http://srna-workbench.cmp.uea.ac.uk/the-uea-small-rna-workbench-version-3-2/"
sleep 2
>&2 echo "Feedback: [email protected]"
sleep 2
>&2 echo ""
ok_log=${log_file/.log/:OK.log}
#Copy all ok log into folder of this run (Cleaning up the log folder)
mv ${workdir}/log/*PPID$$*.log ${workdir}/log/$runDate
echo $(basename $ok_log)
duration=$(date -u -d @${SECONDS} +"%T")
printf "\n-----------END--------------\nmiRPursuit ran in ${SECONDS}secs\nmiRPursuit ran in ${duration}\n"
>&2 echo -e "${green}Finished${NC} - sRNA-workflow finished successfully. Runtime: ${duration}"
mv $log_file $ok_log
RUN=$(( $RUN + 1 ))
sed -ri "s:(RUN=)(.*):\1${RUN}:" ${SOFT_CFG}
exit 0