blib/lib/Bio/Gonzales/Matrix/Util.pm

filter: Statementstmt 40.5% 32 / 79 Branchbran 14.2% 4 / 28 Conditioncond 12.5% 3 / 24 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 50.0% 6 / 12 Podpod 0.0% 0 / 7 totaltotal 27.6% 45 / 163 CC 24 SCAR 33.9
CC
24
Cov
30%
combine_to_matrix
56.0
preview
42.4
as_matrix
20.0
CRAP 29.7
« blib/lib/Bio/Gonzales/Seq/Util.pm ↑ Summary blib/lib/Bio/Gonzales/Phylo/Dendroscope.pm »
1 package Bio::Gonzales::Matrix::Util;
2  
3 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 10 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 10 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 our ( @EXPORT, @EXPORT_OK, %EXPORT_TAGS );
11 10 our $VERSION = '0.062'; # VERSION
12  
13 10 @EXPORT = qw();
14 10 %EXPORT_TAGS = ();
15 10 @EXPORT_OK = qw(uniq_rows uniq_rows_secure as_matrix preview combine_to_matrix xls_idx0_to_a1 xls_range0_to_a1);
16  
17 sub uniq_rows {
18 0 ▶ my $matrix = shift;
Subroutine uniq_rows: not called CC=1 SCAR=6.9
Pod undocumented
19  
20 # http://www.perlmonks.org/?node_id=489796
21  
22 # relaxed
23 0 my %seen;
24 0 my @umatrix = grep { not $seen{ join $;, @$_ }++ } @$matrix;
25  
26 0 return \@umatrix;
27 }
28  
29 sub uniq_rows_secure {
30 0 ▶ my $matrix = shift;
Subroutine uniq_rows_secure: not called CC=1 SCAR=6.9
Pod undocumented
31  
32 # http://www.perlmonks.org/?node_id=489796
33  
34 0 my %seen;
35 0 my @umatrix = grep { not $seen{ join " ", map quotemeta, @$_ }++ } @$matrix;
36  
37 0 return \@umatrix;
38 }
39  
40 sub as_matrix {
41 0 ▶ my $data = shift;
Subroutine as_matrix: not called CC=4 SCAR=30.0
Pod undocumented
42 0 my @m;
43 0 ▶ if ( ref $data eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $data eq "HASH") 0 0 0
44 0 ▶ while ( my ( $k, $v ) = each %$data ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$data) 0 0 0
45 0 ▶ push @m, [ $k, ( ref $v eq 'ARRAY' ? @$v : $v ) ];
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 0 0 0
46 }
47 }
48 0 return \@m;
49 }
50  
51 sub combine_to_matrix {
52 0 ▶ my ( $data, $keys ) = @_;
Subroutine combine_to_matrix: not called CC=7 SCAR=40.3
Pod undocumented
53  
54 0 ▶ if ( !( $keys && @$keys ) && @$data ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $keys && @$keys and @$data) 0 0 0
Condition0%0/6
not $keys && @$keys and @$data
!ll&&!rl&&r
000
$keys && @$keys
!ll&&!rl&&r
000
MC/DC0%0/3
not $keys && @$keys and @$data
$keys @$keys @$data
Truth table0%0/5
not(A && B) and C
A= $keysB= @$keysC= @$data
ABCresult
11X0
0X00
1000
0X11
1011
55 0 $keys = [ sort keys %{ $data->[0] } ];
56 }
57  
58 0 ▶ return unless ( $data && @$data );
Branch: 1 branch
BranchTrueFalseTotal
unless $data and @$data 0 0 0
Condition0%0/3
$data and @$data
!ll&&!rl&&r
000
MC/DC0%0/2
$data and @$data
$data @$data
Truth table0%0/3
A and B
A= $dataB= @$data
ABresult
0X0
100
111
59  
60 0 my @res;
61 0 for my $d (@$data) {
62 0 push @res, [ map { $d->{$_} } @$keys ];
63 }
64 0 return \@res;
65 }
66  
67 sub preview {
68 1 ▶ my ( $m, $c ) = @_;
Subroutine preview: called CC=12 SCAR=37.5
Pod undocumented
69  
70 1 ▶ return unless ( $m && @$m > 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless $m and @$m > 0 0 1 1
Condition33%1/3
$m and @$m > 0
!ll&&!rl&&r
001
MC/DC0%0/2
$m and @$m > 0
$m @$m > 0
Truth table33%1/3
A and B
A= $mB= @$m > 0
ABresult
0X0
100
111
71 1 my @preview;
72 1 ▶ if ( ref $m->[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $m->[0]) { } 1 0 1
73 1 ▶ if ( @$m >= 6 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$m >= 6) { } 1 0 1
74 1 push @preview, @{$m}[ 0 .. 2 ];
75 1 ▶ push @preview, [ ("...") x scalar @{ $m->[0] } ] if ( ( $c->{dots} && @$m > 6 ) || $c->{force_dots} );
Branch: 1 branch
BranchTrueFalseTotal
if $c->{"dots"} and @$m > 6 or $c->{"force_dots"} 1 0 1
Condition33%2/6
$c->{"dots"} and @$m > 6 or $c->{"force_dots"}
l!l&&r!l&&!r
100
$c->{"dots"} and @$m > 6
!ll&&!rl&&r
001
MC/DC0%0/3
$c->{"dots"} and @$m > 6 or $c->{"force_dots"}
$c->{"dots"} @$m > 6 $c->{"force_dots"}
Truth table20%1/5
A and B or C
A= $c->{"dots"}B= @$m > 6C= $c->{"force_dots"}
ABCresult
11X1
0X11
1011
0X00
1000
76 1 push @preview, @{$m}[ -3, -2, -1 ];
77 } else {
78 0 @preview = @$m;
79 }
80 } else {
81 0 ▶ if ( @$m >= 6 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$m >= 6) { } 0 0 0
82 0 push @preview, @{$m}[ 0 .. 2 ];
83  
84 0 ▶ push @preview, '...' if ( ( $c->{dots} && @$m > 6 ) || $c->{force_dots} );
Branch: 1 branch
BranchTrueFalseTotal
if $c->{"dots"} and @$m > 6 or $c->{"force_dots"} 0 0 0
Condition0%0/6
$c->{"dots"} and @$m > 6 or $c->{"force_dots"}
l!l&&r!l&&!r
000
$c->{"dots"} and @$m > 6
!ll&&!rl&&r
000
MC/DC0%0/3
$c->{"dots"} and @$m > 6 or $c->{"force_dots"}
$c->{"dots"} @$m > 6 $c->{"force_dots"}
Truth table0%0/5
A and B or C
A= $c->{"dots"}B= @$m > 6C= $c->{"force_dots"}
ABCresult
11X1
0X11
1011
0X00
1000
85  
86 0 push @preview, @{$m}[ -3, -2, -1 ];
87 } else {
88 0 @preview = @$m;
89 }
90 }
91 1 return \@preview;
92  
93 }
94  
95 sub xls_idx0_to_a1 {
96 0 ▶ my $idx = shift;
Subroutine xls_idx0_to_a1: not called CC=3 SCAR=24.8
Pod undocumented
97  
98 0 my @letters = 'A' .. 'Z';
99  
100 0 my $string_idx = '';
101  
102 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$idx > 0 and do { do { --$idx if $string_idx; $string_idx .= $letters[$idx % 26]; $idx = int $idx / 26 } } 0 0 0
103 0 ▶ $idx-- if ($string_idx);
Branch: 1 branch
BranchTrueFalseTotal
if $string_idx 0 0 0
104 0 $string_idx .= $letters[ ( $idx % 26 ) ];
105 0 $idx = int( $idx / 26 );
106 } while ( $idx > 0 );
107  
108 0 return reverse $string_idx;
109 }
110  
111 sub xls_range0_to_a1 {
112 0 ▶ my $from = shift;
Subroutine xls_range0_to_a1: not called CC=2 SCAR=17.9
Pod undocumented
113 0 my $to = shift;
114 0 ▶ if ( !defined($to) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $to) 0 0 0
115 0 return idx0_to_a1($from) . ":" . idx0_to_a1($from);
116 }
117  
118 0 return idx0_to_a1($from) . ":" . idx0_to_a1($to);
119 }
120  
121 10 1;
« blib/lib/Bio/Gonzales/Seq/Util.pm ↑ Summary blib/lib/Bio/Gonzales/Phylo/Dendroscope.pm »