-
Notifications
You must be signed in to change notification settings - Fork 1
/
Differentially expressed analysis.R
51 lines (50 loc) · 1.68 KB
/
Differentially expressed analysis.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
# this function is single drug datasets, a is the starting index of 1st group, b is the ending index of 1st group, c is the starting index of 2nd group, d is the ending index of 2nd group
ttest <- function(exp, a, b, c, d){
Pvalue <- c()
FC = c()
logFC = c()
for(i in 1:nrow(exp)){
y = try(t.test(as.numeric(exp[i, a:b]), as.numeric(exp[i, c:d ])), silent=FALSE)
if('try-error' %in% class(y))
{
Pvalue = c(Pvalue, NA)
FC = c(FC, NA)
logFC = c(logFC, NA)
}else{
y = t.test(as.numeric(exp[i, a:b]), as.numeric(exp[i, c:d ]))
Pvalue = c(Pvalue, y$p.value)
pre = rowMeans(exp[i, a:b] , na.rm = TRUE)
post = rowMeans(exp[i, c:d ] , na.rm = TRUE)
FC =c(FC, pre-post)
logFC = c(logFC, pre-post)
}
}
FDR=p.adjust(Pvalue, "BH")
out<-cbind(exp, Pvalue, FDR, FC, logFC)
out
}
# this function is combine drug datasets, a is the starting index of 1st group, b is the ending index of 1st group, c is the starting index of 2nd group, d is the ending index of 2nd group
ttest.D <- function(exp, a, b, c, d){
Pvalue <- c()
FC = c()
logFC = c()
for(i in 1:nrow(exp)){
y = try(t.test(as.numeric(exp[i, a:b]), as.numeric(exp[i, c:d ])), silent=FALSE)
if('try-error' %in% class(y))
{
Pvalue = c(Pvalue, NA)
FC = c(FC, NA)
logFC = c(logFC, NA)
}else{
y = t.test(as.numeric(exp[i, a:b]), as.numeric(exp[i, c:d ]))
Pvalue = c(Pvalue, y$p.value)
pre = rowMeans(exp[i, a:b] , na.rm = TRUE)
post = rowMeans(exp[i, c:d ] , na.rm = TRUE)
FC =c(FC, pre/post)
logFC = c(logFC, log2(pre/post))
}
}
FDR=p.adjust(Pvalue, "BH")
out<-cbind(exp, Pvalue, FDR, FC, logFC)
out
}