-
Notifications
You must be signed in to change notification settings - Fork 7
/
cenote-taker2.1.5.sh
2263 lines (2111 loc) · 116 KB
/
cenote-taker2.1.5.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
# Cenote-Taker Logo
echo "$(tput setaf 2)00000000000000000000000000"
echo "00000000000000000000000000"
echo "000000000$(tput setaf 4)^^^^^^^^$(tput setaf 2)000000000"
echo "000000$(tput setaf 4)^^^^^^^^^^^^^^$(tput setaf 2)000000"
echo "00000$(tput setaf 4)^^^^^$(tput setaf 3)CENOTE$(tput setaf 4)^^^^^$(tput setaf 2)00000"
echo "00000$(tput setaf 4)^^^^^$(tput setaf 3)TAKER!$(tput setaf 4)^^^^^$(tput setaf 2)00000"
echo "00000$(tput setaf 4)^^^^^^^^^^^^^^^^$(tput setaf 2)00000"
echo "000000$(tput setaf 4)^^^^^^^^^^^^^^$(tput setaf 2)000000"
echo "000000000$(tput setaf 4)^^^^^^^^$(tput setaf 2)000000000"
echo "00000000000000000000000000"
echo "00000000000000000000000000$(tput sgr 0)"
echo " "
echo "Version 2.1.5"
echo " "
echo "Fun fact: As of this version, the$(tput setaf 4) virion $(tput sgr 0)database is used by default. Wow!"
sleep 2s
# Setting input parameters
original_contigs=$1
F_READS=$2
R_READS=$3
run_title=$4
isolation_source=$5
collection_date=$6
metagenome_type=$7
srr_number=$8
srx_number=$9
biosample=${10}
bioproject=${11}
template_file=${12}
circ_length_cutoff=${13}
linear_length_cutoff=${14}
virus_domain_db=${15}
LIN_MINIMUM_DOMAINS=${16}
handle_knowns=${17}
ASSEMBLER=${18}
MOLECULE_TYPE=${19}
HHSUITE_TOOL=${20}
DATA_SOURCE=${21}
BLASTP=${22}
PROPHAGE=${23}
FOR_PLASMIDS=${24}
BLASTN_DB=${25}
CENOTE_SCRIPT_DIR=${26}
CIRC_MINIMUM_DOMAINS=${27}
SCRATCH_DIR=${28}
MEM=${29}
CPU=${30}
ENFORCE_START_CODON=${31}
ORF_WITHIN=${32}
ANNOTATION_MODE=${33}
CRISPR_FILE=${34}
base_directory=$PWD
CENOTE_DBS=${35}
WRAP=${36}
HALLMARK_TAX=${37}
EXACT=${38}
if [ "$ANNOTATION_MODE" == "True" ] ; then
LIN_MINIMUM_DOMAINS=0
CIRC_MINIMUM_DOMAINS=0
circ_length_cutoff=1000
linear_length_cutoff=1
PROPHAGE="False"
fi
#># check for correct format run name
echo "@@@@@@@@@@@@@@@@@@@@@@@@@"
echo "Your specified arguments:"
echo "original contigs: $original_contigs"
echo "forward reads: $F_READS"
echo "reverse reads: $R_READS"
echo "title of this run: $run_title"
echo "Isolate source: $isolation_source"
echo "collection date: $collection_date"
echo "metagenome_type: $metagenome_type"
echo "SRA run number: $srr_number"
echo "SRA experiment number: $srx_number"
echo "SRA sample number: $biosample"
echo "Bioproject number: $bioproject"
echo "template file: $template_file"
echo "minimum circular contig length: $circ_length_cutoff"
echo "minimum linear contig length: $linear_length_cutoff"
echo "virus domain database: $virus_domain_db"
echo "min. viral hallmarks for linear: $LIN_MINIMUM_DOMAINS"
echo "min. viral hallmarks for circular: $CIRC_MINIMUM_DOMAINS"
echo "handle known seqs: $handle_knowns"
echo "contig assembler: $ASSEMBLER"
echo "DNA or RNA: $MOLECULE_TYPE"
echo "HHsuite tool: $HHSUITE_TOOL"
echo "original or TPA: $DATA_SOURCE"
echo "Do BLASTP?: $BLASTP"
echo "Do Prophage Pruning?: $PROPHAGE"
echo "Filter out plasmids?: $FOR_PLASMIDS"
echo "Run BLASTN against nt? $BLASTN_DB"
echo "Location of Cenote scripts: $CENOTE_SCRIPT_DIR"
echo "Location of scratch directory: $SCRATCH_DIR"
echo "GB of memory: $MEM"
echo "number of CPUs available for run: $CPU"
echo "Annotation only mode? $ANNOTATION_MODE"
echo "Cenote-Taker 2 DBs directory: $CENOTE_DBS"
echo "Wrap circular contigs?: $WRAP"
echo "Taxonomy for each hallmark?: $HALLMARK_TAX"
echo "Exact match DTRs?: $EXACT"
echo "@@@@@@@@@@@@@@@@@@@@@@@@@"
#checking validity of run_title
if [[ "$run_title" =~ ^[a-zA-Z0-9_]+$ ]] && [ ${#run_title} -le 18 ] ; then
echo $run_title ;
else
echo "$run_title is not a valid name for the run title ( -r argument)"
echo " the run title needs to be only letters, numbers and underscores (_) and 18 characters or less. Exiting."
exit
fi
if [ "${SCRATCH_DIR}" == "none" ] ; then
echo "scratch space will not be used in this run"
if [ -s ${CENOTE_DBS}/NCBI_CD/NCBI_CD_a3m.ffdata ] ; then
CD_HHSUITE="${CENOTE_DBS}/NCBI_CD/NCBI_CD"
else
CD_HHSUITE=""
fi
if [ -s ${CENOTE_DBS}/pfam_32_db/pfam_a3m.ffdata ] ; then
PFAM_HHSUITE="${CENOTE_DBS}/pfam_32_db/pfam"
else
PFAM_HHSUITE=""
fi
if [ -s ${CENOTE_DBS}/pdb70/pdb70_a3m.ffdata ] ; then
PDB_HHSUITE="${CENOTE_DBS}/pdb70/pdb70"
else
PDB_HHSUITE=""
fi
echo "HHsuite database locations:"
echo $CD_HHSUITE
echo $PFAM_HHSUITE
echo $PDB_HHSUITE
# downloading taxdump database if it doesn't exist
if [ ! -s ${CENOTE_DBS}/taxdump/names.dmp ] ; then
echo "the required taxdump file (new requirement as of Cenote-Taker 2.1.5) wasn't found. It will be downloaded and upacked at ${CENOTE_DBS}/taxdump/"
if [ ! -d ${CENOTE_DBS}/taxdump ] ; then
mkdir ${CENOTE_DBS}/taxdump
fi
cd ${CENOTE_DBS}/taxdump
wget https://ftp.ncbi.nlm.nih.gov/pub/taxonomy/taxdump.tar.gz
tar -xf taxdump.tar.gz
cd $base_directory
fi
# make sure all required database directories exist
if [ ! -d ${CENOTE_DBS}/blast_DBs/ ] ; then
echo "Can not find blast databases at ${CENOTE_DBS}/blast_DBs/"
echo "Exiting"
exit
fi
if [ ! -d ${CENOTE_DBS}/hmmscan_DBs/ ] ; then
echo "Can not find HMM databases at ${CENOTE_DBS}/hmmscan_DBs/"
echo "Exiting"
exit
fi
if [ ! -d ${CENOTE_DBS}/cdd_rps_db/ ] ; then
echo "Can not find RPSBLAST databases at ${CENOTE_DBS}/hmmscan_DBs/"
echo "Exiting"
exit
fi
if [ ! -d ${CENOTE_DBS}/taxdump/ ] ; then
echo "Can not find Taxonomy databases at ${CENOTE_DBS}/hmmscan_DBs/"
echo "Exiting"
exit
fi
elif [ -d ${SCRATCH_DIR}/ ] ; then
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: setting up lscratch databases: " $MDYT
if [ ! -s ${SCRATCH_DIR}/NCBI_CD/NCBI_CD_a3m.ffdata ] ; then
mkdir ${SCRATCH_DIR}/NCBI_CD
cp ${CENOTE_DBS}/NCBI_CD/NCBI_CD* ${SCRATCH_DIR}/NCBI_CD/
fi
if [ ! -s ${SCRATCH_DIR}/pfam_32_db/pfam_a3m.ffdata ] ; then
mkdir ${SCRATCH_DIR}/pfam_32_db
cp ${CENOTE_DBS}/pfam_32_db/pfam* ${SCRATCH_DIR}/pfam_32_db/
fi
if [ ! -s ${SCRATCH_DIR}/pdb70/pdb70_a3m.ffdata ] ; then
mkdir ${SCRATCH_DIR}/pdb70
cp ${CENOTE_DBS}/pdb70/pdb70* ${SCRATCH_DIR}/pdb70/
fi
CD_HHSUITE="${SCRATCH_DIR}/NCBI_CD/NCBI_CD"
PFAM_HHSUITE="${SCRATCH_DIR}/pfam_32_db/pfam"
PDB_HHSUITE="${SCRATCH_DIR}/pdb70/pdb70"
# mkdir /lscratch/$SLURM_JOB_ID/viral
# cp /fdb/blastdb/viral.* /lscratch/$SLURM_JOB_ID/viral/
else
echo "CAN'T FIND SCRATCH FOLDER. Specify correct folder or don't use scratch space. Exiting."
exit
fi
# setting HHSUITE database argument string
HHSUITE_DB_STR=""
if [ -n "$CD_HHSUITE" ] ; then
HHSUITE_DB_STR="${HHSUITE_DB_STR}-d ${CD_HHSUITE} "
fi
if [ -n "$PFAM_HHSUITE" ] ; then
HHSUITE_DB_STR="${HHSUITE_DB_STR}-d ${PFAM_HHSUITE} "
fi
if [ -n "$PDB_HHSUITE" ] ; then
HHSUITE_DB_STR="${HHSUITE_DB_STR}-d ${PDB_HHSUITE}"
fi
if [ ! -n "$HHSUITE_DB_STR" ] ; then
echo "HHsuite databases not found at ${CENOTE_DBS}"
echo "$HHSUITE_TOOL will not be run"
HHSUITE_TOOL="none"
fi
# looking for template file and contigs in working directory, or else copying them there
if [ -s ${base_directory}/${template_file} ] ; then
echo ${base_directory}/${template_file} ;
else
cp ${template_file} ${base_directory}/ ;
template_file=$( basename $template_file )
fi
if [ -s ${base_directory}/${original_contigs} ] ; then
echo ${base_directory}/${original_contigs} ;
else
cp ${original_contigs} ${base_directory}/ ;
original_contigs=$( basename $original_contigs )
fi
if [ -s ${base_directory}/${CRISPR_FILE} ] ; then
echo ${base_directory}/${CRISPR_FILE} ;
elif [ "${CRISPR_FILE}" == "none" ] ; then
echo "no CRISPR file given"
else
cp ${CRISPR_FILE} ${base_directory}/ ;
CRISPR_FILE=$( basename $CRISPR_FILE )
fi
if [ "$PROPHAGE" == "True" ] && [ $LIN_MINIMUM_DOMAINS -le 0 ] ; then
echo "Prophage pruning requires --lin_minimum_hallmark_genes >= 1. changing to:"
echo "--lin_minimum_hallmark_genes 1"
LIN_MINIMUM_DOMAINS=1
fi
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: locating inputs: " $MDYT
# looking for template file and contigs in working directory, or else copying them there
if [ -s ${base_directory}/${original_contigs} ] ; then
echo ${base_directory}/${original_contigs} ;
else
cp ${original_contigs} ${base_directory}/ ;
original_contigs=$( basename $original_contigs )
fi
# Making output folder
if [ ! -d "$run_title" ]; then
mkdir "$run_title"
else
rand_dir=$( head /dev/urandom | tr -dc A-Za-z0-9 | head -c 3 ; echo '' )
DAY1=$( date +"%m-%d-%y" )
mv ${run_title}/ ${run_title}_old_${DAY1}_${rand_dir}
mkdir "$run_title"
fi
if [ ${original_contigs: -3} == ".fa" ]; then
echo "renaming $original_contigs to ${original_contigs}sta"
mv $original_contigs ${original_contigs}sta
original_contigs=${original_contigs}sta
fi
if [ ${original_contigs: -4} == ".fna" ]; then
echo "renaming $original_contigs to ${original_contigs%fna}fasta"
mv $original_contigs ${original_contigs%fna}fasta
original_contigs=${original_contigs%fna}fasta
fi
if [ ${original_contigs: -4} == ".fsa" ]; then
echo "renaming $original_contigs to ${original_contigs%fsa}fasta"
mv $original_contigs ${original_contigs%fsa}fasta
original_contigs=${original_contigs%fsa}fasta
fi
# Removing contigs under $circ_length_cutoff nts and detecting circular contigs
if [ $circ_length_cutoff -gt $linear_length_cutoff ] ; then
LENGTH_MINIMUM=$linear_length_cutoff
else
LENGTH_MINIMUM=$circ_length_cutoff
fi
#LASTDBQ=$( find $CENOTE_SCRIPT_DIR -type f -wholename "$CENOTE_SCRIPT_DIR/last-*/lastdb" )
#LASTALQ=$( find $CENOTE_SCRIPT_DIR -type f -wholename "$CENOTE_SCRIPT_DIR/last-*/lastal" )
if [ ${original_contigs: -6} == ".fasta" ]; then
echo "$(tput setaf 5)File with .fasta extension detected, attempting to keep contigs over $LENGTH_MINIMUM nt and find circular sequences with apc.pl$(tput sgr 0)"
bioawk -v run_var="$run_title" -v contig_cutoff="$LENGTH_MINIMUM" -c fastx '{ if(length($seq) > contig_cutoff) { print ">"run_var NR" "$name; print $seq }}' $original_contigs > ${original_contigs%.fasta}.over_${LENGTH_MINIMUM}nt.fasta ;
cd $run_title
echo "cenote_shortcut" > ${run_title}_CONTIG_SUMMARY.tsv
if [ "$EXACT" == "True" ] ; then
perl ${CENOTE_SCRIPT_DIR}/apc_exact1.pl -b $run_title -c lastdb -d lastal ../${original_contigs%.fasta}.over_${LENGTH_MINIMUM}nt.fasta >/dev/null 2>&1
else
perl ${CENOTE_SCRIPT_DIR}/apc_cenote1.pl -b $run_title -c lastdb -d lastal ../${original_contigs%.fasta}.over_${LENGTH_MINIMUM}nt.fasta >/dev/null 2>&1
fi
find . -type f -name "apc_aln*" -exec rm -f {} \;
APC_CIRCS=$( find . -maxdepth 1 -type f -name "${run_title}*.fa" )
if [ -n "$APC_CIRCS" ] ;then
for fa1 in $APC_CIRCS ; do
#-#-# adding wrap option to clip DTRs or not
if [ "$WRAP" == "True" ] ; then
CIRC_NEW_NAME=$( head -n1 $fa1 | sed 's/|.*//g ; s/>//g ; s/ .*//g' ) ;
sed 's/|.*//g ; /^$/d' $fa1 > ${CIRC_NEW_NAME}.fasta
else
CIRC_SEQ_NAME=$( head -n1 $fa1 | sed 's/|.*//g' ) ;
CIRC_NEW_NAME=$( echo "$CIRC_SEQ_NAME" | sed 's/>//g ; s/ .*//g' )
grep -A1 "^$CIRC_SEQ_NAME" ../${original_contigs%.fasta}.over_${LENGTH_MINIMUM}nt.fasta | sed '/--/d' > ${CIRC_NEW_NAME}.fasta
fi
echo "${CIRC_NEW_NAME}.fasta has DTRs/circularity"
rm -f $fa1
done
else
echo "No circular contigs detected."
fi
elif [ ${original_contigs: -6} == ".fastg" ]; then
bioawk -v contig_cutoff="$LENGTH_MINIMUM" -c fastx '{ if(length($seq) > contig_cutoff) {print }}' $original_contigs | grep "[a-zA-Z0-9]:\|[a-zA-Z0-9];" | grep -v "':" | awk '{ print ">"$1 ; print $2 }' | sed 's/:.*//g; s/;.*//g' | bioawk -v run_var="$run_title" -c fastx '{ print ">"run_var NR" "$name; print $seq }' > ${original_contigs%.fastg}.over_${LENGTH_MINIMUM}nt.fasta
cd $run_title
echo "cenote_shortcut" > ${run_title}_CONTIG_SUMMARY.tsv
perl ${CENOTE_SCRIPT_DIR}/apc_cenote1.pl -b $run_title -c $LASTDBQ -d $LASTALQ ../${original_contigs%.fastg}.over_${LENGTH_MINIMUM}nt.fasta >/dev/null 2>&1
rm -f apc_aln*
APC_CIRCS=$( find . -maxdepth 1 * -type f -name "${run_title}*.fa" )
if [ -n "$APC_CIRCS" ] ;then
for fa1 in $APC_CIRCS ; do
if [ "$WRAP" == "True" ] ; then
CIRC_NEW_NAME=$( head -n1 $fa1 | sed 's/|.*//g ; s/>//g ; s/ .*//g' ) ;
sed 's/|.*//g ; /^$/d' $fa1 > ${CIRC_NEW_NAME}.fasta
else
CIRC_SEQ_NAME=$( head -n1 $fa1 | sed 's/|.*//g' ) ;
CIRC_NEW_NAME=$( echo "$CIRC_SEQ_NAME" | sed 's/>//g ; s/ .*//g' )
grep -A1 "^$CIRC_SEQ_NAME" ../${original_contigs%.fasta}.over_${LENGTH_MINIMUM}nt.fasta | sed '/--/d' > ${CIRC_NEW_NAME}.fasta
fi
echo "${CIRC_NEW_NAME}.fasta has DTRs/circularity"
rm -f $fa1
done
else
echo "No circular contigs detected."
fi
else
echo "$(tput setaf 4)File with .fasta of .fastg extension not detected as first input. Exiting.$(tput sgr 0)" ;
exit
fi
# Removing cirles that are smaller than user specified cutoff
CIRC_CONTIGS=$( find . -maxdepth 1 -type f -name "*.fasta" )
if [ ! -z "$CIRC_CONTIGS" ] ;then
for CIRCLE1 in $CIRC_CONTIGS ; do
CIRCLE1_LENGTH=$( bioawk -c fastx '{print length($seq) }' $CIRCLE1 )
if [[ $CIRCLE1_LENGTH -lt $circ_length_cutoff ]] ; then
mv $CIRCLE1 ${CIRCLE1%.fasta}.too_short.fasta
fi
done
fi
rm -f *.too_short.fasta
# Aligning reads to contigs
FIRST_F_READS=$( echo "$F_READS" | sed 's/,.*//g' )
if [ ! -s "$FIRST_F_READS" ] ; then
echo "no reads provided or reads not found"
else
echo "$(tput setaf 4)Aligning provided reads to contigs over cutoff to determine coverage. $(tput sgr 0)"
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: making bowtie2 indices " $MDYT
mkdir bt2_indices ;
#### update the script to allow for contigs from other directories
bowtie2-build ../${original_contigs%.fasta}.over_${LENGTH_MINIMUM}nt.fasta bt2_indices/${run_title}_bt2_index >/dev/null 2>&1
echo "$(tput setaf 4)Aligning reads to BowTie2 index. $(tput sgr 0)"
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: aligning reads to bowtie2 indices " $MDYT
if [ ! -s "$R_READS" ] ;then
bowtie2 -q -p${CPU} -x bt2_indices/${run_title}_bt2_index -U $F_READS -S reads_to_all_contigs_over${LENGTH_MINIMUM}nt.sam --very-fast
else
bowtie2 -q -p${CPU} -x bt2_indices/${run_title}_bt2_index -1 $F_READS -2 $R_READS -S reads_to_all_contigs_over${LENGTH_MINIMUM}nt.sam --very-fast
fi
echo "$(tput setaf 4)Calculating read coverage of each contig with BBTools Pileup. $(tput sgr 0)"
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: running BBTools Pileup " $MDYT
pileup.sh in=reads_to_all_contigs_over${LENGTH_MINIMUM}nt.sam out=reads_to_all_contigs_over${LENGTH_MINIMUM}nt.coverage.txt
rm -f reads_to_all_contigs_over${LENGTH_MINIMUM}nt.sam
fi
# Detecting whether any circular contigs were present
original_fastas=$( find . -maxdepth 1 -type f -name "*.fasta" )
# "$(tput setaf 5)$var1$(tput sgr 0)"
if [ -z "$original_fastas" ] ; then
echo "$(tput setaf 4)No circular fasta files detected. $(tput sgr 0)"
#exit
mkdir other_contigs
if [ ${original_contigs: -6} == ".fasta" ]; then
grep -A1 "^>" ../${original_contigs%.fasta}.over_${LENGTH_MINIMUM}nt.fasta | sed 's/--//g' | bioawk -v contig_cutoff="$linear_length_cutoff" -c fastx '{ if (length($seq) > contig_cutoff) { print ">"$name" "$4 ; print $seq }}' > other_contigs/all_non_circular.fasta
elif [ ${original_contigs: -6} == ".fastg" ]; then
grep -A1 "^>" ../${original_contigs%.fastg}.over_${LENGTH_MINIMUM}nt.fasta | sed 's/--//g' | bioawk -v contig_cutoff="$linear_length_cutoff" -c fastx '{ if (length($seq) > contig_cutoff) { print ">"$name" "$4 ; print $seq }}' > other_contigs/all_non_circular.fasta
fi
if [ -s other_contigs/all_non_circular.fasta ] ; then
grep "^>" other_contigs/all_non_circular.fasta | sed 's/>//g' | cut -d " " -f1 | while read LINE ; do
grep -A1 "$LINE [^\s]" other_contigs/all_non_circular.fasta > other_contigs/$LINE.fasta ;
done
fi
else
echo "$(tput setaf 5)Circular fasta file(s) detected$(tput sgr 0)"
echo " "
cat *fasta > all_circular_contigs_${run_title}.fna
# Putting non-circular contigs in a separate directory
echo "$(tput setaf 4)Putting non-circular contigs in a separate directory $(tput sgr 0)"
mkdir other_contigs
for CIRCLE in $original_fastas ; do
grep "^>" $CIRCLE | sed 's/|.*//g' >> circular_contigs_spades_names.txt
done
if [ ${original_contigs: -6} == ".fasta" ]; then
LINEAR_COUNT=$( grep -v -f circular_contigs_spades_names.txt ../${original_contigs%.fasta}.over_${LENGTH_MINIMUM}nt.fasta | grep -A1 "^>" | wc -l )
if [ $LINEAR_COUNT -ge 1 ] ; then
grep -v -f circular_contigs_spades_names.txt ../${original_contigs%.fasta}.over_${LENGTH_MINIMUM}nt.fasta | grep -A1 "^>" | sed 's/--//g' | bioawk -v contig_cutoff="$linear_length_cutoff" -c fastx '{ if (length($seq) > contig_cutoff) { print ">"$name" "$4 ; print $seq }}' > other_contigs/all_non_circular.fasta
else
echo "No linear contigs over ${LENGTH_MINIMUM}nt found in run"
fi
elif [ ${original_contigs: -6} == ".fastg" ]; then
LINEAR_COUNT=$( grep -v -f circular_contigs_spades_names.txt ../${original_contigs%.fastg}.over_${LENGTH_MINIMUM}nt.fasta | grep -A1 "^>" | wc -l )
if [ $LINEAR_COUNT -ge 1 ] ; then
grep -v -f circular_contigs_spades_names.txt ../${original_contigs%.fastg}.over_${LENGTH_MINIMUM}nt.fasta | grep -A1 "^>" | sed 's/--//g' | bioawk -v contig_cutoff="$linear_length_cutoff" -c fastx '{ if (length($seq) > contig_cutoff) { print ">"$name" "$4 ; print $seq }}' > other_contigs/all_non_circular.fasta
else
echo "No linear contigs over ${LENGTH_MINIMUM}nt found in run"
fi
fi
if [ -s other_contigs/all_non_circular.fasta ] ; then
grep "^>" other_contigs/all_non_circular.fasta | sed 's/>//g' | cut -d " " -f1 | while read LINE ; do
grep -A1 "$LINE [^\s]" other_contigs/all_non_circular.fasta > other_contigs/$LINE.fasta ;
done
fi
fi
cd other_contigs
CONTIGS_NON_CIRCULAR=$( find . -maxdepth 1 -type f -name "*[0-9].fasta" )
if [ ! -z "$CONTIGS_NON_CIRCULAR" ] ;then
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: running IRF for ITRs in non-circular contigs" $MDYT
for NONCIR in $CONTIGS_NON_CIRCULAR ; do
LEN_CHECKQ=$( cat $NONCIR | bioawk -c fastx '{ if(length($seq) > 4000) { print $name }}' ) ;
if [ ! -z "$LEN_CHECKQ" ] ; then
${CENOTE_SCRIPT_DIR}/irf307.linux.exe $NONCIR 2 3 5 80 10 40 500000 10000 -d -h >/dev/null 2>&1
fi
done
mkdir ../ITR_containing_contigs
DAT_FILES=$( find * -maxdepth 0 -type f -name "*.dat" )
if [ -n "$DAT_FILES" ] ; then
for DAT in $DAT_FILES ; do
if grep -q "^[0-9]" $DAT ; then
LENGTH=$( bioawk -c fastx '{ print length($seq) }' ${DAT%.2.3.5.80.10.40.500000.10000.dat} | sed 's/ //g; s/\///g' ) ;
ITR_STARTS=$( grep "^[0-9]" $DAT | cut -d " " -f1 ) ;
ITR_ENDS=$( grep "^[0-9]" $DAT | cut -d " " -f5 ) ;
LOW_START=$( echo $ITR_STARTS | tr " " "\n" | sort -g | head -n1| sed 's/ //g' ) ;
HIGH_END=$( echo $ITR_ENDS | tr " " "\n" | sort -g | tail -n1 | sed 's/ //g' ) ;
if [ $LOW_START -gt 0 ] && [ $HIGH_END -gt 0 ] ; then
HIGH_DIST=$(( $LENGTH-$HIGH_END )) ;
if [ $LOW_START -lt 1000 ] && [ $HIGH_DIST -lt 1000 ] ; then
echo ${DAT%.2.3.5.80.10.40.500000.10000.dat} "contains ITRs" ;
#echo $LENGTH "5-prime ITR:" $LOW_START "3-prime ITR:" $HIGH_END ;
mv ${DAT%.2.3.5.80.10.40.500000.10000.dat} ../ITR_containing_contigs/${DAT%.fasta.2.3.5.80.10.40.500000.10000.dat}.fasta
#echo "$(tput setaf 4) Making ITR .tbl file $(tput sgr 0)"
L_END_A=$( grep "^$LOW_START" $DAT | cut -d " " -f2 )
L_START_B=$( grep "^$LOW_START" $DAT | cut -d " " -f4 )
L_END_B=$( grep "^$LOW_START" $DAT | cut -d " " -f5 )
H_START_A=$( grep " $HIGH_END " $DAT | cut -d " " -f1 )
H_END_A=$( grep " $HIGH_END " $DAT | cut -d " " -f2 )
H_START_B=$( grep " $HIGH_END " $DAT | cut -d " " -f4 )
echo -e "$LOW_START\t""$L_END_A\t""repeat_region\n""\t\t\trpt_type\tITR\n""$L_START_B\t""$L_END_B\t""repeat_region\n""\t\t\trpt_type\tITR\n""$H_START_A\t""$H_END_A\t""repeat_region\n""\t\t\trpt_type\tITR\n""$H_START_B\t""$HIGH_END\t""repeat_region\n""\t\t\trpt_type\tITR\n" >> ../ITR_containing_contigs/${DAT%.fasta.2.3.5.80.10.40.500000.10000.dat}.ITR.tbl;
fi ;
fi ;
fi ;
done
fi
CONTIGS_NON_CIRCULAR=$( find . -maxdepth 1 -type f -name "*[0-9].fasta" )
mkdir ../no_end_contigs_with_viral_domain
if [ $LIN_MINIMUM_DOMAINS -le 0 ] ; then
for LIN in $CONTIGS_NON_CIRCULAR ; do
mv ${LIN} ../no_end_contigs_with_viral_domain/${LIN%.fasta}.fna
done
else
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: running prodigal on linear contigs " $MDYT
echo "$CONTIGS_NON_CIRCULAR" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t prodigal -a {}.AA.fasta -i {}.fasta -p meta -q >/dev/null 2>&1
for NO_END in $CONTIGS_NON_CIRCULAR ; do
sed 's/ /@/g' ${NO_END%.fasta}.AA.fasta | bioawk -c fastx '{print}' | while read LINE ; do
START_BASE=$( echo "$LINE" | cut -d "#" -f 2 | sed 's/@//g' ) ;
END_BASE=$( echo "$LINE" | cut -d "#" -f 3 | sed 's/@//g' ) ;
ORF_NAME=$( echo "$LINE" | cut -d "#" -f 1 | sed 's/@//g; s/\./_/g' ) ;
AA_SEQ=$( echo "$LINE" | cut -f2 ) ;
ORIG_CONTIG=$( grep ">" ${NO_END} | cut -d " " -f2 )
if echo $AA_SEQ | grep -q "\*" ; then
INC3=""
else
INC3="3primeInc"
fi
FAA=${AA_SEQ:0:1}
if [ "$FAA" != "M" ] && [ $START_BASE -le 3 ] ; then
INC5="5primeInc"
else
INC5=""
fi
echo ">"${ORF_NAME} "["$START_BASE" - "$END_BASE"]" ${INC5}${INC3} $ORIG_CONTIG ; echo $AA_SEQ ;
done > ${NO_END%.fasta}.AA.sorted.fasta
done
LIN_NO_ITR_AA=$( find . -maxdepth 1 -type f -name "*.AA.sorted.fasta" )
if [ -n "$LIN_NO_ITR_AA" ] ; then
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: running linear contigs with hmmscan against virus hallmark gene database: $virus_domain_db " $MDYT
#cat $( find . -maxdepth 1 -type f -name "*.AA.sorted.fasta" ) > all_large_genome_proteins.AA.fasta
for LIN in $LIN_NO_ITR_AA ; do
cat $LIN
done > all_large_genome_proteins.AA.fasta
TOTAL_AA_SEQS=$( grep -F ">" all_large_genome_proteins.AA.fasta | wc -l | bc )
if [ $TOTAL_AA_SEQS -ge 1 ] ; then
AA_SEQS_PER_FILE=$( echo "scale=0 ; $TOTAL_AA_SEQS / $CPU" | bc )
if [ $AA_SEQS_PER_FILE = 0 ] ; then
AA_SEQS_PER_FILE=1
fi
awk -v seq_per_file="$AA_SEQS_PER_FILE" 'BEGIN {n_seq=0;} /^>/ {if(n_seq%seq_per_file==0){file=sprintf("SPLIT_LARGE_GENOME_AA_%d.fasta",n_seq);} print >> file; n_seq++; next;} { print >> file; }' < all_large_genome_proteins.AA.fasta
SPLIT_AA_LARGE=$( find . -maxdepth 1 -type f -name "SPLIT_LARGE_GENOME_AA_*.fasta" )
if [[ $virus_domain_db = "standard" ]] ; then
echo "$SPLIT_AA_LARGE" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t hmmscan --tblout {}.AA.hmmscan.out --cpu 1 -E 1e-8 --noali ${CENOTE_DBS}/hmmscan_DBs/virus_specific_baits_plus_missed6a {}.fasta >/dev/null 2>&1
echo "$SPLIT_AA_LARGE" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t hmmscan --tblout {}.AA.hmmscan_replicate.out --cpu 1 -E 1e-15 --noali ${CENOTE_DBS}/hmmscan_DBs/virus_replication_clusters3 {}.fasta >/dev/null 2>&1
elif [[ $virus_domain_db = "virion" ]]; then
echo "$SPLIT_AA_LARGE" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t hmmscan --tblout {}.AA.hmmscan.out --cpu 1 -E 1e-8 --noali ${CENOTE_DBS}/hmmscan_DBs/virus_specific_baits_plus_missed6a {}.fasta >/dev/null 2>&1
elif [[ $virus_domain_db = "rna_virus" ]]; then
echo "$SPLIT_AA_LARGE" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t hmmscan --tblout {}.AA.hmmscan.out --cpu 1 -E 1e-8 --noali ${CENOTE_DBS}/hmmscan_DBs/rna_virus_rdrp_capsid_hmms1 {}.fasta >/dev/null 2>&1
else
echo "$(tput setaf 5) Incorrect argument given for virus_domain_db variable. Try standard, virion, or rna_virus as arguments. For this run, no contigs with viral domains but without circularity or ITRs will be detected $(tput sgr 0)"
rm -f ./*{0..9}.fasta
break
fi
HMM_REP_NUMEBR=$( find . -maxdepth 1 -type f -name "SPLIT_LARGE_GENOME_AA_*AA.hmmscan_replicate.out" | wc -l )
if [[ $FOR_PLASMIDS = "True" ]]; then
if [ $HMM_REP_NUMEBR -gt 0 ] ; then
cat SPLIT_LARGE_GENOME_AA_*AA.hmmscan.out SPLIT_LARGE_GENOME_AA_*AA.hmmscan_replicate.out | grep -v "^#\|plasmid_clust" | sed 's/ \+/ /g' | sort -u -k3,3 > LARGE_GENOME_COMBINED.AA.hmmscan.sort.out
else
cat SPLIT_LARGE_GENOME_AA_*AA.hmmscan.out | grep -v "^#\|plasmid_clust" | sed 's/ \+/ /g' | sort -u -k3,3 > LARGE_GENOME_COMBINED.AA.hmmscan.sort.out
fi
else
if [ $HMM_REP_NUMEBR -gt 0 ] ; then
cat SPLIT_LARGE_GENOME_AA_*AA.hmmscan.out SPLIT_LARGE_GENOME_AA_*AA.hmmscan_replicate.out | grep -v "^#" | sed 's/ \+/ /g' | sort -u -k3,3 > LARGE_GENOME_COMBINED.AA.hmmscan.sort.out
else
cat SPLIT_LARGE_GENOME_AA_*AA.hmmscan.out | grep -v "^#" | sed 's/ \+/ /g' | sort -u -k3,3 > LARGE_GENOME_COMBINED.AA.hmmscan.sort.out
fi
fi
if [ -e LARGE_GENOME_COMBINED.AA.hmmscan.sort.out ] ; then
cut -f3 LARGE_GENOME_COMBINED.AA.hmmscan.sort.out | sed 's/[^_]*$//' | sed 's/\(.*\)_/\1/' | sort -u | while read HIT ; do
HALL_COUNT=$( grep "${HIT}_" LARGE_GENOME_COMBINED.AA.hmmscan.sort.out | wc -l | bc )
if [ $HALL_COUNT -ge $LIN_MINIMUM_DOMAINS ] ; then
mv "${HIT}.fasta" "../no_end_contigs_with_viral_domain/${HIT}.fna"
grep "${HIT}_" LARGE_GENOME_COMBINED.AA.hmmscan.sort.out > ../no_end_contigs_with_viral_domain/${HIT}.AA.hmmscan.sort.out
# ../no_end_contigs_with_viral_domain/${NO_END%.fasta}.no_hmmscan1.fasta
grep "${HIT}_" LARGE_GENOME_COMBINED.AA.hmmscan.sort.out | sort -u -k3,3 | cut -f3 | sed 's/\(.*\)/\1 /' > ${HIT}.AA.called_hmmscan.txt
grep -v -f ${HIT}.AA.called_hmmscan.txt ${HIT}.AA.sorted.fasta | grep -A1 ">" | sed '/--/d' > ../no_end_contigs_with_viral_domain/${HIT}.AA.no_hmmscan1.fasta
mv "${HIT}.AA.sorted.fasta" ../no_end_contigs_with_viral_domain/
else
cat ${HIT}.fasta >> non_viral_domains_contigs.fna
rm -f ${HIT}.fasta
fi
done
fi
else
echo "no AA seqs found in linear contigs, discover virus module"
fi
for REMAINDER in $CONTIGS_NON_CIRCULAR ; do
if [ -s $REMAINDER ] ; then
if [ "$ANNOTATION_MODE" == "True" ] ; then
mv $REMAINDER ../no_end_contigs_with_viral_domain/${REMAINDER%.fasta}.fna
else
cat $REMAINDER >> non_viral_domains_contigs.fna
rm -f $REMAINDER
fi
fi
done
else
echo "no linear seqs without ITRs"
fi
fi
fi
cd ${base_directory}/${run_title}
DTR_SEQS=$( find . -maxdepth 1 -type f -regextype sed -regex "./${run_title}[0-9]\{1,6\}.fasta" | sed 's/\.\///g' )
if [ ! -z "$DTR_SEQS" ] ; then
mkdir DTR_contigs_with_viral_domain
if [ $CIRC_MINIMUM_DOMAINS -le 0 ] ; then
for CIRC in $DTR_SEQS ; do
mv ${CIRC} DTR_contigs_with_viral_domain/${CIRC%.fasta}.fna
mv ${CIRC%.fasta}.DTR.tbl DTR_contigs_with_viral_domain/
done
else
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: Calling ORFs for circular/DTR sequences with prodigal " $MDYT
echo "$DTR_SEQS" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t prodigal -a {}.AA.fasta -i {}.fasta -p meta -q >/dev/null 2>&1
for CIRC in $DTR_SEQS ; do
mv ${CIRC%.fasta}.DTR.tbl DTR_contigs_with_viral_domain/
sed 's/ /@/g' ${CIRC%.fasta}.AA.fasta | bioawk -c fastx '{print}' | while read LINE ; do
START_BASE=$( echo "$LINE" | cut -d "#" -f 2 | sed 's/@//g' ) ;
END_BASE=$( echo "$LINE" | cut -d "#" -f 3 | sed 's/@//g' ) ;
ORF_NAME=$( echo "$LINE" | cut -d "#" -f 1 | sed 's/@//g; s/\./_/g' ) ;
AA_SEQ=$( echo "$LINE" | cut -f2 ) ;
ORIG_CONTIG=$( grep ">" ${CIRC} | cut -d " " -f2 )
if echo $AA_SEQ | grep -q "\*" ; then
INC3=""
else
INC3="3primeInc"
fi
FAA=${AA_SEQ:0:1}
if [ "$FAA" != "M" ] && [ $START_BASE -le 3 ] ; then
INC5="5primeInc"
else
INC5=""
fi
echo ">"${ORF_NAME} "["$START_BASE" - "$END_BASE"]" ${INC5}${INC3} $ORIG_CONTIG ; echo $AA_SEQ ;
done > ${CIRC%.fasta}.AA.sorted.fasta
done
#cat $( find . -maxdepth 1 -type f -name "*.AA.sorted.fasta" ) > all_circular_genome_proteins.AA.fasta
DTR_SEQS_SORT_AA=$( find . -maxdepth 1 -type f -name "*.AA.sorted.fasta" )
for DTRQ in $DTR_SEQS_SORT_AA ; do
cat $DTRQ
done > all_circular_genome_proteins.AA.fasta
TOTAL_AA_SEQS=$( grep -F ">" all_circular_genome_proteins.AA.fasta | wc -l | bc )
if [ $TOTAL_AA_SEQS -ge 1 ] ; then
AA_SEQS_PER_FILE=$( echo "scale=0 ; $TOTAL_AA_SEQS / $CPU" | bc )
if [ $AA_SEQS_PER_FILE = 0 ] ; then
AA_SEQS_PER_FILE=1
fi
awk -v seq_per_file="$AA_SEQS_PER_FILE" 'BEGIN {n_seq=0;} /^>/ {if(n_seq%seq_per_file==0){file=sprintf("SPLIT_CIRCULAR_AA_%d.fasta",n_seq);} print >> file; n_seq++; next;} { print >> file; }' < all_circular_genome_proteins.AA.fasta
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: running hmmscan on circular/DTR contigs " $MDYT
SPLIT_AA_CIRC=$( find . -maxdepth 1 -type f -name "SPLIT_CIRCULAR_AA_*.fasta" )
if [[ $virus_domain_db = "standard" ]] ; then
echo "$SPLIT_AA_CIRC" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t hmmscan --tblout {}.AA.hmmscan.out --cpu 1 -E 1e-8 --noali ${CENOTE_DBS}/hmmscan_DBs/virus_specific_baits_plus_missed6a {}.fasta >/dev/null 2>&1
echo "$SPLIT_AA_CIRC" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t hmmscan --tblout {}.AA.hmmscan_replicate.out --cpu 1 -E 1e-15 --noali ${CENOTE_DBS}/hmmscan_DBs/virus_replication_clusters3 {}.fasta >/dev/null 2>&1
elif [[ $virus_domain_db = "virion" ]]; then
echo "$SPLIT_AA_CIRC" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t hmmscan --tblout {}.AA.hmmscan.out --cpu 1 -E 1e-8 --noali ${CENOTE_DBS}/hmmscan_DBs/virus_specific_baits_plus_missed6a {}.fasta >/dev/null 2>&1
elif [[ $virus_domain_db = "rna_virus" ]]; then
echo "$SPLIT_AA_CIRC" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t hmmscan --tblout {}.AA.hmmscan.out --cpu 1 -E 1e-8 --noali ${CENOTE_DBS}/hmmscan_DBs/rna_virus_rdrp_capsid_hmms1 {}.fasta >/dev/null 2>&1
else
echo "$(tput setaf 5) Incorrect argument given for virus_domain_db variable. Try standard, virion, or rna_virus as arguments. For this run, no contigs with viral domains but without circularity or ITRs will be detected $(tput sgr 0)"
rm -f ./*{0..9}.fasta
break
fi
HMM_REP_NUMEBR=$( find . -maxdepth 1 -type f -name "SPLIT_CIRCULAR_AA_*AA.hmmscan_replicate.out" | wc -l )
if [[ $FOR_PLASMIDS = "True" ]]; then
if [ $HMM_REP_NUMEBR -gt 0 ] ; then
cat SPLIT_CIRCULAR_AA_*AA.hmmscan.out SPLIT_CIRCULAR_AA_*AA.hmmscan_replicate.out | grep -v "^#\|plasmid_clust" | sed 's/ \+/ /g' | sort -u -k3,3 > CIRCULAR_GENOME_COMBINED.AA.hmmscan.sort.out
else
cat SPLIT_CIRCULAR_AA_*AA.hmmscan.out | grep -v "^#\|plasmid_clust" | sed 's/ \+/ /g' | sort -u -k3,3 > CIRCULAR_GENOME_COMBINED.AA.hmmscan.sort.out
fi
else
if [ $HMM_REP_NUMEBR -gt 0 ] ; then
cat SPLIT_CIRCULAR_AA_*AA.hmmscan.out SPLIT_CIRCULAR_AA_*AA.hmmscan_replicate.out | grep -v "^#" | sed 's/ \+/ /g' | sort -u -k3,3 > CIRCULAR_GENOME_COMBINED.AA.hmmscan.sort.out
else
cat SPLIT_CIRCULAR_AA_*AA.hmmscan.out | grep -v "^#" | sed 's/ \+/ /g' | sort -u -k3,3 > CIRCULAR_GENOME_COMBINED.AA.hmmscan.sort.out
fi
fi
if [ -s CIRCULAR_GENOME_COMBINED.AA.hmmscan.sort.out ] ; then
cut -f3 CIRCULAR_GENOME_COMBINED.AA.hmmscan.sort.out | sed 's/[^_]*$//' | sed 's/\(.*\)_/\1/' | sort -u | while read HIT ; do
HALL_COUNT=$( grep "${HIT}_" CIRCULAR_GENOME_COMBINED.AA.hmmscan.sort.out | wc -l | bc )
if [ $HALL_COUNT -ge $CIRC_MINIMUM_DOMAINS ] ; then
mv ${HIT}.fasta DTR_contigs_with_viral_domain/${HIT}.fna
grep "${HIT}_" CIRCULAR_GENOME_COMBINED.AA.hmmscan.sort.out > DTR_contigs_with_viral_domain/${HIT}.AA.hmmscan.sort.out
grep "${HIT}_" CIRCULAR_GENOME_COMBINED.AA.hmmscan.sort.out | sort -u -k3,3 | cut -f3 | sed 's/\(.*\)/\1 /'> ${HIT}.AA.called_hmmscan.txt
grep -v -f ${HIT}.AA.called_hmmscan.txt ${HIT}.AA.sorted.fasta | grep -A1 ">" | sed '/--/d' > DTR_contigs_with_viral_domain/${HIT}.AA.no_hmmscan1.fasta
mv ${HIT}.AA.sorted.fasta DTR_contigs_with_viral_domain/
mv ${HIT}.AA.fasta DTR_contigs_with_viral_domain/
elif [ -s ${HIT}.fasta ] ; then
sed 's/ /#/g' ${HIT}.fasta | bioawk -c fastx '{print ">"$name"#DTRs" ; print $seq}' | sed 's/#/ /g' >> other_contigs/non_viral_domains_contigs.fna
rm -f ${HIT}.fasta
rm -f ${HIT}.AA.fasta
rm -f ${HIT}.AA.sorted.fasta
fi
done
fi
else
echo "No AA seqs found in circular contigs, discover viruses module"
fi
for REMAINDER in $DTR_SEQS ; do
if [ -s $REMAINDER ] ; then
if [ "$ANNOTATION_MODE" == "True" ] ; then
mv $REMAINDER DTR_contigs_with_viral_domain/${REMAINDER%.fasta}.fna
else
sed 's/ /#/g' $REMAINDER | bioawk -c fastx '{print ">"$name"#DTRs" ; print $seq}' | sed 's/#/ /g' >> other_contigs/non_viral_domains_contigs.fna
rm -f ${REMAINDER%fasta}*fasta
fi
fi
done
fi
fi
ITR_SEQS=$( find * -maxdepth 1 -type f -wholename "ITR_containing_contigs/*fasta" )
if [ ! -z "$ITR_SEQS" ] ; then
cd ITR_containing_contigs
ITR_SEQS=$( find . -maxdepth 1 -type f -wholename "*fasta" )
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: Calling ORFs for ITR sequences with prodigal " $MDYT
echo "$ITR_SEQS" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t prodigal -a {}.AA.fasta -i {}.fasta -p meta -q >/dev/null 2>&1
for CIRC in $ITR_SEQS ; do
sed 's/ /@/g' ${CIRC%.fasta}.AA.fasta | bioawk -c fastx '{print}' | while read LINE ; do
START_BASE=$( echo "$LINE" | cut -d "#" -f 2 | sed 's/@//g' ) ;
END_BASE=$( echo "$LINE" | cut -d "#" -f 3 | sed 's/@//g' ) ;
ORF_NAME=$( echo "$LINE" | cut -d "#" -f 1 | sed 's/@//g; s/\./_/g' ) ;
AA_SEQ=$( echo "$LINE" | cut -f2 ) ;
ORIG_CONTIG=$( grep ">" ${CIRC} | cut -d " " -f2 )
if echo $AA_SEQ | grep -q "\*" ; then
INC3=""
else
INC3="3primeInc"
fi
FAA=${AA_SEQ:0:1}
if [ "$FAA" != "M" ] && [ $START_BASE -le 3 ] ; then
INC5="5primeInc"
else
INC5=""
fi
echo ">"${ORF_NAME} "["$START_BASE" - "$END_BASE"]" ${INC5}${INC3} $ORIG_CONTIG ; echo $AA_SEQ ;
done > ${CIRC%.fasta}.AA.sorted.fasta
done
#cat $( find . -maxdepth 1 -type f -name "*.AA.sorted.fasta" ) > all_ITR_genome_proteins.AA.fasta
ITR_SEQ_SORT_AA=$( find . -maxdepth 1 -type f -name "*.AA.sorted.fasta" )
for ITRQ in $ITR_SEQ_SORT_AA ; do
cat $ITRQ
done > all_ITR_genome_proteins.AA.fasta
TOTAL_AA_SEQS=$( grep -F ">" all_ITR_genome_proteins.AA.fasta | wc -l | bc )
if [ $TOTAL_AA_SEQS -ge 1 ] ; then
AA_SEQS_PER_FILE=$( echo "scale=0 ; $TOTAL_AA_SEQS / $CPU" | bc )
if [ $AA_SEQS_PER_FILE = 0 ] ; then
AA_SEQS_PER_FILE=1
fi
awk -v seq_per_file="$AA_SEQS_PER_FILE" 'BEGIN {n_seq=0;} /^>/ {if(n_seq%seq_per_file==0){file=sprintf("SPLIT_ITR_AA_%d.fasta",n_seq);} print >> file; n_seq++; next;} { print >> file; }' < all_ITR_genome_proteins.AA.fasta
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: running hmmscan on ITR contigs " $MDYT
SPLIT_AA_CIRC=$( find . -maxdepth 1 -type f -name "SPLIT_ITR_AA_*.fasta" )
if [[ $virus_domain_db = "standard" ]] ; then
echo "$SPLIT_AA_CIRC" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t hmmscan --tblout {}.AA.hmmscan.out --cpu 1 -E 1e-8 --noali ${CENOTE_DBS}/hmmscan_DBs/virus_specific_baits_plus_missed6a {}.fasta >/dev/null 2>&1
echo "$SPLIT_AA_CIRC" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t hmmscan --tblout {}.AA.hmmscan_replicate.out --cpu 1 -E 1e-15 --noali ${CENOTE_DBS}/hmmscan_DBs/virus_replication_clusters3 {}.fasta >/dev/null 2>&1
elif [[ $virus_domain_db = "virion" ]]; then
echo "$SPLIT_AA_CIRC" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t hmmscan --tblout {}.AA.hmmscan.out --cpu 1 -E 1e-8 --noali ${CENOTE_DBS}/hmmscan_DBs/virus_specific_baits_plus_missed6a {}.fasta >/dev/null 2>&1
elif [[ $virus_domain_db = "rna_virus" ]]; then
echo "$SPLIT_AA_CIRC" | sed 's/.fasta//g' | xargs -n 1 -I {} -P $CPU -t hmmscan --tblout {}.AA.hmmscan.out --cpu 1 -E 1e-8 --noali ${CENOTE_DBS}/hmmscan_DBs/rna_virus_rdrp_capsid_hmms1 {}.fasta >/dev/null 2>&1
else
echo "$(tput setaf 5) Incorrect argument given for virus_domain_db variable. Try standard, virion, or rna_virus as arguments. For this run, no contigs with viral domains but without circularity or ITRs will be detected $(tput sgr 0)"
rm -f ./*{0..9}.fasta
break
fi
HMM_REP_NUMEBR=$( find . -maxdepth 1 -type f -name "SPLIT_ITR_AA_*AA.hmmscan_replicate.out" | wc -l )
if [[ $FOR_PLASMIDS = "True" ]]; then
if [ $HMM_REP_NUMEBR -gt 0 ] ; then
cat SPLIT_ITR_AA_*AA.hmmscan.out SPLIT_ITR_AA_*AA.hmmscan_replicate.out | grep -v "^#\|plasmid_clust" | sed 's/ \+/ /g' | sort -u -k3,3 > ITR_GENOME_COMBINED.AA.hmmscan.sort.out
else
cat SPLIT_ITR_AA_*AA.hmmscan.out | grep -v "^#\|plasmid_clust" | sed 's/ \+/ /g' | sort -u -k3,3 > ITR_GENOME_COMBINED.AA.hmmscan.sort.out
fi
else
if [ $HMM_REP_NUMEBR -gt 0 ] ; then
cat SPLIT_ITR_AA_*AA.hmmscan.out SPLIT_ITR_AA_*AA.hmmscan_replicate.out | grep -v "^#" | sed 's/ \+/ /g' | sort -u -k3,3 > ITR_GENOME_COMBINED.AA.hmmscan.sort.out
else
cat SPLIT_ITR_AA_*AA.hmmscan.out | grep -v "^#" | sed 's/ \+/ /g' | sort -u -k3,3 > ITR_GENOME_COMBINED.AA.hmmscan.sort.out
fi
fi
if [ -e ITR_GENOME_COMBINED.AA.hmmscan.sort.out ] ; then
cut -f3 ITR_GENOME_COMBINED.AA.hmmscan.sort.out | sed 's/[^_]*$//' | sed 's/\(.*\)_/\1/' | sort -u | while read HIT ; do
HALL_COUNT=$( grep "${HIT}_" ITR_GENOME_COMBINED.AA.hmmscan.sort.out | wc -l | bc )
if [ $HALL_COUNT -ge $CIRC_MINIMUM_DOMAINS ] ; then
mv ${HIT}.fasta ${HIT}.fna
grep "${HIT}_" ITR_GENOME_COMBINED.AA.hmmscan.sort.out > ${HIT}.AA.hmmscan.sort.out
grep "${HIT}_" ITR_GENOME_COMBINED.AA.hmmscan.sort.out | sort -u -k3,3 | cut -f3 | sed 's/\(.*\)/\1 /' > ${HIT}.AA.called_hmmscan.txt
grep -v -f ${HIT}.AA.called_hmmscan.txt ${HIT}.AA.sorted.fasta | grep -A1 ">" | sed '/--/d' > ${HIT}.AA.no_hmmscan1.fasta
rm ${HIT}.AA.fasta
elif [ -s ${HIT}.fasta ] ; then
sed 's/ /#/g' ${HIT}.fasta | bioawk -c fastx '{print ">"$name"#ITRs" ; print $seq}' | sed 's/#/ /g' >> ../other_contigs/non_viral_domains_contigs.fna
rm -f ${HIT}.fasta
fi
done
fi
else
echo "no AA seqs found in ITR contigs, discover viruses module"
fi
for REMAINDER in $ITR_SEQS ; do
if [ -s $REMAINDER ] ; then
if [ "$ANNOTATION_MODE" == "True" ] ; then
mv $REMAINDER ${REMAINDER%.fasta}.fna
else
sed 's/ /#/g' $REMAINDER | bioawk -c fastx '{print ">"$name"#ITRs" ; print $seq}' | sed 's/#/ /g' >> ../other_contigs/non_viral_domains_contigs.fna
rm -f $REMAINDER
fi
fi
done
fi
cd ${base_directory}/${run_title}
if [ -s all_circular_genome_proteins.AA.fasta ] ; then
mv all_circular_genome_proteins.AA.fasta DTR_contigs_with_viral_domain/
fi
if [ -s CIRCULAR_GENOME_COMBINED.AA.hmmscan.sort.out ] ; then
mv CIRCULAR_GENOME_COMBINED.AA.hmmscan.sort.out DTR_contigs_with_viral_domain/
fi
# script for pruning no_end contigs with viral domains
LIST_OF_VIRAL_DOMAIN_CONTIGS=$( find * -maxdepth 1 -type f -wholename "no_end_contigs_with_viral_domain/*fna" )
if [ ! -z "$LIST_OF_VIRAL_DOMAIN_CONTIGS" ] && [ "$PROPHAGE" == "True" ] ;then
echo "$(tput setaf 3) Starting pruning of non-DTR/circular contigs with viral domains $(tput sgr 0)"
. ${CENOTE_SCRIPT_DIR}/prune_linear_contigs_0.1.sh
fi
cd ${base_directory}/${run_title}
if [ -d DTR_contigs_with_viral_domain ] ; then
cd DTR_contigs_with_viral_domain
fi
#-# rotate DTRs
rm -f *no_hmmscan1.fasta
CIRCULAR_HALLMARK_CONTIGS=$( find . -maxdepth 1 -type f -name "*fna" )
if [ -n "$CIRCULAR_HALLMARK_CONTIGS" ] ; then
if [ "$WRAP" == "True" ] ; then
MDYT=$( date +"%m-%d-%y---%T" )
echo "Annotating DTR contigs " $MDYT
echo "rotating DTR contigs"
rm *DTR.tbl
for nucl_fa in $CIRCULAR_HALLMARK_CONTIGS ; do
prodigal -a ${nucl_fa%.fna}.AA.fasta -i $nucl_fa -c -p meta -q >/dev/null 2>&1
FWD_GENES=$( grep "^>" ${nucl_fa%.fna}.AA.fasta | sed 's/ # / /g' | awk '{FS=OFS="\t"}{if ($0 ~ "partial=00;start_type" && $4 == 1) {print $4}}' | wc -l )
REV_GENES=$( grep "^>" ${nucl_fa%.fna}.AA.fasta | sed 's/ # / /g' | awk '{FS=OFS="\t"}{if ($0 ~ "partial=00;start_type" && $4 == -1) {print $4}}' | wc -l )
if [ $FWD_GENES -ge $REV_GENES ] && [ $FWD_GENES -ge 1 ]; then
START_BASE=$( grep "^>" ${nucl_fa%.fna}.AA.fasta | sed 's/ # / /g' | awk '{FS=OFS="\t"}{if ($0 ~ "partial=00;start_type" && $4 == 1) {print $2, ($3-$2)}}' | sort -rg -k2,2 | head -n1 | cut -f1 )
cat $nucl_fa | seqkit restart -i ${START_BASE} > ${nucl_fa%.fna}.rotate.fasta
elif [ $REV_GENES -ge 1 ]; then
seqkit seq $nucl_fa --quiet -t DNA -r -p > ${nucl_fa%.fna}.rc.fna
prodigal -a ${nucl_fa%.fna}.AA.rc.fasta -i ${nucl_fa%.fna}.rc.fna -p meta -q >/dev/null 2>&1
RC_FWD_GENES=$( grep "^>" ${nucl_fa%.fna}.AA.rc.fasta | sed 's/ # / /g' | awk '{FS=OFS="\t"}{if ($0 ~ "partial=00;start_type" && $4 == 1) {print $4}}' | wc -l )
if [ $RC_FWD_GENES -ge 1 ] ; then
START_BASE=$( grep "^>" ${nucl_fa%.fna}.AA.rc.fasta | sed 's/ # / /g' | awk '{FS=OFS="\t"}{if ($0 ~ "partial=00;start_type" && $4 == 1) {print $2, ($3-$2)}}' | sort -rg -k2,2 | head -n1 | cut -f1 )
cat ${nucl_fa%.fna}.rc.fna | seqkit restart -i ${START_BASE} > ${nucl_fa%.fna}.rotate.fasta
else
echo "Can't find suitable ORF to set rotation of $nucl_fa and will remain unrotated"
cp $nucl_fa ${nucl_fa%.fna}.rotate.fasta
fi
else
echo "Can't find suitable ORF to set rotation of $nucl_fa and will remain unrotated"
cp $nucl_fa ${nucl_fa%.fna}.rotate.fasta
fi
done
else
echo "Annotating DTR contigs"
echo "contigs will not be wrapped: --wrap False"
echo "(rotate.fasta) files will be created for processing purposes (but these are not wrapped)"
for nucl_fa in $CIRCULAR_HALLMARK_CONTIGS ; do
cp $nucl_fa ${nucl_fa%.fna}.rotate.fasta
done
fi
fi
#-# blastx for translation decision
ROTATED_DTR_CONTIGS=$( find . -maxdepth 1 -type f -regextype sed -regex "./${run_title}[0-9]\{1,6\}.rotate.fasta" | sed 's/\.\///g' )
if [ -n "$ROTATED_DTR_CONTIGS" ] ; then
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: running BLASTX, DTR contigs " $MDYT
echo "$ROTATED_DTR_CONTIGS" | sed 's/.rotate.fasta//g' | xargs -n 1 -I {} -P $CPU -t blastx -evalue 1e-4 -outfmt "6 qseqid stitle pident evalue length" -threshold 21 -word_size 5 -num_threads 1 -num_alignments 1 -db ${CENOTE_DBS}/blast_DBs/virus_refseq_adinto_polinto_clean_plasmid_prot_190925 -query {}.rotate.fasta -out {}.tax_guide.blastx.out >/dev/null 2>&1
echo "$ROTATED_DTR_CONTIGS" | sed 's/.rotate.fasta/.fasta/g' | while read nucl_fa ; do
#-#-# Reworking taxonomy
if [ ! -s "${nucl_fa%.fasta}.tax_guide.blastx.out" ]; then
echo "No homologues found" > ${nucl_fa%.fasta}.tax_guide.blastx.out ;
elif grep -q "virophage" ${nucl_fa%.fasta}.tax_guide.blastx.out ; then
echo "Virophage Unclassified Taxon" >> ${nucl_fa%.fasta}.tax_guide.blastx.out
elif grep -q "adinto" ${nucl_fa%.fasta}.tax_guide.blastx.out ; then
echo "Adintovirus Unclassified Taxon" >> ${nucl_fa%.fasta}.tax_guide.blastx.out
elif grep -i -q "polinton" ${nucl_fa%.fasta}.tax_guide.blastx.out ; then
echo "Polinton-like virus Unclassified Taxon" >> ${nucl_fa%.fasta}.tax_guide.blastx.out
else
ORGANISM_H=$( head -n1 ${nucl_fa%.fasta}.tax_guide.blastx.out | sed 's/\[/&\n/;s/.*\n//;s/\]/\n&/;s/\n.*//' )
if grep -q " | ${ORGANISM_H} | " ${CENOTE_DBS}/taxdump/names.dmp ; then
taxid=$( grep " | ${ORGANISM_H} | " ${CENOTE_DBS}/taxdump/names.dmp | head -n1 | cut -f1 )
echo "taxid: "$taxid >> ${nucl_fa%.fasta}.tax_guide.blastx.out
efetch -db taxonomy -id $taxid -format xml | xtract -pattern Taxon -block "*/Taxon" -tab "\n" -element TaxId,ScientificName,Rank >> ${nucl_fa%.fasta}.tax_guide.blastx.out
sleep 0.4s
fi
fi
if [ ! -s ${nucl_fa%.fasta}.tax_guide.blastx.out ] ; then
echo "No homologues found" > ${nucl_fa%.fasta}.tax_guide.blastx.out
fi
if grep -i -q "Caudovir\|Ackermannvir\|Herellevir\|Corticovir\|Levivir\|Tectivir\|crAss-like virus\|CrAssphage\|crassvirales\|Cyanophage\|Microvir\microphage\|Siphoviridae\|Myoviridae\|phage\|Podovir\|Halovir\|sphaerolipovir\|pleolipovir\|plasmid\|Inovir\|Ampullavir\|Bicaudavir\|Fusellovir\|Guttavir\|Ligamenvir\|Plasmavir\|Salterprovir\|Cystovir" ${nucl_fa%.fasta}.tax_guide.blastx.out ; then
echo ${nucl_fa%.fasta}.rotate.fasta >> DTR_seqs_for_phanotate.txt
else
echo ${nucl_fa%.fasta}.rotate.fasta >> DTR_seqs_for_prodigal.txt
fi
done
if [ -s DTR_seqs_for_phanotate.txt ] ; then
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: running PHANOTATE, annotate DTR contigs " $MDYT
cat DTR_seqs_for_phanotate.txt | sed 's/.rotate.fasta//g' | xargs -n 1 -I {} -P $CPU phanotate.py -f fasta -o {}.rotate.phan.fasta {}.rotate.fasta
for PHAN in *.phan.fasta ; do
if [ "$ENFORCE_START_CODON" == "True" ] ; then
sed 's/ /@/g' ${PHAN} | bioawk -c fastx '{ print }' | awk '{ if ($2 ~ /^[ATCG]TG/) { print ">"$1 ; print $2 }}' | sed 's/@/ /g' > ${PHAN%.fasta}.sort.fasta
else
sed 's/ /@/g' ${PHAN} | bioawk -c fastx '{ print }' | awk '{ print ">"$1 ; print $2 }' | sed 's/@/ /g' > ${PHAN%.fasta}.sort.fasta
fi
done
PHANQ=$( find . -maxdepth 1 -type f -regextype sed -regex ".*phan.sort.fasta" )
echo "$PHANQ" | sed 's/\.phan\.sort\.fasta//g' | xargs -n 1 -I {} -P $CPU seqkit translate -x -T 11 {}.phan.sort.fasta -o {}.trans.fasta >/dev/null 2>&1
for PHAN in *.phan.fasta ; do
ORIG_CONTIG=$( grep ">" ${PHAN%.rotate.phan.fasta}.fna | cut -d " " -f2 ) ;
sed 's/\[START=//g ; s/\]//g ; s/ \[SCORE=.*//g' ${PHAN%.phan.fasta}.trans.fasta | bioawk -v OC="$ORIG_CONTIG" -c fastx '{ split($1, start, "[. ]") ; split(start[2], sq, "[_]") ; if (substr($seq, 1, 1) == "M" || $4 > 3) {FIVE=""} else {FIVE="5primeInc"} ; if (substr($seq, length($seq), 1) == "*") {THREE=""} else {THREE="3primeInc"}; print ">" start[1]"_"NR " ["$4" - "sq[1]"] "FIVE THREE" "OC ; print $seq }' > ${PHAN%.phan.fasta}.AA.fasta
done
fi
if [ -s DTR_seqs_for_prodigal.txt ] ; then
MDYT=$( date +"%m-%d-%y---%T" )
echo "time update: running prodigal, annotate DTR contigs " $MDYT
cat DTR_seqs_for_prodigal.txt | sed 's/.rotate.fasta//g' | xargs -n 1 -I {} -P $CPU prodigal -a {}.rotate.prodigal.fasta -i {}.rotate.fasta -p meta -q >/dev/null 2>&1
for PROD in *rotate.prodigal.fasta ; do
sed 's/ /@/g' ${PROD} | bioawk -c fastx '{print}' | while read LINE ; do
ORIENTATION=$( echo "$LINE" | cut -d "#" -f 4 | sed 's/@//g' ) ;
if [[ "$ORIENTATION" == 1 ]] ; then
START_BASE=$( echo "$LINE" | cut -d "#" -f 2 | sed 's/@//g' ) ;
END_BASE=$( echo "$LINE" | cut -d "#" -f 3 | sed 's/@//g' ) ;
else
START_BASE=$( echo "$LINE" | cut -d "#" -f 3 | sed 's/@//g' ) ;
END_BASE=$( echo "$LINE" | cut -d "#" -f 2 | sed 's/@//g' ) ;
fi
ORF_NAME=$( echo "$LINE" | cut -d "#" -f 1 | sed 's/@//g; s/\./_/g' ) ;
ORIG_CONTIG=$( grep ">" ${PROD%.prodigal.fasta}.fasta | cut -d " " -f2 ) ;
AA_SEQ=$( echo "$LINE" | cut -f2 ) ;
if echo $AA_SEQ | grep -q "\*" ; then
INC3=""
else
INC3="3primeInc"
fi
FAA=${AA_SEQ:0:1}
if [ "$FAA" != "M" ] && [ $START_BASE -le 3 ] ; then
INC5="5primeInc"
else
INC5=""
fi
echo ">"${ORF_NAME} "["$START_BASE" - "$END_BASE"]" ${INC5}${INC3} $ORIG_CONTIG ; echo $AA_SEQ ;
done > ${PROD%.prodigal.fasta}.AA.fasta
done
fi
ROTATE_AAs=$( find . -maxdepth 1 -type f -name "${run_title}*rotate.AA.fasta" | sed 's/\.\///g' )
if [ -n "$ROTATE_AAs" ] ; then
for ROT in $ROTATE_AAs ; do
bioawk -c fastx '{FS="\t"; OFS=" "} {print ">"$name $3, $4, $5, $6, $7; print $seq}' $ROT > ${ROT%.fasta}.sorted.fasta
done
fi
fi
#-# 4 hhmscan circles/DTRs
ROTATE_SORT_AAs=$( find . -maxdepth 1 -type f -name "${run_title}*rotate.AA.sorted.fasta" | sed 's/\.\///g' )
if [ -n "$ROTATE_SORT_AAs" ] ; then
#cat $( find . -maxdepth 1 -type f -name "${run_title}*rotate.AA.sorted.fasta" ) > all_DTR_sort_genome_proteins.AA.fasta
for ROTQ in $ROTATE_SORT_AAs ; do
cat $ROTQ
done > all_DTR_sort_genome_proteins.AA.fasta
TOTAL_AA_SEQS=$( grep -F ">" all_DTR_sort_genome_proteins.AA.fasta | wc -l | bc )
if [ $TOTAL_AA_SEQS -ge 1 ] ; then
AA_SEQS_PER_FILE=$( echo "scale=0 ; $TOTAL_AA_SEQS / $CPU" | bc )
if [ $AA_SEQS_PER_FILE = 0 ] ; then
AA_SEQS_PER_FILE=1
fi
awk -v seq_per_file="$AA_SEQS_PER_FILE" 'BEGIN {n_seq=0;} /^>/ {if(n_seq%seq_per_file==0){file=sprintf("SPLIT_DTR_sort_GENOME_AA_%d.fasta",n_seq);} print >> file; n_seq++; next;} { print >> file; }' < all_DTR_sort_genome_proteins.AA.fasta
SPLIT_AA_DTR_sort=$( find . -maxdepth 1 -type f -name "SPLIT_DTR_sort_GENOME_AA_*.fasta" )
MDYT=$( date +"%m-%d-%y---%T" )