我用excel生成了一个相关矩阵,它有以下输出类型:
tae-miR1127 tae-miR1131 tae-miR164 tae-miR5084 tae-miR1138
tae-miR1127 1
tae-miR1131 0.335050711 1
tae-miR164 0.167933504 -0.134901833 1
tae-miR5084 -0.140902598 0.119780666 -0.189285165 1
tae-miR1138 -0.031264072 0.16572515 -0.178381246 0.080697284 1
我想让这个输出像 -
tae-miR1127 tae-miR1131 tae-miR164 tae-miR5084 tae-miR1138
tae-miR1127 1 0.335050711 0.167933504 -0.140902598 -0.031264072
tae-miR1131 0.335050711 1 -0.134901833 0.119780666 0.16572515
tae-miR164 0.167933504 -0.134901833 1 -0.189285165 -0.178381246
tae-miR5084 -0.140902598 0.119780666 -0.189285165 1 0.080697284
tae-miR1138 -0.031264072 0.16572515 -0.178381246 0.080697284 1
答案 0 :(得分:1)
好问题。你可以试试这个:
use warnings;
use strict;
my %h;
my @a;
while (<DATA>) {
if ($. == 1) {
@a=split;
printLine([' ', @a]);
next;
}
my @b=split;
for (1..$#b) {
$h{$b[0]}{$a[($_-1)]}=$b[$_];
$h{$a[($_-1)]}{$b[0]}=$b[$_];
}
}
for (@a) {
printLine([$_, @{$h{$_}}{@a}]);
}
sub printLine {
my ($a) = @_;
for (@$a) {
printf "%-16s",$_;
}
print "\n";
}
__DATA__
tae-miR1127 tae-miR1131 tae-miR164 tae-miR5084 tae-miR1138
tae-miR1127 1
tae-miR1131 0.335050711 1
tae-miR164 0.167933504 -0.134901833 1
tae-miR5084 -0.140902598 0.119780666 -0.189285165 1
tae-miR1138 -0.031264072 0.16572515 -0.178381246 0.080697284 1
输出:
tae-miR1127 tae-miR1131 tae-miR164 tae-miR5084 tae-miR1138
tae-miR1127 1 0.335050711 0.167933504 -0.140902598 -0.031264072
tae-miR1131 0.335050711 1 -0.134901833 0.119780666 0.16572515
tae-miR164 0.167933504 -0.134901833 1 -0.189285165 -0.178381246
tae-miR5084 -0.140902598 0.119780666 -0.189285165 1 0.080697284
tae-miR1138 -0.031264072 0.16572515 -0.178381246 0.080697284 1