Skip to content

Commit

Permalink
update format + remove trailing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
csiu committed Oct 17, 2016
1 parent 65b87ef commit 5c23307
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ shinyServer(function(input, output, session) {

#shows the button when first population selected in plot
observe({
if((((is.null(selected_data()) | is.null(dim(selected_data()))) & !input$selectDefinedGroup) |
if((((is.null(selected_data()) | is.null(dim(selected_data()))) & !input$selectDefinedGroup) |
input$selectDefinedGroup & length(input$whichGroups)==0) | !is.null(rValues$selected_vector1)){
disable("pop_one_selected")
} else{
Expand Down Expand Up @@ -103,14 +103,14 @@ shinyServer(function(input, output, session) {
show('histPlot')
show("reload")
})

#output$newPlot <- renderPlotly({
# input$pop_selected
#new_tsne <- isolate(selected_data())
#plot_ly(new_tsne, x = ~x, y = ~y, text = ~key) %>%
# layout(dragmode = "select")})


# do I want to select defined groups?------
observe({
if(input$selectDefinedGroup){
Expand All @@ -137,7 +137,7 @@ shinyServer(function(input, output, session) {
})
}
})

observe({
if(input$pop_two_selected == 1){
hide('div_select_two')
Expand All @@ -159,31 +159,31 @@ shinyServer(function(input, output, session) {
})
}
})

second_clicked_eds <-reactive({input$pop_two_selected
g1 = tsne[ tsne$barcode %in% barcodes$Barcode[isolate({rValues$selected_vector1})],]
g2 = tsne[tsne$barcode %in% barcodes$Barcode[isolate({rValues$selected_vector2})],]
list(g1, g2)})




second_clicked <-reactive({input$pop_two_selected})



# Once group 1 and group 2 of cells are selected,
# create 10 boxplots showing the gene expression distributions
# of group 1 and group 2 for the top 10 up-regulated and
# top 10 down-regulated genes
output$histPlot <- renderPlotly({
if ( !is.null(differentiallyExpressed()) ) {
gene_cnt <- 10

nbr_group1 <- sum(rValues$selected_vector1)
nbr_group2 <- sum(rValues$selected_vector2)
nbr_barcodes <- nbr_group1 + nbr_group2

diff_genes <- differentiallyExpressed()$`Gene Symbol`
if(is.null(input$difGeneTable_rows_selected)){
gene_idx <- c(1:gene_cnt, (length(diff_genes)-gene_cnt+1):length(diff_genes))
Expand All @@ -195,8 +195,8 @@ shinyServer(function(input, output, session) {
gene_idx <- which(genes$Symbol == diff_genes[n])
dat1 <- log2(expression[gene_idx, rValues$selected_vector1] + 0.1)
dat2 <- log2(expression[gene_idx, rValues$selected_vector2] + 0.1)
dg_mat <- rbind(dg_mat,

dg_mat <- rbind(dg_mat,
data.frame(gene = diff_genes[n],
expr = c(dat1, dat2),
group = c(rep("1", nbr_group1),
Expand All @@ -205,20 +205,20 @@ shinyServer(function(input, output, session) {
)
)
}

# dg_mat %>% mutate(
# gene = as.factor(gene),
# expr = as.numeric(expr),
# group = as.factor(group),
# panel = as.factor(panel)) %>%
dg_mat <-
dg_mat <-
dg_mat %>% mutate(
gene = as.character(gene),
expr = as.numeric(expr),
group = as.factor(group),
panel = as.factor(panel)) %>%
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() +
Expand All @@ -229,22 +229,22 @@ shinyServer(function(input, output, session) {
plotly_empty()
}
})





output$tSNE_summary <- renderPlotly({
groups <- second_clicked_eds()
g1 = groups[[1]]
g2 = groups[[2]]
g1["group"] <- rep('group 1', dim(g1)[1])
g2["group"] <- rep('group 2', dim(g2)[1])
both_groups = rbind(g1, g2)
plot_ly(both_groups, x = ~tSNE_1, y = ~tSNE_2, text = ~barcode, color = ~group, colors = c("dark blue", "dark red"),
plot_ly(both_groups, x = ~tSNE_1, y = ~tSNE_2, text = ~barcode, color = ~group, colors = c("dark blue", "dark red"),
key = ~barcode, source = "selection_plot_two") %>%
layout(dragmode = "select",xaxis = list(range = c(-40,40)),
yaxis = list(range = c(-40,40)))
})

# histogram of cells -----------
output$cell_type_summary <- renderPlotly({
tsne_id <- table(tsne$id)
Expand All @@ -264,8 +264,8 @@ shinyServer(function(input, output, session) {
add_trace(y=~g2_cell_counts, name = "group 2") %>%
layout( yaxis = list(title = 'Count'), barmode = 'group')
})



output$downloadDifGenes = downloadHandler(
filename = 'difGenes.tsv',
Expand Down Expand Up @@ -325,7 +325,7 @@ shinyServer(function(input, output, session) {
enable('exprGeneButton')
}
})

geneExpr_genes <- reactive({
# Take a dependency on input$goButton
input$exprGeneButton
Expand Down Expand Up @@ -357,7 +357,11 @@ shinyServer(function(input, output, session) {
output[[plotname]] <- renderPlotly({
gene_of_interest <- parse_gene_input(geneExpr_genes()[my_i])
gene_name <- parse_gene_input(geneExpr_genes()[my_i], get="name")
plot_geneExpr(gene_of_interest, gene_name, input_midplot=input$Midpoint, color_low = input$colmin, color_mid = input$colmid, color_high = input$colmax)
plot_geneExpr(gene_of_interest, gene_name,
input_midplot=input$Midpoint,
color_low = input$colmin,
color_mid = input$colmid,
color_high = input$colmax)
})
})
}
Expand Down

0 comments on commit 5c23307

Please sign in to comment.