Newer
Older
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
109
110
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
remove(list = ls())
gc()
# setting directory
work.dir <- "C:/Users/harta005/Projects/seed-germination-qtl/"
setwd(work.dir)
# load library
library(shiny)
library(topGO)
library(org.At.tair.db)
library(ggplot2)
# load variables for goe test
x <- org.At.tairCHR
all.genes <- as.list(as.character(read.csv('files/gene-list.csv', header = F)[, 1]))
hc.go.list <- as.data.frame(matrix(data = NA, nrow = 0, ncol = 8))
colnames(hc.go.list) <- c('GO.ID', 'Term', 'Annotated', 'Significant', 'Expected', 'Fisher',
'FDR')
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Gene ontology enrichment test for Joosen data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
textAreaInput(inputId = 'gene.list',
label = 'Put your list of gene here!',
width = '100%',
height = '400px',
value = '',
placeholder = "AT4G22890\nAT2G34630\nAT2G03270\nAT2G25590\nAT5G25130",
actionButton('button', label = 'Submit!')
),
selectInput(inputId = 'go.term',
label = 'Select the GO term:',
choices = c('biological process', 'molecular function', 'cellular component'),
selected = 'biological process'
),
actionButton(inputId = 'submit', label = 'Submit')
),
# Show a plot of the generated distribution
mainPanel(
downloadButton(outputId = 'download', 'Download'),
DT::dataTableOutput("go.result")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
reactive.gene.list <- eventReactive(input$submit, {
input$gene.list
})
# creating data table
data_table <- reactive({
gene.list <- reactive.gene.list()
gene.set <- unlist(strsplit(gene.list, '\n'))
gene.set <- factor(as.integer(all.genes %in% gene.set))
ontology <- ifelse(input$go.term == 'biological process', 'BP',
ifelse(input$go.term == 'molecular function', 'MF', 'CC'))
names(gene.set) <- all.genes
GOdata <- new("topGOdata",
description = "Analyzing clustering results",
ontology = ontology,
allGenes = gene.set,
annot = annFUN.org,mapping= "org.At.tair.db")
resultFisher <- runTest(GOdata, algorithm = 'weight', statistic = "fisher")
result.df <- GenTable(GOdata, pval = resultFisher,
orderBy = "Fisher", ranksOf = "Fisher", topNodes = length(resultFisher@score))
result.df$FDR <- round(p.adjust(p = result.df$pval, method = 'fdr'), 4)
result.df$pval <- round(as.numeric(result.df$pval), 4)
result.df <- result.df[order(result.df$FDR), ]
#result.df <- filter(result.df, FDR <= 0.001)
#hc.go.list <- rbind(hc.go.list, result.df)
result.df
})
output$go.result <- DT::renderDataTable({
data_table()
})
output$download <- downloadHandler(
filename = paste0(input$go.term, ".csv"),
content = function(file) {
write.csv(data_table(), file, row.names = FALSE)
}
)
}
# Run the application
shinyApp(ui = ui, server = server)