| 
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -10,11 +10,9 @@ library(flextable) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					source("funcions.R") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					ui <- fluidPage( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    # Application title | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    titlePanel("ELISPOTs"), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    sidebarLayout( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  #Navbar | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  navbarPage("ELISPOTS", | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					             tabPanel("Diseño", | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        sidebarPanel( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            fileInput(inputId = "file1", label = "Dades", multiple = F), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            selectInput(inputId = "test", "Test Estadístic", selected = "Ttest", choices = c("T-test (adj Holm)","Wilcoxon (adj Holm)")), | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -28,7 +26,26 @@ ui <- fluidPage( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            plotOutput("distPlot"), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            uiOutput("flexstats") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        ) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    ) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    ), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    tabPanel("Exportar", | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					             sidebarPanel(width=2, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					               sliderInput("width", "Ancho", min=1000, max=20000, step=1000, value=10000), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					               sliderInput("height", "Altura", min=1000, max=20000, step=1000, value=6000), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					               textInput("colors", label="Colors", value=""), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					               sliderInput("boxplot-width", "% Ancho Boxplots", min=0.1, max=1, step=0.1, value=0.7), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					               sliderInput("point-size", "Tamaño puntos", min=1, max=10, step=1, value=3), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					               sliderInput("font-size", "Tamaño textos", min=5, max=30, step=1, value=11), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					               checkboxInput(inputId = "stats2", label = "Mostrar estadística", value = F), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					               checkboxInput(inputId = "legend", label = "Mostrar llegenda", value = T), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					               selectInput("theme", "Seleccionar Tema", selected="BW", choices=c("BW", "Default", "Classic")), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					               downloadButton("downloadPicture", "Exportar") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					             ), | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					             mainPanel( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					               uiOutput("expPlotUI") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					             ) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      ) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					  ) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					# Define server logic required to draw a histogram | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -36,6 +53,9 @@ server <- function(input, output) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    dades<-reactiveValues() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    dades$taula<-NULL | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    dades$stats<-NULL | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    dades$final<-NULL | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    dades$maps<-NULL | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    dades$plot<-NULL | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    observe({ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (!is.null(input$file1)){  | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            dades$taula<-read_xlsx(input$file1$datapath) | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -68,7 +88,6 @@ server <- function(input, output) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					              t_substr[,3:ncol(t_substr)]<-apply(t_substr[,3:ncol(t_substr)],2, function(x) replace(x, which(x < 0),0)) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					              colnames(t_substr)<-c("Mice", "Groups", colnames(t_mean)[2:ncol(t_mean)]) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            }else{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					              print(1) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					              t_especifica<-t_mean[,grep("Mock_", colnames(t_mean), invert=T)] | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					              t_mock<-t_mean[,c(which(colnames(t_mean) == "Mice"),grep("Mock_", colnames(t_mean)))] | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					              t_temp<-melt(t_especifica, variable.name = "condition", value.name = "spots") | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -97,6 +116,7 @@ server <- function(input, output) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                t_maps[["brackets"]]<-as.data.frame(matrix(nrow = 0, ncol=4)) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                colnames(t_maps$brackets)<-c("y1", "y2", "x1", "x2") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                dades$stats<<-t_stats | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                dades$maps<<-t_maps | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            }else{ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					              if (input$test == "T-test (adj Holm)"){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                t_stats<-multi_stats(t, "value", "variable", "Groups", stat.test = "ttest") | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -109,8 +129,9 @@ server <- function(input, output) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					              t_stats<-t_stats %>% filter(p.signif != "ns") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					               | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					              t_maps<-generate_labstats(t_stats, t, "value", "variable", "Groups") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					              dades$maps<<-t_maps | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					             | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            dades$final<<-t_substr %>% select(-c(ctrl, mock)) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            set.seed(123) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            if (input$positive == T){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					                ggplot(melt(t_substr, id=c("Mice", ctrl, "Groups")), aes(variable, value))+ | 
				
			
			
		
	
	
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
				
				 | 
				
					@ -162,6 +183,53 @@ server <- function(input, output) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    }) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    output$expPlotUI<- renderUI({ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      if (!is.null(dades$final)){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        plotOutput("expPlot", width=paste0(input$width/10,"px"), height = paste0(input$height/10, "px")) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    }) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    output$expPlot <- renderPlot({ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      observeEvent(dades$final, {}) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      if (!is.null(dades$final)){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        t_substr<-dades$final | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        t_stats<-dades$stats %>% filter(p.signif != "ns") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        t_maps<-dades$maps | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					         | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        ids<-c("Mice", "Groups") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        set.seed(123) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        g<-ggplot(melt(t_substr, id=ids), aes(variable, value))+ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          labs(x="", y="Spots/2.5*10^5 cells")+ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          geom_boxplot(color="black", aes(fill=Groups), alpha=0.4, outlier.alpha = 0, position=position_dodge(width=0.8),width=input$`boxplot-width`)+ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          geom_jitter(position=position_jitterdodge(jitter.width = 0.2), shape=21, aes(fill=Groups), size=input$`point-size`)+ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          scale_x_discrete(limits=colnames(t_substr)[!colnames(t_substr) %in% c("Mice", "Groups")]) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (input$theme == "BW"){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          g<-g+theme_bw(base_size = input$`font-size`) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (input$theme == "Classic"){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            g<-g+theme_classic(base_size = input$`font-size`)   | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (input$theme == "Default"){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          g<-g+theme_gray(base_size = input$`font-size`) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        g<-g+theme(axis.text.x=element_text(angle=45, hjust=1)) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (input$stats2 == T){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          g<-g+geom_segment(data=t_maps$brackets, aes(x=x1, xend=x2, y=y1, yend=y2), color="black")+ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            geom_text(data=t_stats, aes(t_maps$label$x, t_maps$label$y, label=p.signif), color="black") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (input$legend == F){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          g<-g+guides(color=FALSE, fill=FALSE) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        if (input$colors != ""){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          v_col<-strsplit(input$colors, ",")[[1]] | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					          g<-g+scale_color_manual(values=v_col)+ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            scale_fill_manual(values=v_col) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        dades$plot<<-g | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        g | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    }, res=72) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					     | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    output$downloadData <- downloadHandler( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        filename = function() { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					            paste("elispot", ".zip", sep="") | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
				
				 | 
				
					@ -179,6 +247,20 @@ server <- function(input, output) { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        }, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        contentType="application/zip" | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    ) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    output$downloadPicture <- downloadHandler( | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      filename = function() { | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        paste("Figura", ".png", sep="") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      }, | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      content = function(file){ | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        print(file) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        # tempReport <- file.path(tempdir(), "elispots.Rmd") | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        # file.copy("elispots.Rmd", tempReport, overwrite = TRUE) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        png(file, width = input$width, height=input$height, units = "px", res=720) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        plot(dades$plot) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					        dev.off() | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					         | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					      } | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					    ) | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					} | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					
 | 
				
			
			
		
	
		
			
				
					 | 
					 | 
				
				 | 
				
					# Run the application  | 
				
			
			
		
	
	
		
			
				
					| 
						
						
						
					 | 
				
				 | 
				
					
 |