blib/lib/Microarray/ExprSet.pm

filter: Statementstmt 96.7% 119 / 123 Branchbran 91.3% 42 / 46 Conditioncond 72.7% 8 / 11 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 100% 16 / 16 Podpod 100% 13 / 13 totaltotal 93.0% 201 / 216 CC 29 SCAR 18.3
CC
29
Cov
94%
unique_features
12.0
is_valid
8.0
remove_empty_features
5.0
CRAP 6.2
↑ Summary
1 package Microarray::ExprSet;
2  
3 # Simple description of microarray data
4 # contains three elements
5 # data matrix
6 # feature (gene) names array
7 # sample names array
8  
9 5 ▶use List::Vectorize;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 our $VERSION = "0.11";
14  
15 5 1;
16  
17  
18 4 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
19  
20 4 my $invocant = shift;
21 4 ▶ my $class = ref($invocant) || $invocant;
Condition66%2/3
ref $invocant || $invocant
l!l&&r!l&&!r
130
MC/DC0%0/2
ref $invocant || $invocant
ref $invocant $invocant
Truth table66%2/3
A || B
A= ref $invocantB= $invocant
ABresult
1X1
011
000
22 4 my $self = { feature => undef,
23 phenotype => undef,
24 matrix => undef,
25 error => undef,};
26 4 bless($self, $class);
27 4 return $self;
28
29 }
30  
31  
32 # probe name
33 35 ▶sub feature {
Subroutine feature: called CC=1 SCAR=0.0
Pod documented
34  
35 35 my $self = shift;
36
37 35 return $self->{feature};
38  
39 }
40  
41 11 ▶sub set_feature {
Subroutine set_feature: called CC=1 SCAR=0.0
Pod documented
42
43 11 my $self = shift;
44
45 11 List::Vectorize::check_prototype(@_, '\@');
46
47 10 my $feature = shift;
48
49 10 $self->{feature} = $feature;
50
51 10 return $self;
52  
53 }
54  
55 # sample name
56 20 ▶sub phenotype {
Subroutine phenotype: called CC=1 SCAR=0.0
Pod documented
57
58 20 my $self = shift;
59
60 20 return $self->{phenotype};
61  
62 }
63  
64 5 ▶sub set_phenotype {
Subroutine set_phenotype: called CC=1 SCAR=0.0
Pod documented
65
66 5 my $self = shift;
67
68 5 List::Vectorize::check_prototype(@_, '\@');
69
70 4 my $phenotype = shift;
71
72 4 $self->{phenotype} = $phenotype;
73
74 4 return $self;
75
76 }
77  
78 10 ▶sub set_matrix {
Subroutine set_matrix: called CC=3 SCAR=11.0
Pod documented
79  
80 10 my $self = shift;
81
82 10 List::Vectorize::check_prototype(@_, '\@');
83
84 10 my $matrix = shift;
85
86 # check whether it is a valid matrix
87 10 my ($nr, $nc) = dim($matrix);
88 10 ▶ if(!defined($nr) or !defined($nc)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nr and defined $nc) 1 9 10
Condition66%2/3
defined $nr and defined $nc
!ll&&!rl&&r
109
MC/DC50%1/2
defined $nr and defined $nc
defined $nr defined $nc
Truth table66%2/3
A and B
A= defined $nrB= defined $nc
ABresult
0X0
100
111
89 1 croak "ERROR: Not a valid matrix";
90 }
91
92 9 $self->{matrix} = $matrix;
93
94 9 return $self;
95
96 }
97  
98 34 ▶sub matrix {
Subroutine matrix: called CC=1 SCAR=0.0
Pod documented
99
100 34 my $self = shift;
101
102 34 return $self->{matrix};
103  
104 }
105  
106 12 ▶sub is_valid {
Subroutine is_valid: called CC=8 SCAR=20.8
Pod documented
107
108 12 my $self = shift;
109 12 $self->{error} = undef;
110
111 12 ▶ if(defined($self->matrix)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->matrix) { } 11 1 12
112
113 11 my ($nr, $nc) = dim($self->matrix);
114
115 11 ▶ if(!defined($nr) or !defined($nc)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nr and defined $nc) 1 10 11
Condition66%2/3
defined $nr and defined $nc
!ll&&!rl&&r
1010
MC/DC50%1/2
defined $nr and defined $nc
defined $nr defined $nc
Truth table66%2/3
A and B
A= defined $nrB= defined $nc
ABresult
0X0
100
111
116 1 $self->{error} = "Not a matrix";
117 1 return 0;
118 }
119
120 10 ▶ if(defined($self->feature)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->feature) 8 2 10
121 8 ▶ if(len($self->feature) != $nr) {
Branch: 1 branch
BranchTrueFalseTotal
if (len($self->feature) != $nr) 3 5 8
122 3 $self->{error} = "Length of feature names is not identical to the number of matrix rows";
123 3 return 0;
124 }
125 }
126
127 7 ▶ if(defined($self->phenotype)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->phenotype) 6 1 7
128 6 ▶ if(len($self->phenotype) != $nc) {
Branch: 1 branch
BranchTrueFalseTotal
if (len($self->phenotype) != $nc) 1 5 6
129 1 $self->{error} = "Length of phenotype names is not identical to the number of matrix columns";
130 1 return 0;
131 }
132 }
133 }
134 else {
135 1 $self->{error} = "Expression matrix is not defined";
136 1 return 0;
137 }
138
139 6 return 1;
140 }
141  
142  
143 2 ▶sub remove_empty_features {
Subroutine remove_empty_features: called CC=5 SCAR=16.1
Pod documented
144  
145 2 my $self = shift;
146
147 2 my $old_feature = $self->feature;
148 2 my $old_matrix = $self->matrix;
149
150 2 ▶ if(is_empty($old_feature)) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_empty($old_feature)) { } 0 2 2
elsif (not $self->is_valid) { } 1 1 2
151 0 carp "WARN: Feature names are empty. ";
152 }
153 elsif(! $self->is_valid) {
154 1 croak $self->{error};
155 }
156
157 1 my $new_feature;
158 my $new_matrix;
159
160 1 ▶ for(my $i = 0; $i < len($old_feature); $i ++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < len($old_feature)) 6 1 7
161
162 6 ▶ if($old_feature->[$i] !~ /^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($old_feature->[$i] =~ /^\s*$/) 5 1 6
163 5 push(@$new_feature, $old_feature->[$i]);
164 5 push(@$new_matrix, $old_matrix->[$i]);
165 }
166 }
167
168 1 $self->set_feature($new_feature);
169 1 $self->set_matrix($new_matrix);
170 1 undef($old_feature);
171 1 undef($old_matrix);
172  
173 1 return $self;
174 }
175  
176 1 ▶sub n_feature {
Subroutine n_feature: called CC=1 SCAR=0.0
Pod documented
177
178 1 my $self = shift;
179
180 1 return len($self->feature);
181  
182 }
183  
184 1 ▶sub n_phenotype {
Subroutine n_phenotype: called CC=1 SCAR=0.0
Pod documented
185
186 1 my $self = shift;
187
188 1 return len($self->phenotype);
189  
190 }
191  
192 # using mean or median
193 3 ▶sub unique_features {
Subroutine unique_features: called CC=12 SCAR=24.9
Pod documented
194
195 3 my $self = shift;
196 3 ▶ my $method = shift || "mean";
Condition100%2/2
shift() || 'mean'
l!l
21
MC/DC100%1/1
shift() || 'mean'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
197
198 3 my $fun;
199 3 ▶ if($method eq "mean") {
Branch: 2 branches
BranchTrueFalseTotal
if ($method eq 'mean') { } 1 2 3
elsif ($method eq 'median') { } 1 1 2
200 1 $fun = \&mean;
201 }
202 elsif($method eq "median") {
203 1 $fun = \&median;
204 }
205 else {
206 1 $fun = \&mean;
207 }
208
209 3 my $fh;
210 3 my $feature = $self->feature;
211
212 3 ▶ if(is_empty($feature)) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_empty($feature)) { } 0 3 3
elsif (not $self->is_valid) { } 1 2 3
213 0 carp "WARN: Feature names are empty. ";
214 }
215 elsif(! $self->is_valid) {
216 1 croak $self->{error};
217 }
218
219 2 ▶ for(my $i = 0; $i < len($feature); $i ++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < len($feature)) 9 2 11
220 9 ▶ if($fh->{$feature->[$i]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$fh{$feature->[$i]}) { } 3 6 9
221 3 push(@{$fh->{$feature->[$i]}}, $i);
222 }
223 else {
224 6 $fh->{$feature->[$i]}->[0] = $i;
225 }
226 }
227  
228 2 my $new_feature;
229 my $new_matrix;
230 2 my $matrix = $self->matrix;
231 2 foreach my $f (keys %$fh) {
232
233 6 my $index = $fh->{$f};
234 6 push(@$new_feature, $f);
235
236 6 ▶ if(len($index) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (len($index) == 1) { } 4 2 6
237 4 push(@$new_matrix, $matrix->[$index->[0]]);
238 }
239 else {
240 2 my $new_array;
241 2 ▶ for(my $i = 0; $i < len($matrix->[0]); $i ++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < len($matrix->[0])) 12 2 14
242 12 my $tmp_array;
243 12 ▶ for(my $j = 0; $j < len($index); $j ++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < len($index)) 30 12 42
244
245 30 push(@$tmp_array, $matrix->[$index->[$j]]->[$i]);
246
247 }
248 12 push(@$new_array, &$fun($tmp_array));
249 }
250 2 push(@$new_matrix, $new_array);
251 }
252 }
253
254 2 $self->set_feature($new_feature);
255 2 $self->set_matrix($new_matrix);
256 2 undef($feature);
257 2 undef($matrix);
258  
259 2 return $self;
260 }
261  
262 4 ▶sub save {
Subroutine save: called CC=4 SCAR=14.6
Pod documented
263
264 4 my $self = shift;
265
266 4 List::Vectorize::check_prototype(@_, '$');
267
268 4 my $file = shift;
269
270 4 ▶ if(is_empty($self->feature)) {
Branch: 3 branches
BranchTrueFalseTotal
if (is_empty($self->feature)) { } 0 4 4
elsif (is_empty($self->phenotype)) { } 3 1 4
elsif (not $self->is_valid) { } 0 1 1
271 0 croak "ERROR: Feature names are required. ";
272 } elsif(is_empty($self->phenotype)) {
273 3 croak "ERROR: Phenotype names are required. ";
274 } elsif(! $self->is_valid) {
275 0 croak "ERROR: not a valid ".__PACKAGE__." object";
276 }
277
278 1 write_table($self->matrix, "file" => $file, "row.names" => $self->feature, "col.names" => $self->phenotype);
279
280 1 return 1;
281 }
282  
283  
284 __END__
↑ Summary