add POD to the load_trait_props.pl script.
[sgn.git] / bin / transpose_matrix.pl
blobdf0fe03097d3d65576464ea043028893bd282119
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 use strict;
6 use warnings;
8 my @line;
9 my @outline;
10 my $lastcol;
11 my $oldlastcol;
13 while (<>) {
14 chomp;
15 @line = split /\t/;
16 $oldlastcol = $lastcol;
17 $lastcol = $#line if $#line > $lastcol;
18 for (my $i=$oldlastcol; $i < $lastcol; $i++) {
19 $outline[$i] = "\t" x $oldlastcol;
21 for (my $i=0; $i <=$lastcol; $i++) {
22 if ($outline[$i] =~ /[\w.]/) {
23 $outline[$i] .= "\t$line[$i]";
24 } else {
25 $outline[$i] = $line[$i];
29 for (my $i=0; $i <= $lastcol; $i++) {
30 $outline[$i] =~ s/[\f\n\r]*$//g;
31 print $outline[$i]."\n";