-
Notifications
You must be signed in to change notification settings - Fork 16
/
server.R
100 lines (74 loc) · 2.7 KB
/
server.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
library(shiny)
library(MASS)
library(preprocessCore)
options(shiny.maxRequestSize=100*1024^2)
### Deconvolution
sigRNAseq <- read.delim("data/sigmatrixRNAseq.txt", check.names = F)
sigMicroarray <- read.delim("data/sigmatrixMicro.txt", check.names = F)
target <- read.delim("data/target.txt", header = F)
### Gene viewer
MedianTPM <- read.delim("data/Median_TPMTMM_values.txt", header = T, check.names = F)
Annotation <- read.delim("data/Annotation_genes.txt", header = T, check.names = F)
rownames(Annotation) <- Annotation[,1]
function(input, output) {
###################################
###### DECONVOLUTION PART #########
dataset <- reactive( {
req(input$GeneExpr)
read.delim(input$GeneExpr$datapath, row.names = 1)
})
Dec_res <- reactive({
# req(dataset())
# dataset()
input$goButton # this would activate this render function
isolate({
if(input$ExprType == "R"){
genes <- intersect(rownames(dataset()), rownames(sigRNAseq))
Dec <- (apply(dataset()[genes, , drop=F], 2, function(x) coef(rlm( as.matrix(sigRNAseq[genes,]), x, maxit =100 )))) *100
}
if(input$ExprType == "M"){
genes <- intersect(rownames(dataset()), rownames(sigMicroarray))
dataset2 <- normalize.quantiles.use.target(as.matrix(dataset()[genes,]), target[,1],copy=TRUE,subset=NULL)
colnames(dataset2) <-colnames(dataset())
rownames(dataset2) <- genes
Dec <- (apply(dataset2, 2, function(x) coef(rlm( as.matrix(sigMicroarray[genes,]), x, maxit =100 )))) *100
}
Dec <- signif(Dec, 3)
})
})
output$TableDec <- renderTable({
Dec_res()
},rownames = TRUE)
#### Save the files!
output$downloadData <- downloadHandler(
filename = function() {
paste(input$GeneExpr$name, "_deconvolution.txt", sep = "")
},
content = function(file) {
write.table( Dec_res(), file, sep="\t", row.names = T)
}
)
####################################
######### GENE VIEWER ############
IDgene <- reactive({
input$goButtonGeneViewer
isolate({
if(grepl("^ENSG", input$geneInput )){
grep(input$geneInput,Annotation[,1])[1]
}else if( grepl( "[A-Z]+", input$geneInput)){
grep(input$geneInput,Annotation[,2])[1]
}else{
grep(input$geneInput,Annotation[,3])[1]
}
})
})
output$BarPlot <- renderPlot({
values <- as.numeric(MedianTPM[IDgene(),])
names(values) <- colnames(MedianTPM)
par(mar=c(7,5,1,2))
barplot(values, col = "lightblue", ylab = "Median TPM_TMM value", las=2)
})
output$tabGene <- renderTable({
t(Annotation[IDgene(),])
}, include.rownames=T, include.colnames=FALSE)
}