Repository navigation
Expand file tree
/
Copy pathcomets
More file actions
726 lines (706 loc) · 24.1 KB
/
Copy pathcomets
File metadata and controls
726 lines (706 loc) · 24.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
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
#!/bin/bash
############################################################################### USAGE ###############################################################################
usage () {
echo
echo "COMETS (COmpare METagenomeS)"
echo
echo "Usage:"
echo " comets -p pe|se|pe_se -f auto|<path_to_fastp> -k auto|<path_to_kaiju-multi> [-z <int>] [-d <path_to_kaiju_db>] [-K <path_to_kaiju2table>] [-n <path_to_nodes.dmp>] [-N <path_to_names.dmp>] -t -g All|Prokaryotes|Bacteria|Archaea|Eukaryota|Viruses -r"
echo
echo "Example:"
echo " comets -p pe -f auto -k auto -z 25 -t -g All -r"
echo
echo "The above example will run COMETS with paired-end reads, starting with fastp quality filter (will automatically find the path to fastp), followed by kaiju taxonomic assignment (will automatically find the"
echo "path to kaiju-multi, kaiju2table, nodes.dmp and names.dmp) using 25 threads and the default kaiju database (kaiju_db_nr_euk.fmi), the creation of phyloseq tables for all taxonomic groups and the creation of R plots"
echo
echo "Options:"
echo " -h: help message"
echo " -p: paired-end (pe), single-end (se), or both (pe_se). Always needed"
echo " -f: path to fastp (if "auto", will automatically look for fastp in ~/, which may take a while. If option is not provided, will not run fastp quality filter)"
echo " -k: path to kaiju-multi (if "auto", will automatically look for kaiju-multi, kaiju2table, nodes.dmp and names.dmp in ~/, which may take a while."
echo " If path provided, will also need to provide -K, -n, and -N. If option is not provided, will not run kaiju taxonomic assignment)"
echo " -z: number of threads to use for kaiju taxonomic assignment (recomendation is 25 if server has enough cores. If option is not provided will use default: 1)"
echo " -d: path to kaiju database (if option is not provided will automatically look for kaiju_db_nr_euk.fmi in ~/, which may take a while. Please note that a minimum of approximately 130Gb of memory is required to run against the nr_euk database)"
echo " -K: path to kaiju2table (needed if -k path is provided)"
echo " -n: path to nodes.dmp (needed if -k path is provided)"
echo " -N: path to names.dmp (needed if -k path is provided)"
echo " -t: create phyloseq tables (no arguments needed. If provided, will also need to provide -g. If option is not provided, will not create phyloseq tables)"
echo " -g: taxonomic group to create phyloseq tables for (Options are All, Prokaryotes, Bacteria, Archaea, Eukaryota, Viruses. Needed if -t or -r is provided)"
echo " -r: create R plots (no arguments needed. If provided, will also need to provide -g. If option is not provided, will not create R plots)"
}
############################################################################## OPTIONS ##############################################################################
if [[ $# -eq 0 ]] ; then
echo "ERROR: no arguments provided"
usage
exit 0
fi
while getopts "hp:f:k:z:d:K:n:N:tg:r" opt; do
case $opt in
h)
echo "Help message"
usage
exit 0
;;
p)
echo "p: $OPTARG"
if [[ $OPTARG = "pe" ]] || [[ $OPTARG = "se" ]] || [[ $OPTARG = "pe_se" ]]; then
p=$OPTARG
echo "$p is a valid option for -p"
else
echo "ERROR: invalid option for -p. Valid options are pe, se, or pe_se"
usage
exit 0
fi
;;
f)
echo "f: $OPTARG"
if [[ -z ${p+x} ]]; then
echo "ERROR: -f needs -p to be set to pe or se or pe_se"
usage
exit 1
else
fastp=$OPTARG
if [[ "$fastp" = "auto" ]]; then
echo "Looking for fastp in ~/..."
if [[ $(find ~/ -name fastp | grep -w bin | head -n1) ]]; then
fastp=$(find ~/ -name fastp | grep -w bin | head -n1)
echo "fastp found! Location: $fastp"
else
echo "ERROR: unable to find required package fastp. The latest version may be needed: wget http://opengene.org/fastp/fastp"
exit 1
fi
else
echo "User-provided fastp path: $fastp"
fi
fi
;;
k)
echo "k: $OPTARG"
if [[ -z ${p+x} ]]; then
echo "ERROR: -k needs -p to be set to pe or se or pe_se"
usage
exit 1
else
kaiju=$OPTARG
if [[ "$kaiju" = "auto" ]]; then
echo "Looking for kaiju-multi in ~/..."
if [[ $(find ~/ -name kaiju-multi | grep -w bin | head -n1) ]]; then
kaiju=$(find ~/ -name kaiju-multi | grep -w bin | head -n1)
echo "kaiju found! Location: $kaiju"
else
echo "ERROR: unable to find required package kaiju-multi"
exit 1
fi
echo "kaiju also requires a nodes.dmp file. Looking for it..."
if [[ $(find ~/ -name nodes.dmp | head -n1) ]]; then
nodes=$(find ~/ -name nodes.dmp | head -n1)
echo "nodes.dmp found! Location: $nodes"
else
echo "ERROR: unable to find nodes.dmp"
exit 1
fi
echo "Making sure kaiju2table is installed..."
if [[ $(find ~/ -name kaiju2table | grep -w bin | head -n1) ]]; then
kaiju2table=$(find ~/ -name kaiju2table | grep -w bin | head -n1)
echo "kaiju2table found! Location: $kaiju2table"
else
echo "ERROR: unable to find required package kaiju2table"
exit 1
fi
echo "kaiju2table requires a names.dmp file. Looking for it..."
if [[ $(find ~/ -name names.dmp | head -n1) ]]; then
names=$(find ~/ -name names.dmp | head -n1)
echo "names.dmp found! Location: $names"
else
echo "ERROR: unable to find names.dmp"
exit 1
fi
else
echo "User-provided kaiju path: $kaiju"
fi
fi
;;
z)
echo "z: $OPTARG"
z=$OPTARG
if $(echo "$z" | grep -vqE '^[0-9]+$'); then
echo "ERROR: '$z' is not a valid option for -z. Must be integer"
usage
exit 1
else
echo "$z parallel threads will be used for kaiju taxonomic assignment"
fi
;;
d)
echo "d: $OPTARG"
kaiju_db=$OPTARG
echo "kaiju database is set to: $kaiju_db"
;;
K)
echo "K: $OPTARG"
kaiju2table=$OPTARG
echo "User-provided kaiju2table path: $kaiju2table"
;;
n)
echo "n: $OPTARG"
nodes=$OPTARG
echo "User-provided nodes.dmp path: $nodes"
;;
N)
echo "N: $OPTARG"
names=$OPTARG
echo "User-provided names.dmp path: $names"
;;
t)
t=true
echo "t: phyloseq tables activated"
;;
g)
echo "g: $OPTARG"
group=$OPTARG
if [[ "$group" = "All" ]] || [[ "$group" = "Prokaryotes" ]] || [[ "$group" = "Bacteria" ]] || [[ "$group" = "Archaea" ]] || [[ "$group" = "Eukaryota" ]] || [[ "$group" = "Viruses" ]]; then
echo "$group is a valid option for -g"
else
echo "ERROR: '$group' is not a valid option for -g"
usage
exit 1
fi
;;
r)
r=true
echo "r: R plots activated"
if [[ $(find ~/ -name comets_plots.R | head -n1) ]]; then
comets_plots=$(find ~/ -name comets_plots.R | head -n1)
echo "comets_plots.R found! Location: $comets_plots"
else
echo "ERROR: unable to find comets_plots.R"
exit 1
fi
;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage
exit 0
;;
:)
echo "Option -$OPTARG requires an argument." >&2
usage
exit 0
;;
esac
done
if [[ -z ${kaiju+x} ]]; then
:
else
if [[ -z ${z+x} ]]; then
echo "-z is unset. Will use default=1"
z=1
fi
if [[ -z ${kaiju_db+x} ]]; then
echo "-d is unset. Will use default=kaiju_db_nr_euk.fmi"
echo "looking for kaiju_db_nr_euk.fmi..."
if [[ $(find ~/ -name kaiju_db_nr_euk.fmi | head -n1) ]]; then
kaiju_db=$(find ~/ -name kaiju_db_nr_euk.fmi | head -n1)
echo "kaiju_db_nr_euk.fmi found! Location: $kaiju_db"
else
echo "ERROR: unable to find kaiju_db_nr_euk.fmi"
exit 1
fi
fi
if [[ -z ${kaiju2table+x} ]]; then
echo "-K is unset. If manually providing kaiju path, user must also provide kaiju2table path with -K. Alternatively use -k auto"
usage
exit 1
fi
if [[ -z ${nodes+x} ]]; then
echo "-n is unset. If manually providing kaiju path, user must also provide nodes.dmp path with -n. Alternatively use -k auto"
usage
exit 1
fi
if [[ -z ${names+x} ]]; then
echo "-N is unset. If manually providing kaiju path, user must also provide names.dmp path with -N. Alternatively use -k auto"
usage
exit 1
fi
fi
if [[ -z ${t+x} ]]; then
:
else
if [[ -z ${group+x} ]]; then
echo "ERROR: -t is set but -g is not set. -g must be set to All, Prokaryotes, Bacteria, Archaea, Eukaryota or Viruses if -t is set"
usage
exit 1
fi
fi
############################################################################# FUNCTIONS #############################################################################
fastp_pe () {
cd $main_dir
mkdir fastp
fastp_dir=fastp
for i in $(ls *_1.fastq.gz | sort); do
echo "Running quality filter for $i and "${i%1.fastq.gz}2.fastq.gz". Sequences are deduplicated"
$fastp -i $i -I "${i%1.fastq.gz}2.fastq.gz" -o $fastp_dir/"${i%.fastq.gz}.fastp.fastq.gz" -O $fastp_dir/"${i%1.fastq.gz}2.fastp.fastq.gz" -j $fastp_dir/"${i%_1.fastq.gz}.fastp.json" -h $fastp_dir/"${i%_1.fastq.gz}.fastp.html" -D -V 2> $fastp_dir/"${i%_1.fastq.gz}.fastp.out"
echo Done processing $i and "${i%1.fastq.gz}2.fastq.gz". Quality filtered files are: $main_dir/$fastp_dir/"${i%.fastq.gz}.fastp.fastq.gz" and $main_dir/$fastp_dir/"${i%1.fastq.gz}2.fastp.fastq.gz"
done
}
kaiju_pe () {
cd fastp
mkdir kaiju
kaiju_dir=kaiju
echo "Making sure read names are in the correct format"
for i in $(ls *.fastq.gz | sort); do
mv $i $i'_original'
done
for i in $(ls *_original | sort); do
pigz -c -d $i | sed 's/\.1 / 1 /g' | sed 's/\.2 / 2 /' | pigz > "${i%_original}"
done
rm *_original
echo "Done"
in_1=$(ls *1.fastp.fastq.gz | sort | tr -s '\n' ',')
in_2=$(ls *2.fastp.fastq.gz | sort | tr -s '\n' ',')
out=$(ls *1.fastp.fastq.gz | sort | sed 's/_1\.fastp\.fastq\.gz/\.kaiju\.out/g' | tr -s '\n' ',')
echo "Running taxonomic classification for $in_1 and $in_2"
$kaiju -z $z -t $nodes -f $kaiju_db -i $in_1 -j $in_2 -o $out -v 2> $kaiju_dir/kaiju.err
mv *.kaiju.out $kaiju_dir
echo "Done processing $in_1 and $in_2"
echo "Kaiju output files within $kaiju_dir directory are: $out"
}
fastp_se () {
cd $main_dir
mkdir fastp
fastp_dir=fastp
for i in $(ls *.fastq.gz | sort); do
echo "Running quality filter for $i. Sequences are deduplicated"
$fastp -i $i -o $fastp_dir/"${i%.fastq.gz}.fastp.fastq.gz" -j $fastp_dir/"${i%.fastq.gz}.fastp.json" -h $fastp_dir/"${i%.fastq.gz}.fastp.html" -D -V 2> $fastp_dir/"${i%.fastq.gz}.fastp.out"
echo Done processing $i. Quality filtered file is: $main_dir/$fastp_dir/"${i%.fastq.gz}.fastp.fastq.gz"
done
}
kaiju_se () {
cd fastp
mkdir kaiju
kaiju_dir=kaiju
input=$(ls *.fastp.fastq.gz | sort | tr -s '\n' ',')
out=$(ls *.fastp.fastq.gz | sort | sed 's/\.fastp\.fastq\.gz/\.kaiju\.out/g' | tr -s '\n' ',')
echo "Running taxonomic classification for $input"
$kaiju -z $z -t $nodes -f $kaiju_db -i $input -o $out -v 2> $kaiju_dir/kaiju.err
mv *.kaiju.out $kaiju_dir
echo "Done processing $input"
echo "Kaiju output files within $kaiju_dir directory are: $out"
}
kaiju2table () {
cd kaiju
if [[ -d ../../../kaiju2table ]]; then
echo "Using already existing directory: kaiju2table"
else
mkdir ../../../kaiju2table
fi
kaiju2table_dir=../../../kaiju2table
for i in $(ls *.out | sort); do
echo "Creating classification summary for $i"
$kaiju2table -t $nodes -n $names -e -r species -l superkingdom,phylum,class,order,family,genus,species -v -o $kaiju2table_dir/"${i%.out}.tsv" $i 2> $kaiju2table_dir/"${i%.out}.err"
echo Done processing $i. Classification summary file is $kaiju2table_dir/"${i%.out}.tsv"
done
}
phyloseq_tables () {
if [[ -d phyloseq_tables ]]; then
if [[ -f phyloseq_tables/SAM.table ]]; then
if [[ -f phyloseq_tables/"$group"_OTU.table && -f phyloseq_tables/"$group"_TAX.table ]]; then
echo "phyloseq tables already exist. Skipping to plot generation"
cd phyloseq_tables
else
echo "Starting $group phyloseq OTU and TAX tables building"
if [[ $(ls kaiju2table/*.tsv) ]]; then
echo "kaiju2table output files.kaiju.tsv detected:"
cd kaiju2table
ls *.tsv
if [[ $(grep ';' *.tsv) ]]; then
echo "Modifying .tsv ';' delimiters to tab"
sed -i 's/;/ /g' *.tsv
else
echo ".tsv files already tab delimited"
fi
echo "Creating kaiju2table/$group/ directory"
mkdir $group
if [[ ! -f unclassified.txt ]]; then
echo "Extracting unclassified reads to kaiju2table/unclassified.txt"
grep -v -E 'Bacteria|Archaea|Eukaryota|Viruses' *.tsv > unclassified.txt
else
echo "kaiju2table/unclassified.txt file already created"
fi
echo "Extracting $group data from tables"
if [[ "$group" = "All" ]]; then
for i in $(ls *.tsv); do
grep -E 'Bacteria|Archaea|Eukaryota|Viruses' $i > $group/"${i%.kaiju.tsv}_$group.tsv"
echo done extracting $group data from $i. Data written to: $group/"${i%.kaiju.tsv}_$group.tsv"
done
elif [[ "$group" = "Prokaryotes" ]]; then
for i in $(ls *.tsv); do
grep -E 'Bacteria|Archaea' $i > $group/"${i%.kaiju.tsv}_$group.tsv"
echo done extracting $group data from $i. Data written to: $group/"${i%.kaiju.tsv}_$group.tsv"
done
else
for i in $(ls *.tsv); do
grep $group $i > $group/"${i%.kaiju.tsv}_$group.tsv"
echo done extracting $group data from $i. Data written to: $group/"${i%.kaiju.tsv}_$group.tsv"
done
fi
cd $group
cat *.tsv | cut -f 4,5,6,7,8,9,10,11 | sort -u | sed 's/^/ /' > taxonomy.ref
echo "Creating $group OTU table"
echo "Getting list of all tax_ids"
cat *.tsv | cut -f 4 | sort -u > all_tax_ids.tmp
for i in $(ls *.tsv); do
echo "Getting read counts for $i"
cat all_tax_ids.tmp | while read line; do
if [[ $(awk -v awkvar="$line" -F '\t' '{if ($4 == awkvar) print $0;}' $i) ]]; then
awk -v awkvar="$line" -F '\t' '{if ($4 == awkvar) print $0;}' $i | awk -F '\t' '{sum += $3} END {print sum}'
else
echo "0"
fi
done > "${i%.tsv}.counts"
done
paste all_tax_ids.tmp *.counts > counts.temp
header=$(cat *.tsv | cut -f1 | sort -u | sed 's/\.kaiju\.out/\.kaiju\.tsv/' | grep -v 'file')
echo $header | sed '1s/^/otu /' | sed 's/ */ /g' > header.temp
cat header.temp counts.temp > "$group"_OTU.table
echo "Done creating $group OTU table"
echo "Creating $group TAX table"
cat all_tax_ids.tmp | while read line; do
awk -v awkvar="$line" -F '\t' '{if ($4 == awkvar) print $4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9"\t"$10"\t"$11}' taxonomy.ref
done > tax.temp
header=$(echo otu Superkingdom Phylum Class Order Family Genus Species)
echo $header | sed 's/ */ /g' > tax_header.tmp
cat tax_header.tmp tax.temp > "$group"_TAX.table
echo "Done creating $group TAX table"
mv *.table ../../phyloseq_tables
echo "$group OTU table written to phyloseq_tables/"$group"_OTU.table"
echo "$group TAX table written to phyloseq_tables/"$group"_TAX.table"
echo "Done creating $group phyloseq tables"
rm *.temp *.tmp *.counts *.ref
cd ../../phyloseq_tables
else
echo "ERROR: unable to find kaiju2table output files.kaiju.tsv. Expecting (example): kaiju2table/sample1.kaiju.tsv, kaiju2table/sample2.kaiju.tsv"
exit 1
fi
fi
else
echo "ERROR: phyloseq_tables/SAM.table file does not exist. It must be a tab separated metadata table to be loaded by phyloseq. Samples must be listed in alphabetical order"
exit 1
fi
else
echo "ERROR: phyloseq_tables/ directory does not exist"
exit 1
fi
}
comets_R (){
if [[ -z ${t+x} ]]; then
cd phyloseq_tables
fi
echo "Starting drawing $group plots"
$comets_plots "$group"_OTU.table "$group"_TAX.table SAM.table 2> comets_plots.err
echo "Done drawing $group plots"
}
############################################################################### MAIN ###############################################################################
echo
echo "** START **"
if [[ "$p" = "pe" ]]; then
echo "Running paired end analysis"
if [[ -z ${fastp+x} ]]; then
if [[ -z ${kaiju+x} ]]; then
if [[ -z ${t+x} ]]; then
if [[ -z ${r+x} ]]; then
echo "ERROR: -f, -k, -t, and -r flags not set. At least one of these flags must be set"
exit 1
else
comets_R
fi
else
if [[ $(ls kaiju2table/*.tsv) ]]; then
echo "sample.tsv files detected:"
ls kaiju2table/*.tsv
phyloseq_tables
if [[ -z ${r+x} ]]; then
echo "-r flag not set. Omitting further analyses"
exit 1
else
comets_R
fi
else
echo "ERROR: unable to find kaiju2table/*.tsv files. Expecting (example): kaiju2table/sample1.tsv, kaiju2table/sample2.tsv"
exit 1
fi
fi
else
if [[ $(ls paired_end/fastp/*.fastp.fastq.gz) ]]; then
echo "fastp paired end files detected:"
ls paired_end/fastp/*.fastp.fastq.gz
cd paired_end
kaiju_pe
kaiju2table
cd ../../..
if [[ -z ${t+x} ]]; then
echo "-t flag not set. Omitting further analyses"
exit 1
else
phyloseq_tables
if [[ -z ${r+x} ]]; then
echo "-r flag not set. Omitting further analyses"
exit 1
else
comets_R
fi
fi
else
echo "ERROR: unable to detect fastp paired end files. Expecting (example): paired_end/fastp/sample1_1.fastp.gz and paired_end/fastp/sample1_2.fastp.gz"
exit 1
fi
fi
else
if [[ $(ls *_?.fastq.gz) ]]; then
echo "Paired end files detected:"
ls *_?.fastq.gz
echo "Creating a directory for paired end files:"
mkdir paired_end
main_dir=paired_end/
echo "$main_dir"
echo "Moving paired end files to $main_dir"
mv *_?.fastq.gz $main_dir
fastp_pe
if [[ -z ${kaiju+x} ]]; then
echo "-k flag not set. Omitting further analyses"
exit 1
else
kaiju_pe
kaiju2table
cd ../../..
if [[ -z ${t+x} ]]; then
echo "-t flag not set. Omitting further analyses"
exit 1
else
phyloseq_tables
if [[ -z ${r+x} ]]; then
echo "-r flag not set. Omitting further analyses"
exit 1
else
comets_R
fi
fi
fi
else
echo "ERROR: unable to find paired end files. Must have _1.fastq.gz and _2.fastq.gz extensions"
exit 1
fi
fi
elif [[ "$p" = "se" ]]; then
echo "Running single end analysis"
if [[ -z ${fastp+x} ]]; then
if [[ -z ${kaiju+x} ]]; then
if [[ -z ${t+x} ]]; then
if [[ -z ${r+x} ]]; then
echo "ERROR: -f, -k, -t, and -r flags not set. At least one of these flags must be set"
exit 1
else
comets_R
fi
else
if [[ $(ls kaiju2table/*.tsv) ]]; then
echo "sample.tsv files detected:"
ls kaiju2table/*.tsv
phyloseq_tables
if [[ -z ${r+x} ]]; then
echo "-r flag not set. Omitting further analyses"
exit 1
else
comets_R
fi
else
echo "ERROR: unable to find kaiju2table/*.tsv files. Expecting (example): kaiju2table/sample1.tsv, kaiju2table/sample2.tsv"
exit 1
fi
fi
else
if [[ $(ls single_end/fastp/*.fastp.fastq.gz) ]]; then
echo "fastp single end files detected:"
ls single_end/fastp/*.fastp.fastq.gz
cd single_end
kaiju_se
kaiju2table
cd ../../..
if [[ -z ${t+x} ]]; then
echo "-t flag not set. Omitting further analyses"
exit 1
else
phyloseq_tables
if [[ -z ${r+x} ]]; then
echo "-r flag not set. Omitting further analyses"
exit 1
else
comets_R
fi
fi
else
echo "ERROR: unable to detect fastp single end files. Expecting (example): single_end/fastp/sample1.fastp.gz"
exit 1
fi
fi
else
if [[ $(ls *.fastq.gz | grep -v '_[1-2]\.fastq\.gz') ]]; then
echo "Single end files detected:"
ls *.fastq.gz | grep -v '_[1-2]\.fastq\.gz'
echo "Creating a directory for single end files:"
mkdir single_end
main_dir=single_end
echo "$main_dir/"
echo "Moving single end files to $main_dir/"
for i in $(ls *.fastq.gz | grep -v '_[1-2]\.fastq\.gz'); do
mv $i $main_dir
done
fastp_se
if [[ -z ${kaiju+x} ]]; then
echo "-k flag not set. Omitting further analyses"
exit 1
else
kaiju_se
kaiju2table
cd ../../..
if [[ -z ${t+x} ]]; then
echo "-t flag not set. Omitting further analyses"
exit 1
else
phyloseq_tables
if [[ -z ${r+x} ]]; then
echo "-r flag not set. Omitting further analyses"
exit 1
else
comets_R
fi
fi
fi
else
echo "ERROR: unable to detect single end files. Must NOT have _1 or _2 suffix before .fastq.gz"
exit 1
fi
fi
elif [[ "$p" = "pe_se" ]]; then
echo "Running paired and single end analysis"
if [[ -z ${fastp+x} ]]; then
if [[ -z ${kaiju+x} ]]; then
if [[ -z ${t+x} ]]; then
if [[ -z ${r+x} ]]; then
echo "ERROR: -f, -k, -t, and -r flags not set. At least one of these flags must be set"
exit 1
else
comets_R
fi
else
if [[ $(ls kaiju2table/*.tsv) ]]; then
echo "sample.tsv files detected:"
ls kaiju2table/*.tsv
phyloseq_tables
if [[ -z ${r+x} ]]; then
echo "-r flag not set. Omitting further analyses"
exit 1
else
comets_R
fi
else
echo "ERROR: unable to find kaiju2table/*.tsv files. Expecting (example): kaiju2table/sample1.tsv, kaiju2table/sample2.tsv"
exit 1
fi
fi
else
if [[ $(ls paired_end/fastp/*.fastp.fastq.gz) ]]; then
echo "fastp paired end files detected:"
ls paired_end/fastp/*.fastp.fastq.gz
cd paired_end
kaiju_pe
kaiju2table
cd ../../../
if [[ $(ls single_end/fastp/*.fastp.fastq.gz) ]]; then
echo "fastp single end files detected:"
ls single_end/fastp/*.fastp.fastq.gz
cd single_end
kaiju_se
kaiju2table
cd ../../..
if [[ -z ${t+x} ]]; then
echo "-t flag not set. Omitting further analyses"
exit 1
else
phyloseq_tables
if [[ -z ${r+x} ]]; then
echo "-r flag not set. Omitting further analyses"
exit 1
else
comets_R
fi
fi
else
echo "ERROR: unable to detect fastp single end files. Expecting (example): single_end/fastp/sample1.fastp.gz and single_end/fastp/sample2.fastp.gz"
exit 1
fi
else
echo "ERROR: unable to detect fastp paired end files. Expecting (example): paired_end/fastp/sample1_1.fastp.gz and paired_end/fastp/sample1_2.fastp.gz"
exit 1
fi
fi
else
if [[ $(ls *_?.fastq.gz) ]]; then
echo "Paired end files detected:"
ls *_?.fastq.gz
echo "Creating a directory for paired end files:"
mkdir paired_end
main_dir=paired_end/
echo "$main_dir"
echo "Moving paired end files to $main_dir"
mv *_?.fastq.gz $main_dir
fastp_pe
if [[ -z ${kaiju+x} ]]; then
echo "-k flag not set. Omitting further analyses on paired end files"
else
kaiju_pe
kaiju2table
fi
cd ../../..
if [[ $(ls *.fastq.gz | grep -v '_[1-2]\.fastq\.gz') ]]; then
echo "Single end files detected:"
ls *.fastq.gz | grep -v '_[1-2]\.fastq\.gz'
echo "Creating a directory for single end files:"
mkdir single_end
main_dir=single_end
echo "$main_dir/"
echo "Moving single end files to $main_dir/"
for i in $(ls *.fastq.gz | grep -v '_[1-2]\.fastq\.gz'); do
mv $i $main_dir
done
fastp_se
if [[ -z ${kaiju+x} ]]; then
echo "-k flag not set. Omitting further analyses on single end files"
else
kaiju_se
kaiju2table
cd ../../..
if [[ -z ${t+x} ]]; then
echo "-t flag not set. Omitting further analyses"
exit 1
else
phyloseq_tables
if [[ -z ${r+x} ]]; then
echo "-r flag not set. Omitting further analyses"
exit 1
else
comets_R
fi
fi
fi
else
echo "ERROR: unable to detect single end files. Must NOT have _1 or _2 suffix before .fastq.gz"
exit 1
fi
else
echo "ERROR: unable to find paired end files. Must have _1.fastq.gz and _2.fastq.gz extensions"
exit 1
fi
fi
fi
echo "** END **"