-
Notifications
You must be signed in to change notification settings - Fork 6
/
FindPercentile.R
53 lines (36 loc) · 1.23 KB
/
FindPercentile.R
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
#args[1] = file in
args=commandArgs(trailingOnly=TRUE)
if(length(args) != 2) {
stop("Improper parameters:\n\n\tRscript FindPercentile.r [file name] [otuput file name]\n\n")
}
file=args[1];
outFile = args[2];
outFile = paste(outFile, ".stats", sep = "")
table = read.table(file, sep="\t", header = FALSE, comment.char = "");
mew = mean(table[,2]);
sigma = sd(table[,2]);
cat("", file = outFile)
xVals = c();
count = 1;
for(i in table[,1]) {
#cat(i, " ", table[count,2], "\n", file = stderr())
x = pnorm(table[count,2], mean = mew, sd = sigma, lower.tail = FALSE);
xVals=c(xVals, x);
#cat(i, table[count,2], x, "\n", file = outFile, append = TRUE);
count = count + 1;
}
library(qvalue)
q = qvalue(xVals);
count = 1;
for(i in table[,1]) {
#cat(i, table[count,2], xVals[count], q$qvalues[count], "\n", file = outFile, append = TRUE, sep = "\t");
cat(i, table[count,2], xVals[count], file = outFile, append = TRUE, sep = "\t")
if(length(q$qvalues) > 0) {
cat("\t", q$qvalues[count], file = outFile, append = TRUE, sep = "")
}
cat("\n", file = outFile, append = TRUE)
count = count + 1
}
#outFile = paste(file, ".stats", sep = "")
#cat(q$qvalues, "\n", file = stderr());
#cat(paste("q=", q, "\n", sep = ""), file = outFile, append = TRUE)