From 5c233079ed4c30a9b416c6db9ceab76e11807359 Mon Sep 17 00:00:00 2001 From: csiu Date: Sun, 16 Oct 2016 22:05:06 -0700 Subject: [PATCH] update format + remove trailing whitespace --- server.R | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/server.R b/server.R index 11c3f37..673705a 100644 --- a/server.R +++ b/server.R @@ -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{ @@ -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){ @@ -137,7 +137,7 @@ shinyServer(function(input, output, session) { }) } }) - + observe({ if(input$pop_two_selected == 1){ hide('div_select_two') @@ -159,19 +159,19 @@ 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 @@ -179,11 +179,11 @@ shinyServer(function(input, output, session) { 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)) @@ -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), @@ -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() + @@ -229,9 +229,9 @@ shinyServer(function(input, output, session) { plotly_empty() } }) - - + + output$tSNE_summary <- renderPlotly({ groups <- second_clicked_eds() g1 = groups[[1]] @@ -239,12 +239,12 @@ shinyServer(function(input, output, session) { 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) @@ -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', @@ -325,7 +325,7 @@ shinyServer(function(input, output, session) { enable('exprGeneButton') } }) - + geneExpr_genes <- reactive({ # Take a dependency on input$goButton input$exprGeneButton @@ -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) }) }) }