Microarray/File/Data.pm

filter: Statementstmt 12.0% 20 / 166 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 12.8% 5 / 39 Podpod n/a totaltotal 10.3% 25 / 242 CC 21 SCAR 22.5
CC
21
Cov
10%
new
30.0
get_spots
20.0
log2_ratio
20.0
CRAP 9.5
« Microarray/File/GAL.pm ↑ Summary Microarray.pm »
1 package Microarray::File::Data;
2  
3 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 our $VERSION = '2.22';
7  
8 3 require Microarray::File;
9 3 require Microarray::Spot;
10  
11 { package data_file;
12  
13 3 our @ISA = qw( delimited_file );
14  
15 0 ▶ sub new {
Subroutine new: not called CC=5 SCAR=34.0
16 0 my $class = shift;
17 0 my $self = { };
18 0 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
19 0 $self->{ _file_name } = shift; # shift in file name
20 0 bless $self, $class;
21 0 ▶ $self->set_filehandle(shift) if (@_); # Fh is passed from CGI
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
22 0 ▶ if ($class eq 'data_file'){
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq "data_file") 0 0 0
23 # try and guess which file type we're dealing with
24 0 ▶ if(my $new_class = $self->guess_class){
Branch: 1 branch
BranchTrueFalseTotal
if (my $new_class = $self->guess_class) 0 0 0
25 # we've found a better match, recreate ourself
26 0 my $file_name = $self->file_name;
27 0 my $source = $self->get_source;
28 0 $self = { _file_name => $file_name,
29 _source => $source
30 };
31 0 bless $self,$new_class;
32 }
33 }
34 0 $self->import_data;
35 } else {
36 0 bless $self, $class;
37 }
38 0 return $self;
39 }
40 0 ▶ sub guess_class {
Subroutine guess_class: not called CC=5 SCAR=29.9
41 3 ▶ use Module::List qw(list_modules);
Subroutine BEGIN: called CC=1 SCAR=0.0
42 0 my $self = shift;
43
44 0 my $source = $self->get_source;
45
46 0 my $hModules = list_modules('Microarray::File::Data::',{list_modules=>1,list_prefixes=>1});
47 0 for my $module (keys %$hModules){
48 0 eval "require $module";
49 0 ▶ next unless ($module->can('auto_data_file'));
Branch: 1 branch
BranchTrueFalseTotal
unless $module->can("auto_data_file") 0 0 0
50 0 ▶ if (my ($class,$search_term) = $module->auto_data_file){
Branch: 1 branch
BranchTrueFalseTotal
if (() = $module->auto_data_file) 0 0 0
51 0 ▶ return $class if ($source =~ /$search_term/i);
Branch: 1 branch
BranchTrueFalseTotal
if $source =~ /$search_term/i 0 0 0
52 }
53 }
54 0 warn "Microarray::File::Data ERROR: Could not deduce the type of file from '".$self->file_name."'\n";
55 0 return;
56 }
57 0 ▶ sub import_data {
Subroutine import_data: not called CC=1 SCAR=6.9
58 0 my $self = shift;
59 0 my $aaData = $self->load_file_data;
60 0 $self->sort_data($aaData);
61 }
62  
63 # _spot_data = scanner data imported as array of arrays
64 #Ê_data_fields = column field names and indeces
65 # _header_info = scanner set up information from the data file header
66 # _spots = spot objects
67 0 ▶ sub sort_data {
Subroutine sort_data: not called CC=1 SCAR=6.9
68 0 my $self = shift;
69 0 my $aaData = shift;
70 0 $self->set_data_fields(shift @$aaData); # method in class delimited_file
71 0 $self->{ _spot_data } = $aaData; # all the numbers
72 0 $self->{ _spot_count } = scalar @$aaData;
73 }
74 # not anything to do with the above, but instead is the data
75 # sorted on any specific field other than spot_index -
76 # used to discriminate processed_data from other data
77 0 ▶ sub comes_sorted {
Subroutine comes_sorted: not called CC=1 SCAR=6.9
78 0 return;
79 }
80 # the size of the data array after removing data fields
81 # for the number of spot OBJECTS created, use number_spots()
82 0 ▶ sub spot_count {
Subroutine spot_count: not called CC=1 SCAR=6.9
83 0 my $self = shift;
84 0 $self->{ _spot_count };
85 }
86 0 ▶ sub import_header_info { # import a hash ref containing header information
Subroutine import_header_info: not called CC=1 SCAR=6.9
87 0 my $self = shift;
88 0 $self->{ _header_info } = shift;
89 }
90 # sets spot objects for all data in one go
91 0 ▶ sub set_spot_objects {
Subroutine set_spot_objects: not called CC=3 SCAR=24.8
92 0 my $self = shift;
93 0 my $aaData = $self->spot_data;
94 0 my $aData_Fields = $self->data_file_fields; # required data fields from any data file format
95 0 my $spot_object_count = 0; # count of number of objects created
96 0 ▶ for (my $i=0; $i<@$aaData; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$aaData) 0 0 0
97 0 my $oSpot = array_spot->new(); # new spot object
98 0 for my $field (@$aData_Fields){ # each spot field name
99 0 $oSpot->$field($self->$field($i)); #Êfill the spot object with the spot_row data
100 }
101 # add spot object to data_file
102 0 $self->add_spot($oSpot);
103 0 $spot_object_count++;
104 }
105 0 $self->number_spots($spot_object_count);
106 }
107 # the data array
108 0 ▶ sub spot_data {
Subroutine spot_data: not called CC=1 SCAR=6.9
109 0 my $self = shift;
110 0 $self->{ _spot_data };
111 }
112 # return a spot object for a specific index
113 0 ▶ sub spot_object {
Subroutine spot_object: not called CC=3 SCAR=24.8
114 0 my $self = shift;
115 0 my $index = shift;
116 0 ▶ if (my $oSpot = $self->get_spots($index)){
Branch: 1 branch
BranchTrueFalseTotal
if (my $oSpot = $self->get_spots($index)) { } 0 0 0
117 0 return $oSpot;
118 } else {
119 0 my $aData_Fields = $self->data_file_fields; # required data fields from any data file format
120 0 my $oSpot = array_spot->new(); # new spot object
121 0 for my $field (@$aData_Fields){ # each spot field name
122 0 $oSpot->$field($self->$field($index-1)); #Êfill the spot object with the spot_row data
123 }
124 0 return $oSpot;
125 }
126 }
127
128 # adds spot objects to the arrayref held in { _spots }
129 # NOTE: the zero index in this arrayref is a count of the total number of spots,
130 # and spots are placed in the array index corresponding to their "spot index"
131 0 ▶ sub add_spot {
Subroutine add_spot: not called CC=1 SCAR=6.9
132 0 my $self = shift;
133 0 my $oSpot = shift;
134 0 my $aSpots = $self->get_spots;
135 0 $$aSpots[ $oSpot->spot_index ] = $oSpot;
136 }
137 # the total number of spot OBJECTS in the array
138 # for number of spots counted from data array length, use spot_count()
139 0 ▶ sub number_spots {
Subroutine number_spots: not called CC=2 SCAR=17.9
140 0 my $self = shift;
141 0 my $aSpots = $self->get_spots;
142 0 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
143 0 $$aSpots[0] = shift; # set from set_spot_objects()
144 } else {
145 0 $$aSpots[0]; # first index is the number of spots
146 }
147 }
148 # the spots objects are stored as an array ref
149 # each spot is placed at the array index that matches the spot index
150 # THEREFORE THE INDEX[0] DOES NOT CONTAIN A SPOT!
151 0 ▶ sub get_spots {
Subroutine get_spots: not called CC=4 SCAR=30.0
152 0 my $self = shift;
153 0 ▶ unless (defined $self->{ _spots }){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_spots"}) 0 0 0
154 0 $self->{ _spots } = [];
155 }
156 0 ▶ if (@_) { # passed a spot index
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
157 0 my $index = shift;
158 0 ▶ return unless (defined $self->{ _spots }[$index]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_spots"}[$index] 0 0 0
159 0 $self->{ _spots }[$index];
160 } else { # return all objects
161 0 $self->{ _spots };
162 }
163 }
164 0 ▶ sub data_file_fields { # minimum required fields
Subroutine data_file_fields: not called CC=1 SCAR=6.9
165 0 [ 'spot_index','feature_id','synonym_id',
166 'channel1_signal','channel2_signal',
167 'channel1_quality','channel2_quality',
168 'block_row','block_col',
169 'spot_diameter','flag_id',
170 'spot_row','spot_col','x_pos','y_pos',
171 'ch1_mean_f','ch1_median_b','ch2_mean_f','ch2_median_b',
172 'channel1_snr','channel2_snr',
173 'log2_ratio'];
174 }
175 0 ▶ sub return_data {
Subroutine return_data: not called CC=1 SCAR=6.9
176 0 my $self = shift;
177 0 my $aaData = $self->spot_data;
178 0 return $aaData->[shift][shift];
179 }
180 0 ▶ sub image_file_names {
Subroutine image_file_names: not called CC=1 SCAR=6.9
181 0 my $self = shift;
182 0 return ($self->channel1_image_file,$self->channel2_image_file);
183 }
184 0 ▶ sub fluor_names {
Subroutine fluor_names: not called CC=1 SCAR=6.9
185 0 my $self = shift;
186 0 return ($self->channel1_name,$self->channel2_name);
187 }
188 0 ▶ sub laser_powers {
Subroutine laser_powers: not called CC=1 SCAR=6.9
189 0 my $self = shift;
190 0 return ($self->channel1_laser,$self->channel2_laser);
191 }
192 0 ▶ sub pmt_voltages {
Subroutine pmt_voltages: not called CC=1 SCAR=6.9
193 0 my $self = shift;
194 0 return ($self->channel1_pmt,$self->channel2_pmt);
195 }
196  
197 ### calculated fields ###
198 0 ▶ sub channel1_signal {
Subroutine channel1_signal: not called CC=1 SCAR=6.9
199 0 my $self = shift;
200 0 my $index = shift;
201 0 $self->ch1_mean_f($index) - $self->ch1_median_b($index);
202 }
203 0 ▶ sub channel2_signal {
Subroutine channel2_signal: not called CC=1 SCAR=6.9
204 0 my $self = shift;
205 0 my $index = shift;
206 0 $self->ch2_mean_f($index) - $self->ch2_median_b($index);
207 }
208 0 ▶ sub log2_ratio {
Subroutine log2_ratio: not called CC=4 SCAR=30.0
209 0 my $self = shift;
210 0 my $index = shift;
211 0 my $ch1 = $self->channel1_signal($index);
212 0 my $ch2 = $self->channel2_signal($index);
213 0 ▶ return if (($ch1 <= 0) || ($ch2 <= 0));
Branch: 1 branch
BranchTrueFalseTotal
if $ch1 <= 0 or $ch2 <= 0 0 0 0
Condition0%0/3
$ch1 <= 0 or $ch2 <= 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$ch1 <= 0 or $ch2 <= 0
$ch1 <= 0 $ch2 <= 0
Truth table0%0/3
A or B
A= $ch1 <= 0B= $ch2 <= 0
ABresult
1X1
011
000
214 0 ▶ if ($self->flip_flop == 1){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->flip_flop == 1) { } 0 0 0
215 0 return log($ch1/$ch2)/log(2);
216 } else {
217 0 return log($ch2/$ch1)/log(2);
218 }
219 }
220 0 ▶ sub flip_flop {
Subroutine flip_flop: not called CC=2 SCAR=17.9
221 0 my $self = shift;
222 0 ▶ if (defined $self->{ _flip_flop }){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'_flip_flop'}) { } 0 0 0
223 0 $self->{ _flip_flop };
224 } else {
225 0 return 1;
226 }
227 }
228 0 ▶ sub flip {
Subroutine flip: not called CC=1 SCAR=6.9
229 0 my $self = shift;
230 0 $self->{ _flip_flop } = -1;
231 }
232 0 ▶ sub flop {
Subroutine flop: not called CC=1 SCAR=6.9
233 0 my $self = shift;
234 0 $self->{ _flip_flop } = 1;
235 }
236 0 ▶ sub channel_signal {
Subroutine channel_signal: not called CC=1 SCAR=6.9
237 0 my $self = shift;
238 0 my $index = shift;
239 0 my $ch = shift;
240 0 my $method = 'channel'.$ch.'_signal';
241 0 $self->$method($index);
242 }
243 0 ▶ sub channel1_snr {
Subroutine channel1_snr: not called CC=1 SCAR=6.9
244 0 my $self = shift;
245 0 my $index = shift;
246 0 $self->ch1_median_f($index) / $self->ch1_sd_b($index);
247 }
248 0 ▶ sub channel2_snr {
Subroutine channel2_snr: not called CC=1 SCAR=6.9
249 0 my $self = shift;
250 0 my $index = shift;
251 0 $self->ch2_median_f($index) / $self->ch2_sd_b($index);
252 }
253 0 ▶ sub channel_snr {
Subroutine channel_snr: not called CC=1 SCAR=6.9
254 0 my $self = shift;
255 0 my $index = shift;
256 0 my $ch = shift;
257 0 my $method = 'channel'.$ch.'_snr';
258 0 $self->$method($index);
259 }
260 0 ▶ sub channel_quality {
Subroutine channel_quality: not called CC=1 SCAR=6.9
261 0 my $self = shift;
262 0 my $index = shift;
263 0 my $ch = shift;
264 0 my $method = 'channel'.$ch.'_quality';
265 0 $self->$method($index);
266 }
267 0 ▶ sub channel_sat {
Subroutine channel_sat: not called CC=1 SCAR=6.9
268 0 my $self = shift;
269 0 my $index = shift;
270 0 my $ch = shift;
271 0 my $method = 'channel'.$ch.'_sat';
272 0 $self->$method($index);
273 }
274 0 ▶ sub guess_barcode {
Subroutine guess_barcode: not called CC=1 SCAR=1.7
275 3 ▶ use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
276 0 my $self = shift;
277 0 my $file = basename($self->file_name);
278 0 my @aName = split(/-|_| /,$file);
279 0 return $aName[0];
280 }
281 0 ▶ sub channel_image_file {
Subroutine channel_image_file: not called CC=1 SCAR=6.9
282 0 my $self = shift;
283 0 my $ch = shift;
284 0 my $method = "channel".$ch."_image_file";
285 0 $self->$method;
286 }
287 0 ▶ sub num_channels {
Subroutine num_channels: not called CC=1 SCAR=6.9
288 0 2
289 }
290
291 }
292  
293  
294 3 1;
295  
296  
297 __END__
« Microarray/File/GAL.pm ↑ Summary Microarray.pm »