forked from BIGtigr/GenomicPipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FDR.pl
57 lines (52 loc) · 1.41 KB
/
FDR.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/perl
use Getopt::Long;
use Statistics::R;
GetOptions (\%opt,"table:s","help");
$R=Statistics::R->new();
open IN, "$ARGV[0]" or die "$!";
$R->startR;
#<IN>;
while($line = <IN>){
chomp $line;
next if ($line eq "");
@line = split /\t/,$line;
push @p,$line[-1];
push @obs,$line;
}
$temp=join(",",@p);
#print "$temp\n";
$R->send("parray <- c($temp)");
$R->send("print (parray)");
$a=$R->read;
#print "P:$a\n";
$R->send("q <- p.adjust(parray, method='fdr')");
$R->send("print (q)");
$q=$R->read;
#print "Q:$q\n";
$R->stopR();
@fdr=split(" ",$q);
for($j=0;$j<@fdr;$j++){
if ($fdr[$j]=~/\[|\]/){
splice (@fdr,$j,1);
}
}
for($j=0;$j<@fdr;$j++){
$fdr = sprintf("%.8f",$fdr[$j]);
$term = "$obs[$j]\t$fdr[$j]\t$fdr";
#print "$obs[$j]\t$fdr[$j]\n";
push @result,$term;
}
@result_sort = sort {(split /\t/,$a)[7] <=> (split /\t/,$b)[7]} @result;
$pwd = `pwd`;
chomp $pwd;
#`mkdir selected_ortholog`;
for($j=0;$j<@result_sort;$j++){
print "$result_sort[$j]\n";
if ((split /\t/,$result_sort[$j])[7] < 0.05){
$selected_gene++;
$ortholog_name = (split /\t/,$result_sort[$j])[0];
$ortholog_name =~ s/\.phy$//;
#`cp $pwd/prank/$ortholog_name.fas $pwd/selected_ortholog`;
#`cp $pwd/prank/$ortholog_name.fas.fa $pwd/selected_ortholog`;
}
}