| 1 | package Microarray::DataMatrix::CdtFile; | ||
| 2 | |||
| 3 | # License information (the MIT license) | ||
| 4 | |||
| 5 | # Copyright (c) 2003 Christian Rees, Janos Demeter, John Matese, Gavin | ||
| 6 | # Sherlock; Stanford University | ||
| 7 | |||
| 8 | # Permission is hereby granted, free of charge, to any person | ||
| 9 | # obtaining a copy of this software and associated documentation files | ||
| 10 | # (the "Software"), to deal in the Software without restriction, | ||
| 11 | # including without limitation the rights to use, copy, modify, merge, | ||
| 12 | # publish, distribute, sublicense, and/or sell copies of the Software, | ||
| 13 | # and to permit persons to whom the Software is furnished to do so, | ||
| 14 | # subject to the following conditions: | ||
| 15 | |||
| 16 | # The above copyright notice and this permission notice shall be | ||
| 17 | # included in all copies or substantial portions of the Software. | ||
| 18 | |||
| 19 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 20 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 21 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
| 22 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
| 23 | # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
| 24 | # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| 25 | # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| 26 | # SOFTWARE. | ||
| 27 | |||
| 28 | |||
| 29 | # Author : Gavin Sherlock | ||
| 30 | # Date : 1st August 2002 | ||
| 31 | |||
| 32 | # This package is intended to provide an abstraction to a cdtFile, | ||
| 33 | # whose format is detailed at: | ||
| 34 | # | ||
| 35 | # http://genome-www5.Stanford.EDU/MicroArray/help/formats.shtml#cdt | ||
| 36 | # | ||
| 37 | |||
| 38 | use strict; | ||
| 39 | use vars qw (@ISA); | ||
| 40 | |||
| 41 | use Microarray::DataMatrix::TabDelimitedDataMatrix; | ||
| 42 | @ISA = qw (Microarray::DataMatrix::TabDelimitedDataMatrix); | ||
| 43 | |||
| 44 | # CLASS GLOBALS | ||
| 45 | |||
| 46 | # use the following so we only ever access hash entries | ||
| 47 | # using variables, to prevent typos, or accidental cloberring. | ||
| 48 | |||
| 49 | # These values are assigned here and then are READ-ONLY. | ||
| 50 | |||
| 51 | my $PACKAGE = "Microarray::DataMatrix::CdtFile"; | ||
| 52 | |||
| 53 | my $kHasGID = $PACKAGE.'::__hasGID'; # whether it has a GID column | ||
| 54 | my $kHasAID = $PACKAGE.'::__hasAID'; # whether it has an AID line | ||
| 55 | my $kGIDs = $PACKAGE.'::__GIDs'; # array of GIDs | ||
| 56 | my $kAIDs = $PACKAGE.'::__AIDs'; # array of AIDs | ||
| 57 | my $kRowNames = $PACKAGE.'::__rowNames'; # array of row names | ||
| 58 | my $kRowDescs = $PACKAGE.'::__rowDescs'; # array of row descriptions | ||
| 59 | my $kgWeights = $PACKAGE.'::__gWeights'; # array of gweights in the file | ||
| 60 | my $kIdName = $PACKAGE.'::__idName'; # name of the first column | ||
| 61 | my $kDescName = $PACKAGE.'::__descName'; # name of the second column | ||
| 62 | my $kNumLeadingMetaLines = $PACKAGE.'::__numLeadingMetaLines'; # number of leadin lines of meta data | ||
| 63 | |||
| 64 | ###################################################################### | ||
| 65 | sub new{ | ||
| 66 | ###################################################################### | ||
| 67 | # This is the constructor. It requires that the filename of the cdt | ||
| 68 | # file that is being used to construct the object is passed in. In | ||
| 69 | # addition you can set a variable, autodump, to indicate whether data | ||
| 70 | # should be automatically dumped out after any method call that | ||
| 71 | # transforms or filters the data. If this is not set, then you must | ||
| 72 | # manually call the dumpData method. The default is for autodumping | ||
| 73 | # to be off. This is useful, for instance, because you may run | ||
| 74 | # several filters/transformations over the data, and only want to dump | ||
| 75 | # the data at the end, which is more optimal that dumping it at every | ||
| 76 | # step. | ||
| 77 | # | ||
| 78 | # Usage : | ||
| 79 | # | ||
| 80 | # my $cdtFile = cdtFile->new(file=>$file, | ||
| 81 | # autodump=>1); | ||
| 82 | # | ||
| 83 | # The constructor simply sets up the object attributes. It does | ||
| 84 | # not read in any data. This will be done on demand, if a method | ||
| 85 | # is called that requires the data to be read in. | ||
| 86 | |||
| 87 | my $self = {}; | ||
| 88 | |||
| 89 | my ($class, %args) = @_; | ||
| 90 | |||
| 91 | bless $self, $class; | ||
| 92 | |||
| 93 | $self->_setFile($args{'file'}); | ||
| 94 | $self->{$kRowNames} = []; | ||
| 95 | $self->{$kRowDescs} = []; | ||
| 96 | $self->{$kgWeights} = []; | ||
| 97 | |||
| 98 | $self->_init; | ||
| 99 | |||
| 100 | $self->SUPER::_init($args{'tmpDir'}); # required by the anySizeMatrixClass | ||
| 101 | |||
| 102 | $self->_setAutoDump($args{'autodump'}) if (exists($args{'autodump'})); | ||
| 103 | |||
| 104 | return $self; | ||
| 105 | |||
| 106 | } | ||
| 107 | |||
| 108 | ##################################################################### | ||
| 109 | sub _init{ | ||
| 110 | ##################################################################### | ||
| 111 | # This method determines whether the file has a GID column, and an AID | ||
| 112 | # row, and stores that information, and the number of leading meta | ||
| 113 | # lines. | ||
| 114 | |||
| 115 | my ($self) = @_; | ||
| 116 | |||
| 117 | my $fh = $self->_fileHandle(reset=>1); | ||
| 118 | |||
| 119 | my $line = <$fh>; # grab first line | ||
| 120 | |||
| 121 | my $lineRef = $self->_arrayRefForLine(\$line); | ||
| 122 | |||
| 123 | if ($lineRef->[0] eq "GID"){ | ||
| 124 | |||
| 125 | $self->__setHasGID(1); | ||
| 126 | |||
| 127 | }else{ | ||
| 128 | |||
| 129 | $self->__setHasGID(0); | ||
| 130 | |||
| 131 | } | ||
| 132 | |||
| 133 | $line = <$fh>; # grab second line in file | ||
| 134 | |||
| 135 | $lineRef = $self->_arrayRefForLine(\$line); | ||
| 136 | |||
| 137 | if ($lineRef->[0] eq "AID"){ | ||
| 138 | |||
| 139 | $self->__setNumLeadingMetaLines(2); | ||
| 140 | $self->__setHasAID(1); | ||
| 141 | |||
| 142 | }else{ | ||
| 143 | |||
| 144 | $self->__setHasAID(0); | ||
| 145 | $self->__setNumLeadingMetaLines(1); | ||
| 146 | |||
| 147 | } | ||
| 148 | |||
| 149 | $self->_fileHandle(reset=>1); # reset the handle again | ||
| 150 | |||
| 151 | } | ||
| 152 | |||
| 153 | ##################################################################### | ||
| 154 | sub __usage{ | ||
| 155 | ##################################################################### | ||
| 156 | # This private method prints out a usage message for the constructor, | ||
| 157 | # and then dies with a specific error message. | ||
| 158 | # | ||
| 159 | # Usage : $self->__usage("$file does not exist"); | ||
| 160 | |||
| 161 | my ($self, $error) = @_; | ||
| 162 | |||
| 163 | print STDERR ' | ||
| 164 | Usage: | ||
| 165 | |||
| 166 | my $dataMatrix = cdtFile->new(file=>$file, | ||
| 167 | autoDump=>1, | ||
| 168 | tmpDir=>$dir); | ||
| 169 | |||
| 170 | where the file is a cdt file, formatted according to : | ||
| 171 | |||
| 172 | http://genome-www5.Stanford.EDU/MicroArray/help/formats.shtml#cdt | ||
| 173 | |||
| 174 | '; | ||
| 175 | |||
| 176 | |||
| 177 | die "$error.\n"; | ||
| 178 | |||
| 179 | } | ||
| 180 | |||
| 181 | ###################################################################### | ||
| 182 | sub _numLeadingMetaLines{ | ||
| 183 | ###################################################################### | ||
| 184 | # This method returns the number of leading meta lines that exist in | ||
| 185 | # the cdt file. It will be either 1 or 2, depending on whether arrays | ||
| 186 | # were clustered or not. It is determined at object initialization. | ||
| 187 | |||
| 188 | return ($_[0]->{$kNumLeadingMetaLines}); | ||
| 189 | |||
| 190 | } | ||
| 191 | |||
| 192 | ###################################################################### | ||
| 193 | sub __setNumLeadingMetaLines{ | ||
| 194 | ###################################################################### | ||
| 195 | # This method sets the number of leading meta lines that exist in the | ||
| 196 | # file. | ||
| 197 | |||
| 198 | my ($self, $numLines) = @_; | ||
| 199 | |||
| 200 | if (! defined $numLines || ($numLines !=1 && $numLines !=2)){ | ||
| 201 | |||
| 202 | die "number of leading meta lines must be 1 or 2, not '$numLines'.\n"; | ||
| 203 | |||
| 204 | } | ||
| 205 | |||
| 206 | $self->{$kNumLeadingMetaLines} = $numLines; | ||
| 207 | |||
| 208 | } | ||
| 209 | |||
| 210 | ###################################################################### | ||
| 211 | sub __setHasAID{ | ||
| 212 | ###################################################################### | ||
| 213 | # This private method allows setting of an attribute to indicate | ||
| 214 | # whether or not the cdt file has an AID row. It expects either a 0 | ||
| 215 | # or 1 to be passed in. | ||
| 216 | # | ||
| 217 | # Usage : $self->__setHasAID(0); | ||
| 218 | |||
| 219 | my ($self, $value) = @_; | ||
| 220 | |||
| 221 | if ($value != 0 && $value != 1){ | ||
| 222 | |||
| 223 | die "__setHasAID called with a value of $value.\nOnly 0 or 1 are allowed"; | ||
| 224 | |||
| 225 | } | ||
| 226 | |||
| 227 | $self->{$kHasAID} = $value; | ||
| 228 | |||
| 229 | } | ||
| 230 | |||
| 231 | ###################################################################### | ||
| 232 | sub __setHasGID{ | ||
| 233 | ###################################################################### | ||
| 234 | # This private method allows setting of an attribute to indicate | ||
| 235 | # whether or not the cdt file has an GID column. It expects either a 0 | ||
| 236 | # or 1 to be passed in. | ||
| 237 | # | ||
| 238 | # Usage : $self->__setHasGID(0); | ||
| 239 | |||
| 240 | my ($self, $value) = @_; | ||
| 241 | |||
| 242 | if ($value != 0 && $value != 1){ | ||
| 243 | |||
| 244 | die "__setHasGID called with a value of $value.\nOnly 0 or 1 are allowed"; | ||
| 245 | |||
| 246 | } | ||
| 247 | |||
| 248 | $self->{$kHasGID} = $value; | ||
| 249 | |||
| 250 | } | ||
| 251 | |||
| 252 | ###################################################################### | ||
| 253 | sub __hasAID{ | ||
| 254 | ###################################################################### | ||
| 255 | # This private method returns a boolean to indicate whether the cdt file | ||
| 256 | # has an AID row | ||
| 257 | |||
| 258 | return $_[0]->{$kHasAID}; | ||
| 259 | |||
| 260 | } | ||
| 261 | |||
| 262 | ###################################################################### | ||
| 263 | sub __hasGID{ | ||
| 264 | ###################################################################### | ||
| 265 | # This private method returns a boolean to indicate whether the cdt file | ||
| 266 | # has an GID column | ||
| 267 | |||
| 268 | return $_[0]->{$kHasGID}; | ||
| 269 | |||
| 270 | } | ||
| 271 | |||
| 272 | ###################################################################### | ||
| 273 | sub _parseFileHeaders{ | ||
| 274 | ###################################################################### | ||
| 275 | # This private method removes the file headers from a cdt file. It | ||
| 276 | # accepts a file handle as input, and assumes that the file handle is | ||
| 277 | # pointing to the very beginning of the file. | ||
| 278 | |||
| 279 | my ($self, $fh) = @_; | ||
| 280 | |||
| 281 | my $line = <$fh>; | ||
| 282 | |||
| 283 | if (!exists($self->{$kIdName})){ # if we've not read this line before | ||
| 284 | |||
| 285 | my $lineRef = $self->_arrayRefForLine(\$line); | ||
| 286 | |||
| 287 | $self->__parseFirstLine($lineRef); | ||
| 288 | |||
| 289 | } | ||
| 290 | |||
| 291 | if ($self->__hasAID){ # need to parse out the AID line | ||
| 292 | |||
| 293 | $line = <$fh>; | ||
| 294 | |||
| 295 | if (!exists $self->{$kAIDs}){ # the second line has the AIDs | ||
| 296 | |||
| 297 | my $lineRef = $self->_arrayRefForLine(\$line); | ||
| 298 | |||
| 299 | $self->__parseSecondLine($lineRef); | ||
| 300 | |||
| 301 | } | ||
| 302 | |||
| 303 | } | ||
| 304 | |||
| 305 | # now set the data line row count to zero, as the next line | ||
| 306 | # to be read in will be the first data line | ||
| 307 | |||
| 308 | $self->_setCurrFileDataRow(0); | ||
| 309 | |||
| 310 | } | ||
| 311 | |||
| 312 | ###################################################################### | ||
| 313 | sub __parseFirstLine{ | ||
| 314 | ###################################################################### | ||
| 315 | # This method deals with recording data from the first line of a cdt | ||
| 316 | # file. It accepts as input a reference to an array that contains | ||
| 317 | # the fields on the first line split on tabs. | ||
| 318 | |||
| 319 | my ($self, $lineRef) = @_; | ||
| 320 | |||
| 321 | shift @{$lineRef} if ($self->__hasGID); | ||
| 322 | |||
| 323 | $self->idName (shift @{$lineRef}); | ||
| 324 | $self->descName(shift @{$lineRef}); | ||
| 325 | |||
| 326 | if (shift @{$lineRef} ne "GWEIGHT"){ | ||
| 327 | |||
| 328 | $self->__usage("Your file, ".$self->file." has no GWEIGHT column header"); | ||
| 329 | |||
| 330 | } | ||
| 331 | |||
| 332 | $self->columnNamesArrayRef($lineRef); | ||
| 333 | |||
| 334 | } | ||
| 335 | |||
| 336 | ###################################################################### | ||
| 337 | sub __parseSecondLine{ | ||
| 338 | ###################################################################### | ||
| 339 | # This method deals with recording data from the second line of a cdt | ||
| 340 | # file. It accepts as input a reference to an array that contains | ||
| 341 | # the fields on the second line split on tabs. | ||
| 342 | |||
| 343 | my ($self, $lineRef) = @_; | ||
| 344 | |||
| 345 | # this subroutine deals with parsing out the AID line. | ||
| 346 | # it will die if the line passed in is not an AID line. | ||
| 347 | |||
| 348 | die "A non-AID line was passed into __parseSecondLine()" if ($lineRef->[0] ne "AID"); | ||
| 349 | |||
| 350 | if ($self->__hasGID){ # there's a gid column to remove | ||
| 351 | |||
| 352 | shift @{$lineRef}; | ||
| 353 | |||
| 354 | } | ||
| 355 | |||
| 356 | # now simply store the array clustering information | ||
| 357 | |||
| 358 | $self->AIDsArrayRef([@{$lineRef}[3..$#$lineRef]]); # anonymous array reference | ||
| 359 | |||
| 360 | } | ||
| 361 | |||
| 362 | ###################################################################### | ||
| 363 | sub _removeMetaDataFromLine{ | ||
| 364 | ###################################################################### | ||
| 365 | # This method removes and stores meta data from a data line in a cdt file. | ||
| 366 | # Because the array of data is passed in by reference, the array to which | ||
| 367 | # this reference refers is directly manipulated, such that the caller's | ||
| 368 | # array will have meta data removed from it | ||
| 369 | |||
| 370 | my ($self, $currFileDataRow, $lineRef) = @_; | ||
| 371 | |||
| 372 | if ($self->_metaDataRecorded($currFileDataRow)){ | ||
| 373 | |||
| 374 | # if we've already recorded the meta data for this line number, | ||
| 375 | # simply remove the data from the line | ||
| 376 | |||
| 377 | shift @{$lineRef} if ($self->__hasGID); # remove extra column if we have GID column | ||
| 378 | |||
| 379 | shift @{$lineRef}; shift @{$lineRef}; shift @{$lineRef}; | ||
| 380 | |||
| 381 | }else{ | ||
| 382 | |||
| 383 | # otherwise record the data, and then remember that we've recorded it | ||
| 384 | |||
| 385 | $self->GID($currFileDataRow, shift @{$lineRef}) if ($self->__hasGID); | ||
| 386 | |||
| 387 | $self->rowName($currFileDataRow, shift @{$lineRef}); | ||
| 388 | $self->rowDesc($currFileDataRow, shift @{$lineRef}); | ||
| 389 | $self->gWeight($currFileDataRow, shift @{$lineRef}); | ||
| 390 | |||
| 391 | $self->_indicateMetaDataRecorded($currFileDataRow); | ||
| 392 | |||
| 393 | } | ||
| 394 | |||
| 395 | } | ||
| 396 | |||
| 397 | ###################################################################### | ||
| 398 | sub GID{ | ||
| 399 | ###################################################################### | ||
| 400 | # This polymorphic setter/getter method returns the GID value for a given | ||
| 401 | # row in the cdt file. If a new GID is provided, it will update that | ||
| 402 | # name to the new value. Note the row number that is passed in is based | ||
| 403 | # on the row number in the file used for object construction. | ||
| 404 | # | ||
| 405 | # Usage: | ||
| 406 | # | ||
| 407 | # $self->GID($rowNum, $newGID); | ||
| 408 | # | ||
| 409 | # my $gid = $self->GID($rowNum); | ||
| 410 | |||
| 411 | my ($self, $rowNum, $data) = @_; | ||
| 412 | |||
| 413 | defined ($data) && ($self->{$kGIDs}->[$rowNum] = $data); | ||
| 414 | |||
| 415 | return $self->{$kGIDs}->[$rowNum]; | ||
| 416 | |||
| 417 | } | ||
| 418 | |||
| 419 | |||
| 420 | ###################################################################### | ||
| 421 | sub rowName{ | ||
| 422 | ###################################################################### | ||
| 423 | # This polymorphic setter/getter method returns the row name for a given | ||
| 424 | # row in the cdt file. If a new name is provided, it will update that | ||
| 425 | # name to the new value. Note the row number that is passed in is based | ||
| 426 | # on the row number in the file used for object construction. | ||
| 427 | # | ||
| 428 | # Usage: | ||
| 429 | # | ||
| 430 | # $self->rowName($rowNum, $newName); | ||
| 431 | # | ||
| 432 | # my $rowName = $self->rowName($rowNum); | ||
| 433 | |||
| 434 | my ($self, $rowNum, $data) = @_; | ||
| 435 | |||
| 436 | defined ($data) && ($self->{$kRowNames}->[$rowNum] = $data); | ||
| 437 | |||
| 438 | return $self->{$kRowNames}->[$rowNum]; | ||
| 439 | |||
| 440 | } | ||
| 441 | |||
| 442 | ###################################################################### | ||
| 443 | sub rowDesc{ | ||
| 444 | ###################################################################### | ||
| 445 | # This polymorphic setter/getter method returns the row description | ||
| 446 | # for a given row in the cdt file. If a new description is provided, | ||
| 447 | # it will update that description to the new value. Note the row | ||
| 448 | # number that is passed in is based on the row number in the file used | ||
| 449 | # for object construction. | ||
| 450 | # | ||
| 451 | # Usage: | ||
| 452 | # | ||
| 453 | # $self->rowDesc($rowNum, $newDesc); | ||
| 454 | # | ||
| 455 | # my $rowDesc = $self->rowDesc($rowNum); | ||
| 456 | |||
| 457 | my ($self, $rowNum, $data) = @_; | ||
| 458 | |||
| 459 | defined ($data) && ($self->{$kRowDescs}->[$rowNum] = $data); | ||
| 460 | |||
| 461 | return $self->{$kRowDescs}->[$rowNum]; | ||
| 462 | |||
| 463 | } | ||
| 464 | |||
| 465 | ###################################################################### | ||
| 466 | sub gWeight{ | ||
| 467 | ###################################################################### | ||
| 468 | # This polymorphic setter/getter method returns the gWeight for a | ||
| 469 | # given row in the cdt file. If a new gWeight is provided, it will | ||
| 470 | # update that gWeight to the new value. Note the row number that is | ||
| 471 | # passed in is based on the row number in the file used for object | ||
| 472 | # construction. | ||
| 473 | # | ||
| 474 | # Usage: | ||
| 475 | # | ||
| 476 | # $self->gWeight($rowNum, $newGWeight); | ||
| 477 | # | ||
| 478 | # my $gWeight = $self->gWeight($rowNum); | ||
| 479 | |||
| 480 | my ($self, $rowNum, $data) = @_; | ||
| 481 | |||
| 482 | defined ($data) && ($self->{$kgWeights}->[$rowNum] = $data); | ||
| 483 | |||
| 484 | return $self->{$kgWeights}->[$rowNum]; | ||
| 485 | |||
| 486 | } | ||
| 487 | |||
| 488 | ###################################################################### | ||
| 489 | sub AIDsArrayRef{ | ||
| 490 | ###################################################################### | ||
| 491 | # This polymorphic setter/getter method returns a reference to an | ||
| 492 | # array of the AIDs that existed in the original file, in the | ||
| 493 | # order that they appeared. If a new array reference is provided, it | ||
| 494 | # will give the experiments new AIDs. | ||
| 495 | # | ||
| 496 | # Usage: | ||
| 497 | # | ||
| 498 | # my $AIDsArrayRef = $self->AIDsArrayRef; | ||
| 499 | # $self->AIDsArrayRef(\@AIDs); | ||
| 500 | |||
| 501 | my ($self, $data) = @_; | ||
| 502 | |||
| 503 | defined ($data) && ($self->{$kAIDs} = $data); | ||
| 504 | |||
| 505 | return $self->{$kAIDs}; | ||
| 506 | |||
| 507 | } | ||
| 508 | |||
| 509 | ###################################################################### | ||
| 510 | sub idName{ | ||
| 511 | ###################################################################### | ||
| 512 | # This polymorphic setter/getter method returns the name of the id | ||
| 513 | # column that was used in the original file. If a new value is passed | ||
| 514 | # in, it will instead use that value as the id column name. | ||
| 515 | # | ||
| 516 | # Usage: | ||
| 517 | # | ||
| 518 | # print $self->idName; | ||
| 519 | # $self->idName($idName); | ||
| 520 | |||
| 521 | my ($self, $data) = @_; | ||
| 522 | |||
| 523 | defined ($data) && ($self->{$kIdName} = $data); | ||
| 524 | |||
| 525 | return $self->{$kIdName}; | ||
| 526 | |||
| 527 | } | ||
| 528 | |||
| 529 | ###################################################################### | ||
| 530 | sub descName{ | ||
| 531 | ###################################################################### | ||
| 532 | # This method returns the name of the description column that was used | ||
| 533 | # in the original file | ||
| 534 | |||
| 535 | my ($self, $data) = @_; | ||
| 536 | |||
| 537 | defined ($data) && ($self->{$kDescName} = $data); | ||
| 538 | |||
| 539 | return $_[0]->{$kDescName}; | ||
| 540 | |||
| 541 | } | ||
| 542 | |||
| 543 | |||
| 544 | ###################################################################### | ||
| 545 | sub _printLeadingMeta{ | ||
| 546 | ###################################################################### | ||
| 547 | # This method prints the first two lines of a cdt file out. | ||
| 548 | # | ||
| 549 | # Usage : $self->_printLeadingMeta($fh, $validColumnsArrayRef, $hasExtraInfo, $extraInfoName); | ||
| 550 | # | ||
| 551 | # This method prints to the passed in file handle. It will only print | ||
| 552 | # meta information for those valid columns. If the $extraInfo | ||
| 553 | # variable is true (ie a non-zero value) it will leave a print a | ||
| 554 | # column called $extraInfoName in between each column of meta data. | ||
| 555 | |||
| 556 | my ($self, $fh, $validColumnsArrayRef, $hasExtraInfo, $extraInfoName) = @_; | ||
| 557 | |||
| 558 | # print the experiment names line | ||
| 559 | |||
| 560 | if ($self->__hasGID){ | ||
| 561 | |||
| 562 | print $fh "GID\t"; | ||
| 563 | |||
| 564 | } | ||
| 565 | |||
| 566 | print $fh $self->idName, "\t", $self->descName, "\tGWEIGHT"; | ||
| 567 | |||
| 568 | my $columnNamesArrayRef = $self->columnNamesArrayRef; | ||
| 569 | |||
| 570 | foreach my $column (sort {$a <=> $b } @{$validColumnsArrayRef}){ | ||
| 571 | |||
| 572 | print $fh "\t", $columnNamesArrayRef->[$column]; | ||
| 573 | |||
| 574 | $hasExtraInfo && print($fh "\t$extraInfoName"); | ||
| 575 | |||
| 576 | } | ||
| 577 | |||
| 578 | print $fh "\n"; | ||
| 579 | |||
| 580 | # now print the AID line, if there is one | ||
| 581 | |||
| 582 | if ($self->__hasAID){ | ||
| 583 | |||
| 584 | print $fh "AID\t\t"; | ||
| 585 | |||
| 586 | if ($self->__hasGID){ | ||
| 587 | |||
| 588 | print $fh "\t"; # need an extra column | ||
| 589 | |||
| 590 | } | ||
| 591 | |||
| 592 | my $AIDsArrayRef = $self->AIDsArrayRef; | ||
| 593 | |||
| 594 | foreach my $column (sort {$a <=> $b } @{$validColumnsArrayRef}){ | ||
| 595 | |||
| 596 | print $fh "\t", $AIDsArrayRef->[$column]; | ||
| 597 | |||
| 598 | $hasExtraInfo && print($fh "\t"); | ||
| 599 | |||
| 600 | } | ||
| 601 | |||
| 602 | print $fh "\n"; | ||
| 603 | |||
| 604 | } | ||
| 605 | |||
| 606 | } | ||
| 607 | |||
| 608 | ###################################################################### | ||
| 609 | sub _printRowMetaData{ | ||
| 610 | ###################################################################### | ||
| 611 | # This method (required by the tabDelimitedDataMatrix) prints out the | ||
| 612 | # meta data for a single row, to a passed in file handle | ||
| 613 | # | ||
| 614 | # Usage : $self->_printRowMetaData($fh, $row); | ||
| 615 | |||
| 616 | my ($self, $fh, $row) = @_; | ||
| 617 | |||
| 618 | if ($self->__hasGID){ | ||
| 619 | |||
| 620 | print $fh $self->GID($row), "\t"; | ||
| 621 | |||
| 622 | } | ||
| 623 | |||
| 624 | print $fh $self->rowName($row), "\t", $self->rowDesc($row), "\t", $self->gWeight($row); | ||
| 625 | |||
| 626 | } | ||
| 627 | |||
| 628 | sub _printTrailingMeta{ | ||
| 629 | |||
| 630 | # nothing needs to be done | ||
| 631 | |||
| 632 | } | ||
| 633 | |||
| 634 | ###################################################################### | ||
| 635 | sub convertToPcl{ | ||
| 636 | ###################################################################### | ||
| 637 | # This method will create a pclFile from a cdtFile. It will do this | ||
| 638 | # by stripping out the GID column, and the AID row. It will also add | ||
| 639 | # in an EWEIGHTs row. It must be given the name of the file that | ||
| 640 | # should be created. If no .pcl extension is given, one will be added | ||
| 641 | # | ||
| 642 | # Usage : $cdtFile->convertToPcl($file); | ||
| 643 | |||
| 644 | my ($self, $file) = @_; | ||
| 645 | |||
| 646 | my $hasGID = $self->__hasGID; | ||
| 647 | my $hasAID = $self->__hasAID; | ||
| 648 | |||
| 649 | $self->__setHasGID(0); # so they get stripped out when printing | ||
| 650 | $self->__setHasAID(0); | ||
| 651 | |||
| 652 | my $validColumnsArrayRef = $self->_validColumnsArrayRef; | ||
| 653 | |||
| 654 | if ($file !~ /\.pcl$/){ | ||
| 655 | |||
| 656 | $file .= ".pcl"; | ||
| 657 | |||
| 658 | } | ||
| 659 | |||
| 660 | open (PCL, ">$file") || die "Cannot open $file : $!\n"; | ||
| 661 | |||
| 662 | $self->_printLeadingMeta(\*PCL, $validColumnsArrayRef); | ||
| 663 | |||
| 664 | print PCL "EWEIGHT\t\t"; | ||
| 665 | |||
| 666 | foreach (@{$validColumnsArrayRef}){ | ||
| 667 | |||
| 668 | print PCL "\t1"; | ||
| 669 | |||
| 670 | } | ||
| 671 | |||
| 672 | print PCL "\n"; | ||
| 673 | |||
| 674 | foreach my $row (sort {$a<=>$b} @{$self->_validRowsArrayRef}){ | ||
| 675 | |||
| 676 | $self->__setHasGID($hasGID); # so getting the data works correctly | ||
| 677 | $self->__setHasAID($hasAID); | ||
| 678 | |||
| 679 | my $dataRef = $self->_dataLine($row); # get the data | ||
| 680 | |||
| 681 | $self->__setHasGID(0); # now set to zero so printing works correctly | ||
| 682 | $self->__setHasAID(0); | ||
| 683 | |||
| 684 | # now print it out, with no GID or AID | ||
| 685 | |||
| 686 | $self->_printRow(\*PCL, $row, $dataRef, $validColumnsArrayRef); | ||
| 687 | |||
| 688 | } | ||
| 689 | |||
| 690 | $self->__setHasGID($hasGID); # now reset back to previous state | ||
| 691 | $self->__setHasAID($hasAID); | ||
| 692 | |||
| 693 | close PCL; | ||
| 694 | |||
| 695 | } | ||
| 696 | |||
| 697 | |||
| 698 | |||
| 699 | 1; # to keep perl happy | ||
| 700 | |||
| 701 | =pod | ||
| 702 | |||
| 703 | =head1 NAME | ||
| 704 | |||
| 705 | Microarray::DataMatrix::CdtFile - abstraction to cdtfile | ||
| 706 | |||
| 707 | =head1 Abstract | ||
| 708 | |||
| 709 | cdtFile.pm provides an abstraction layer to a cdt file, in that | ||
| 710 | it provides methods for manipulating or querying the contents of a | ||
| 711 | cdt file. | ||
| 712 | |||
| 713 | =head1 Overall Logic | ||
| 714 | |||
| 715 | This is for programmers only - do not rely on any of these details | ||
| 716 | when programming clients of the object, as the underlying implementation | ||
| 717 | is subject to change at any time without notice. | ||
| 718 | |||
| 719 | The cdtFile does little more than providing the parsing ability for | ||
| 720 | cdt files. All filtering/transformations are taken care of by | ||
| 721 | anyDataMatrix, from which it inherits. | ||
| 722 | |||
| 723 | =head1 Public Methods | ||
| 724 | |||
| 725 | =head2 new | ||
| 726 | |||
| 727 | Constructor - will take a fully qualified filename that correspond to | ||
| 728 | a cdt file as a name argument - see - | ||
| 729 | http://genome-www5.stanford.edu/MicroArray/help/formats.shtml. In | ||
| 730 | addition you can set a variable, autodump, to indicate whether data | ||
| 731 | should be automatically dumped out after any method call that | ||
| 732 | transforms or filters the data. If this is not set, then you must | ||
| 733 | manually call the dumpData method. The default is for autodumping to | ||
| 734 | be off. This is useful, for instance, because you may run several | ||
| 735 | filters/transformations over the data, and only want to dump the data | ||
| 736 | at the end, which is more optimal that dumping it at every step. Note | ||
| 737 | that if autodumping is on, then the data are only dumped if a method | ||
| 738 | completes successfully. Currently, if a method fails, the matrix may | ||
| 739 | be left in an uncertain state, and should not be used further. | ||
| 740 | |||
| 741 | Construction requires that a directory be provided where temp files | ||
| 742 | may be written, which may be generated during matrix filtering and | ||
| 743 | transformation. | ||
| 744 | |||
| 745 | Usage: | ||
| 746 | |||
| 747 | my $cdtFile = cdtFile->new(file=>$file, | ||
| 748 | autodump=>1, | ||
| 749 | tmpDir=>$tmpDir); | ||
| 750 | |||
| 751 | returns : a cdtFile object. | ||
| 752 | |||
| 753 | =head2 dumpData | ||
| 754 | |||
| 755 | This method dumps the current contents of the cdtFile object to a | ||
| 756 | file, either whose name was provided as a single argument, or to a | ||
| 757 | file whose name was used to construct the object. If the data have | ||
| 758 | been filtered based on columnPercentiles, and these were elected to be | ||
| 759 | shown, then these will be dumped out too (see below). | ||
| 760 | |||
| 761 | Usage: | ||
| 762 | |||
| 763 | $cdtFile->dumpData($file); | ||
| 764 | |||
| 765 | or: | ||
| 766 | |||
| 767 | $cdtFile->dumpData; | ||
| 768 | |||
| 769 | =head1 Tranformation and Filtering Methods | ||
| 770 | |||
| 771 | General note on methods that transform the data : If autodumping is | ||
| 772 | on, then by default, they will overwrite the file that was used to | ||
| 773 | create the cdtFile object, unless a new filename is passed in. If | ||
| 774 | a new filename is passed in (as an argument named 'file'), and | ||
| 775 | autodumping is on, then further operations on the cdtFile of | ||
| 776 | filtered data will require instantiation of a cdtFile object with | ||
| 777 | that file. Note, this also means that the program MUST have | ||
| 778 | permissions to overwrite the file, and also to write to the same | ||
| 779 | directory as the file (for temp file purposes). | ||
| 780 | |||
| 781 | All of the transformation and filtering methods return 1 upon success. | ||
| 782 | If an error was encountered, then the method will return 0, and the | ||
| 783 | error message associated with the problem can be retrieved using the | ||
| 784 | errstr() method, eg: | ||
| 785 | |||
| 786 | $cdtFile->methodX(%args) || die "An error occured ".$cdtFile->errstr."\n"; | ||
| 787 | |||
| 788 | All of the transformation and filtering methods allow a verbose | ||
| 789 | argument to be passed in, with valid values for the verbose argument | ||
| 790 | being either 'text' or 'html'. For text, \n will be used as an end of | ||
| 791 | line character after every line of reporting is printed. For html, | ||
| 792 | \n<br> will be used, eg: | ||
| 793 | |||
| 794 | $cdtFile->center(rows=>'mean', | ||
| 795 | verbose=>'html') || die $cdtFile->errstr; | ||
| 796 | |||
| 797 | =head2 center | ||
| 798 | |||
| 799 | This method allows either rows or columns of the cdtFile to be | ||
| 800 | centered using either means or medians (centering is when the average | ||
| 801 | - mean or median - is set to zero, by subtracting the average from | ||
| 802 | every value for that row/column). If centering both rows and columns, | ||
| 803 | centering will be done iteratively, until no datapoint changes by more | ||
| 804 | than 0.01. Alternatively, the maxNumIterations can be specified, or | ||
| 805 | the maxAllowableChange can be specified. If used in combination, the | ||
| 806 | first one that is met will terminate centering. The defaults are: | ||
| 807 | |||
| 808 | maxAllowableChange 0.01 | ||
| 809 | maxNumIterations 10 | ||
| 810 | |||
| 811 | Usage: eg: | ||
| 812 | |||
| 813 | $cdtFile->center(rows=>'mean', | ||
| 814 | columns=>'median') || die $cdtFile->errstr; | ||
| 815 | |||
| 816 | |||
| 817 | returns : 1 upon success, or 0 otherwise | ||
| 818 | |||
| 819 | =head2 filterByPercentPresentData | ||
| 820 | |||
| 821 | This method allows for filtering out of rows or columns which do not | ||
| 822 | have greater than the specified percentage of data available. Note, | ||
| 823 | if filtering by both rows and columns, filtering will be done | ||
| 824 | sequentially, firstly by rows. To overide this, make two seperate | ||
| 825 | calls to the method, in the opposite order. There is no fancy | ||
| 826 | algorithm to maximize the amount of retained data (eg consider filter | ||
| 827 | by rows, then by columns, that removal of a column means that some | ||
| 828 | rows thrown out in the first step may have greater than 80% good data | ||
| 829 | for the remaining columns - this method does not consider this). | ||
| 830 | |||
| 831 | $cdtFile->filterByPercentPresentData(rows=>80, | ||
| 832 | columns=>80); | ||
| 833 | |||
| 834 | $cdtFile->filterByPercentPresentData(rows=>90, | ||
| 835 | file=>$filename); | ||
| 836 | |||
| 837 | returns: 1 upon success, or 0 otherwise | ||
| 838 | |||
| 839 | =head2 filterRowsOnColumnPercentile | ||
| 840 | |||
| 841 | This method will filter out rows whose values do not have a percentile | ||
| 842 | rank for their particular column above a specified percentile rank, in | ||
| 843 | at least numColumns columns. In addition, this method will accept a | ||
| 844 | 'showPercentile' argument, which if set to a non-zero value, will | ||
| 845 | result in the percentiles of the datapoints being dumped out with the | ||
| 846 | data, when the data are aubsequently dumped to a file. Columns of | ||
| 847 | percentiles are interleaved with the data columns, so the resulting | ||
| 848 | file can not be clustered. | ||
| 849 | |||
| 850 | Usage: | ||
| 851 | |||
| 852 | $cdtFile->filterRowsOnColumnPercentile(percentile=>95, | ||
| 853 | numColumns=>1, | ||
| 854 | showPercentiles=>1); | ||
| 855 | |||
| 856 | |||
| 857 | returns : 1 upon success, or 0 otherwise | ||
| 858 | |||
| 859 | =head2 filterRowsOnColumnDeviation | ||
| 860 | |||
| 861 | This method will filter out rows whose values do not deviate from the | ||
| 862 | column mean by a specified number of standard deviations, in at least | ||
| 863 | numColumns columns. | ||
| 864 | |||
| 865 | Usage: | ||
| 866 | |||
| 867 | $cdtFile->filterRowsOnColumnDeviation(deviations=>2, | ||
| 868 | numColumns=>1); | ||
| 869 | |||
| 870 | returns : 1 upon success, or 0 otherwise | ||
| 871 | |||
| 872 | =head2 filterRowsOnValues | ||
| 873 | |||
| 874 | This method filters out rows whose values do not pass a specified | ||
| 875 | criterion, in at least numColumns columns. To specify the criterion, | ||
| 876 | a value, and an operator must be specified. The valid operators are: | ||
| 877 | |||
| 878 | "absolute value >" also aliased by "absgt" and "|>|" | ||
| 879 | "absolute value >=" also aliased by "absgteq" and "|>=|" | ||
| 880 | "absolute value =" also aliased by "abseq" and "|=|" | ||
| 881 | "absolute value <" also aliased by "abslt" and "|<|" | ||
| 882 | "absolute value <=" also aliased by "abslteq" and "|<=|" | ||
| 883 | ">" also aliased by "gt" | ||
| 884 | ">=" also aliased by "gteq" | ||
| 885 | "=" also aliased by "eq" and "==" | ||
| 886 | "<=" also aliased by "lteq" | ||
| 887 | "<" also aliased by "lt" | ||
| 888 | "not equal" also aliased by "ne" and "!=" | ||
| 889 | |||
| 890 | |||
| 891 | Usage: | ||
| 892 | |||
| 893 | $cdtFile->filterRowsOnValues(operator=>"absolute value >", | ||
| 894 | value=>2, | ||
| 895 | numColumns=>1); | ||
| 896 | |||
| 897 | |||
| 898 | returns : 1 upon success, or 0 otherwise | ||
| 899 | |||
| 900 | =head2 filterRowsOnVectorLength | ||
| 901 | |||
| 902 | This method filters out rows based on whether the vector that their | ||
| 903 | values define has a length of greater than the specified length. | ||
| 904 | |||
| 905 | Usage: | ||
| 906 | |||
| 907 | $cdtFile->filterRowsOnVectorLength(length=>2); | ||
| 908 | |||
| 909 | returns : 1 upon success, or 0 otherwise | ||
| 910 | |||
| 911 | =head2 logTransformData | ||
| 912 | |||
| 913 | This method log transforms the contents of the data matrix, using the | ||
| 914 | specified base. If any values less than or equal to zero are | ||
| 915 | encountered, then the transformation will fail. The matrix will be | ||
| 916 | returned to its state prior to log transformation if the operation | ||
| 917 | fails. | ||
| 918 | |||
| 919 | Usage : | ||
| 920 | |||
| 921 | $cdtFile->logTransformData(base=>2); | ||
| 922 | |||
| 923 | returns : 1 upon success, or 0 otherwise | ||
| 924 | |||
| 925 | =head2 scaleColumnData | ||
| 926 | |||
| 927 | This method scales the data for particular columns as specified by the | ||
| 928 | client, by dividing the values by specified factors. It could, for | ||
| 929 | instance, be used to renormalize the data. Note it is only | ||
| 930 | appropriate to normalize ratio data, not log transformed data. | ||
| 931 | |||
| 932 | The client passes in a hash, by reference, of the column numbers | ||
| 933 | (starting from zero) as the keys, and the scaling factors as the | ||
| 934 | values. | ||
| 935 | |||
| 936 | If a column number which is invalid is specified, then a warning to | ||
| 937 | STDERR will be printed. Also, if a scaling factor of zero (or undef) | ||
| 938 | is supplied for a column, a warning will also be printed to STDERR, | ||
| 939 | and the column data for that column will not be scaled. | ||
| 940 | |||
| 941 | Usage: | ||
| 942 | |||
| 943 | $cdtFile->scaleColumnData(columns=>{0=>1.2, | ||
| 944 | 2=>0.8}); | ||
| 945 | |||
| 946 | returns : 1 upon success, or 0 otherwise | ||
| 947 | |||
| 948 | =head1 Public Accessor Methods | ||
| 949 | |||
| 950 | =head2 file | ||
| 951 | |||
| 952 | This methods returns the name of the file that was used to construct | ||
| 953 | the object. | ||
| 954 | |||
| 955 | Usage: | ||
| 956 | |||
| 957 | my $file = $cdtFile->file; | ||
| 958 | |||
| 959 | returns: a scalar | ||
| 960 | |||
| 961 | =head2 numRows | ||
| 962 | |||
| 963 | This method returns the number of rows that are currently valid in the | ||
| 964 | data matrix. | ||
| 965 | |||
| 966 | Usage: | ||
| 967 | |||
| 968 | my $numRows = $cdtFile->numRows; | ||
| 969 | |||
| 970 | returns: a scalar | ||
| 971 | |||
| 972 | =head2 numColumns | ||
| 973 | |||
| 974 | This method returns the number of columns that are currently valid in | ||
| 975 | the data matrix. | ||
| 976 | |||
| 977 | Usage: | ||
| 978 | |||
| 979 | my $numColumns = $cdtFile->numColumns; | ||
| 980 | |||
| 981 | returns: a scalar | ||
| 982 | |||
| 983 | =head2 errstr | ||
| 984 | |||
| 985 | This method returns an error string that is associated with the last | ||
| 986 | failed call to a data transformation/filtering method. Calling this | ||
| 987 | method will clear the contents of the error string. | ||
| 988 | |||
| 989 | =head1 Public Setter Methods | ||
| 990 | |||
| 991 | =head2 setAutoDump | ||
| 992 | |||
| 993 | This method can be used to turn autodumping on or off. | ||
| 994 | |||
| 995 | Usage: | ||
| 996 | |||
| 997 | $cdtFile->setAutoDump($n); # where $n can be 0 or 1 | ||
| 998 | |||
| 999 | =head1 Public setter/getter methods | ||
| 1000 | |||
| 1001 | =head2 rowName | ||
| 1002 | |||
| 1003 | This polymorphic setter/getter method returns the row name for a given | ||
| 1004 | row in the cdt file. If a new name is provided, it will update that | ||
| 1005 | name to the new value. Note the row number that is passed in is based | ||
| 1006 | on the row number in the file used for object construction. | ||
| 1007 | |||
| 1008 | Usage: | ||
| 1009 | |||
| 1010 | $self->rowName($rowNum, $newName); | ||
| 1011 | |||
| 1012 | my $rowName = $self->rowName($rowNum); | ||
| 1013 | |||
| 1014 | =head2 rowDesc | ||
| 1015 | |||
| 1016 | This polymorphic setter/getter method returns the row description for | ||
| 1017 | a given row in the cdt file. If a new description is provided, it | ||
| 1018 | will update that description to the new value. Note the row number | ||
| 1019 | that is passed in is based on the row number in the file used for | ||
| 1020 | object construction. | ||
| 1021 | |||
| 1022 | Usage: | ||
| 1023 | |||
| 1024 | $self->rowDesc($rowNum, $newDesc); | ||
| 1025 | |||
| 1026 | my $rowDesc = $self->rowDesc($rowNum); | ||
| 1027 | |||
| 1028 | =head2 gWeight | ||
| 1029 | |||
| 1030 | This polymorphic setter/getter method returns the gWeight for a given | ||
| 1031 | row in the cdt file. If a new gWeight is provided, it will update | ||
| 1032 | that gWeight to the new value. Note the row number that is passed in | ||
| 1033 | is based on the row number in the file used for object construction. | ||
| 1034 | |||
| 1035 | Usage: | ||
| 1036 | |||
| 1037 | $self->gWeight($rowNum, $newGWeight); | ||
| 1038 | |||
| 1039 | my $gWeight = $self->gWeight($rowNum); | ||
| 1040 | |||
| 1041 | =head2 eweightsArrayRef | ||
| 1042 | |||
| 1043 | This polymorphic setter/getter method returns a reference to an array | ||
| 1044 | of the eweights that existed in the original file, in the order that | ||
| 1045 | they appeared. If a new array reference is provided, it will give the | ||
| 1046 | experiments new eweights. | ||
| 1047 | |||
| 1048 | Usage: | ||
| 1049 | |||
| 1050 | my $eweightsArrayRef = $self->eweightsArrayRef; | ||
| 1051 | $self->eweightsArrayRef(\@eweights); | ||
| 1052 | |||
| 1053 | =head2 idName | ||
| 1054 | |||
| 1055 | This polymorphic setter/getter method returns the name of the id | ||
| 1056 | column that was used in the original file. If a new value is passed | ||
| 1057 | in, it will instead use that value as the id column name. | ||
| 1058 | |||
| 1059 | Usage: | ||
| 1060 | |||
| 1061 | print $self->idName; | ||
| 1062 | $self->idName($idName); | ||
| 1063 | |||
| 1064 | =head2 descName | ||
| 1065 | |||
| 1066 | This polymorphic setter/getter method either returns the name of the | ||
| 1067 | description column that was used in the original file, or allows it to | ||
| 1068 | be set to a new value. | ||
| 1069 | |||
| 1070 | Usage: | ||
| 1071 | |||
| 1072 | print $self->descName; | ||
| 1073 | $self->descName($descName); | ||
| 1074 | |||
| 1075 | =head1 Protected methods | ||
| 1076 | |||
| 1077 | =head2 _printLeadingMeta | ||
| 1078 | |||
| 1079 | This method prints the first two lines of a cdt file out. It prints | ||
| 1080 | to the passed in file handle. It will only print meta information for | ||
| 1081 | those valid columns. If the $extraInfo variable is true (ie a | ||
| 1082 | non-zero value) it will leave a print a column called $extraInfoName | ||
| 1083 | in between each column of meta data. This method is implemented as | ||
| 1084 | required by its superclass, anySizeDataMatrix. | ||
| 1085 | |||
| 1086 | Usage: | ||
| 1087 | |||
| 1088 | $self->_printLeadingMeta($fh, $validColumnsArrayRef, $hasExtraInfo, $extraInfoName); | ||
| 1089 | |||
| 1090 | =head2 _printTrailingMeta | ||
| 1091 | |||
| 1092 | This method is implemented as required by its superclass, | ||
| 1093 | anySizeDataMatrix. For a cdtFile, it down;t actually need to do | ||
| 1094 | anything. | ||
| 1095 | |||
| 1096 | Usage: | ||
| 1097 | |||
| 1098 | $self->_printTrailingMeta($fh, $self->_validColumnsArrayRef); | ||
| 1099 | |||
| 1100 | =head1 Private Methods | ||
| 1101 | |||
| 1102 | =head2 __usage | ||
| 1103 | |||
| 1104 | This private method prints out a usage message for the constructor, | ||
| 1105 | and then dies with a specific error message. | ||
| 1106 | |||
| 1107 | Usage : | ||
| 1108 | |||
| 1109 | $self->__usage("$file does not exist"); | ||
| 1110 | |||
| 1111 | =head2 _parseFileHeaders | ||
| 1112 | |||
| 1113 | This private method removes the file headers from a cdt file. It | ||
| 1114 | accepts a file handle as input, and assumes that the file handle is | ||
| 1115 | pointing to the very beginning of the file. | ||
| 1116 | |||
| 1117 | Usage: | ||
| 1118 | |||
| 1119 | $self->_parseFileHeaders($fh); | ||
| 1120 | |||
| 1121 | =head2 __parseFirstLine | ||
| 1122 | |||
| 1123 | This method deals with recording data from the first line of a cdt | ||
| 1124 | file. It accepts as input a reference to an array that contains the | ||
| 1125 | fields on the first line split on tabs. | ||
| 1126 | |||
| 1127 | Usage: | ||
| 1128 | |||
| 1129 | $self->__parseFirstLine($lineRef); | ||
| 1130 | |||
| 1131 | =head2 __parseSecondLine | ||
| 1132 | |||
| 1133 | This method deals with recording data from the second line of a cdt | ||
| 1134 | file. It accepts as input a reference to an array that contains the | ||
| 1135 | fields on the first second split on tabs. | ||
| 1136 | |||
| 1137 | Usage: | ||
| 1138 | |||
| 1139 | $self->__parseSecondLine($lineRef); | ||
| 1140 | |||
| 1141 | =head2 _removeMetaDataFromLine | ||
| 1142 | |||
| 1143 | This method removes and stores meta data from a data line in a cdt | ||
| 1144 | file. Because the array of data is passed in by reference, the array | ||
| 1145 | to which this reference refers is directly manipulated, such that the | ||
| 1146 | callers array will have meta data removed from it. | ||
| 1147 | |||
| 1148 | Usage: | ||
| 1149 | |||
| 1150 | $self->_removeMetaDataFromLine($currFileDataRow, $lineRef); | ||
| 1151 | |||
| 1152 | =head1 AUTHOR | ||
| 1153 | |||
| 1154 | Gavin Sherlock | ||
| 1155 | |||
| 1156 | sherlock@genome.stanford.edu | ||
| 1157 | |||
| 1158 | =cut | ||
| 1159 |