- 论坛徽章:
- 0
|
各位怎么都不回答呢?
还是贴一个大神的代码吧!
- #!/usr/bin/perl
- use strict;
- @ARGV != 1 || die "require 2 parameters";
- my ($groupfile, $relafile) = @ARGV;
- my(@temp1, %group, $toptable, @names, @data, @array);
- open GROUP, "<", $groupfile;
- while(<GROUP>){
- chomp;
- @temp1 = split "\t"; $_;
- $group{$temp1[0]} = $temp1[1];
- push @array, $temp1[1];
- }
- print "id" . "\t";
- foreach my $i (0..$#array){
- print $array[$i] . "_ave" . "\t" . $array[$i] . "_std\t" if $array[$i] ne $array[$i+1];
- next;
- }
- print "\n";
- open IN, "<", $relafile;
- chomp ($toptable = <IN>);
- @names = split "\t", $toptable;
- while(<IN>){
- chomp;
- @data = split "\t";
- my %hash1;
- foreach my $index (1..$#data) {
- my $key = $group{$names[$index]};
- if ($hash1{$key}){
- push @{$hash1{$key}}, $data[$index];
- }else {
- $hash1{$key} = [$data[$index]];
- }
- }
- print $data[0] . "\t";
- foreach my $elen ( sort keys %hash1) {
- print average(@{$hash1{$elen}}) . "\t" . std(@{$hash1{$elen}}) . "\t";
- }
- print "\n"
复制代码
|
|