Skip to content

Commit

Permalink
enrichment analysis now will separate the up and downregulated part
Browse files Browse the repository at this point in the history
  • Loading branch information
hsiaoyi0504 committed Oct 12, 2022
1 parent 9f900b1 commit 4448d45
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 32 deletions.
19 changes: 15 additions & 4 deletions R/enrichment_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ enrichr_mod <- function(genes, databases = NULL) {

test_ora_mod <- function(dep,
databases,
contrasts = TRUE) {
contrasts = TRUE, direction="UP", log2_threshold=0.7, alpha=0.05) {
# Show error if inputs are not the required classes
assertthat::assert_that(inherits(dep, "SummarizedExperiment"),
is.character(databases),
Expand Down Expand Up @@ -106,14 +106,25 @@ test_ora_mod <- function(dep,
# Get gene symbols
df <- row_data %>%
as.data.frame() %>%
select(name, ends_with("_significant")) %>%
# select(name, ends_with("_significant")) %>%
mutate(name = gsub("[.].*", "", name))


constrast_columns <- df %>% select(ends_with("_significant")) %>% colnames()
constrasts <- gsub("_significant", "", constrast_columns)

# Run enrichR for every contrast
df_enrich <- NULL
for(contrast in colnames(df[2:ncol(df)])) {
for(contrast in constrast_columns) {
message(gsub("_significant", "", contrast))
# contrast column might have NA
df[is.na(df[[contrast]]),contrast] <- F
significant <- df[df[[contrast]],]
if (direction == "UP"){
significant <- significant[(significant[gsub("_significant", "_diff", contrast)] > log2_threshold),]
} else if (direction == "DOWN") {
significant <- significant[significant[gsub("_significant", "_diff", contrast)] < -log2_threshold,]
}
significant <- significant[significant[gsub("_significant", "_p.adj", contrast)] < alpha,]
genes <- significant$name
if (length(genes) != 0){
enriched <- enrichr_mod(genes, databases)
Expand Down
6 changes: 4 additions & 2 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,8 @@ server <- function(input, output, session) {
})

if(!is.null(input$contrast)){
go_results <- test_ora_mod(dep(), databases = as.character(input$go_database), contrasts = TRUE)
go_results <- test_ora_mod(dep(), databases = as.character(input$go_database), contrasts = TRUE,
direction = input$go_direction, log2_threshold = input$lfc, alpha = input$p)
null_enrichment_test(go_results)
plot_go <- plot_enrichment(go_results, number = 5, alpha = 0.05, contrasts = input$contrast,
databases = as.character(input$go_database), nrow = 2, term_size = 8)
Expand All @@ -748,7 +749,8 @@ server <- function(input, output, session) {

pathway_input<-eventReactive(input$pathway_analysis,{
progress_indicator("Pathway Analysis is running....")
pathway_results <- test_ora_mod(dep(), databases=as.character(input$pathway_database), contrasts = TRUE)
pathway_results <- test_ora_mod(dep(), databases=as.character(input$pathway_database), contrasts = TRUE,
direction = input$pathway_direction, log2_threshold = input$lfc, alpha = input$p)
null_enrichment_test(pathway_results)
plot_pathway<-plot_enrichment(pathway_results, number = 5, alpha = 0.05, contrasts =input$contrast_1,
databases=as.character(input$pathway_database), nrow = 2, term_size = 8)
Expand Down
69 changes: 43 additions & 26 deletions ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ ui <- function(request){shinyUI(
width = 12,
tabPanel(title = "Volcano plot",
fluidRow(
box(uiOutput("volcano_cntrst"), width = 5),
box(uiOutput("volcano_cntrst"), width = 4),
box(numericInput("fontsize",
"Font size",
min = 0, max = 8, value = 4),
Expand Down Expand Up @@ -368,7 +368,7 @@ ui <- function(request){shinyUI(
id="qc_tab",
column(
width=6,
tabBox(title = "QC Plots", width = 12, id="qc_tabBox",
tabBox(title = "QC Plots", width = 12, id="qc_tabBox", height=700,
tabPanel(title = "PCA Plot",
plotlyOutput("pca_plot", height=600)
# downloadButton('download_pca_svg', "Save svg")
Expand Down Expand Up @@ -411,30 +411,38 @@ ui <- function(request){shinyUI(
),
column(
width=6,
tabBox(title = "Enrichment", width = 12,
tabBox(title = "Enrichment", width = 12, height=600,
tabPanel(title="Gene Ontology",
box(uiOutput("contrast"), width = 5),
box(
selectInput("go_database", "GO database:",
c("Molecular Function"="GO_Molecular_Function_2017b",
"Cellular Component"="GO_Cellular_Component_2017b",
"Biological Process"="GO_Biological_Process_2017b")),
width= 5),
actionButton("go_analysis", "Run Enrichment"),
plotOutput("go_enrichment", height=600),
downloadButton('downloadGO', 'Download Table')
box(uiOutput("contrast"), width = 4),
box(selectInput("go_database", "GO database:",
c("Molecular Function"="GO_Molecular_Function_2021",
"Cellular Component"="GO_Cellular_Component_2021",
"Biological Process"="GO_Biological_Process_2021")),
width= 4),
box(radioButtons("go_direction",
"Direction",
choices = c("Up"="UP", "Down"="DOWN"),
selected = "UP"), width = 2),
actionButton("go_analysis", "Run Enrichment"),
box(plotOutput("go_enrichment", height=500),
width=12),
downloadButton('downloadGO', 'Download Table')
),
tabPanel(title= "Pathway enrichment",
box(uiOutput("contrast_1"), width = 5),
box(
selectInput("pathway_database", "Pathway database:",
c("Hallmark"="MSigDB_Hallmark_2020",
"KEGG"="KEGG_2021_Human",
"Reactome"="Reactome_2022")),
width= 5),
actionButton("pathway_analysis", "Run Enrichment"),
plotOutput("pathway_enrichment", height=600),
downloadButton('downloadPA', 'Download Table')
box(uiOutput("contrast_1"), width = 4),
box(selectInput("pathway_database", "Pathway database:",
c("Hallmark"="MSigDB_Hallmark_2020",
"KEGG"="KEGG_2021_Human",
"Reactome"="Reactome_2022")),
width= 4),
box(radioButtons("pathway_direction",
"Direction",
choices = c("Up"="UP", "Down"="DOWN"),
selected = "UP"), width = 2),
actionButton("pathway_analysis", "Run Enrichment"),
box(plotOutput("pathway_enrichment", height=500),
width=12),
downloadButton('downloadPA', 'Download Table')
)
) # Tab box close
) # column end
Expand Down Expand Up @@ -733,9 +741,18 @@ ui <- function(request){shinyUI(
# ))) # fluidrow qc close
# ) # Tab items close
),
tags$footer(
tags$p("Supported by: Proteomics & Integrative Bioinformatics Lab (University of Michigan) and the Monash Proteomics & Metabolomics Facility (Monash University)"),
align = "right")
fluidRow(
tags$div(
tags$footer(
tags$p("Proteomics & Integrative Bioinformatics Lab (University of Michigan) and the Monash Proteomics & Metabolomics Facility (Monash University)"),
align = "left",
style = "margin-left: 20px;")
# style = "position:absolute;
# bottom:0;
# width:100%;
# height:50px; /* Height of the footer */")
)
)
) # Dasbboardbody close
) #Dashboard page close
)#Shiny U Close
Expand Down

0 comments on commit 4448d45

Please sign in to comment.