Detectar si hay pestaña para sexo de los ratones y adaptarse.

This commit is contained in:
Costa
2022-02-24 14:45:24 +01:00
parent ffc930ce5f
commit 882e7eab47
+24 -6
View File
@@ -1,8 +1,6 @@
library(shiny) library(shiny)
# library(ggplot2)
library(reshape2) library(reshape2)
library(openxlsx) library(openxlsx)
# library(dplyr)
library(car) library(car)
library(ggbeeswarm) library(ggbeeswarm)
library(gtools) library(gtools)
@@ -104,8 +102,10 @@ server <- function(input, output) {
} }
dades$taula<-taula dades$taula<-taula
dades$groups<-read.xlsx(input$file_sizes$datapath, sheet = 2, colName=F)[,1] dades$groups<-read.xlsx(input$file_sizes$datapath, sheet = 2, colName=F)[,1]
if (readxl::excel_sheets(input$file_sizes$datapath) %>% length > 2){
dades$sex<-read.xlsx(input$file_sizes$datapath, sheet = 3, sep.names = " ") dades$sex<-read.xlsx(input$file_sizes$datapath, sheet = 3, sep.names = " ")
} }
}
}) })
output$firstPlot <- renderPlot({ output$firstPlot <- renderPlot({
observeEvent(dades$taula, {}) observeEvent(dades$taula, {})
@@ -150,7 +150,12 @@ server <- function(input, output) {
low_cuttof<-input$lowcut low_cuttof<-input$lowcut
# print(up_cuttof) # print(up_cuttof)
df<-df[df$Volume < up_cuttof & df$Volume >= low_cuttof,] df<-df[df$Volume < up_cuttof & df$Volume >= low_cuttof,]
if (is.null(dades$sex)){
df<-add_column(df, sex="undefined")
}else{
df<-merge(df, dades$sex) df<-merge(df, dades$sex)
}
# df["Mouse"]<-gsub("[a-zA-Z]", "", df$MouseID) # df["Mouse"]<-gsub("[a-zA-Z]", "", df$MouseID)
# print(df$Volume) # print(df$Volume)
@@ -159,7 +164,7 @@ server <- function(input, output) {
ngroup<-length(dades$groups) ngroup<-length(dades$groups)
df_def<-list() df_def<-list()
# print(head(df)) # print(head(df))
for (sex.var in c("male","female")){ for (sex.var in unique(df$sex)){
# print(sex.var) # print(sex.var)
df_sex<-df %>% filter(`sex` == sex.var) df_sex<-df %>% filter(`sex` == sex.var)
ind.list<-list() ind.list<-list()
@@ -194,16 +199,26 @@ server <- function(input, output) {
# print(df_sex) # print(df_sex)
df_def[[sex.var]]<-merge(df_sex %>% select(-group), ind.list[[index]]) df_def[[sex.var]]<-merge(df_sex %>% select(-group), ind.list[[index]])
} }
# df_def<-do.call(rbind, c(df_def, make.row.names=F)) df_def<-do.call(rbind, c(df_def, make.row.names=F))
# lapply(df_def, function(x) x %>% as_tibble %>% print(n=Inf)) # lapply(df_def, function(x) x %>% as_tibble %>% print(n=Inf))
df_def<-rbind(df_def[[1]], df_def[[2]], make.row.names=F) # df_def<-rbind(df_def[[1]], df_def[[2]], make.row.names=F)
if ("Group" %in% colnames(df_def)){ if ("Group" %in% colnames(df_def)){
df_def<-df_def %>% select(-"Group") df_def<-df_def %>% select(-"Group")
} }
df_def<-merge(merge(dades$taula, dades$sex) %>% select(-Group), df_def[,c("ID animal", "group")] %>% unique, all=T, by="ID animal") %>% select(c(`ID animal`, `sex`,`ID tumor`, Volume, Cage, Major, Minor, group)) df_def<-merge(
if(!is.null(dades$sex)){merge(dades$taula, dades$sex)}else{dades$taula %>% add_column(sex="undefined")} %>% select(-Group),
df_def[,c("ID animal", "group")] %>% unique, all=T, by="ID animal") %>%
select(c(`ID animal`, `sex`,`ID tumor`, Volume, Cage, Major, Minor, group))
df_def[!paste0(df_def$`ID animal`, df_def$`ID tumor`) %in% paste0(df$`ID animal`, df$`ID tumor`),"group"]<-NA df_def[!paste0(df_def$`ID animal`, df_def$`ID tumor`) %in% paste0(df$`ID animal`, df$`ID tumor`),"group"]<-NA
dades$db<-df_def dades$db<-df_def
if (is.null(dades$sex)){
ggplot(df_def, aes(group, Volume))+
geom_boxplot(outlier.alpha = F)+
geom_jitter(width=0.25)+
geom_point(stat="summary", color="blue", size=3)+
theme(axis.text.x = element_text(angle=90, hjust=1, vjust=0.5))
}else{
ggarrange( ggarrange(
ggplot(df_def, aes(group, Volume))+ ggplot(df_def, aes(group, Volume))+
geom_boxplot(outlier.alpha = F)+ geom_boxplot(outlier.alpha = F)+
@@ -220,7 +235,10 @@ server <- function(input, output) {
guides(fill="none")+ guides(fill="none")+
theme(axis.text.x = element_text(angle=90, hjust=1, vjust=0.5)), ncol = 1, heights = c(0.35, 0.65)), theme(axis.text.x = element_text(angle=90, hjust=1, vjust=0.5)), ncol = 1, heights = c(0.35, 0.65)),
nrow = 1, aligh="h", widths = c(0.65, 0.35)) nrow = 1, aligh="h", widths = c(0.65, 0.35))
}
}) })
output$distPlot <- renderPlot({ output$distPlot <- renderPlot({
observeEvent(dades$taula, {}) observeEvent(dades$taula, {})
if (!is.null(dades$taula)){ if (!is.null(dades$taula)){