| 1 | package GnaData::Transpose; | ||
| 2 | use strict; | ||
| 3 | |||
| 4 | sub transpose { | ||
| 5 | my ($inh, $outh) = @_; | ||
| 6 | my ($row) = 0; | ||
| 7 | my ($maxcol) = 0; | ||
| 8 | my ($line) = 0; | ||
| 9 | my ($store) = [[]]; | ||
| 10 | |||
| 11 | while ($line = <>) { | ||
| 12 | chop $line; | ||
| 13 | my (@items) = split (/\t/, $line); | ||
| 14 | my ($col, $item); | ||
| 15 | $col = 0; | ||
| 16 | foreach $item (@items) { | ||
| 17 | $store->[$row]->[$col] = $item; | ||
| 18 | $col++; | ||
| 19 | } | ||
| 20 | if ($col > $maxcol) { | ||
| 21 | $maxcol = $col; | ||
| 22 | } | ||
| 23 | $row++; | ||
| 24 | } | ||
| 25 | |||
| 26 | my ($i,$j); | ||
| 27 | for ($i=0; $i < $maxcol; $i++) { | ||
| 28 | my (@items) = (); | ||
| 29 | for ($j=0; $j < $row; $j++) { | ||
| 30 | push (@items, $store->[$j]->[$i]); | ||
| 31 | } | ||
| 32 | $outh->print(join("\t", @items), "\n"); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | 1; |