无中间文件计算fdr
#!perl
use warnings;
use strict;
die "perl $0 <pvalue file> <outprefix>\n" if @ARGV != 2;
my (%va, %out);
open FA, $ARGV[0] or die $!;
while(<FA>)
{
<span style="white-space:pre"> </span>chomp;
<span style="white-space:pre"> </span>my @tmp = split;
<span style="white-space:pre"> </span>$va{$tmp[0]} = $tmp[7];
<span style="white-space:pre"> </span>$out{$tmp[0]} = $_;
}
my @arr;
my $n = 0;
foreach my $i(sort {$va{$a} <=> $va{$b}} keys %va)
{
<span style="white-space:pre"> </span>$arr[$n]{$i} = $va{$i};
<span style="white-space:pre"> </span>$n ++;
}
open OUT, "> $ARGV[1].fdr" or die $!;
for(my $i = 0; $i < @arr; $i ++)
{
<span style="white-space:pre"> </span>foreach my $j(keys %{$arr[$i]})
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>my $fdr = ($arr[$i]{$j} * ($n + 1)) / ($i + 1);
<span style="white-space:pre"> </span>print OUT "$out{$j}\t$fdr\n";
<span style="white-space:pre"> </span>}
}
perl的sort还是不熟啊。。。
多组方差分析(无齐性检验)
args<-commandArgs(T)
mat <- read.table(args[1], sep="\t")
column <- c(rep(0, nrow(mat)))
for(i in 1:nrow(mat))
{
dat <- as.numeric(mat[i, 2:ncol(mat)])
groups <- factor(rep(letters[1:3], each = 2))
fit <- lm(formula = dat ~ groups)
column[i] <- anova(fit)[1,5]
}
f = cbind(mat, column)
write.table(f, file=args[2], sep ="\t", quote=FALSE,row.names=FALSE, col.names=F)