Microarray/File/Data/Manor_Output.pm untested

filter: Statementstmt 0.0% 0 / 106 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 13 totaltotal 0.0% 0 / 158 CC 12 SCAR 18.2
CC
12
Cov
0%
get_data
12.0
set_manor_data
12.0
get_locations
6.0
CRAP 6.1
1 package Microarray::File::Data::Manor_Output;
2  
3 use 5.006;
4 use strict;
5 use warnings;
6 our $VERSION = '1.8';
7  
8 # not yet tested
9  
10 { package manor_clone_level;
11  
12 require Microarray::File;
13  
14 our @ISA = qw( simple_delimited_file );
15  
16 sub import_data {
17 my $self = shift;
18 my $aaData = $self->load_file_data; # from package delimited_file
19 my $line_num = @$aaData;
20 $self->line_num($line_num-1); # ignore column header
21 $self->sort_data($aaData);
22 $self->set_manor_data;
23 }
24 sub get_data {
25 my $self = shift;
26 if (wantarray()) {
27 return ($self->get_all_locations,$self->get_all_log2,$self->get_all_bacs);
28 } elsif (defined wantarray()) { # scalar context
29 my $hData = { };
30 my $aChr = $self->chromosomes_seen;
31 for my $chr (@$aChr){
32 $hData->{ $chr } = [$self->get_locations($chr),$self->get_log2($chr),$self->get_bacs($chr)];
33 }
34 return $hData;
35 }
36 }
37 sub set_manor_data {
38 my $self = shift;
39
40 my $aaData = $self->get_imported_data;
41
42 # get which column indexes of the data we'll be using
43 my $log_col = $self->get_column_id('LogRatio');
44 my $locn_col = $self->get_column_id('Position');
45 my $chrom_col = $self->get_column_id('Chromosome');
46 my $bac_col = $self->get_column_id('Name');
47  
48 my $last_name = "";
49 my %hChromosomes = ();
50
51 for my $aData_Row (@$aaData){
52 my $bac_name = $aData_Row->[$bac_col];
53 next if ($last_name eq $bac_name);
54 $last_name = $bac_name;
55  
56 my $log2 = $aData_Row->[$log_col]; # spot log2 ch1/ch2 value
57 next if ($log2 eq 'NA');
58  
59 my $chromosome = $aData_Row->[$chrom_col];
60 my $chr_locn = $aData_Row->[$locn_col]; # bp location
61 $self->set_values($chromosome,$chr_locn,$log2,$bac_name);
62 $hChromosomes{ $chromosome }++;
63 }
64 my @aChromosomes = keys %hChromosomes;
65 $self->chromosomes_seen(\@aChromosomes);
66 }
67 sub set_values {
68 my $self = shift;
69 my ($chromosome,$chr_locn,$log2,$bac_name) = @_;
70
71 my $aLocns = $self->get_locations($chromosome);
72 my $aLog2 = $self->get_log2($chromosome);
73 my $aBacs = $self->get_bacs($chromosome);
74
75 push(@$aLocns,$chr_locn);
76 push(@$aLog2,$log2);
77 push(@$aBacs,$bac_name);
78 }
79 sub get_locations {
80 my $self = shift;
81 my $chr = shift;
82 unless(defined $self->{ "_locns_$chr" }){
83 $self->{ "_locns_$chr" } = [];
84 }
85 return $self->{ "_locations_$chr" };
86 }
87 sub get_log2 {
88 my $self = shift;
89 my $chr = shift;
90 unless(defined $self->{ "_log2_$chr" }){
91 $self->{ "_log2_$chr" } = [];
92 }
93 return $self->{ "_log2_$chr" };
94 }
95 sub get_bacs {
96 my $self = shift;
97 my $chr = shift;
98 unless(defined $self->{ "_bacs_$chr" }){
99 $self->{ "_bacs_$chr" } = [];
100 }
101 return $self->{ "_bacs_$chr" };
102 }
103 sub get_all_locations {
104 my $self = shift;
105 unless(defined $self->{ _all_locns }){
106 my $aLocations = [];
107 for my $chr ((1..24)){
108 my $aChr_Locn = $self->get_locations($chr);
109 my @aLocn = map $_ + genomic_locn($chr), @$aChr_Locn;
110 push(@$aLocations,\@aLocn);
111 }
112 $self->{ _all_locns } = $aLocations;
113 }
114 $self->{ _all_locns };
115 }
116 sub get_all_log2 {
117 my $self = shift;
118 unless(defined $self->{ _all_log2 }){
119 my $aLog2 = [];
120 for my $chr ((1..24)){
121 push(@$aLog2,$self->get_log2($chr));
122 }
123 $self->{ _all_log2 } = $aLog2;
124 }
125 $self->{ _all_log2 };
126 }
127 sub get_all_bacs {
128 my $self = shift;
129 unless(defined $self->{ _all_bacs }){
130 my $aBacs = [];
131 for my $chr ((1..24)){
132 push(@$aBacs,$self->get_bacs($chr));
133 }
134 $self->{ _all_bacs } = $aBacs;
135 }
136 $self->{ _all_bacs };
137 }
138 sub chromosomes_seen {
139 my $self = shift;
140 @_ ? $self->{ _chromosomes_seen } = shift
141 : $self->{ _chromosomes_seen };
142 }
143 sub chr_length { # NCBI36 figures
144 my $chromosome = shift;
145 my %hLengths = (
146 1 => 247249719,
147 2 => 242951149,
148 3 => 199501827,
149 4 => 191273063,
150 5 => 180857866,
151 6 => 170899992,
152 7 => 158821424,
153 8 => 146274826,
154 9 => 140273252,
155 10 => 135374737,
156 11 => 134452384,
157 12 => 132349534,
158 13 => 114142980,
159 14 => 106368585,
160 15 => 100338915,
161 16 => 88827254,
162 17 => 78774742,
163 18 => 76117153,
164 19 => 63811651,
165 20 => 62435964,
166 21 => 46944323,
167 22 => 49691432,
168 23 => 154913754,
169 24 => 57772954 # TOTAL=3080419480
170 );
171 return $hLengths{$chromosome};
172 }
173 sub genomic_locn { # NCBI36 figures
174 my $chromosome = shift;
175 my $location = shift;
176 my %hChromosome = (
177 # start bp # length
178 1 => 0, # 247249719
179 2 => 247249720, # 242951149
180 3 => 490200869, # 199501827
181 4 => 689702696, # 191273063
182 5 => 880975759, # 180857866
183 6 => 1061833625, # 170899992
184 7 => 1232733617, # 158821424
185 8 => 1391555041, # 146274826
186 9 => 1537829867, # 140273252
187 10 => 1678103119, # 135374737
188 11 => 1813477856, # 134452384
189 12 => 1947930240, # 132349534
190 13 => 2080279774, # 114142980
191 14 => 2194422754, # 106368585
192 15 => 2300791339, # 100338915
193 16 => 2401130254, # 88827254
194 17 => 2489957508, # 78774742
195 18 => 2568732250, # 76117153
196 19 => 2644849403, # 63811651
197 20 => 2708661054, # 62435964
198 21 => 2771097018, # 46944323
199 22 => 2818041341, # 49691432
200 23 => 2867732773, # 154913754
201 24 => 3022646527, # 57772954 TOTAL=3080419480
202 25 => 3080419480
203 );
204 return $hChromosome{$chromosome};
205 }
206
207 }
208  
209 1;
210  
211 __END__