#!/usr/bin/perl

$head = $ARGV[0];
$reffile = $ARGV[1];
open IN, "temp/$head.$reffile.score.txt";
while (<IN>){
	split(/\t/);
	if($_[2] < 51){
		push(@{$data[$_[2]]},$_[7]);
		$mean[$_[2]] += $_[7];
	}
}
close IN;
open OUT, ">temp/$head.meansd.txt";
for($i=5;$i<51;$i++){
	$n = @{$data[$i]};
	next unless $n;
	$mean[$i] /= $n;
	$var = 0;
	for($j=0;$j<@{$data[$i]};$j++){
		$var += ($data[$i]->[$j] - $mean[$i])**2/$n;
	}
	$sd = $var**0.5;
	print OUT "$i\t$mean[$i]\t$sd\t$n\n";
}
close OUT;
exit;

