-
Notifications
You must be signed in to change notification settings - Fork 4
/
RFSC.sh
executable file
·1551 lines (1537 loc) · 59.6 KB
/
RFSC.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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
#####################################################################
# ================================================================= #
# = = #
# = R F S C = #
# = = #
# = A Reference-Free Sequence Classification Tool = #
# = for DNA sequences in metagenomic samples. = #
# = = #
# ================================================================= #
#####################################################################
#
SHOW_HELP=0;
SHOW_VERSION=0;
INSTALL=0;
CLEAN=0;
CLEAN_ALL=0;
YES=0;
#
DOWNLOAD_DB_VIRUS=0;
DOWNLOAD_DB_BACTERIA=0;
DOWNLOAD_DB_ARCHAEA=0;
DOWNLOAD_DB_PROTOZOA=0;
DOWNLOAD_DB_FUNGI=0;
DOWNLOAD_DB_PLANT=0;
#DOWNLOAD_DB_INVERTEBRATE=0;
#DOWNLOAD_DB_VERTEBRATE_MAMMALIAN=0;
#DOWNLOAD_DB_VERTEBRATE_OTHER=0;
DOWNLOAD_DB_MITOCHONDRIAL=0;
DOWNLOAD_DB_PLASTID=0;
BASE_URL="https://share.bioinformatics-ua.pt/share.cgi?ssid=c0ed19a308ae4ef2b48cc48b7e73b1cb&fid=c0ed19a308ae4ef2b48cc48b7e73b1cb&path=%2F&openfolder=forcedownload&ep="
#
GEN_ADAPTERS=0;
#
THREADS_AVAILABLE=`cat /proc/cpuinfo | awk '/^processor/{print $3}' | wc -l`;
THREADS=0;
GET_THREADS="";
#
SET_THRESHOLD_REF_BASED=0;
MAX_THRESHOLD_REF_BASED=70;
MIN_THRESHOLD_REF_BASED=1;
GET_MAX_THRESHOLD_REF_BASED="";
GET_MIN_THRESHOLD_REF_BASED="";
#
GEN_SYNTHETIC=0;
REF_FILE1="";
REF_FILE2="";
REF_FILE3="";
REF_FILE4="";
LAST_MIX=0;
#
CRYFA_FLAG=0;
#
TRIMMING_FLAG=0;
TRIMMING_TYPE="";
TRIMMING_THREADS=0;
TRIMMING_MODE=""; # SE or PE
#
ASSEMBLY_FLAG=0;
#
SET_LEN_COV=0;
NODE_LENGTH=100;
NODE_COVERAGE=3;
SET_NODE_LENGTH="";
SET_NODE_COVERAGE="";
#
FALCON_FLAG=0;
FALCON_MODE="";
FALCON_DOMAIN="";
FALCON_TARGET_DOMAIN="DB-viral" # Default
BLASTN_REMOTE_FLAG=0;
#
RUN_DECRYPT=0;
RUN_ENCRYPT=0;
#
ORFFINDER_FLAG=0;
#
ORF_DATASETS=0;
ORF_TOOL="";
ORF_DOMAIN="";
#
NC_DNA_FLAG=0;
NC_DNA_DOMAIN="";
#
NC_AA_FLAG=0;
NC_AA_DOMAIN="";
#
GC_CONTENT_FLAG=0;
GC_CONTENT_DOMAIN="";
#
LEN_SEQ_FLAG=0;
LEN_SEQ_DOMAIN="";
#
EFETCH_FLAG=0;
EFETCH_ID="";
EFETCH_FOLDER="";
#
TRAIN_TEST_DATASET_FLAG=0;
TRAIN_TEST_DATASET_PARTITION="";
#
LIMIT_SAMPLES_DATASET_FLAG=0;
LIMIT_SAMPLES_DATASET="";
#
RUN_GNB=0;
NUM_DOMAINS="";
PREDICTORS_CODE="";
#
RUN_KNN=0;
KNN_K="";
#
RUN_XGB=0;
#
TEST_KNN_FLAG=0;
TEST_KNN_MODE="";
#
TEST_XGB_FLAG=0;
TEST_XGB_MODE="";
#
TEST_GNB_CV_FLAG=0;
TEST_GNB_DOMAIN="";
#
TEST_GNB_FLAG=0;
TEST_GNB_TRAIN_PERCENTAGE="";
#
ACCURACY_KNN_FLAG=0;
ACCURACY_KNN_MODE="";
ACCURACY_KNN_TRAIN="";
#
ACCURACY_XGB_FLAG=0;
ACCURACY_XGB_MODE="";
ACCURACY_XGB_TRAIN="";
#
ACCURACY_GNB_FLAG=0;
ACCURACY_GNB_MODE="";
ACCURACY_GNB_TRAIN="";
ACCURACY_GNB_TRAIN_PERC="";
#
RUN_CLASSIFIERS_FLAG=0;
RUN_CLASSIFIERS_MODE="";
#
MUTATE_GET=0;
MUTATE_FEATURES=0;
MUTATE_CLASSIFICATION=0;
#
SYNTHETIC_GET=0;
SYNTHETIC_FEATURES=0;
SYNTHETIC_CLASSIFICATION=0;
COMPUTE_KRAKEN=0;
#
# ==================================================================
# VERIFICATION FUNCTIONS
#
CHECK_ADAPTERS() {
if [ ! -f Input_Data/ReferenceBased/adapters.fa ]; then
echo -e "\033[1;33m[RFSC] ERROR: adapter sequences (adapter.fa) not found! \033[0m"
echo -e "\033[1;34m[RFSC] \033[0;33m ./RFSC.sh --gen-adapters \033[0m : To generate the adapter sequences ...";
fi
}
#
# ==================================================================
# GENERATE SYNTHETIC SEQUENCE
#
GENERATE_SYNTHETIC () {
./src/SyntheticGenerator/mixRefs.sh "$REF_FILE1" "$REF_FILE2" "$REF_FILE3";
LAST_MIX=$( ls src/SyntheticGenerator/Inputs/ | wc -l )
./src/SyntheticGenerator/syntheticGen.sh src/SyntheticGenerator/Inputs/"mix${LAST_MIX}.fa";
}
#
# ==================================================================
# TRIMMING/FILTERING SEQUENCES
#
TRIMMING_SEQUENCE() {
#
# Fetch the input files
i=0;
for file in Input_Data/ReferenceBased/*.fq.gz
do
input_file[i]="$file"
(( i++ ))
done
#
if [[ $TRIMMING_TYPE == "TT" ]]; then
echo -e "\033[1;34m[RFSC]\033[0m Trimming using Trimmomatic";
TRIMMING_THREADS=$THREADS_AVAILABLE;
echo -e "\033[1;34m[RFSC]\033[0m Currently using $TRIMMING_THREADS available threads!";
#
CHECK_ADAPTERS;
cp Input_Data/ReferenceBased/adapters.fa adapters.fa
#
if [[ $TRIMMING_MODE == "PE" ]]; then
trimmomatic $TRIMMING_MODE -threads $TRIMMING_THREADS -phred33 ${input_file[0]} ${input_file[1]} GeneratedFiles/o_fw_pr.fq GeneratedFiles/o_fw_unpr.fq GeneratedFiles/o_rv_pr.fq GeneratedFiles/o_rv_unpr.fq ILLUMINACLIP:adapters.fa:2:30:10 LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:25
elif [[ $TRIMMING_MODE == "SE" ]]; then
trimmomatic $TRIMMING_MODE -threads $TRIMMING_THREADS -phred33 ${input_file[0]} GeneratedFiles/out.fq ILLUMINACLIP:adapters.fa:2:30:10 LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:25
else
echo -e "\033[1;34m[RFSC] \033[1;31m Invalid Argument - $TRIMMING_MODE! \033[0m";
echo -e "\033[1;34m[RFSC]\033[0m Use one of the follow:";
echo -e "\033[1;34m[RFSC] \033[0;33m PE \033[0m : To use paired end reads";
echo -e "\033[1;34m[RFSC] \033[0;33m SE \033[0m : To use single end reads";
exit 0;
fi
#
rm adapters.fa
#
elif [[ $TRIMMING_TYPE == "FP" ]]; then
echo -e "\033[1;34m[RFSC]\033[0m Trimming with FASTP";
#
if [[ $TRIMMING_MODE == "PE" ]]; then
fastp -i ${input_file[0]} -I ${input_file[1]} -o GeneratedFiles/out1.fq.gz -O GeneratedFiles/out2.fq.gz
elif [[ $TRIMMING_MODE == "SE" ]]; then
fastp -i ${input_file[0]} -o GeneratedFiles/out.fq.gz
else
echo -e "\033[1;34m[RFSC] \033[1;31m Invalid Argument - $TRIMMING_MODE! \033[0m";
echo -e "\033[1;34m[RFSC]\033[0m Use one of the follow:";
echo -e "\033[1;34m[RFSC] \033[0;33m PE \033[0m : To use paired end reads";
echo -e "\033[1;34m[RFSC] \033[0;33m SE \033[0m : To use single end reads";
exit 0;
fi
#
mv fastp.html Outputs/
mv fastp.json Outputs/
else
echo -e "\033[1;34m[RFSC] \033[1;31m Invalid Argument - $TRIMMING_TYPE! \033[0m";
echo -e "\033[1;34m[RFSC]\033[0m Use one of the follow:";
echo -e "\033[1;34m[RFSC] \033[0;33m TT \033[0m : To use the Trimmomatic Tool";
echo -e "\033[1;34m[RFSC] \033[0;33m FP \033[0m : To use the FASTP Tool";
exit 0;
fi
}
#
# ==================================================================
# DE-NOVO ASSEMBLY
#
SPADES_ASSEMBLY() {
if [[ $TRIMMING_TYPE == "TT" ]]; then
if [[ $TRIMMING_MODE == "PE" ]]; then
spades.py -t 16 --careful -o GeneratedFiles/out_spades_$1 -1 GeneratedFiles/o_fw_pr.fq -2 GeneratedFiles/o_rv_pr.fq -s GeneratedFiles/o_fw_unpr.fq -s GeneratedFiles/o_rv_unpr.fq
else
spades.py -t 16 --careful -o GeneratedFiles/out_spades_$1 -s GeneratedFiles/out.fq
fi
else
if [[ $TRIMMING_MODE == "PE" ]]; then
spades.py -t 16 --careful -o GeneratedFiles/out_spades_$1 -1 GeneratedFiles/out1.fq.gz -2 GeneratedFiles/out2.fq.gz
else
spades.py -t 16 --careful -o GeneratedFiles/out_spades_$1 -s GeneratedFiles/out.fq.gz
fi
fi
}
#
# ==================================================================
# PARSE SCAFFOLDS INTO NODES (MINOR SCAFFOLDS)
#
PARSE_SCAFFOLDS() {
echo -e "\033[1;34m[RFSC]\033[0m Start parsing scaffolds.fasta"
mkdir GeneratedFiles/out_spades_/Nodes
awk '/>/{filename="GeneratedFiles/out_spades_/Nodes/"NR".fasta"}; {print >filename}' GeneratedFiles/out_spades_/scaffolds.fasta
echo -e "\033[1;34m[RFSC]\033[0m Parse finnished! The result can be find in GeneratedFiles/out_spades_/Nodes/"
echo -e "\033[1;34m[RFSC]\033[0m Start filtering nodes based on Lenght & Coverage!"
for file in GeneratedFiles/out_spades_/Nodes/*
do
REF=`grep ">" < $file`
NODE_LEN=$(awk -F_ '{print $4}' <<< ${REF})
NODE_COV=$(awk -F_ '{print $6}' <<< ${REF})
COV_TO_INT=(${NODE_COV//./ })
if [[ "$NODE_LEN" -gt "$NODE_LENGTH" ]] && [[ "${COV_TO_INT[0]}" -ge "$NODE_COVERAGE" ]]; then
continue
else
rm $file
echo -e "\033[1;34m[RFSC]\033[0m $file Node has been removed in the filtering process!"
fi
done
}
#
# ==================================================================
# FALCON ANALYSIS - SELECT DOMAIN
#
FALCON_SELECT_DOMAIN() {
if [[ "$FALCON_DOMAIN" == "Viral" ]]; then
FALCON_TARGET_DOMAIN="DB"
if [[ ! -f "References/NCBI-Virus/DB.fa" ]]; then
echo -e "\033[1;34m[RFSC]\033[0m DB-viral.fa was not found! Aborting..."
exit 0
fi
elif [[ "$FALCON_DOMAIN" == "Bacteria" ]]; then
FALCON_TARGET_DOMAIN="DB-bacteria"
if [[ ! -f "References/NCBI-Bacteria/DB-bacteria.fa" ]]; then
echo -e "\033[1;34m[RFSC]\033[0m DB-bacteria.fa was not found! Aborting..."
exit 0
fi
elif [[ "$FALCON_DOMAIN" == "Archaea" ]]; then
FALCON_TARGET_DOMAIN="DB-archaea"
if [[ ! -f "References/NCBI-Archaea/DB-archaea.fa" ]]; then
echo -e "\033[1;34m[RFSC]\033[0m DB-archaea.fa was not found! Aborting..."
exit 0
fi
elif [[ "$FALCON_DOMAIN" == "Fungi" ]]; then
FALCON_TARGET_DOMAIN="DB-fungi"
if [[ ! -f "References/NCBI-Fungi/DB-fungi.fa" ]]; then
echo -e "\033[1;34m[RFSC]\033[0m DB-fungi.fa was not found! Aborting..."
exit 0
fi
elif [[ "$FALCON_DOMAIN" == "Plant" ]]; then
FALCON_TARGET_DOMAIN="DB-plant"
if [[ ! -f "References/NCBI-Plant/DB-plant.fa" ]]; then
echo -e "\033[1;34m[RFSC]\033[0m DB-plant.fa was not found! Aborting..."
exit 0
fi
elif [[ "$FALCON_DOMAIN" == "Protozoa" ]]; then
FALCON_TARGET_DOMAIN="DB-protozoa"
if [[ ! -f "References/NCBI-Protozoa/DB-protozoa.fa" ]]; then
echo -e "\033[1;34m[RFSC]\033[0m DB-protozoa.fa was not found! Aborting..."
exit 0
fi
elif [[ "$FALCON_DOMAIN" == "Mitochondrial" ]]; then
FALCON_TARGET_DOMAIN="DB-mitochondrion"
if [[ ! -f "References/NCBI-Mitochondrial/DB-mitochondrion.fa" ]]; then
echo -e "\033[1;34m[RFSC]\033[0m DB-mitochondrion.fa was not found! Aborting..."
exit 0
fi
elif [[ "$FALCON_DOMAIN" == "Plastid" ]]; then
FALCON_TARGET_DOMAIN="DB-plastid"
if [[ ! -f "References/NCBI-Plastid/DB-plastid.fa" ]]; then
echo -e "\033[1;34m[RFSC]\033[0m DB-plastid.fa was not found! Aborting..."
exit 0
fi
else
echo -e "\033[1;34m[RFSC]\033[0m $FALCON_DOMAIN not recognized! Please select a valid domain from the next ones:"
echo -e "\033[1;34m[RFSC]\033[0m Viral | Bacteria | Archaea | Fungi | Plant | Protozoa | Mitochondrial | Plastid"
exit 0
fi
}
#
# ==================================================================
# FALCON ANALYSIS - SCAFFOLDS
#
FALCON_SO_MODE() {
FALCON_SELECT_DOMAIN;
FALCON -n $THREADS_AVAILABLE -v -F -x Outputs/falcon_SO_results.txt GeneratedFiles/out_spades_/scaffolds.fasta References/NCBI-Virus/$FALCON_TARGET_DOMAIN.fa
echo -e "\033[1;34m[RFSC]\033[0m Outputs/falcon_SO_results.txt file was successfully been generated!"
#
readarray -t results <Outputs/falcon_SO_results.txt
#
NUM_RES=${#results[@]}
for (( i=0; i<$NUM_RES; i++ ));
do
VIRUS=`echo "${results[i]}"|awk 'NF>1{print $NF}'`
PER=`echo "${results[i]}"|awk '{print $3}'`
BOOL=`echo "$PER > 70.000" | bc`
#
if [[ $BOOL -eq "1" ]]; then
printf "$VIRUS\n" >> Results/ref_result.txt
fi
done
}
#
# ==================================================================
# FALCON ANALYSIS - EACH READS
#
FALCON_RM_MODE() {
FALCON_SELECT_DOMAIN;
reads=0
for file in GeneratedFiles/out_spades_/Nodes/*
do
array[ $reads ]=$file
(( reads++ ))
done
#
mkdir Outputs/FalconNodes
len=${#array[@]}
i=0
while [[ $i != $len ]]
do
if [[ $(( ($len - $i) % 2)) == 0 ]]; then
path1=${array[i]}
path2=${array[i+1]}
path_to_file1=(${path1//// })
path_to_file2=(${path2//// })
R1=${path_to_file1[3]}
R2=${path_to_file2[3]}
echo -e "\033[1;34m[RFSC]\033[0m Analysing Nodes $R1 & $R2 with $(($THREADS_AVAILABLE/2)) threads each!"
FALCON -n $(($THREADS_AVAILABLE/2)) -v -F -x Outputs/FalconNodes/falcon_RM_"${R1}"_results.txt GeneratedFiles/out_spades_/Nodes/$R1 References/NCBI-Virus/$FALCON_TARGET_DOMAIN.fa | FALCON -n $(($THREADS_AVAILABLE/2)) -v -F -x Outputs/FalconNodes/falcon_RM_"${R2}"_results.txt GeneratedFiles/out_spades_/Nodes/$R2 References/NCBI-Virus/$FALCON_TARGET_DOMAIN.fa
(( i+=2 ))
else
path=${array[i]}
path_to_file=(${path//// })
R=${path_to_file[3]}
echo -e "\033[1;34m[RFSC]\033[0m Analysing Node $R with $(($THREADS_AVAILABLE)) threads!"
FALCON -n $(($THREADS_AVAILABLE)) -v -F -x Outputs/FalconNodes/falcon_RM_"${R}"_results.txt GeneratedFiles/out_spades_/Nodes/$R References/NCBI-Virus/$FALCON_TARGET_DOMAIN.fa
(( i++ ))
fi
done
}
#
# ==================================================================
# SELECT RESULTS (AFTER FALCON)
#
SELECT_RESULTS() {
echo -e "\033[1;34m[RFSC]\033[0m Starting selection procedure"
mkdir Results/falcon_seq
for file in Outputs/FalconNodes/*
do
readarray -t fasta_node <$file
NLINES=${#fasta_node[@]}
for (( i=0; i<$NLINES; i++ ));
do
PER=`echo "${fasta_node[i]}"|awk '{print $3}'`
FIND_MATCH=`echo "$PER > $MAX_THRESHOLD_REF_BASED" | bc`
SECOND_PHASE=`echo "$PER > $MIN_THRESHOLD_REF_BASED && $PER < $MAX_THRESHOLD_REF_BASED" | bc`
file=${file#"Outputs/FalconNodes/falcon_RM_"}
file=${file%"_results.txt"}
if [[ $FIND_MATCH -eq "1" ]]; then
GENOME=`echo "${fasta_node[i]}"|awk '{print $4}'`
echo -e "\033[1;34m[RFSC]\033[0m Moving $file to Results/falcon_seq"
mv GeneratedFiles/out_spades_/Nodes/$file Results/falcon_seq
ALREADY_FOUND=`grep -x $GENOME Results/ref_result.txt`
if [[ $ALREADY_FOUND != "" ]]; then
echo -e "\033[1;34m[RFSC]\033[0m Sequence already stated in Results/ref_result.txt"
else
printf "$GENOME\n" >> Results/ref_result.txt
fi
break
elif [[ $SECOND_PHASE -eq "1" ]]; then
echo -e "\033[1;34m[RFSC]\033[0m Moving $file to Input_Data/ReferenceFree"
mv GeneratedFiles/out_spades_/Nodes/$file Input_Data/ReferenceFree
break
else
echo -e "\033[1;34m[RFSC]\033[0m Deleting $file"
rm GeneratedFiles/out_spades_/Nodes/$file
break
fi
done
done
}
#
# ==================================================================
# FALCON ANALYSIS
#
FALCON_ANALYSIS() {
if [[ $FALCON_MODE == "SO" ]]; then
FALCON_SO_MODE;
elif [[ $FALCON_MODE == "RM" ]]; then
FALCON_SO_MODE;
PARSE_SCAFFOLDS;
FALCON_RM_MODE;
SELECT_RESULTS;
else
echo -e "\033[1;34m[RFSC] \033[1;31m Invalid Argument - $FALCON_MODE! \033[0m";
echo -e "\033[1;34m[RFSC]\033[0m Use one of the follow:";
echo -e "\033[1;34m[RFSC] \033[0;33m SO \033[0m : To analyse only the scaffold";
echo -e "\033[1;34m[RFSC] \033[0;33m RM \033[0m : To use redundancy in the analyse (Run each Read)";
exit 0;
fi
}
#
# ==================================================================
# BLASTN ANALYSIS
#
BLASTN_ANALYSIS() {
PARSE_SCAFFOLDS;
mkdir Outputs/BlastnNodes
for file in GeneratedFiles/out_spades_/Nodes/*
do
file_name=$(basename $file);
echo -e "\033[1;34m[RFSC]\033[0m Blastn is now processing $file"
blastn -db nt -task blastn-short -query $file -remote > Outputs/BlastnNodes/$file_name.txt
done
}
#
# ==================================================================
# ORF FINDER SEARCH (ORFfinder)
#
ORF_SEARCH() {
mkdir ORFs/NodesProteins
for file in Input_Data/ReferenceFree/*
do
node_file=$(basename $file);
echo -e "\033[1;34m[RFSC]\033[0m ORFfinder is now processing $node_file"
node_file=${node_file%".fasta"}
./ORFs/ORFfinder -s 1 -in Input_Data/ReferenceFree/$node_file.fasta -outfmt 0 -out ORFs/NodesProteins/$node_file.protein.fasta
done
}
#
# ==================================================================
# ENCRYPTION
#
ENCRYPT_DATA() {
echo -e "\033[1;34m[RFSC]\033[0;32m Please insert the password to encrypt the files contained in /Data_Security/Encrypt_Input: \033[0m";
read -s password
echo "$password" > key.txt
#
for file in Data_Security/Encrypt_Input/*
do
echo -e "\033[1;34m[RFSC]\033[0;32m Encrypting $file ... \033[0m";
out_file=$(basename $file);
cryfa -k key.txt $file > Data_Security/Encrypted_Data/$out_file.enc
done
rm -f key.txt
echo -e "\033[1;34m[RFSC]\033[0;32m $file has been encrypted! \033[0m";
}
#
# ==================================================================
# DECRYPTION
#
DECRYPT_DATA() {
for file in Data_Security/Encrypted_Data/*
do
echo -e "\033[1;34m[RFSC]\033[0;32m Decrypting $file ... \033[0m";
out_file=$(basename $file);
echo -e "\033[1;34m[RFSC]\033[0;32m Please insert the password to decrypt the file $file: \033[0m";
read -s password
echo "$password" > key.txt
cryfa -k key.txt -d $file > Data_Security/Decrypted_Data/$out_file.dec;
echo -e "\033[1;34m[RFSC]\033[0;32m $file has been decrypted! \033[0m";
rm -f key.txt;
done
}
#
# ==================================================================
# OPTIONS
#
if [ "$#" -eq 0 ]; then
SHOW_HELP=1;
fi
#
POSITIONAL=();
#
while [[ $# -gt 0 ]]
do
i="$1";
case $i in
-h|--help|?)
SHOW_HELP=1;
shift
;;
-v|-V|--version)
SHOW_VERSION=1;
shift
;;
-i|--install)
INSTALL=1;
shift
;;
-t|--threads)
THREADS=1;
GET_THREADS="$2";
shift 2
;;
-tmm|--set-threshold-max-min)
SET_THRESHOLD_REF_BASED=1;
GET_MAX_THRESHOLD_REF_BASED="$2";
GET_MIN_THRESHOLD_REF_BASED="$3";
shift 3
;;
-dlc|--set-len-cov)
SET_LEN_COV=1;
SET_NODE_LENGTH="$2";
SET_NODE_COVERAGE="$3";
shift 3
;;
-dviral|--download-ref-virus)
DOWNLOAD_DB_VIRUS=1;
shift
;;
-dbact|--download-ref-bacteria)
DOWNLOAD_DB_BACTERIA=1;
shift
;;
-darch|--download-ref-archaea)
DOWNLOAD_DB_ARCHAEA=1;
shift
;;
-dprot|--download-ref-protozoa)
DOWNLOAD_DB_PROTOZOA=1;
shift
;;
-dfung|--download-ref-fungi)
DOWNLOAD_DB_FUNGI=1;
shift
;;
-dplan|--download-ref-plant)
DOWNLOAD_DB_PLANT=1;
shift
;;
-dmito|--download-ref-mitochondrial)
DOWNLOAD_DB_MITOCHONDRIAL=1;
shift
;;
-dplas|--download-ref-plastid)
DOWNLOAD_DB_PLASTID=1;
shift
;;
-gad|--gen-adapters)
GEN_ADAPTERS=1;
shift
;;
-synt|--synthetic)
GEN_SYNTHETIC=1;
REF_FILE1="$2";
REF_FILE2="$3";
REF_FILE3="$4";
shift 4
;;
-trim|--filter)
TRIMMING_FLAG=1;
TRIMMING_TYPE="$2";
TRIMMING_MODE="$3";
shift 3
;;
-rda|--run-de-novo)
ASSEMBLY_FLAG=1;
shift
;;
-rfa|--run-falcon)
FALCON_FLAG=1;
FALCON_MODE="$2";
FALCON_DOMAIN="$3"
shift 3
;;
-rbr|--run-blastn-remote)
BLASTN_REMOTE_FLAG=1;
shift
;;
-orf|--orf-finder)
ORFFINDER_FLAG=1;
shift
;;
-orfd|--orf-dataset)
ORF_DATASETS=1;
ORF_TOOL="$2";
ORF_DOMAIN="$3";
shift 3
;;
-enc|--encrypt)
RUN_ENCRYPT=1;
shift
;;
-dec|--decrypt)
RUN_DECRYPT=1;
shift
;;
-ncd|--nc-dna-csv)
NC_DNA_FLAG=1;
NC_DNA_DOMAIN="$2";
shift 2
;;
-nca|--nc-aa-csv)
NC_AA_FLAG=1;
NC_AA_DOMAIN="$2";
shift 2
;;
-gc|--gc-content-csv)
GC_CONTENT_FLAG=1;
GC_CONTENT_DOMAIN="$2";
shift 2
;;
-lenseq|--len-dna-aa-csv)
LEN_SEQ_FLAG=1;
LEN_SEQ_DOMAIN="$2";
shift 2
;;
-efetch|--efetch-fasta)
EFETCH_FLAG=1;
EFETCH_ID="$2";
EFETCH_FOLDER="$3";
shift 3
;;
-train-test|--train-test-dataset-csv)
TRAIN_TEST_DATASET_FLAG=1;
TRAIN_TEST_DATASET_PARTITION="$2";
shift 2
;;
-sdataset|--small-dataset-csv)
LIMIT_SAMPLES_DATASET_FLAG=1;
LIMIT_SAMPLES_DATASET="$2";
shift 2
;;
-gnb|--run-gaussian-naive-bayes-classifier)
RUN_GNB=1;
NUM_DOMAINS="$2";
PREDICTORS_CODE="$3";
shift 3
;;
-knn|--run-k-nearest-neighbor-classifier)
RUN_KNN=1;
KNN_K="$2";
shift 2
;;
-xgb|--run-xgboost)
RUN_XGB=1;
shift
;;
-testKNN)
TEST_KNN_FLAG=1;
TEST_KNN_MODE="$2";
shift 2
;;
-testXGB)
TEST_XGB_FLAG=1;
TEST_XGB_MODE="$2";
shift 2
;;
-testGNB)
TEST_GNB_FLAG=1;
TEST_GNB_TRAIN_PERCENTAGE="$2";
shift 2
;;
-testGNB-CV|--testGNB-CrossV)
TEST_GNB_CV_FLAG=1;
TEST_GNB_DOMAIN="$2";
shift 2
;;
-aKNN|--accuracy-KNN)
ACCURACY_KNN_FLAG=1;
ACCURACY_KNN_MODE="$2";
ACCURACY_KNN_TRAIN="$3";
shift 3
;;
-aXGB|--accuracy-XGB)
ACCURACY_XGB_FLAG=1;
ACCURACY_XGB_MODE="$2";
ACCURACY_XGB_TRAIN="$3";
shift 3
;;
-aGNB|--accuracy-GNB)
ACCURACY_GNB_FLAG=1;
ACCURACY_GNB_MODE="$2";
ACCURACY_GNB_TRAIN="$3";
ACCURACY_GNB_TRAIN_PERC="$4"
shift 4
;;
-mget|--mutate-getter)
MUTATE_GET=1;
shift 1
;;
-cfem|--compute-features-mutation)
MUTATE_FEATURES=1;
shift 1
;;
-cclm|--compute-classification-mutation)
MUTATE_CLASSIFICATION=1;
shift 1
;;
-sget|--synthetic-getter)
SYNTHETIC_GET=1;
shift 1
;;
-cfes|--compute-features-synthetic)
SYNTHETIC_FEATURES=1;
shift 1
;;
-ccls|--compute-classification-synthetic)
SYNTHETIC_CLASSIFICATION=1;
shift 1
;;
-ckra|--compute-kraken2)
COMPUTE_KRAKEN=1;
shift 1
;;
-runAll|--run-all-classifiers)
RUN_CLASSIFIERS_FLAG=1;
if [[ -z $2 ]]; then
RUN_CLASSIFIERS_MODE="All";
else
RUN_CLASSIFIERS_MODE="$2";
shift 1
fi
shift 1
;;
-clc|--clean)
CLEAN=1;
if [[ $2 = "y" ]]; then
YES=1;
shift 1
fi
shift 1
;;
-cla|--clean-all)
CLEAN_ALL=1;
if [[ $2 = "y" ]]; then
YES=1;
shift 1
fi
shift 1
;;
-all|--run-all)
CLEAN=1;
SET_THRESHOLD_REF_BASED=1;
GET_MAX_THRESHOLD_REF_BASED="70";
GET_MIN_THRESHOLD_REF_BASED="1";
SET_LEN_COV=1;
SET_NODE_LENGTH="100";
SET_NODE_COVERAGE="3";
TRIMMING_FLAG=1;
TRIMMING_TYPE="TT";
TRIMMING_MODE="PE";
ASSEMBLY_FLAG=1;
FALCON_FLAG=1;
FALCON_MODE="RM";
FALCON_DOMAIN="Viral";
RUN_KNN=1;
KNN_K="2";
shift
;;
-*) # Unknown option
echo -e "\033[1;34m[RFSC] \033[1;31m Invalid arg ($1)! \033[0m";
echo -e "\033[1;34m[RFSC]\033[0m For more help, try: \033[0;33m./RFSC.sh -h \033[0m"
exit 1;
;;
esac
done
#
set -- "${POSITIONAL[@]}" # Restore positional parameters
#
# ======================================================================
# HELP MENU
#
if [ "$SHOW_HELP" -eq "1" ]; then
echo " "
echo -e " \033[0;36m ____ _____ ____ ____ \033[0m "
echo -e " \033[0;36m | _ \| ___/ ___| / ___| \033[0m "
echo -e " \033[0;36m | |_) | |_ \___ \| | \033[0m "
echo -e " \033[0;36m | _ <| _| ___) | |___ \033[0m "
echo -e " \033[0;36m |_| \_\_| |____/ \____| \033[0m "
echo " "
echo -e " \033[1;34m P I P E L I N E \033[0m "
echo " "
echo -e " \033[3;34m A Reference-Free Sequence Classification Tool \033[0m "
echo -e " \033[3;34m for DNA sequences in metagenomic samples. \033[0m "
echo " "
echo -e " \033[1;33m Usage: ./RFSC.sh [options] \033[0m "
echo " "
echo " -h, --help Show this help message and exit "
echo " -v, --version Show the version and some information "
echo " -i, --install Installation of all the needed tools "
echo " "
echo -e " -t, --threads \033[0;34m<THREADS>\033[0m "
echo " Number of threads to be used "
echo " "
echo " -dec, --decrypt Decrypt all files in /Data_Security/Decrypted_Data "
echo " -enc, --encrypt Encrypt all files in /Data_Security/Encrypted_data "
echo " "
echo -e " -tmm, --set-threshold-max-min \033[0;34m<MAX> <MIN>\033[0m "
echo " Set Max & Min thresholds for percentage "
echo " similarity in reference based analysis "
echo " "
echo -e " -dlc, --set-len-cov \033[0;34m<LEN> <COV>\033[0m "
echo " Define the Length and Coverage values "
echo " for the scaffolds filtering process "
echo " "
echo " -gad, --gen-adapters Generate FASTA file with adapters "
echo " "
echo -e " -synt, --synthetic \033[0;34m[FILE1]:[FILE3]\033[0m "
echo " Generate a synthetical sequence using 3 "
echo " reference files for testing purposes "
echo " "
echo -e " -trim, --filter \033[0;34m<TOOL> <MODE>\033[0m "
echo " TOOL: Filter Reads using Trimmomatic (TT) "
echo " or using FASTP (FP) "
echo " MODE: Paired End Reads (PE) "
echo " or Single End Reads (SE) "
echo " "
echo " -rda, --run-de-novo De-Novo Sequence Assembly "
echo " "
echo " -orf, --orf-finder Perform DNA sequence translation for amino acids, "
echo " finds all open reading frames (ORF) and remove "
echo " stop codons "
echo " "
echo -e " -orfd, --orf-dataset \033[0;34m<TOOL> <DOMAIN> \033[0m "
echo " Converts nucleotide sequences presented in the "
echo " NCBI databases into protein sequences "
echo " TOOL: orfM (-orfm) [DEFAULT] "
echo " or using ORF-Finder (-orffinder) "
echo " DOMAIN: --viral, --bacteria, --archaea, ... "
echo " "
echo -e " -ncd, --nc-dna-csv \033[0;34m<DOMAIN> \033[0m "
echo " Compresses and generates a CSV file for the "
echo " DNA NCBI datasets "
echo " DOMAIN: --viral, --bacteria, --archaea, ... "
echo " "
echo -e " -nca, --nc-aa-csv \033[0;34m<DOMAIN> \033[0m "
echo " Compresses and generates a CSV file for the "
echo " AA NCBI datasets "
echo " DOMAIN: --viral, --bacteria, --archaea, ... "
echo " "
echo -e " -gc, --gc-content-csv \033[0;34m<DOMAIN> \033[0m "
echo " Analyses the percentage of GC-Content in each "
echo " sequece of the choosen NCBI database "
echo " DOMAIN: --viral, --bacteria, --archaea, ... "
echo " "
echo -e " -lenseq, --len-dna-aa-csv \033[0;34m<DOMAIN> \033[0m "
echo " Analyses the Length (DNA & AA) sequences the "
echo " choosen NCBI database "
echo " DOMAIN: --viral, --bacteria, --archaea, ... "
echo " "
echo -e " -efetch, --efetch-fasta \033[0;34m<ID> <FOLDER> \033[0m "
echo " Use entrez efetch to fetch a nucleotide using an ID"
echo " ID: Nucleotide Identifier "
echo " FOLDER: Destination Folder (RefBased or RefFree) "
echo -e " \033[1;33m - - - - - - - - - - - - - - - - - - - - - - \033[0m "
echo -e " \033[1;33m M U T A T E D D A T A \033[0m "
echo " "
echo " -mget, --mutate-getter "
echo -e " Gathers small set of sequences from the 8 domains "
echo -e " (Randomly, if seed is changed) "
echo " "
echo " -cfem, --compute-features-mutation "
echo -e " Compute features for mutated sequences "
echo " "
echo " -cclm, --compute-classification-mutation "
echo -e " Compute classification for mutated sequences "
echo " "
echo -e " \033[1;33m - - - - - - - - - - - - - - - - - - - - - - \033[0m "
echo -e " \033[1;33m S Y N T H E T I C D A T A \033[0m "
echo " "
echo " -sget, --synthetic-getter "
echo -e " Gathers small set of sequences from the 8 domains "
echo -e " (Randomly, if seed is changed) "
echo " "
echo " -cfes, --compute-features-synthetic "
echo -e " Creates synthetic sequences "
echo -e " Compute features for synthetic sequences "
echo " "
echo " -ccls, --compute-classification-synthetic "
echo -e " Compute classification for synthetic sequences "
echo " "
echo " -ckra, --compute-kraken2 "
echo -e " Compute synthetic sequences using Kraken2 "
echo -e " (only for comparison purposes, "
echo -e " requires Kraken2 installation) "
echo " "
echo -e " \033[1;33m - - - - - - - - - - - - - - - - - - - - - - \033[0m "
echo -e " \033[1;33m D O W N L O A D D A T A B A S E S \033[0m "
echo " "
echo " -dviral, --download-ref-virus "
echo -e " Download reference database for \033[1;36mvirus\033[0m "
echo " -dbact, --download-ref-bacteria "
echo -e " Download reference database for \033[1;36mbacterias\033[0m "
echo " -darch, --download-ref-archaea "
echo -e " Download reference database for \033[1;36marchaeas\033[0m "
echo " -dprot, --download-ref-protozoa "
echo -e " Download reference database for \033[1;36mprotozoa\033[0m "
echo " -dfung, --download-ref-fungi "
echo -e " Download reference database for \033[1;36mfungi\033[0m "
echo " -dplan, --download-ref-plant "
echo -e " Download reference database for \033[1;36mplant\033[0m "
echo " -dmito, --download-ref-mitochondrial "
echo -e " Download reference database for \033[1;36mmitochondrial\033[0m "
echo " -dplas, --download-ref-plastid "
echo -e " Download reference database for \033[1;36mplastid\033[0m "
echo -e " \033[1;33m - - - - - - - - - - - - - - - - - - - - - - \033[0m "
echo " "
echo -e " \033[1;33m R E F E R E N C E B A S E D A P P R O A C H \033[0m "
echo " "
echo -e " -rfa, --run-falcon \033[0;34m<MODE> <DOMAIN> \033[0m "
echo " Run Data Analysis with FALCON "
echo " MODE: Use only scaffolds (SO) or analyse by each "
echo " Read (RM) "
echo " DOMAIN: Select Domain to analyse (Viral, Bacteria) "
echo " Archaea, Fungi, Plant, Plastid, etc. "
echo " "
echo " -rbr, --run-blastn-remote "
echo " Run Data Analysus with Blast+ using remote "
echo " access to NCBI databases "
echo -e " \033[1;33m - - - - - - - - - - - - - - - - - - - - - - \033[0m "
echo " "
echo -e " -train-test, --train-test-dataset-csv \033[0;34m<TRAIN_PARTITION> \033[0m "
echo " Divide the dataset into a train and test dataset "
echo " (Usefull for testing the KNN Classifier) "
echo " TRAIN_PARTITION: value (0..1) for the train partition"
echo " "
echo -e " -sdataset, --small-dataset-csv \033[0;34m<MAX_SAMPLES> \033[0m "
echo " Create a small dataset with a maximum of samples "
echo " for each domain "
echo " MAX_SAMPLES: Maximum samples per domain "
echo " "
echo -e " \033[1;33m R E F E R E N C E F R E E A P P R O A C H \033[0m "
echo " "
echo -e " -gnb, --run-gaussian-naive-bayes-classifier \033[0;34m<NUM_DOMAINS> <PREDICTORS>\033[0m "
echo " NUM_DOMAINS: Number of domains supported "
echo " PREDICTORS: Code regarding the desired predictors: "
echo " '1111' -> All predictors "
echo " '0001' -> Only Nucleotide Compression "
echo " '0010' -> Only AA Compression "
echo " '0011' -> Only GC-Content "
echo " '0100' -> Only DNA Length "
echo " '0101' -> Only AA Length "
echo " '0110' -> DNA & AA Compression "