-
Notifications
You must be signed in to change notification settings - Fork 1
/
parseDtests.R
108 lines (73 loc) · 2.75 KB
/
parseDtests.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
get.range <- function(r) {
colrange <- range(r)
}
# Sets number of digits for P-values.
# Can change to any integer.
p.digits = 10
# Filenames must end with .txt and .z (for popfiles)
filenames <- list.files(pattern="*.txt")
zfilenames <- list.files(pattern="*.z")
popPvalue=list()
popz=list()
# *.z files produced from CompD
for (i in 1:length(zfilenames)) {
zfiles <- read.delim(zfilenames[i], header=TRUE, sep="\t")
Pvalue <- zfiles[[3]]
popPvalue[i] <- round(Pvalue, digits = p.digits)
avgz <- round(zfiles[[2]], digits = 5)
popz[i] <- avgz
}
df_total <- data.frame()
# *.txt file produced from CompD
for (j in 1:length(filenames)) {
test <- tools::file_path_sans_ext(filenames[j])
dataset <- read.delim(filenames[j], header=TRUE, sep="\t")
rws <- nrow(dataset)
newP <- dataset[[13]]
zrange <- get.range(dataset[[12]])
minz <- round(zrange[1], digits = 5)
maxz <- round(zrange[2], digits = 5)
Z <- paste0("[", minz, ",", maxz,"]")
stdev_d <- sd(dataset[[8]])
mean_d <- mean(dataset[[8]])
d <- round(mean_d, digits = 5)
STDEV_D <- round(stdev_d, digits = 5)
D <- paste0(d, " (", STDEV_D, ")")
# Chi-Square No. Significant/Not Significant tests
sigChi <- sum(dataset[[11]] <= 0.05)
Chi_sig_notsig <- paste(sigChi, rws, sep="/")
# If P-value <= 0.05
sigtests <- sum(newP <= 0.05)
# Adds Z.Significant/NotSignificant tests to DataFrame
sig_notsig <- paste(sigtests, rws, sep="/")
# Bonferroni Correction from number of tests
bonferroni <- 0.05 / rws
pop.p.adj.bonf <- popPvalue[[j]] * as.numeric(rws)
if (pop.p.adj.bonf > 1.0)
{
pop.p.adj.bonf = 1.0
}
# P-value <= Bonferroni alpha
bon_sig <- sum(newP <= bonferroni)
#Adds Sig/NotSig to DataFrame
bonsig_notsig <- paste(bon_sig, rws, sep="/")
df <- data.frame(test, D, Z, Chi_sig_notsig, sig_notsig,
round(bonferroni, digits = p.digits), bonsig_notsig,
popz[j], popPvalue[j],
pop.p.adj.bonf,
stringsAsFactors = FALSE)
colnames(df) <- c("Test", "Mean.D (STDEV.D)", "Z-Range",
"Chi-Square.Sig", "Z.Significant",
"Bonferroni.Alpha", "Bonferroni.Significant",
"Population-Z", "Pop_P-value", "Pop.P.Adjusted")
row.names(df_total) <- NULL
df_total <- rbind(df_total, df)
}
# Outfile to write to. Will overwrite if script is run again.
ofile <- "summary.tsv"
write.table(format(df_total, digits = p.digits, scientific=F),
file=ofile,
quote=FALSE,
sep="\t",
col.names=TRUE,
row.names=FALSE)