Merge pull request #2802 from solgenomics/topic/cross_progenies
[sgn.git] / bin / transpose_matrix.pl
blob06975e8ff83bbc987d915625bcf674e29982a2fc
1 #!/usr/bin/perl
2 # 'transpose' swaps rows and columns in the given tab-delimited table.
3 # syntax perl transpose.pl input.txt > output.txt
5 while (<>) {
6 chomp;
7 @line = split /\t/;
8 $oldlastcol = $lastcol;
9 $lastcol = $#line if $#line > $lastcol;
10 for (my $i=$oldlastcol; $i < $lastcol; $i++) {
11 $outline[$i] = "\t" x $oldlastcol;
13 for (my $i=0; $i <=$lastcol; $i++) {
14 $outline[$i] .= "$line[$i]\t"
17 for (my $i=0; $i <= $lastcol; $i++) {
18 $outline[$i] =~ s/\s*$//g;
19 print $outline[$i]."\n";