| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | while ( my ( $k, $v ) = each %$data ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | push @m, [ $k, ( ref $v eq 'ARRAY' ? @$v : $v ) ]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
not $keys && @$keys and @$data
$keys && @$keys
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $keys = [ sort keys %{ $data->[0] } ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | return unless ( $data && @$data ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$data and @$data
MC/DC0%0/2
$data and @$data
$data
@$data
Truth table0%0/3
A and B
A= $dataB= @$data
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$m and @$m > 0
MC/DC0%0/2
$m and @$m > 0
$m
@$m > 0
Truth table33%1/3
A and B
A= $mB= @$m > 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | my @preview; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | if ( ref $m->[0] ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | if ( @$m >= 6 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$c->{"dots"} and @$m > 6 or $c->{"force_dots"}
$c->{"dots"} and @$m > 6
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | push @preview, @{$m}[ 0 .. 2 ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | push @preview, '...' if ( ( $c->{dots} && @$m > 6 ) || $c->{force_dots} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$c->{"dots"} and @$m > 6 or $c->{"force_dots"}
$c->{"dots"} and @$m > 6
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | $idx-- if ($string_idx); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||||||||