Skip to content

Commit

Permalink
Make it so that boxplot of gene expression is possible #19
Browse files Browse the repository at this point in the history
  • Loading branch information
csiu committed Oct 17, 2016
1 parent 85c7d0b commit e8d6e3e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
33 changes: 33 additions & 0 deletions global.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library(readr)
library(dplyr)
library(tidyr)
library(Matrix)
library(plotly)
library(magrittr)
Expand Down Expand Up @@ -81,3 +82,35 @@ plot_geneExpr <- function(gene_of_interest, gene_name,
ggtitle(gene_name)
ggplotly()
}

#' Draw geneExpr boxplot by cluster
plot_geneExprGeneCluster <- function(gene_of_interest, gene_name){
the_genes <- setNames(gene_name, gene_of_interest)

gene_expr <-
expression[names(the_genes),] %>%
as.matrix() %>%
t() %>%
as.data.frame() %>%
tibble::rownames_to_column("barcode")
tsne1 <-
left_join(tsne, gene_expr, by="barcode") %>%
gather(gene, expr, starts_with("ENSG")) %>%
mutate(
gene = as.factor(gene),
gene = plyr::revalue(gene, the_genes)
)
tsne1 %>%
ggplot(aes(x=id, y=expr)) +
geom_boxplot() +
facet_wrap(~gene) +
xlab("Cluster") +
ylab("Normalized expression") +
theme_classic() +
theme(
axis.text.x = element_text(angle=90, hjust=1, vjust=0.5),
strip.background = element_rect(fill = NA, colour = NA)
)
ggplotly()
}

13 changes: 10 additions & 3 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ shinyServer(function(input, output, session) {
} else{
gene_idx = input$difGeneTable_rows_selected
}

dg_mat <- c()
for ( n in gene_idx ) {
gene_idx <- which(genes$Symbol == diff_genes[n])
Expand All @@ -216,8 +216,8 @@ shinyServer(function(input, output, session) {
arrange(panel)

dg_mat$gene <- factor(dg_mat$gene, levels = dg_mat$gene)
ggplot(dg_mat, aes(x=group, y=expr, fill=group)) + geom_boxplot() +
facet_wrap(~gene, scales="free_x", nrow=2, ncol=gene_cnt) +
ggplot(dg_mat, aes(x=group, y=expr, fill=group)) + geom_boxplot() +
facet_wrap(~gene, scales="free_x", nrow=2, ncol=gene_cnt) +
theme(panel.margin = unit(1, "lines"),
panel.background = element_rect(fill = "white"),
strip.background = element_rect(fill = "white"),
Expand Down Expand Up @@ -365,5 +365,12 @@ shinyServer(function(input, output, session) {
})
}

output$geneExprGeneCluster <- renderPlotly({
gene_of_interest <- parse_gene_input(geneExpr_genes())
gene_name <- parse_gene_input(geneExpr_genes(), get="name")
plot_geneExprGeneCluster(gene_of_interest, gene_name)
})


}
)
2 changes: 1 addition & 1 deletion ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ shinyUI(
)

),
column(8, uiOutput("geneExprPlot"))
column(8, uiOutput("geneExprPlot"), plotlyOutput("geneExprGeneCluster"))
),
# exploration of selection
tabPanel( 'Compare',
Expand Down

0 comments on commit e8d6e3e

Please sign in to comment.