blib/lib/App/Dazz/Command/overlap.pm

filter: Statementstmt 67.0% 67 / 100 Branchbran 34.6% 9 / 26 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 5 / 5 totaltotal 62.5% 92 / 147 CC 20 SCAR 35.6
CC
20
Cov
59%
execute
67.2
validate_args
6.0
BEGIN
1.0
CRAP 35.1
« blib/lib/App/Dazz/Command/overlap2.pm ↑ Summary blib/lib/App/Dazz/Common.pm »
1 package App::Dazz::Command::overlap;
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use App::Dazz -command;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use App::Dazz::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 ▶use constant abstract => "detect overlaps by daligner";
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 6 ▶sub opt_spec {
Subroutine opt_spec: called CC=1 SCAR=0.0
Pod documented
12 return (
13 6 [ "outfile|o=s", "output filename, [stdout] for screen", ],
14 [ "len|l=i", "minimal length of overlaps", { default => 500 }, ],
15 [ "idt|i=f", "minimal identity of overlaps", { default => 0.7 }, ],
16 [ "serial", "serials instead of original names in the output file", ],
17 [ "all", "all overlaps instead of proper overlaps", ],
18 [ "tmp=s", "user defined tempdir", ],
19 [ "parallel|p=i", "number of threads", { default => 8 }, ],
20 [ "verbose|v", "verbose mode", ],
21 { show_defaults => 1, }
22 );
23 }
24  
25 6 ▶sub usage_desc {
Subroutine usage_desc: called CC=1 SCAR=0.0
Pod documented
26 6 return "dazz overlap [options] <infiles>";
27 }
28  
29 1 ▶sub description {
Subroutine description: called CC=1 SCAR=0.0
Pod documented
30 1 my $desc;
31 1 $desc .= ucfirst(abstract) . ".\n";
32 1 $desc .= "\tThis command is for small files.\n ";
33 1 $desc .= "\tAll operations are running in a tempdir and no intermediate files are kept.\n";
34 1 return $desc;
35 }
36  
37 5 ▶sub validate_args {
Subroutine validate_args: called CC=6 SCAR=18.0
Pod documented
38 5 my ( $self, $opt, $args ) = @_;
39  
40 5 ▶ if ( @{$args} < 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$args;} < 1) 1 4 5
41 1 my $message = "This command need one or more input files.\n\tIt found";
42 1 $message .= sprintf " [%s]", $_ for @{$args};
43 1 $message .= ".\n";
44 1 $self->usage_error($message);
45 }
46 4 for ( @{$args} ) {
47 5 ▶ if ( !Path::Tiny::path($_)->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Path::Tiny::path($_)->is_file) 3 2 5
48 3 $self->usage_error("The input file [$_] doesn't exist.");
49 }
50 }
51  
52 1 ▶ if ( !exists $opt->{outfile} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $opt->{"outfile"}) 0 1 1
53 0 $opt->{outfile} = Path::Tiny::path( $args->[0] )->absolute . ".ovlp.tsv";
54 }
55 }
56  
57 1 ▶sub execute {
Subroutine execute: called CC=15 SCAR=42.1
Pod documented
58 1 my ( $self, $opt, $args ) = @_;
59  
60 # absolute pathes as we will chdir to tempdir later
61 1 my @infiles;
62 1 for my $infile ( @{$args} ) {
63 1 push @infiles, Path::Tiny::path($infile)->absolute->stringify;
64 }
65  
66 1 ▶ if ( lc $opt->{outfile} ne "stdout" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $opt->{"outfile"} ne "stdout") 0 1 1
67 0 $opt->{outfile} = Path::Tiny::path( $opt->{outfile} )->absolute->stringify;
68 }
69  
70 # record cwd, we'll return there
71 1 my $cwd = Path::Tiny->cwd;
72 1 my $tempdir;
73 1 ▶ if ( $opt->{tmp} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'tmp'}) { } 0 1 1
74 $tempdir = Path::Tiny->tempdir(
75 TEMPLATE => "dazz_ovlp_XXXXXXXX",
76 DIR => $opt->{tmp},
77 0 );
78 }
79 else {
80 1 $tempdir = Path::Tiny->tempdir("dazz_ovlp_XXXXXXXX");
81 }
82 1 chdir $tempdir;
83  
84 1 my $basename = $tempdir->basename();
85 1 $basename =~ s/\W+/_/g;
86  
87 { # Preprocess reads to format them for dazzler
88 1 my $cmd = "cat";
89 1 $cmd .= sprintf " %s", $_ for @infiles;
90 1 $cmd .= " | dazz dazzname stdin -o stdout";
91 1 $cmd .= " | faops filter -l 0 stdin renamed.fasta";
92 1 App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } );
93  
94 1 ▶ if ( !$tempdir->child("stdout.replace.tsv")->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tempdir->child("stdout.replace.tsv")->is_file) 0 1 1
95 0 Carp::croak "Failed: create stdout.replace.tsv\n";
96 }
97 }
98  
99 { # Make the dazzler DB, each block is of size 50 MB
100 1 my $cmd;
101 1 $cmd .= "fasta2DB $basename renamed.fasta";
102 1 $cmd .= " && DBdust $basename";
103 1 $cmd .= " && DBsplit -s50 $basename";
104 1 App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } );
105  
106 1 ▶ if ( !$tempdir->child("$basename.db")->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tempdir->child("$basename.db")->is_file) 1 0 1
107 1 Carp::croak "Failed: fasta2DB\n";
108 }
109 }
110  
111 { # Run daligner
112 1 my $block_number;
113 0 for my $line ( $tempdir->child("$basename.db")->lines ) {
114 0 ▶ if ( $line =~ /^blocks\s+=\s+(\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^blocks\s+=\s+(\d+)/) 0 0 0
115 0 $block_number = $1;
116 0 last;
117 }
118 }
119  
120 0 my $cmd;
121 0 $cmd
122 .= "HPC.daligner $basename -M16 -T$opt->{parallel} -e$opt->{idt} -l$opt->{len} -s$opt->{len} -mdust";
123 0 $cmd .= " | sed 's/ -vS / -S /'"; # don't show LAcheck prompts
124 0 $cmd .= " | bash";
125 0 App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } );
126  
127 0 ▶ if ( defined $block_number and $block_number > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $block_number and $block_number > 1) 0 0 0
Condition0%0/3
defined $block_number and $block_number > 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $block_number and $block_number > 1
defined $block_number $block_number > 1
Truth table0%0/3
A and B
A= defined $block_numberB= $block_number > 1
ABresult
0X0
100
111
128 0 $cmd = "LAcat $basename.\@.las > $basename.las";
129 0 App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } );
130 }
131  
132 0 ▶ if ( !$tempdir->child("$basename.las")->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tempdir->child("$basename.las")->is_file) 0 0 0
133 0 Carp::croak "Failed: daligner\n";
134 }
135 }
136  
137 { # outputs
138 0 my $cmd = "LAshow -o $basename.db $basename.las > show.txt";
139 0 ▶ if ( $opt->{all} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{"all"}) 0 0 0
140 0 $cmd = "LAshow $basename.db $basename.las > show.txt";
141 }
142 0 App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } );
143  
144 0 ▶ if ( !$tempdir->child("show.txt")->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tempdir->child("show.txt")->is_file) 0 0 0
145 0 Carp::croak "Failed: LAshow\n";
146 }
147  
148 0 $cmd = "dazz show2ovlp renamed.fasta show.txt";
149 0 ▶ if ( !$opt->{serial} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt->{"serial"}) 0 0 0
150 0 $cmd .= " -r stdout.replace.tsv";
151 }
152 0 $cmd .= " -o $opt->{outfile}";
153 0 App::Dazz::Common::exec_cmd( $cmd, { verbose => $opt->{verbose}, } );
154 }
155  
156 0 chdir $cwd;
157 }
158  
159 11 1;
« blib/lib/App/Dazz/Command/overlap2.pm ↑ Summary blib/lib/App/Dazz/Common.pm »