CDF/Probeset.pm untested

filter: Statementstmt 0.0% 0 / 149 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 20 Podpod 0.0% 0 / 16 totaltotal 0.0% 0 / 263 CC 28 SCAR 36.8
CC
28
Cov
0%
unit_type
110.0
_parse_from_filehandle
56.0
_parse_from_filehandle_bin
42.0
CRAP 39.6
1 #!/usr/bin/perl
2  
3 # A Affymetrix probeset. We gloss over the fact that multiple
4 # Unit_blocks are allowed per Unit, since this whole set of modules
5 # only really cares about expression
6  
7 package Bio::Affymetrix::CDF::Probeset;
8  
9 use Bio::Affymetrix::CDF::Probe;
10  
11 use Carp;
12  
13 use warnings;
14 use strict;
15 our $VERSION=0.5;
16  
17 # Docs come before the code
18  
19 =head1 NAME
20  
21 Bio::Affymetrix::CDF::Probeset- an Affymetrix probeset in an CDF file
22  
23 =head1 SYNOPSIS
24  
25 use Bio::Affymetrix::CDF;
26  
27 # Parse the CDF file
28  
29 my $cdf=new Bio::Affymetrix::CDF();
30  
31 $cdf->parse_from_file("foo.cdf");
32  
33 # Print out the probeset name of Unit 1001
34  
35 my $probeset=$cdf->probesets()->{1001};
36  
37 print $probeset->name();
38  
39 =head1 DESCRIPTION
40  
41 The Affymetrix microarray system produces files in a variety of
42 formats. If this means nothing to you, these modules are probably not
43 for you :). After these modules have parsed a CDF file, the resulting
44 Bio::Affymetrix::CDF file contains a hash of
45 Bio::Affmetrix::CDF::Probeset objects, keyed on the unit number. This allows you look at the
46 details of the probeset.
47  
48 If you have parsed a CDF file with probe-level parsing turned on, you
49 can examine the individual probes using the probes method. By altering
50 the contents of this array, you can redesign the chip! NASC use this
51 in our cross-species work (http://affymetrix.arabidopsis.info/xspecies).
52  
53 =head2 HINTS
54  
55 You can only get probe-level information if you have parsed the CDF
56 object with probe-level parsing turned on.
57  
58 =head2 WARNING
59  
60 The probe level parsing interface is a bit inelegant at the
61 moment. This might change in future versions.
62  
63 =head1 COPYRIGHT
64  
65 Copyright (C) 2005 by Nick James, David J Craigon, NASC (arabidopsis.info), The
66 University of Nottingham
67  
68 This module is free software. You can copy or redistribute it under the same terms as Perl itself.
69  
70 Affymetrix is a registered trademark of Affymetrix Inc., Santa
71 Clara, California, USA.
72  
73 =head1 AUTHORS
74
75 Nick James (nick at arabidopsis.info)
76  
77 David J Craigon (david at arabidopsis.info)
78  
79 Nottingham Arabidopsis Stock Centre (http://arabidopsis.info), University of Nottingham.
80  
81 =head1 METHODS
82  
83 =cut
84  
85  
86 =head2 new
87  
88 Arg [0] : none
89 Example : my $cdf=new Bio::Affymetrix::CDF::Probeset();
90 Description: constructor for Bio::Affymetrix::CDF::Probeset
91 object. You probably do not want to make these objects yourself yet, however.
92 Returntype : new Bio::Affmetrix::CDF::Probeset object
93 Exceptions : none
94 Caller : general
95  
96 =cut
97  
98  
99 sub new {
100 my $class=shift;
101 my $q=shift;
102 my $self={};
103 $self->{"PROBES"}=[];
104  
105 bless $self,$class;
106  
107  
108 return $self;
109 }
110  
111 # Getter/setters
112  
113 # Probeset trivia
114  
115  
116 # Unit Name is always None for expression arrays
117  
118 =head2 unit_name
119 Arg [1] : string $unit_name (optional)
120 Example : my $unit_name=$ps->unit_name()
121 Description: Always NONE for expression arrays. Only available in MAS5 files
122 Returntype : string
123 Exceptions : none
124 Caller : general
125 =cut
126  
127 sub unit_name {
128 my $self=shift;
129
130 if (my $q=shift) {
131 $self->{"UNITNAME"}=$q;
132 }
133
134 return $self->{"UNITNAME"};
135 }
136  
137 # Sense or anti sense probeset? Returns true, or false
138  
139 =head2 is_sense
140 Arg [1] : boolean $sense (optional)
141 Example : if ($ps->is_sense()) { .... }
142 Description: Returns true when this is a sense (rather than
143 anti-sense) probeset. Only available in MAS5 files
144 Returntype : boolean
145 Exceptions : none
146 Caller : general
147 =cut
148  
149  
150 sub is_sense {
151 my $self=shift;
152  
153 if (my $q=shift) {
154 $self->{"SENSE"}=$q;
155 }
156 return $self->{"SENSE"};
157 }
158  
159 # These are all named "original_" because they aren't calculated, they are what a parsed file claims
160  
161 # number of probepairs making up the probeset
162  
163  
164 =head2 original_num_probepairs
165 Arg [0] : none
166 Example : my $probepairs=$ps->original_num_probepairs()
167 Description: Get the number of probepairs in this probeset
168 Returntype : integer
169 Exceptions : none
170 Caller : general
171 =cut
172  
173 sub original_num_probepairs {
174 my $self=shift;
175 return $self->{"NUMATOMS"};
176 }
177  
178 # number of squares making up the probeset
179 =head2 original_num_probes
180 Arg [0] : none
181 Example : my $probepairs=$ps->original_num_probes()
182 Description: Get the number of probes in this probeset
183 Returntype : integer
184 Exceptions : none
185 Caller : general
186 =cut
187  
188  
189 sub original_num_probes {
190 my $self=shift;
191 return $self->{"NUMCELLS"};
192 }
193  
194 # arbitrary number for the probeset
195  
196 =head2 original_unit_number
197 Arg [0] : none
198 Example : my $probepairs=$ps->unit_number()
199 Description: Get the unit number of this probeset (a unique number
200 assigned to each probe in the CDF file but otherwise meaningless)
201 Returntype : integer
202 Exceptions : none
203 Caller : general
204 =cut
205  
206 sub original_unit_number {
207 my $self=shift;
208 return $self->{"UNITNUMBER"};
209 }
210  
211 sub unit_number {
212 my $self=shift;
213 carp "unit_number is deprecated. Use original_unit_number instead (same function only renamed)";
214 $self->original_unit_number(@_);
215 }
216  
217 # type of unit as an ENUM like thing
218  
219  
220 =head2 unit_type
221 Arg [1] : optional, one of "CustomSeq", "genotyping", "expression", "tag/GenFlex"
222 Example : my $unit_type=$ps->unit_type()
223 Description: Get/Set the unit number of this probeset. Probably expression only
224 Returntype : one of "CustomSeq", "genotyping", "expression", "tag/GenFlex"
225 Exceptions : none
226 Caller : general
227 =cut
228  
229 sub unit_type {
230 my $self=shift;
231  
232 if (my $q=shift) {
233 if ($q eq "CustomSeq") {
234 $self->{"UNITTYPE"}=1;
235 } elsif ($q eq "genotyping") {
236 $self->{"UNITTYPE"}=2;
237 } elsif ($q eq "expression") {
238 $self->{"UNITTYPE"}=3;
239 } elsif ($q eq "tag/GenFlex") {
240 $self->{"UNITTYPE"}=7;
241 } else {
242 die "Not a valid unit type";
243 }
244 }
245  
246 if ($self->{"UNITTYPE"}==1) {
247 return "CustomSeq";
248 } elsif ($self->{"UNITTYPE"}==2) {
249 return "genotyping";
250 } elsif ($self->{"UNITTYPE"}==3) {
251 return "expression";
252 } elsif ($self->{"UNITTYPE"}==7) {
253 return "tag/GenFlex";
254 }
255 }
256  
257 ## Censor this?
258  
259 sub original_number_blocks {
260 my $self=shift;
261 return $self->{"NUMBERBLOCKS"};
262 }
263  
264  
265 # 0= substitution 1= insertion 2=deletion. No effort made here- we
266 # don't really do genotyping arrays
267  
268 =head2 mutation_type
269 Arg [0] : integer
270 Example : none
271 Description: Get/set mutation_type. If this is a genotyping probe
272 set, 0=substitution, 1=insertion, 2=deletion. Only available in MAS5
273 arrays using this software.
274 Returntype : integer
275 Exceptions : none
276 Caller : general
277 =cut
278  
279  
280 sub mutation_type {
281 my $self=shift;
282  
283 if (my $q=shift) {
284 $self->{"MUTATIONTYPE"}=$q;
285 }
286 return $self->{"MUTATIONTYPE"};
287 }
288  
289 =head2 name
290 Arg [1] : string
291 Example : my $name=$ps->name()
292 Description: Get/set name of probeset
293 Returntype : string
294 Exceptions : none
295 Caller : general
296 =cut
297  
298  
299 sub name {
300 my $self=shift;
301  
302 if (my $q=shift) {
303 $self->{"NAME"}=$q;
304 }
305 return $self->{"NAME"};
306 }
307  
308 =head2 probe_pairs
309 Arg [1] : arrayref $probelist
310 Example : my @probes=$ps->probe_pairs()
311 Description: Get/set list of probe pairs making up this array. Only available if
312 with probes mode is used.
313  
314 Returns an reference to an array of "probe pairs". Each "probe pair"
315 is an array reference containing two Bio::Affymetrix::CDF::Probe
316 objects.
317
318 The design of the CDF file implies that one point chips with 3
319 mismatch probes and one perfect match probe were mooted, but we
320 are unsure whether any of these were ever released to the
321 public. Nevertheless, these modules are ready!
322  
323 Returntype : reference to array of arrayrefs of Bio::Affymetrix::CDF::Probe objects
324 Exceptions : none
325 Caller : general
326 =cut
327  
328  
329 sub probe_pairs {
330 my $self=shift;
331 if (!$self->{"probemode"}) {
332 die "Probes is not available when not in probemode";
333 }
334  
335 if (my $q=shift) {
336 $self->{"PROBES"}=$q;
337 }
338 return $self->{"PROBES"};
339 }
340  
341  
342 sub probes {
343 my $self=shift;
344  
345 carp ("probes deprecated. Use probe_pairs instead");
346 $self->probe_pairs(@_);
347 }
348  
349  
350 =head2 CDF
351 Arg [1] : Bio::Affymetrix::CDF object $probelist
352 Example : my $cdf=$ps->probes()
353 Description: Get/set CDF object this probeset belongs to.
354 Returntype : Bio::Affymetrix::CDF object
355 Exceptions : none
356 Caller : general
357 =cut
358  
359  
360 sub CDF {
361 my $self=shift;
362  
363 if (my $q=shift) {
364 $self->{"CDF"}=$q;
365 }
366 return $self->{"CDF"};
367 }
368  
369  
370  
371 # Parses from FileHandle
372  
373  
374 sub _parse_from_filehandle {
375 my $self=shift;
376 my $fh=shift;
377  
378 $self->{"probemode"}=shift;
379  
380 $self->{"FH"}=$fh;
381  
382 # Handle trivia from unit header
383 my $i;
384  
385 while (defined($i=<$fh>) && (!($i=~/^\[.*\]$/o))) {
386 if ($i=~/^([^=]+)=(.*)$/o) {
387 my $name=$1;
388 my $value=$2;
389 if (uc $name eq "NAME") {
390 $self->{"UNITNAME"}=$value;
391 } elsif (uc $name eq "DIRECTION") {
392 $self->{"SENSE"}=($value==1);
393 } else {
394 $self->{uc $name}=$value;
395 }
396 }
397 }
398  
399 # Block section
400 while (defined($i=<$fh>) && (!($i=~/^\[.*\]$/o))) {
401 if ($i=~/^([^=]+)=(.*)$/o) {
402 my $name=$1;
403 my $value=$2;
404 if ($self->{"probemode"}&&$name=~/Cell\d+/o) {
405 my $h= new Bio::Affymetrix::CDF::Probe();
406 my @s=split /\t/,$value;
407 $h->{"NAME"}=$name;
408 $h->{"X"}=$s[0];
409 $h->{"Y"}=$s[1];
410 $h->{"PROBE"}=$s[2];
411 $h->{"EXPOS"}=$s[5];
412 $h->{"POS"}=$s[6];
413 $h->{"PBASE"}=$s[8];
414 $h->{"TBASE"}=$s[9];
415 $h->{"ATOM"}=$s[10];
416 $h->{"INDEX"}=$s[11];
417 $h->{"PROBESET"}=$self;
418 push @{$self->{"PROBES"}->[$h->{"ATOM"}]},$h;
419 $self->{"CDF"}->{"PROBEGRID"}->[$h->{"X"}][$h->{"Y"}]=$h;
420  
421 } elsif (uc $name eq "NAME") {
422 $self->{"NAME"}=$value;
423 }
424 }
425 }
426  
427 return $i;
428 }
429  
430 # Parses from FileHandle for XDA format file
431  
432  
433 sub _parse_from_filehandle_bin {
434 my $self=shift;
435 my $fh=shift;
436  
437 $self->{"probemode"}=shift;
438  
439 $self->{"FH"}=$fh;
440  
441 # Handle trivia from unit header
442  
443 my $buffer;
444  
445 # General header information
446  
447 (read ($fh, $buffer, 20)==20) or die "Can no longer read from file";
448  
449 ($self->{"UNITTYPE"},$self->{"DIRECTION"},$self->{"NUMATOMS"},undef,$self->{"NUMCELLS"},$self->{"UNITNUMBER"},$self->{"ATOMSPERCELL"})=unpack ("SCV4C",$buffer);
450  
451 # Translate UNITTYPE into equivalent numbers for MAS5
452  
453 if ($self->{"UNITTYPE"}==1) {
454 $self->{"UNITTYPE"}=3;
455 } elsif ($self->{"UNITTYPE"}==2) {
456 $self->{"UNITTYPE"}=2;
457 } elsif ($self->{"UNITTYPE"}==3) {
458 $self->{"UNITTYPE"}=1;
459 } elsif ($self->{"UNITTYPE"}==4) {
460 $self->{"UNITTYPE"}=7;
461 }
462  
463 # Block information- we assume one block only since we only do expression arrays
464  
465 $self->{"NUMBERBLOCKS"}=1;
466  
467 (read ($fh, $buffer, 82)==82) or die "Can no longer read from file";
468  
469 {
470 my @temp=unpack ("V2C2V2Z64",$buffer);
471 $self->{"NAME"}=$temp[6];
472 }
473  
474 $self->{"UNITNAME"}="NONE";
475  
476 $self->{"PROBES"}=[];
477  
478 for (my $i=1;$i<=$self->{"NUMCELLS"};$i++) {
479 (read ($fh, $buffer, 14)==14) or die "Can no longer read from file";
480 if ($self->{"probemode"}) {
481 my $h= new Bio::Affymetrix::CDF::Probe();
482
483 ($h->{"ATOM"},$h->{"X"},$h->{"Y"},$h->{"POS"},$h->{"PBASE"},$h->{"TBASE"})=unpack("VS2VC2",$buffer);
484
485 $h->{"INDEX"}=$i;
486
487 $h->{"PBASE"}=uc(chr($h->{"PBASE"}));
488 $h->{"TBASE"}=uc(chr($h->{"TBASE"}));
489 $h->{"PROBESET"}=$self;
490
491 push @{$self->{"PROBES"}->[$h->{"ATOM"}]},$h;
492 $self->{"CDF"}->{"PROBEGRID"}->[$h->{"X"}][$h->{"Y"}]=$h;
493 }
494 }
495  
496 }
497  
498  
499 1;