line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::Gonzales::Matrix::Util; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
119170
|
use warnings; |
|
9
|
|
|
|
|
34
|
|
|
9
|
|
|
|
|
351
|
|
4
|
9
|
|
|
9
|
|
65
|
use strict; |
|
9
|
|
|
|
|
33
|
|
|
9
|
|
|
|
|
181
|
|
5
|
9
|
|
|
9
|
|
71
|
use Carp; |
|
9
|
|
|
|
|
26
|
|
|
9
|
|
|
|
|
517
|
|
6
|
|
|
|
|
|
|
|
7
|
9
|
|
|
9
|
|
198
|
use 5.010; |
|
9
|
|
|
|
|
64
|
|
8
|
|
|
|
|
|
|
|
9
|
9
|
|
|
9
|
|
54
|
use base 'Exporter'; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
8962
|
|
10
|
|
|
|
|
|
|
our ( @EXPORT, @EXPORT_OK, %EXPORT_TAGS ); |
11
|
|
|
|
|
|
|
our $VERSION = '0.083'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
@EXPORT = qw(); |
14
|
|
|
|
|
|
|
%EXPORT_TAGS = (); |
15
|
|
|
|
|
|
|
@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
|
|
|
0
|
0
|
0
|
my $matrix = shift; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# http://www.perlmonks.org/?node_id=489796 |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# relaxed |
23
|
0
|
|
|
|
|
0
|
my %seen; |
24
|
0
|
|
|
|
|
0
|
my @umatrix = grep { not $seen{ join $;, @$_ }++ } @$matrix; |
|
0
|
|
|
|
|
0
|
|
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
0
|
return \@umatrix; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub uniq_rows_secure { |
30
|
0
|
|
|
0
|
0
|
0
|
my $matrix = shift; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# http://www.perlmonks.org/?node_id=489796 |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
0
|
my %seen; |
35
|
0
|
|
|
|
|
0
|
my @umatrix = grep { not $seen{ join " ", map quotemeta, @$_ }++ } @$matrix; |
|
0
|
|
|
|
|
0
|
|
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
return \@umatrix; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub as_matrix { |
41
|
0
|
|
|
0
|
0
|
0
|
my $data = shift; |
42
|
0
|
|
|
|
|
0
|
my @m; |
43
|
0
|
0
|
|
|
|
0
|
if ( ref $data eq 'HASH' ) { |
44
|
0
|
|
|
|
|
0
|
while ( my ( $k, $v ) = each %$data ) { |
45
|
0
|
0
|
|
|
|
0
|
push @m, [ $k, ( ref $v eq 'ARRAY' ? @$v : $v ) ]; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
0
|
return \@m; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub combine_to_matrix { |
52
|
0
|
|
|
0
|
0
|
0
|
my ( $data, $keys ) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
0
|
|
|
0
|
if ( !( $keys && @$keys ) && @$data ) { |
|
|
|
0
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
$keys = [ sort keys %{ $data->[0] } ]; |
|
0
|
|
|
|
|
0
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
0
|
|
|
0
|
return unless ( $data && @$data ); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
my @res; |
61
|
0
|
|
|
|
|
0
|
for my $d (@$data) { |
62
|
0
|
|
|
|
|
0
|
push @res, [ map { $d->{$_} } @$keys ]; |
|
0
|
|
|
|
|
0
|
|
63
|
|
|
|
|
|
|
} |
64
|
0
|
|
|
|
|
0
|
return \@res; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub preview { |
68
|
1
|
|
|
1
|
0
|
142
|
my ( $m, $c ) = @_; |
69
|
|
|
|
|
|
|
|
70
|
1
|
50
|
33
|
|
|
9
|
return unless ( $m && @$m > 0 ); |
71
|
1
|
|
|
|
|
2
|
my @preview; |
72
|
1
|
50
|
|
|
|
5
|
if ( ref $m->[0] ) { |
73
|
1
|
50
|
|
|
|
4
|
if ( @$m >= 6 ) { |
74
|
1
|
|
|
|
|
2
|
push @preview, @{$m}[ 0 .. 2 ]; |
|
1
|
|
|
|
|
4
|
|
75
|
1
|
50
|
33
|
|
|
11
|
push @preview, [ ("...") x scalar @{ $m->[0] } ] if ( ( $c->{dots} && @$m > 6 ) || $c->{force_dots} ); |
|
1
|
|
33
|
|
|
5
|
|
76
|
1
|
|
|
|
|
4
|
push @preview, @{$m}[ -3, -2, -1 ]; |
|
1
|
|
|
|
|
3
|
|
77
|
|
|
|
|
|
|
} else { |
78
|
0
|
|
|
|
|
0
|
@preview = @$m; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} else { |
81
|
0
|
0
|
|
|
|
0
|
if ( @$m >= 6 ) { |
82
|
0
|
|
|
|
|
0
|
push @preview, @{$m}[ 0 .. 2 ]; |
|
0
|
|
|
|
|
0
|
|
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
0
|
|
|
0
|
push @preview, '...' if ( ( $c->{dots} && @$m > 6 ) || $c->{force_dots} ); |
|
|
|
0
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
0
|
push @preview, @{$m}[ -3, -2, -1 ]; |
|
0
|
|
|
|
|
0
|
|
87
|
|
|
|
|
|
|
} else { |
88
|
0
|
|
|
|
|
0
|
@preview = @$m; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
1
|
|
|
|
|
5
|
return \@preview; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub xls_idx0_to_a1 { |
96
|
0
|
|
|
0
|
0
|
|
my $idx = shift; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my @letters = 'A' .. 'Z'; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $string_idx = ''; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
do { |
103
|
0
|
0
|
|
|
|
|
$idx-- if ($string_idx); |
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
|
|
|
0
|
0
|
|
my $from = shift; |
113
|
0
|
|
|
|
|
|
my $to = shift; |
114
|
0
|
0
|
|
|
|
|
if ( !defined($to) ) { |
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
|
|
|
|
|
|
|
1; |