-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbugs_differential_analysis.R
69 lines (36 loc) · 1.57 KB
/
bugs_differential_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#######################
## This script performs differential abundance for metaphlan results with a small sample size per group.
#######################
library(doBy)
library(foreach)
library(parallel)
library(doParallel)
cl<-makeCluster(detectCores())
registerDoParallel(cl)
meta<-read.table("mapping.tsv",sep="\t",stringsAsFactors = F,header = T)
bugs<-read.table('bugs/uc_bugs.tsv',sep="\t",header = T,stringsAsFactors = F)
bugs<-bugs[which(bugs$sample_id%in%meta$id),]
meta<-meta[which(meta$id%in%bugs$sample_id),]
meta<-meta[match(bugs$sample_id,meta$id),]
bugs<-bugs[match(meta$id,bugs$sample_id),]
table(meta$id==bugs$sample_id)
bugs$sample_id<-NULL
bugs<-cbind(meta,bugs)
taxa<-colnames(bugs[,3:ncol(bugs)])
data<-matrix(nrow=0,ncol=8)
colnames(data)<-c("variable","zero_proportion","Hc","Post-uc","Pre-uc ","kw_pre_post.p","kw_pre_hc.p","kw_post_hc.p")
dec=3
data<-foreach(i=taxa,.combine = "rbind")%dopar%{
zeroProp<-zero_prop(bugs,i)
form<-as.formula(paste0(i," ~ category"))
means<-mean_groups(bugs,form)
kw_pre_post<-kruskal_pvalue(bugs,c("Pre-uc","Post-uc"),form)
kw_pre_hc<-kruskal_pvalue(bugs,c("Pre-uc","Hc"),form)
kw_post_hc<-kruskal_pvalue(bugs,c("Post-uc","Hc"),form)
row<-c(i,round(zeroProp,dec),means,round(kw_pre_post,dec),round(kw_pre_hc,dec),round(kw_post_hc,dec))
names(row)<-c("variable","zero_proportion","mean_Hc","mean_Post-uc","mean_Pre-uc ","kw_pre_post.p","kw_pre_hc.p","kw_post_hc.p")
row
}
#Multiple testing correction
write.table(data,'bugs_comparison.tsv',sep="\t",col.names = T, row.names = F,quote = F)
stopCluster(cl)