Skip to content

Commit 7f95bb2

Browse files
author
nthomasCUBE
authored
Add files via upload
1 parent 44f2af0 commit 7f95bb2

File tree

2 files changed

+68
-17
lines changed

2 files changed

+68
-17
lines changed

methods.R

+50-17
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,20 @@ calc_cmp_transcriptomics_traits=function(v){
1919
print(c("INFO|transcriptomics VS traits"))
2020
cn=c("---",colnames(v$trait))
2121
appendTab(inputId = "tabset",
22-
tabPanel("Correlation",
22+
tabPanel("Correlation with a trait",
2323
isolate(selectInput("phen0", "Select Phenotype",choices=cn)),
2424
radioButtons("corr_type", "Correlation coefficient:", c("Spearman" = "spearman","Pearson" = "pearson")),
25+
radioButtons("multiple_test_correction", "Multiple testing correction:", c("Benjamini-Hochberg (BH)"="BH","Bonferroni" = "bonferroni")),
2526
isolate(actionButton("go_alpha2", "Go!"))
2627
))
2728
appendTab(inputId = "tabset",
2829
tabPanel("Compare phenotypes",
2930
isolate(selectInput("phen1", "Phenotype-1",choices=cn)),
3031
isolate(selectInput("phen2", "Phenotype-2",choices=cn)),
3132
isolate(selectInput("phen3", "Phenotype-3",choices=cn)),
33+
radioButtons("corr_type2", "Correlation coefficient:", c("Spearman" = "spearman","Pearson" = "pearson")),
34+
radioButtons("multiple_test_correction2", "Multiple testing correction:", c("Benjamini-Hochberg (BH)"="BH","Bonferroni" = "bonferroni")),
35+
radioButtons("significance_level", "Significance level:", c("0.001"=0.001,"0.05" = 0.05)),
3236
isolate(actionButton("go_alpha3", "Go!"))
3337
))
3438
appendTab(inputId = "tabset",
@@ -40,54 +44,84 @@ calc_cmp_transcriptomics_traits=function(v){
4044
}
4145

4246
cmp_traits=function(v,my_trait1,my_trait2,my_trait3){
43-
print("INFO|cmp_traits")
47+
print("INFO|cmp_traits|start")
4448

4549
shinyjs::show("plot")
4650
shinyjs::hide("plot2")
4751

52+
mt_cor=v$multiple_test_correction2
53+
cor_type=v$corr_type2
54+
sign_level=as.double(v$significance_level)
55+
4856
A=(colnames(v$transcriptomics))
4957
B=v$trait[,1]
5058
AB=B[B%in%A]
5159
ix=which(v$trait[,1]%in%AB)
5260
N=dim(v$transcriptomics)[1]
5361
SET_A=c(); SET_B=c(); SET_C=c()
62+
63+
raw_p_val1=c()
64+
raw_p_val2=c()
65+
raw_p_val3=c()
66+
5467
for(x in 1:N){
68+
print(paste0("INFO|cmp_traits|start",x,"|",N))
69+
print(sign_level)
5570
if(my_trait1!="---"){
5671
iy=which(colnames(v$trait)==my_trait1)
5772
T1=as.numeric(v$trait[ix,iy])
5873
T2=as.numeric(unlist(v$transcriptomics[x,AB]))
59-
my_p=(cor.test(T1,T2))
60-
if(my_p$p.value<0.05){
61-
SET_A=c(SET_A,v$transcriptomics[x,1])
62-
}
74+
my_p=(cor.test(T1,T2,method=cor_type))
75+
SET_A=c(SET_A,v$transcriptomics[x,1])
76+
raw_p_val1=c(raw_p_val1,my_p$p.value)
6377
}
6478
if(my_trait2!="---"){
6579
iy=which(colnames(v$trait)==my_trait2)
6680
T1=as.numeric(v$trait[ix,iy])
6781
T2=as.numeric(unlist(v$transcriptomics[x,AB]))
68-
my_p=(cor.test(T1,T2))
69-
if(my_p$p.value<0.05){
70-
SET_B=c(SET_B,v$transcriptomics[x,1])
71-
}
82+
my_p=(cor.test(T1,T2,method=cor_type))
83+
SET_B=c(SET_B,v$transcriptomics[x,1])
84+
raw_p_val2=c(raw_p_val2,my_p$p.value)
7285
}
7386
if(my_trait3!="---"){
7487
iy=which(colnames(v$trait)==my_trait3)
7588
T1=as.numeric(v$trait[ix,iy])
7689
T2=as.numeric(unlist(v$transcriptomics[x,AB]))
77-
my_p=(cor.test(T1,T2))
78-
if(my_p$p.value<0.05){
79-
SET_C=c(SET_C,v$transcriptomics[x,1])
80-
}
90+
my_p=(cor.test(T1,T2,method=cor_type))
91+
SET_C=c(SET_C,v$transcriptomics[x,1])
92+
raw_p_val3=c(raw_p_val3,my_p$p.value)
8193
}
8294

8395
}
96+
print(summary(raw_p_val1))
97+
print(summary(raw_p_val2))
98+
print(summary(raw_p_val3))
99+
100+
raw_p_val1=p.adjust(raw_p_val1,mt_cor)
101+
SET_A=SET_A[raw_p_val1<=sign_level]
102+
raw_p_val2=p.adjust(raw_p_val2,mt_cor)
103+
SET_B=SET_B[raw_p_val2<=sign_level]
104+
raw_p_val3=p.adjust(raw_p_val3,mt_cor)
105+
SET_C=SET_C[raw_p_val3<=sign_level]
106+
107+
print(SET_A)
108+
print(SET_B)
109+
print(SET_C)
110+
111+
print(paste0("SET_A","|",length(SET_A)))
112+
print(paste0("SET_B","|",length(SET_B)))
113+
print(paste0("SET_C","|",length(SET_C)))
114+
84115
area1=SET_A[!(SET_A%in%SET_B)]
85116
area2=SET_B[!(SET_B%in%SET_A)]
86117
cross=SET_A[SET_A%in%SET_B]
87118
area1=length(area1)
88119
area2=length(area2)
89120
cross=length(cross)
90-
if(length(SET_C)>0){
121+
122+
if((length(SET_A)+length(SET_B)+length(SET_C))==0){
123+
shinyalert("INFO", "No genes remained using the current filters!", type = "info")
124+
}else if(length(SET_C)>0){
91125
n12=SET_A[SET_A%in%SET_B]; n12=length(n12)
92126
n23=SET_B[SET_B%in%SET_C]; n23=length(n23)
93127
n13=SET_A[SET_A%in%SET_C]; n13=length(n13)
@@ -137,7 +171,7 @@ make_corr=function(v,my_trait,output){
137171
X4=c(X4,my_trait)
138172
}
139173
L=list()
140-
X2=p.adjust(X2,method="bonferroni")
174+
X2=p.adjust(X2,method=v$multiple_test_correction)
141175
L[[1]]=X1
142176
L[[2]]=X2
143177
L[[3]]=X3
@@ -173,7 +207,6 @@ make_corr=function(v,my_trait,output){
173207
abline(h=0.05,lty=3)
174208
abline(h=0.001,lty=2)
175209

176-
177210
v$df_output=new_entry
178211

179212
return(L)

server.R

+18
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ server <- function(input, output, session)
7272
v$corr_type=input$corr_type;
7373
})
7474

75+
# ----------------------------------------------
76+
# Multiple test correction
77+
# ----------------------------------------------
78+
observeEvent(input$multiple_test_correction,{
79+
v$multiple_test_correction=input$multiple_test_correction
80+
})
81+
82+
# ----------------------------------------------
83+
# Multiple test correction
84+
# ----------------------------------------------
85+
observeEvent(input$multiple_test_correction2,{
86+
v$multiple_test_correction2=input$multiple_test_correction2
87+
})
88+
89+
observeEvent(input$significance_level,{
90+
v$significance_level=input$significance_level
91+
})
92+
7593
output$download1 <- downloadHandler(
7694
filename = function() {
7795
paste("OTUs-traitCorr_report", ".csv", sep = "")

0 commit comments

Comments
 (0)