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

filter: Statementstmt 96.2% 77 / 80 Branchbran 80.5% 29 / 36 Conditioncond 100% 12 / 12 MC/DCmcdc 100% 6 / 6 Subroutinesub 100% 11 / 11 Podpod 100% 5 / 5 totaltotal 93.3% 140 / 150 CC 25 SCAR 24.0
CC
25
Cov
92%
execute
17.2
validate_args
9.1
BEGIN
1.0
CRAP 11.0
« blib/lib/App/Dazz/Common.pm ↑ Summary blib/lib/App/Dazz/Command/dazzname.pm »
1 package App::Dazz::Command::show2ovlp;
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 => 'LAshow outputs to overlaps';
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 [ 'replace|r=s', 'original names of sequences', ],
15 { show_defaults => 1, }
16 );
17 }
18  
19 6 ▶sub usage_desc {
Subroutine usage_desc: called CC=1 SCAR=0.0
Pod documented
20 6 return "dazz show2ovlp [options] <fasta file> <LAshow outputs>";
21 }
22  
23 1 ▶sub description {
Subroutine description: called CC=1 SCAR=0.0
Pod documented
24 1 my $desc;
25 1 $desc .= ucfirst(abstract) . ".\n";
26 1 return $desc;
27 }
28  
29 5 ▶sub validate_args {
Subroutine validate_args: called CC=9 SCAR=22.1
Pod documented
30 5 my ( $self, $opt, $args ) = @_;
31  
32 5 ▶ if ( @{$args} != 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$args;} != 2) 1 4 5
33 1 my $message = "This command need two input files.\n\tIt found";
34 1 $message .= sprintf " [%s]", $_ for @{$args};
35 1 $message .= ".\n";
36 1 $self->usage_error($message);
37 }
38 4 for ( @{$args} ) {
39 7 ▶ next if lc $_ eq "stdin";
Branch: 1 branch
BranchTrueFalseTotal
if lc $_ eq "stdin" 0 7 7
40 7 ▶ if ( !Path::Tiny::path($_)->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Path::Tiny::path($_)->is_file) 1 6 7
41 1 $self->usage_error("The input file [$_] doesn't exist.");
42 }
43 }
44  
45 3 ▶ if ( exists $opt->{replace} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opt->{"replace"}) 2 1 3
46 2 ▶ if ( !Path::Tiny::path( $opt->{replace} )->is_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Path::Tiny::path($opt->{"replace"})->is_file) 1 1 2
47 1 $self->usage_error("The replace file [$opt->{replace}] doesn't exist.\n");
48 }
49 }
50  
51 2 ▶ if ( !exists $opt->{outfile} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $opt->{"outfile"}) 0 2 2
52 0 $opt->{outfile} = Path::Tiny::path( $args->[1] )->absolute . ".ovlp.tsv";
53 }
54 }
55  
56 2 ▶sub execute {
Subroutine execute: called CC=17 SCAR=28.5
Pod documented
57 2 my ( $self, $opt, $args ) = @_;
58  
59 2 my $len_of = App::Dazz::Common::get_len_from_header( $args->[0] );
60  
61 # print STDERR "Get @{[scalar keys %{$len_of}]} records of sequence length\n";
62  
63 2 my $replace_of = {};
64 2 ▶ if ( exists $opt->{replace} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opt->{"replace"}) 1 1 2
65 1 $replace_of = App::Dazz::Common::get_replaces( $opt->{replace} );
66 }
67  
68 # A stream from 'stdin' or a standard file.
69 2 my $in_fh;
70 2 ▶ if ( lc $args->[1] eq 'stdin' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $args->[1] eq 'stdin') { } 0 2 2
71 0 $in_fh = *STDIN{IO};
72 }
73 else {
74 2 open $in_fh, "<", $args->[1];
75 }
76  
77 # A stream to 'stdout' or a standard file.
78 2 my $out_fh;
79 2 ▶ if ( lc $opt->{outfile} eq "stdout" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $opt->{'outfile'} eq 'stdout') { } 2 0 2
80 2 $out_fh = *STDOUT{IO};
81 }
82 else {
83 0 open $out_fh, ">", $opt->{outfile};
84 }
85  
86 2 ▶ while ( my $line = <$in_fh> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $in_fh)) 104 2 106
87 104 $line =~ s/,//g;
88 104 ▶ $line =~ m{
Branch: 1 branch
BranchTrueFalseTotal
$line =~ / ^\D* (\d+) # f_id \s+(\d+) # g_id \s+(\w) # orientation \D+(\d+) # f.B \D+(\d+) # f.E \D+(\d+) # g.B \D+(\d+) # g.E \D+([\d.]+) # identity .*$ /x or next 100 4 104
89 ^\D*
90 (\d+) # f_id
91 \s+(\d+) # g_id
92 \s+(\w) # orientation
93 \D+(\d+) # f.B
94 \D+(\d+) # f.E
95 \D+(\d+) # g.B
96 \D+(\d+) # g.E
97 \D+([\d.]+) # identity
98 .*$
99 }x or next;
100  
101 100 my $f_id = $1;
102 100 my $g_id = $2;
103  
104 100 ▶ next unless exists $len_of->{$f_id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $len_of->{$f_id} 0 100 100
105 100 ▶ next unless exists $len_of->{$g_id};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $len_of->{$g_id} 0 100 100
106  
107 100 ▶ my $g_ori = $3 eq "n" ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$3 eq 'n' ? : 100 0 100
108 100 my $f_B = $4;
109 100 my $f_E = $5;
110 100 my $g_B = $6;
111 100 my $g_E = $7;
112 100 my $identity = ( 100 - $8 ) / 100;
113  
114 100 my $ovlp_len = $f_E - $f_B;
115  
116 100 ▶ printf $out_fh "%s", exists $replace_of->{$f_id} ? $replace_of->{$f_id} : $f_id;
Branch: 1 branch
BranchTrueFalseTotal
exists $replace_of->{$f_id} ? : 50 50 100
117 100 ▶ printf $out_fh "\t%s", exists $replace_of->{$g_id} ? $replace_of->{$g_id} : $g_id;
Branch: 1 branch
BranchTrueFalseTotal
exists $replace_of->{$g_id} ? : 50 50 100
118 100 printf $out_fh "\t%d\t%.3f", $ovlp_len, $identity;
119 100 printf $out_fh "\t%d\t%d\t%d\t%d", 0, $f_B, $f_E, $len_of->{$f_id};
120 100 printf $out_fh "\t%d\t%d\t%d\t%d", $g_ori, $g_B, $g_E, $len_of->{$g_id};
121  
122 # relations
123 100 ▶ if ( ( $len_of->{$g_id} < $len_of->{$f_id} )
Branch: 2 branches
BranchTrueFalseTotal
if ($len_of->{$g_id} < $len_of->{$f_id} and $g_B < 1 and $len_of->{$g_id} - $g_E < 1) { } 30 70 100
elsif ($len_of->{$f_id} < $len_of->{$g_id} and $f_B < 1 and $len_of->{$f_id} - $f_E < 1) { } 30 40 70
Condition100%6/6
$len_of->{$g_id} < $len_of->{$f_id} and $g_B < 1 and $len_of->{$g_id} - $g_E < 1
!ll&&!rl&&r
68230
$len_of->{$g_id} < $len_of->{$f_id} and $g_B < 1
!ll&&!rl&&r
501832
MC/DC100%3/3
$len_of->{$g_id} < $len_of->{$f_id} and $g_B < 1 and $len_of->{$g_id} - $g_E < 1
$len_of->{$g_id} < $len_of->{$f_id} $g_B < 1 $len_of->{$g_id} - $g_E < 1
Truth table100%4/4
A and B and C
A= $len_of->{$g_id} < $len_of->{$f_id}B= $g_B < 1C= $len_of->{$g_id} - $g_E < 1
ABCresult
0XX0
10X0
1100
1111
124 and ( $g_B < 1 )
125 and ( $len_of->{$g_id} - $g_E < 1 ) )
126 {
127 30 printf $out_fh "\tcontains\n";
128 }
129 ▶ elsif ( ( $len_of->{$f_id} < $len_of->{$g_id} )
Condition100%6/6
$len_of->{$f_id} < $len_of->{$g_id} and $f_B < 1 and $len_of->{$f_id} - $f_E < 1
!ll&&!rl&&r
38230
$len_of->{$f_id} < $len_of->{$g_id} and $f_B < 1
!ll&&!rl&&r
201832
MC/DC100%3/3
$len_of->{$f_id} < $len_of->{$g_id} and $f_B < 1 and $len_of->{$f_id} - $f_E < 1
$len_of->{$f_id} < $len_of->{$g_id} $f_B < 1 $len_of->{$f_id} - $f_E < 1
Truth table100%4/4
A and B and C
A= $len_of->{$f_id} < $len_of->{$g_id}B= $f_B < 1C= $len_of->{$f_id} - $f_E < 1
ABCresult
0XX0
10X0
1100
1111
130 and ( $f_B < 1 )
131 and ( $len_of->{$f_id} - $f_E < 1 ) )
132 {
133 30 printf $out_fh "\tcontained\n";
134 }
135 else {
136 40 printf $out_fh "\toverlap\n";
137 }
138 }
139 2 close $in_fh;
140 2 close $out_fh;
141 }
142  
143 11 1;
« blib/lib/App/Dazz/Common.pm ↑ Summary blib/lib/App/Dazz/Command/dazzname.pm »