-
Notifications
You must be signed in to change notification settings - Fork 4
/
run_syny.pl
executable file
·2017 lines (1618 loc) · 49.5 KB
/
run_syny.pl
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
#!/usr/bin/env perl
# Pombert lab, 2022
my $name = 'run_syny.pl';
my $version = '0.8';
my $updated = '2024-05-27';
use strict;
use warnings;
use Getopt::Long qw(GetOptions);
use Getopt::ArgvFile home=>1;
use File::Basename;
use Cwd qw(abs_path);
use File::Path qw(make_path);
use threads;
use threads::shared;
###################################################################################################
## Command line options
###################################################################################################
my $usage = <<"EXIT";
NAME ${name}
VERSION ${version}
UPDATED ${updated}
SYNOPSIS Runs the SYNY pipeline
REQS Perl / PerlIO::gzip - https://metacpan.org/pod/PerlIO::gzip
Python3 / matplotlib / seaborn / pandas - https://www.python.org/
Diamond - https://github.com/bbuchfink/diamond
Minimap2 - https://github.com/lh3/minimap2
MashMap3 - https://github.com/marbl/MashMap
Circos - http://circos.ca/
USAGE ${name} \\
-t 16 \\
-a *.gbff \\
-o SYNY \\
-e 1e-10 \\
-g 0 1 5 \\
--circos pair
OPTIONS:
-h (--help) Display all command line options
-t (--threads) Number of threads to use [Default: 16]
-p (--pthreads) Number of graphs to plot in parralel; defaults to --threads if unspecified
-a (--annot) GenBank GBF/GBFF Annotation files (GZIP files are supported)
-o (--outdir) Output directory [Default = SYNY]
-e (--evalue) DIAMOND BLASTP evalue cutoff [Default = 1e-10]
-g (--gaps) Allowable number of gaps between gene pairs [Default = 0]
--minsize Minimum contig size (in bp) [Default: 1]
--include Select contigs with names from input text file(s) (one name per line); i.e. exclude everything else
--ranges Select contigs with subranges from input text file(s): name start end
--exclude Exclude contigs with names matching the regular expression(s); e.g. --exclude '^AUX'
--aligner Specify genome alignment tool: minimap or mashmap [Default: minimap]
--asm Specify minimap max divergence preset (--asm 5, 10 or 20) [Default: off]
--mpid Specify mashmap3 percentage identity [Default: 85]
--resume Resume minimap/mashmap computations (skip completed alignments)
--no_map Skip minimap/mashmap pairwise genome alignments
--no_clus Skip gene cluster reconstructions
--version Display SYNY version
EXIT
my $plot_options = <<"PLOT_OPTIONS";
### Circos plots
-c (--circos) Circos plot mode: pair (pairwise), cat (concatenated), all (cat + pair) [Default: pair]
--orientation Karyotype orientation: normal, inverted or both [Default: normal]
--circos_prefix Prefix for concatenated plots [Default: circos]
-r (--ref) Reference to use for concatenated plots; uses first genome (alphabetically) if ommitted
-u (--unit) Size unit (Kb or Mb) [Default: Mb]
--winsize Sliding windows size (nucleotide biases) [Default: 10000]
--stepsize Sliding windows step (nucleotide biases) [Default: 5000]
--labels Contig label type: mixed (arabic + roman numbers), arabic, roman, or names [Default: mixed]
--label_size Contig label size [Default: 36]
--label_font Contig label font [Default: bold]
--custom_file Load custom colors from file
--list_preset List available custom color presets
--custom_preset Use a custom color preset, e.g.: --custom_preset chloropicon
--max_ticks Set max number of ticks [Default: 5000]
--max_ideograms Set max number of ideograms [Default: 200]
--max_links Set max number of links [Default: 75000]
--max_points_per_track Set max number of points per track [Default: 75000]
--clusters Color by cluster instead of contig/chromosome [Default: off]
--no_ntbiases Turn off nucleotide biases subplots
--no_cticks Turn off ticks in Circos plots
--no_circos Turn off Circos plots
### Barplots
-bh (--bheight) Barplot figure height in inches [Default: 10.8]
-bw (--bwidth) Barplot figure width in inches [Default: 19.2]
--bfsize Barplot font size [Default: 8]
--palette Barplot color palette [Default: Spectral]
--monobar Use a monochrome barplot color instead: e.g. --monobar blue
--bclusters Color clusters by alternating colors; colors are not related within/between contigs; [Default: off]
--bpmode Barplot mode: pair (pairwise), cat (concatenated), all (cat + pair) [Default: pair]
--no_barplot Turn off barplots
### Dotplots
-dh (--dheight) Dotplot figure height in inches [Default: 10.8]
-dw (--dwidth) Dotplot figure width in inches [Default: 19.2]
--dfsize Dotplot font size [Default: 8]
-m (--multi) Axes units multiplier (for dotplots) [Default: 1e5]
--color Dotplot color [Default: blue]
--dotpalette Use a color palette instead: e.g. --dotpalette inferno
--noticks Turn off ticks on x and y axes
--wdis Horizontal distance (width) between subplots [Default: 0.05]
--hdis Vertical distance (height) between subplots [Default: 0.1]
--no_dotplot Turn off dotplots
### Heatmaps
-hh (--hheight) Heatmap figure height in inches [Default: 10]
-hw (--hwidth) Heatmap figure width in inches [Default: 10]
--hfsize Heatmap font size [Default: 8]
--hmpalette Heatmap color palette [Default: winter_r]
--hmax Set maximum color bar value [Default: 100]
--hmin Set minimum color bar value [Default: 0]
--hauto Set color bar values automatically instead
--no_heatmap Turn off heatmaps
### Linear maps
-lh (--lheight) Linear map figure height in inches [Default: 5]
-lw (--lwidth) Heatmap figure width in inches [Default: 20]
--lm_rpalette Reference genome color palette [Default: tab20]
--lm_xpalette Target genome color palette [Default: Blues]
--lmrotation Contig name rotation [Default: 90]
--lfsize Font size [Default: 8]
--no_linemap Turn off linemaps
PLOT_OPTIONS
unless (@ARGV){
print "\n$usage\n";
exit(0);
};
my @commands = @ARGV;
# Main
my @annot_files;
my $evalue = '1e-10';
my @gaps;
my $outdir = 'SYNY';
my $threads = 16;
my $max_pthreads = $threads;
my $minsize = 1;
my @excluded;
my @included;
my @ranges;
my $aligner = 'minimap';
my $nomap;
my $noclus;
my $resume;
my $asm;
my $mashmap_pid = 85;
my $help;
my $syny_version;
# Circos
my $reference;
my $unit = 'Mb';
my $labels = 'mixed';
my $label_size = 36;
my $label_font = 'bold';
my $circos = 'pair';
my $circos_prefix = 'circos';
my $winsize = 10000;
my $stepsize = 5000;
my $custom_file;
my $custom_colors;
my $list_preset;
my @formats;
my $max_ticks = 5000;
my $max_ideograms = 200;
my $max_links = 75000;
my $max_points_per_track = 75000;
my $clusters;
my $circos_orientation = 'normal';
my $no_ntbiases;
my $no_circos;
my $no_cticks;
# Barplots
my $bheight = 10.8;
my $bwidth = 19.2;
my $bfsize = 8;
my $palette = 'Spectral';
my $monobar;
my $bclusters;
my $bpmode = 'pair';
my $no_barplot;
# Dotplots
my $dheight = 10.8;
my $dwidth = 19.2;
my $dfsize = 8;
my $multiplier = '1e5';
my $color = 'blue';
my $dotpalette;
my $noticks;
my $wdis = 0.05;
my $hdis = 0.1;
my $no_dotplot;
# Heatmaps
my $hheight = 10;
my $hwidth = 10;
my $hfsize = 8;
my $hmpalette = 'winter_r';
my $hmax = 100;
my $hmin = 0;
my $hauto;
my $no_heatmap;
# Linemaps
my $lheight = 5;
my $lwidth = 20;
my $lm_rpalette = 'tab20';
my $lm_xpalette = 'Blues';
my $lmrotation = 90;
my $lfsize = 8;
my $no_linemap;
GetOptions(
# Main
't|threads=i' => \$threads,
'p|pthreads=i' => \$max_pthreads,
'a|annot=s@{1,}' => \@annot_files,
'o|outdir=s' => \$outdir,
'e|evalue=s' => \$evalue,
'g|gaps=i{0,}' => \@gaps,
'minsize=i' => \$minsize,
'excluded=s{0,}' => \@excluded,
'included=s{0,}' => \@included,
'ranges=s{0,}' => \@ranges,
'aligner=s' => \$aligner,
'no_map' => \$nomap,
'no_clus' => \$noclus,
'resume' => \$resume,
'asm=i' => \$asm,
'mpid=s' => \$mashmap_pid,
'h|help' => \$help,
'version' => \$syny_version,
# Circos
'c|circos=s' => \$circos,
'r|ref|reference=s' => \$reference,
'u|unit=s' => \$unit,
'labels=s' => \$labels,
'label_size=s' => \$label_size,
'label_font=s' => \$label_font,
'winsize=i' => \$winsize,
'stepsize=i' => \$stepsize,
'circos_prefix=s' => \$circos_prefix,
'custom_file=s' => \$custom_file,
'custom_preset=s' => \$custom_colors,
'list_preset' => \$list_preset,
'f|format=s{1,}' => \@formats,
'max_ticks=i' => \$max_ticks,
'max_ideograms=i' => \$max_ideograms,
'max_links=i' => \$max_links,
'max_points_per_track=i' => \$max_points_per_track,
'clusters' => \$clusters,
'orientation=s' => \$circos_orientation,
'no_ntbiases' => \$no_ntbiases,
'no_circos' => \$no_circos,
'no_cticks' => \$no_cticks,
# Barplots
'bh|bheight=s' => \$bheight,
'bw|bwidth=s' => \$bwidth,
'bfsize=i' => \$bfsize,
'palette=s' => \$palette,
'monobar=s' => \$monobar,
'bclusters' => \$bclusters,
'bpmode=s' => \$bpmode,
'no_barplot' => \$no_barplot,
# Dotplots
'dh|dheight=s' => \$dheight,
'dw|dwidth=s' => \$dwidth,
'dfsize=i' => \$dfsize,
'm|multiplier=s' => \$multiplier,
'color=s' => \$color,
'dotpalette=s' => \$dotpalette,
'noticks' => \$noticks,
'wdis=s' => \$wdis,
'hdis=s' => \$hdis,
'no_dotplot' => \$no_dotplot,
# Heatmaps
'hh|hheight=s' => \$hheight,
'hw|hwidth=s' => \$hwidth,
'hfsize=i' => \$hfsize,
'hmpalette=s' => \$hmpalette,
'hmax=i' => \$hmax,
'hmin=i' => \$hmin,
'hauto' => \$hauto,
'no_heatmap' => \$no_heatmap,
# Linemaps
'lh|lheight=s' => \$lheight,
'lw|lwidth=s' => \$lwidth,
'lm_rpalette=s' => \$lm_rpalette,
'lm_xpalette=s' => \$lm_xpalette,
'lmrotation=i' => \$lmrotation,
'lfsize=i' => \$lfsize,
'no_linemap' => \$no_linemap
);
# Displaying the full list of options
if ($help){
print "\n".$usage."\n";
print $plot_options."\n";
exit;
}
# Setting default gap value
unless(@gaps){
@gaps = (0);
}
# Grabbing $path location from script
my ($script,$path) = fileparse($0);
my $align_path = $path.'/Alignments';
my $cluster_path = $path.'/Clusters';
my $plot_path = $path.'/Plots';
my $util_path = $path.'/Utils';
# plot threads
my $pthreads = $threads;
if ($max_pthreads){
$pthreads = $max_pthreads;
}
###################################################################################################
## Display syny version
###################################################################################################
if ($syny_version){
my $version_file = $path.'./versions.txt';
open VER, '<', $version_file or die "Can't read $version_file: $!\n";
print "\n";
while (my $line = <VER>){
print $line;
}
print "\n\n";
exit;
}
###################################################################################################
## Precheck Circos options
###################################################################################################
if ($list_preset){
system("
$plot_path/nucleotide_biases.pl \\
--list_preset
") == 0 or checksig();
exit;
}
## Check for plot orientation
my %circos_orientations = (
'normal' => '',
'inverted' => '',
'both' => ''
);
unless ($no_circos){
$circos_orientation = lc($circos_orientation);
if (!exists $circos_orientations{$circos_orientation}){
print "\nCircos orientation $circos_orientation not found. Possible oritentations are:"."\n\n";
for my $key (sort (keys %circos_orientations)){
print ' '.$key."\n";
}
print "\n";
exit;
}
}
## Check for plot fonts
my %circos_fonts = (
'light' => '',
'normal' => '',
'default' => '',
'semibold' => '',
'bold' => '',
'italic' => '',
'bolditalic' => '',
'italicbold' => ''
);
if ($label_font){
my $font = lc($label_font);
if (!exists $circos_fonts{$font}){
print "\nCircos font $font not found. Possible fonts are:"."\n\n";
for my $key (sort (keys %circos_fonts)){
print ' '.$key."\n";
}
print "\n";
exit;
}
}
###################################################################################################
## Precheck matplotlib colors
###################################################################################################
my @matp_colors = ($palette, $hmpalette, $lm_rpalette, $lm_xpalette);
if ($dotpalette){
push (@matp_colors, $dotpalette);
}
my $matp_check = `$util_path/check_mp_colors.py --check @matp_colors`;
if ($matp_check =~ /\[E\]/){
print $matp_check;
exit();
}
###################################################################################################
## Checking dependencies
###################################################################################################
# Diamond
my $diamond_check = `echo \$(command -v diamond)`;
chomp $diamond_check;
if ($diamond_check eq ''){
print STDERR "\n[E]: Cannot find diamond. Please install diamond in your \$PATH. Exiting..\n\n";
exit;
}
# minimap2
if ($aligner =~ /minimap/i){
my $minimap2_check = `echo \$(command -v minimap2)`;
chomp $minimap2_check;
if ($minimap2_check eq ''){
print STDERR "\n[E]: Cannot find minimap2. Please install minimap2 in your \$PATH. Exiting..\n\n";
exit;
}
}
# mashmap3
if ($aligner =~ /mashmap/i){
my $mashmap_check = `echo \$(command -v mashmap)`;
chomp $mashmap_check;
if ($mashmap_check eq ''){
print STDERR "\n[E]: Cannot find mashmap. Please install mashmap in your \$PATH. Exiting..\n\n";
exit;
}
}
# Circos
unless ($no_circos){
my $circos_check = `echo \$(command -v circos)`;
chomp $circos_check;
if ($diamond_check eq ''){
print STDERR "\n[E]: Cannot find circos. Please install circos in your \$PATH. Exiting..\n\n";
exit;
}
}
###################################################################################################
## Precheck annotations files
###################################################################################################
if (!@annot_files){
print "\n[E] No annotation file entered with -a/--annot.\n";
print "[E] Please enter some annotation files to compare. Exiting...\n\n";
exit;
}
else {
my @files;
for my $file (@annot_files){
if ($file =~ /\*/){
@files = glob($file);
}
elsif ($file =~ /\.gbff(\.gz)?$/){
push (@files, $file);
}
}
if (scalar(@files) == 0){
print "\n[E] No .gbff/.gbff.gz file detected: --annot @annot_files\n";
print "[E] Please check the command line. Exiting...\n\n";
exit;
}
elsif (scalar(@files) == 1){
print "\n[E] Only one annotation file (.gbff/.gbff.gz) detected: $files[0]\n";
print "[E] Please enter at least two annotation files to compare. Exiting...\n\n";
exit;
}
}
###################################################################################################
## Output directory creation and setup
###################################################################################################
## Creating path before running abs_path(); otherwise returns nothing
unless (-d $outdir){
make_path($outdir,{mode=>0755}) or die "Can't create $outdir: $!\n";
}
$outdir = abs_path($outdir);
my $mmap_dir = $outdir.'/ALIGNMENTS';
my $list_dir = $outdir.'/LISTS';
## Sequence subdirs
my $seq_dir = $outdir.'/SEQUENCES';
my $prot_dir = $seq_dir.'/PROTEINS';
my $genome_dir = $seq_dir.'/GENOMES';
# Gene cluster subdirs
my $cluster_dir = $outdir.'/CLUSTERS';
my $conserved_dir = $cluster_dir.'/HOMOLOGS';
my $diamond_dir = $cluster_dir.'/DIAMOND';
my $db_dir = $diamond_dir.'/DB';
my $cluster_synteny = $cluster_dir.'/SYNTENY';
# Plots subdirs
my $plots_dir = $outdir.'/PLOTS';
my $paf_hm_dir = $plots_dir.'/HEATMAPS';
my $barplot_dir = $plots_dir.'/BARPLOTS';
my $barplot_cat_dir = $barplot_dir.'/Concatenated';
my $barplot_pair_dir = $barplot_dir.'/Pairwise';
my $dotplot_dir = $plots_dir.'/DOTPLOTS';
my $linemap_dir = $plots_dir.'/LINEMAPS';
my $circos_plot_dir = $plots_dir.'/CIRCOS';
my $circos_data_dir = $plots_dir.'/CIRCOS_DATA';
my $circos_cat_dir = $circos_data_dir.'/concatenated';
my $circos_pair_dir = $circos_data_dir.'/pairwise';
my @outdirs = (
$list_dir,
$seq_dir,$prot_dir,
$genome_dir,
$plots_dir,
$circos_data_dir,
$circos_cat_dir,
$circos_pair_dir,
$diamond_dir,
$db_dir
);
unless ($noclus){
push (@outdirs, $cluster_dir);
push (@outdirs, $cluster_synteny);
}
foreach my $dir (@outdirs){
unless (-d $dir){
make_path($dir,{mode=>0755}) or die "Can't create $dir: $!\n";
}
}
## Logs
my $log_file = $outdir.'/'.'syny.log';
my $log_err = $outdir.'/'.'error.log';
open LOG, '>', $log_file or die "Can't create $log_err: $!\n";
open ERROR, '>', $log_err or die "Can't create $log_err: $!\n";
my $time = localtime();
my $start_time = time();
my $tstart = time();
print LOG "SYNY started on: ".$time."\n\n";
logs(\*LOG, 'Command line', 'header');
print LOG "$0 @commands\n\n";
###################################################################################################
## Options flags
###################################################################################################
my $excluded_flag = '';
if (@excluded){
$excluded_flag = "--exclude @excluded";
}
my $included_flag = '';
if (@included){
$included_flag = "--include @included";
}
my $ranges_flag = '';
if (@ranges){
$ranges_flag = "--ranges @ranges";
}
my $cluster_flag = '';
if ($clusters){
$cluster_flag = '--clusters';
}
my $bcluster_flag = '';
if ($bclusters){
$bcluster_flag = '--clusters';
}
my $custom_cc_file = '';
if ($custom_file){
$custom_cc_file = "--custom_file $custom_file";
}
my $custom_cc = '';
if ($custom_colors){
$custom_cc = "--custom_preset $custom_colors";
}
my $tick_flag = '';
if ($noticks){
$tick_flag = '--noticks'
}
my $monobar_flag = '';
if ($monobar){
$monobar_flag = "--mono $monobar";
}
my $dotpal_flag = '';
if ($dotpalette){
$dotpal_flag = "--palette $dotpalette";
}
my $asm_flag = '';
if ($asm){
$asm_flag = "--asm $asm";
}
my $resume_flag = '';
if ($resume){
$resume_flag = '--resume';
}
my $hm_vauto_flag = '';
if ($hauto){
$hm_vauto_flag = '--vauto';
}
###################################################################################################
## Run list_maker.pl
###################################################################################################
my @threads = initThreads($threads);
print ERROR "\n### list_maker.pl ###\n";
print "\n##### Extracting data from GenBank files\n";
logs(\*LOG, 'Parsing data', 'header');
logs(\*LOG, 'list_maker.pl', 'start');
my @annotations :shared = @annot_files;
my $annot_num = scalar(@annot_files);
for my $thread (@threads){
$thread = threads->create(\&list_maker);
}
for my $thread (@threads){
$thread ->join();
}
logs(\*LOG, 'list_maker.pl', 'end');
###################################################################################################
## Get PAF files with minimap2
###################################################################################################
# Skip minimap if requested
if ($nomap){
goto HOMOLOGY;
}
## Running minimap2/mashmap3 with get_paf.pl
$tstart = time();
print "\n##### Infering colinearity from pairwise genome alignments\n";
print ERROR "\n### get_paf.pl ###\n";
logs(\*LOG, 'Genome alignments', 'header');
logs(\*LOG, 'get_paf.pl', 'start');
my $paf_dir = "$mmap_dir/PAF";
my $pafcat_dir = "$mmap_dir/PAFCAT";
my @pafcat_files;
system("
$align_path/get_paf.pl \\
--fasta $genome_dir/*.fasta \\
--outdir $mmap_dir \\
--aligner $aligner \\
--threads $threads \\
--percent $mashmap_pid \\
$resume_flag \\
$asm_flag
") == 0 or checksig();
opendir (PAFDIR, $paf_dir) or die "\n\n[ERROR]\tCan't open $paf_dir: $!\n\n";
while (my $file = readdir(PAFDIR)){
if ($file =~ /\.paf$/){
my $paf_file = "$paf_dir/$file";
push (@pafcat_files, $paf_file);
if (-z $paf_file){
print LOG " - $paf_file is empty. No collinearity or process terminated by OOM killer?\n";
}
}
}
closedir PAFDIR;
if (($bpmode eq 'cat') or ($bpmode eq 'all')){
unless (-d $pafcat_dir){
mkdir($pafcat_dir,0755) or die "Can't create $pafcat_dir: $!\n";
}
my %references;
for my $paf_file (@pafcat_files){
if ($paf_file =~ /(\w+)_vs_(\w+).\w+.paf$/){
my $query = $1;
my $reference = $2;
push (@{$references{$reference}}, $paf_file);
}
}
for my $ref (keys %references){
my $catfile = $pafcat_dir.'/all_vs_'.$ref.'.mmap.paf';
open CCAT, '>', $catfile or die "Can't create $catfile: $!\n";
for my $file (@{$references{$ref}}){
open SCAT, '<', $file or die "Can't read $file: $!\n";
while (my $line = <SCAT>){
print CCAT "$line";
}
close SCAT;
}
close CCAT;
}
}
logs(\*LOG, 'get_paf.pl', 'end');
## Creating Circos links file
$tstart = time();
print ERROR "\n### paf2links.pl ###\n";
my $paf_links = "$circos_cat_dir/concatenated.mmap.links";
logs(\*LOG, 'paf2links.pl', 'start');
system("
$align_path/paf2links.pl \\
--paf $paf_dir \\
--links $paf_links \\
$cluster_flag \\
$custom_cc \\
$custom_cc_file \\
2>> $log_err
") == 0 or checksig();
logs(\*LOG, 'paf2links.pl', 'end');
#### Calculate/plot PAF metrics
if ($aligner =~ /minimap/){
$tstart = time();
print ERROR "\n### paf_metrics.py ###\n";
print "\n# Calculating metrics (genome alignments):\n";
my $aln_length_dir = $mmap_dir.'/METRICS';
my @paf_files;
opendir (PAFDIR, $paf_dir) or die "\n\n[ERROR]\tCan't open $paf_dir: $!\n\n";
while (my $file = readdir(PAFDIR)){
if ($file =~ /\.paf$/){
push (@paf_files, "$paf_dir/$file");
}
}
closedir PAFDIR;
logs(\*LOG, 'paf_metrics.py', 'start');
system ("
$align_path/paf_metrics.py \\
--paf @paf_files \\
--outdir $aln_length_dir \\
--threads $threads \\
--height 10.8 \\
--width 19.2 \\
--color steelblue \\
2>> $log_err
") == 0 or checksig();
logs(\*LOG, 'paf_metrics.py', 'end');
}
###################################################################################################
## Creating barplots / dotplots / linemaps / heatmaps from minimap2 PAF files
###################################################################################################
# Barplots
unless ($no_barplot){
$tstart = time();
print ERROR "\n### paf_to_barplot.py (genome alignments) ###\n";
logs(\*LOG, 'paf_to_barplot.py', 'start');
if (($bpmode eq 'pair') or ($bpmode eq 'all')){
print "\n# Barplots - pairwise (genome alignments):\n";
unless (-d $barplot_pair_dir){
make_path($barplot_pair_dir,{mode=>0755}) or die "Can't create $barplot_pair_dir: $!\n";
}
system("
$plot_path/paf_to_barplot.py \\
--paf $paf_dir/*.paf \\
--fasta $genome_dir/*.fasta \\
--outdir $barplot_pair_dir \\
--threads $pthreads \\
--height $bheight \\
--width $bwidth \\
--palette $palette \\
--fontsize $bfsize \\
$tick_flag \\
$monobar_flag \\
$bcluster_flag \\
2>> $log_err
") == 0 or checksig();
}
if (($bpmode eq 'cat') or ($bpmode eq 'all')){
print "\n# Barplots - catenated (genome alignments):\n";
unless (-d $barplot_cat_dir){
make_path($barplot_cat_dir,{mode=>0755}) or die "Can't create $barplot_cat_dir: $!\n";
}
system("
$plot_path/paf_to_barplot.py \\
--paf $pafcat_dir/*.paf \\
--fasta $genome_dir/*.fasta \\
--outdir $barplot_cat_dir \\
--threads $pthreads \\
--height $bheight \\
--width $bwidth \\
--palette $palette \\
--fontsize $bfsize \\
--catenate \\
$tick_flag \\
$monobar_flag \\
$bcluster_flag \\
2>> $log_err
") == 0 or checksig();
}
logs(\*LOG, 'paf_to_barplot.py', 'end');
}
# Doplots
unless ($no_dotplot){
$tstart = time();
print ERROR "\n### paf_to_dotplot.py (genome alignments) ###\n";
print "\n# Dotplots (genome alignments):\n";
logs(\*LOG, 'paf_to_dotplot.py', 'start');
system("
$plot_path/paf_to_dotplot.py \\
--paf $paf_dir/*.paf \\
--fasta $genome_dir/*.fasta \\
--threads $pthreads \\
--outdir $dotplot_dir \\
--unit $multiplier \\
--height $dheight \\
--width $dwidth \\
--color $color \\
--fontsize $dfsize \\
$tick_flag \\
$dotpal_flag \\
--wdis $wdis \\
--hdis $hdis \\
2>> $log_err
") == 0 or checksig();
logs(\*LOG, 'paf_to_dotplot.py', 'end');
}
# Linemaps
unless ($no_linemap){
$tstart = time();
print ERROR "\n### linear_maps.py (genome alignments) ###\n";
print "\n# Linemaps (genome alignments):\n";
logs(\*LOG, 'linear_maps.py', 'start');
system("
$plot_path/linear_maps.py \\
--paf $paf_dir/*.paf \\
--fasta $genome_dir/*.fasta \\
--outdir $linemap_dir \\
--threads $pthreads \\
--height $lheight \\
--width $lwidth \\
--rpalette $lm_rpalette \\
--xpalette $lm_xpalette \\
--fontsize $lfsize \\
--rotation $lmrotation \\
2>> $log_err
") == 0 or checksig();
logs(\*LOG, 'linear_maps.py', 'end');
}
# Heatmaps
unless ($no_heatmap){
$tstart = time();
print ERROR "\n### paf_to_hm.py (genome alignments) ###\n";
print "\n# Heatmaps (genome alignments):\n";
logs(\*LOG, 'paf_to_hm.py', 'start');
system("
$plot_path/paf_to_heatmap.py \\
--paf $paf_dir/*.paf \\
--fasta $genome_dir/*.fasta \\
--outdir $paf_hm_dir \\
--height $hheight \\
--width $hwidth \\
--palette $hmpalette \\
--matrix $mmap_dir/paf_matrix.tsv \\
--fontsize $hfsize \\
--vmax $hmax \\
--vmin $hmin \\
$hm_vauto_flag \\
2>> $log_err
") == 0 or checksig();
logs(\*LOG, 'paf_to_hm.py', 'end');
}
###################################################################################################
## Run get_homology.pl
###################################################################################################
# Skip gene cluster if requested
if ($noclus){
goto CIRCOS;
}
# Else, search for gene clusters
HOMOLOGY:
$tstart = time();
print "\n##### Infering colinearity from protein-coding gene clusters\n\n";
print ERROR "\n### get_homology.pl ###\n";
my @prot_files = ();
opendir (FAA, $prot_dir) or die "\n\n[ERROR]\tCan't open $prot_dir: $!\n\n";
while (my $file = readdir(FAA)){
if ($file =~ /\.faa$/){
my $prot_file = $prot_dir.'/'.$file;
## Skipping blank files
if (-z $prot_file){
print "Protein file $prot_file is blank\n";
next;
}
else{
push (@prot_files, $prot_file);
}
}
}
closedir FAA;
## Checking if all protein files are blank, if so no point in searching for shared clusters
if ((scalar @prot_files) == 0){
if ($noclus){
print "\n[W] All protein files are blank. No annotation detected.\n\n";
}
else{