Compare commits

..

28 Commits

Author SHA1 Message Date
marcelcosta 0887ab933a Análisis-Randomización. Evitar la desaparición de ratones sin grupo (excluidos). 2024-09-25 15:46:01 +02:00
marcelcosta a3eaf3e7a9 Corregir que al exportar randomización mantenga "Abs" en columnas si era así en el original. 2024-09-25 15:28:10 +02:00
marcelcosta 1237794f62 Añadido Abs como opción para medidas de IVIS en la pestaña Análisis. 2024-09-25 15:22:15 +02:00
marcelcosta bbf19befaf Corrección firstoper en sección survival. 2024-01-22 12:07:08 +01:00
marcelcosta 3a9907c480 Borrado de "prints". 2024-01-22 12:05:52 +01:00
marcelcosta cda5d7f881 Funcionalidad "incremento de volumen". 2024-01-22 11:43:27 +01:00
marcelcosta 8539caa993 Al exportar gráfic cin_indiv agrupaba por Animal y no Animal+Side. 2024-01-19 14:41:01 +01:00
marcelcosta 7783dc6c4b Bug anterior en sección Exportar. 2024-01-19 14:28:02 +01:00
marcelcosta fe865f55e4 Misma bug que anterior. 2024-01-19 14:24:30 +01:00
marcelcosta b01f7bb11d Solución de bug test for table 2024-01-19 14:19:46 +01:00
marcelcosta 459a8001fe Solución de bug al empezar a día 0 con volumen > 0. 2024-01-19 14:15:42 +01:00
marcelcosta 455901a1db Solucionar bug firstoper. 2024-01-17 13:04:58 +01:00
marcelcosta 43776f80cb Bug al randomizar con sexo. 2024-01-11 14:27:48 +01:00
marcelcosta d9a5689c99 Corrección bug operados. 2023-12-12 17:31:18 +01:00
marcelcosta 092a788125 Eliminar la columna Cage manteniendo la compatibilidad con hojas de cálculo antiguas. 2023-12-12 17:12:05 +01:00
marcelcosta 80362a28db Primer paso migracion a columna única para ID.Animal. 2023-12-04 12:14:25 +01:00
marcelcosta 9f0cda73eb Corrección del Survival y implementación de corte de operados y eliminación de muertes. 2023-10-05 17:30:36 +02:00
marcelcosta 16088aac2b Implementar la posibilidad de eliminar los ratones que hayan muerto prematuramente. 2023-10-05 17:23:39 +02:00
marcelcosta fd6493320f Correcció de bugs a l'exportar survival. 2023-02-16 14:42:02 +01:00
marcelcosta 8dc0177515 Añadir una opción en el apartado de exportar para multiplicar o dividir por mil. 2023-02-16 12:52:55 +01:00
marcelcosta 35a73598d3 Adaptado la normalización a nuevo formato. Se puede indicar el día a normalizar. 2023-02-16 12:42:42 +01:00
marcelcosta 0e4ef399fd Cortar gráficos cuando hay una operación. 2023-02-15 13:57:20 +01:00
marcelcosta 2ca8e2b212 En análisis, coger sólo las 11 primeras columnas. 2023-02-14 16:45:54 +01:00
marcelcosta 54a20f10c7 Eliminar un comentario. 2023-02-10 16:46:45 +01:00
marcelcosta 3e6b97c546 Corrección errores conversión en análisis. 2023-02-10 16:22:12 +01:00
marcelcosta fa2c784602 En análisis, conversión de formato antiguo a moderno. 2023-02-10 16:04:43 +01:00
marcelcosta 633fb5f953 Implementar la pestaña para seleccionar orden y aparición de grupos. 2023-02-10 15:37:01 +01:00
marcelcosta c416a850b5 Solucionar problemas con el exportado de volúmenes. 2023-02-10 15:25:19 +01:00
+339 -111
View File
@@ -26,6 +26,7 @@ ui <- fluidPage(
uiOutput('ncages'), uiOutput('ncages'),
uiOutput('ntumors'), uiOutput('ntumors'),
# selectInput(inputId = "measure_sys", "Sistema de medida", selected = "L-W-D", choices = c("L-W-D","Min-Max","Absorbance")), # selectInput(inputId = "measure_sys", "Sistema de medida", selected = "L-W-D", choices = c("L-W-D","Min-Max","Absorbance")),
uiOutput('day_vol'),
uiOutput('lowcut'), uiOutput('lowcut'),
uiOutput('upcut'), uiOutput('upcut'),
uiOutput('goButton'), uiOutput('goButton'),
@@ -46,6 +47,8 @@ ui <- fluidPage(
uiOutput('cutoffUI'), uiOutput('cutoffUI'),
checkboxInput("filter_stats","Filtrar Estadística"), checkboxInput("filter_stats","Filtrar Estadística"),
checkboxInput("increase_volume","Usar Incremento de Volumen"), checkboxInput("increase_volume","Usar Incremento de Volumen"),
checkboxInput("operated","Cortar al operar", value = TRUE),
checkboxInput("dead","Eliminar ratones muertos", value = FALSE),
downloadButton("downloadVolume", "Descargar Volúmenes") downloadButton("downloadVolume", "Descargar Volúmenes")
), ),
mainPanel( mainPanel(
@@ -64,6 +67,7 @@ ui <- fluidPage(
h3('Seleccionar figura'), h3('Seleccionar figura'),
selectInput("fig_id", "", selected="", choices=c("Cinética Grupo", "Cinética Individual", "Survival")), selectInput("fig_id", "", selected="", choices=c("Cinética Grupo", "Cinética Individual", "Survival")),
h3('Formato'), h3('Formato'),
selectInput("unit_fact", "Factor de unidad", choices = c("0.001","1","1000"), selected="1"),
sliderInput("width", "Ancho", min=1000, max=20000, step=1000, value=10000), sliderInput("width", "Ancho", min=1000, max=20000, step=1000, value=10000),
sliderInput("height", "Altura", min=1000, max=20000, step=1000, value=6000), sliderInput("height", "Altura", min=1000, max=20000, step=1000, value=6000),
textInput("colors", label="Colors", value=""), textInput("colors", label="Colors", value=""),
@@ -86,9 +90,14 @@ ui <- fluidPage(
) )
# Define server logic required to draw a histogram # Define server logic required to draw a histogram
server <- function(input, output) { server <- function(input, output) {
# Diseño ------------------------------------------------------------------
# Diseño # Diseño
dades<-reactiveValues() dades<-reactiveValues()
dades$taula<-NULL dades$taula<-NULL
@@ -97,22 +106,39 @@ server <- function(input, output) {
dades$db<-NULL dades$db<-NULL
observe({ observe({
if (!is.null(input$file_sizes)){ if (!is.null(input$file_sizes)){
taula<-read.xlsx(input$file_sizes$datapath, sheet = 1, sep.names = " ") table<-read.xlsx(input$file_sizes$datapath, sheet = 1, check.names = F, sep.names = " ", detectDates = T,cols=1:11)
if ("DPV" %in% colnames(taula)){ if("ID.animal" %in% colnames(table)){
taula<-dcast(taula, Cage+`ID animal`+`ID tumor`+Group~DPV, value.var = "0") table<-table %>%
# taula$Major<-taula$Major/1000 rename(Animal=`ID.animal`, Side=`ID.tumor`)
# taula$Minor<-taula$Minor/1000 table<-table %>% gather(DayPostInoc, Value, which(!is.na(as.numeric(colnames(table))))) %>%
# taula["Volume"]<-((taula$Major*taula$Minor*taula$Minor)*(pi/6))*1000 relocate(DayPostInoc, .before = Group) %>% spread(DPV, Value) %>%
taula$Major<-taula$Major rename(Long=Major, Wide=Minor) %>%
taula$Minor<-taula$Minor add_column(Date="", .after = "Animal") %>%
taula["Volume"]<-((taula$Major*taula$Minor*taula$Minor)*(pi/6)) add_column(Weight="", .after="Group") %>%
add_column(Volume="",Observations="") %>%
relocate(Side, .after = "Group")
table$DayPostInoc<-as.numeric(table$DayPostInoc)
} }
if ("TS" %in% colnames(taula)){ table$Date<-format(table$Date, format="%d/%m/%Y")
taula<-dcast(taula, Cage+`ID animal`+`ID tumor`+Group~TS, value.var = "0") if ("sex" %in% colnames(table)){table<-select(table, -sex)}
taula["Volume"]<-taula$`TS-Deep`*taula$`TS-Length`*taula$`TS-Width`*pi/6 if ("Abs" %in% colnames(table)){
table<-rename(table, "Volume"="Abs")
}else{
for (i in 1:nrow(table)){
long<-as.numeric(gsub(",",".",strsplit(as.character(table[i,"Long"]),"+", fixed = T)[[1]]))
wide<-as.numeric(gsub(",",".",strsplit(as.character(table[i,"Wide"]),"+", fixed = T)[[1]]))
table[i,"Volume"]<-sum(sapply(1:length(long), function(x) (long[x]*wide[x]*wide[x])*(pi/6)))
}
table$Volume<-as.numeric(table$Volume)
} }
dades$taula<-taula
dades$groups<-read.xlsx(input$file_sizes$datapath, sheet = 2, colNames=F)[,1] if ("Cage" %in% colnames(table)){
table$Animal<-paste0(table$Cage, table$Animal)
table<-table[,-which(colnames(table) == "Cage")]
}
dades$taula<-table
dades$groups<-read.xlsx(input$file_sizes$datapath, sheet = "Groups", colNames=F)[,1]
if (readxl::excel_sheets(input$file_sizes$datapath) %>% length > 2){ 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 = " ")
} }
@@ -121,7 +147,15 @@ server <- function(input, output) {
output$firstPlot <- renderPlot({ output$firstPlot <- renderPlot({
observeEvent(dades$taula, {}) observeEvent(dades$taula, {})
if (!is.null(dades$taula)){ if (!is.null(dades$taula)){
ggplot(dades$taula, aes(x="1", y=Volume))+geom_hline(yintercept = c(input$lowcut, input$upcut), color="red")+geom_quasirandom(width=0.2) ggplot(dades$taula %>% filter(DayPostInoc == input$day_vol), aes(x="1", y=Volume))+
geom_hline(yintercept = c(input$lowcut, input$upcut), color="red")+
geom_quasirandom(width=0.2)
}
})
output$day_vol<-renderUI({
if (!is.null(dades$taula)){
selectInput("day_vol", "Día para volúmenes", choices = sort(unique(dades$taula$DayPostInoc)))
} }
}) })
@@ -132,15 +166,17 @@ server <- function(input, output) {
}) })
output$lowcut<-renderUI({ output$lowcut<-renderUI({
if (!is.null(dades$taula)){ if (!is.null(dades$taula)){
cut.max<-round(max(dades$taula$Volume, na.rm = T), 2) taula<-dades$taula %>% filter(DayPostInoc == input$day_vol)
step<-round(max(dades$taula$Volume, na.rm = T)/100, 2) cut.max<-round(max(taula$Volume, na.rm = T), 2)
step<-round(max(taula$Volume, na.rm = T)/100, 2)
sliderInput("lowcut", "Corte inferior", min=0, max=cut.max, step=step, value=0) sliderInput("lowcut", "Corte inferior", min=0, max=cut.max, step=step, value=0)
} }
}) })
output$upcut<-renderUI({ output$upcut<-renderUI({
if (!is.null(dades$taula)){ if (!is.null(dades$taula)){
cut.max<-round(max(dades$taula$Volume, na.rm = T), 2)+0.01 taula<-dades$taula %>% filter(DayPostInoc == input$day_vol)
step<-round(max(dades$taula$Volume, na.rm = T)/20, 2) cut.max<-round(max(taula$Volume, na.rm = T), 2)+0.01
step<-round(max(taula$Volume, na.rm = T)/20, 2)
sliderInput("upcut", "Corte superior", min=0, max=cut.max, step=step, value=cut.max) sliderInput("upcut", "Corte superior", min=0, max=cut.max, step=step, value=cut.max)
} }
}) })
@@ -161,11 +197,12 @@ server <- function(input, output) {
}) })
grafic<-eventReactive(input$goButton,{ grafic<-eventReactive(input$goButton,{
df<-dades$taula df<-dades$taula %>% filter(DayPostInoc == input$day_vol)
df<-df[!is.na(df$Volume),] df<-df[!is.na(df$Volume),]
print(df)
up_cuttof<-input$upcut up_cuttof<-input$upcut
low_cuttof<-input$lowcut low_cuttof<-input$lowcut
# 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)){ if (is.null(dades$sex)){
df<-add_column(df, sex="undefined") df<-add_column(df, sex="undefined")
@@ -173,16 +210,14 @@ server <- function(input, output) {
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)
s<-shapiro.test(df$Volume)[[2]] s<-shapiro.test(df$Volume)[[2]]
ngroup<-length(dades$groups) ngroup<-length(dades$groups)
df_def<-list() df_def<-list()
# print(head(df))
for (sex.var in unique(df$sex)){ for (sex.var in unique(df$sex)){
# print(sex.var)
df_sex<-df %>% filter(`sex` == sex.var) df_sex<-df %>% filter(`sex` == sex.var)
ind.list<-list() ind.list<-list()
pval.list<-list() pval.list<-list()
@@ -191,8 +226,8 @@ server <- function(input, output) {
for (data in 1:input$iterations){ for (data in 1:input$iterations){
interr=T interr=T
while(interr == T){ while(interr == T){
ind<-sample(rep(dades$groups, each=ceiling(length(unique(df_sex$`ID animal`))/ngroup)), length(unique(df_sex$`ID animal`))) ind<-sample(rep(dades$groups, each=ceiling(length(unique(df_sex$Animal))/ngroup)), length(unique(df_sex$Animal)))
df_sex<-merge(df_sex[,c("ID animal", "ID tumor","Volume")], data.frame("ID animal"=unique(df_sex$`ID animal`), "group"=as.factor(ind),check.names=F)) df_sex<-merge(df_sex[,c("Animal", "Side","Volume")], data.frame("Animal"=unique(df_sex$Animal), "group"=as.factor(ind),check.names=F))
if ((nrow(df_sex)/ngroup) %% 2 == 0){ if ((nrow(df_sex)/ngroup) %% 2 == 0){
interr<-any(table(df_sex$group) < floor(nrow(df_sex)/ngroup) | table(df_sex$group) > ceiling(nrow(df_sex)/ngroup)) interr<-any(table(df_sex$group) < floor(nrow(df_sex)/ngroup) | table(df_sex$group) > ceiling(nrow(df_sex)/ngroup))
}else{ }else{
@@ -200,7 +235,7 @@ server <- function(input, output) {
interr<-diff(range(table(ind))) > 1 interr<-diff(range(table(ind))) > 1
} }
} }
ind.list[[data]]<-df_sex[,c("ID animal","ID tumor","group","Volume")] ind.list[[data]]<-df_sex[,c("Animal","Side","group","Volume")]
lvn.list[data]<-leveneTest(Volume ~ group, data = df_sex[,3:4])[[2]][1] lvn.list[data]<-leveneTest(Volume ~ group, data = df_sex[,3:4])[[2]][1]
if (s < 0.05){ if (s < 0.05){
k<-kruskal.test(df_sex$Volume,df_sex$group) k<-kruskal.test(df_sex$Volume,df_sex$group)
@@ -213,33 +248,36 @@ server <- function(input, output) {
} }
} }
index<-which(unlist(lvn.list) == min(unlist(lvn.list)[which(unlist(pval.list) %in% sort(unlist(pval.list), decreasing = T)[1:20])]))[1] index<-which(unlist(lvn.list) == min(unlist(lvn.list)[which(unlist(pval.list) %in% sort(unlist(pval.list), decreasing = T)[1:20])]))[1]
# 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))
# 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(
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")
if("DPV" %in% colnames(df_def)){df_def<-select(df_def, c(`ID animal`, `sex`,`ID tumor`, Volume, Cage, Major, Minor, group))}
if("TS-Deep" %in% colnames(df_def)){df_def<-select(df_def, c(`ID animal`, `sex`,`ID tumor`, Volume, Cage, `TS-Deep`,`TS-Length`,`TS-Width`, group))}
df_def[!paste0(df_def$`ID animal`, df_def$`ID tumor`) %in% paste0(df$`ID animal`, df$`ID tumor`),"group"]<-NA df_def<-merge(
if(!is.null(dades$sex)){merge(dades$taula %>% filter(DayPostInoc == input$day_vol), dades$sex)%>% select(-Group)}else{
dades$taula %>% filter(DayPostInoc == input$day_vol) %>% add_column(sex="undefined")} %>% select(-Group),
df_def[,c("Animal", "group")] %>% unique, all=T, by="Animal")
df_def<-df_def %>% rename(Group=group)
df_def<-select(df_def, Animal, sex, Date, DayPostInoc, Group, Side, Weight, Long, Wide, Volume, Observations)
# if("DPV" %in% colnames(df_def)){df_def<-select(df_def, c(`ID animal`, `sex`,`ID tumor`, Volume, Cage, Major, Minor, group))}
# if("TS-Deep" %in% colnames(df_def)){df_def<-select(df_def, c(`ID animal`, `sex`,`ID tumor`, Volume, Cage, `TS-Deep`,`TS-Length`,`TS-Width`, group))}
df_def[!paste0(df_def$Animal, df_def$Side) %in% paste0(df$Animal, df$Side),"Group"]<-NA
dades$db<-df_def dades$db<-df_def
if (is.null(dades$sex)){ if (is.null(dades$sex)){
ggplot(df_def, aes(group, Volume))+ ggplot(df_def, aes(Group, Volume))+
geom_boxplot(outlier.alpha = F)+ geom_boxplot(outlier.alpha = F)+
geom_jitter(width=0.25)+ geom_jitter(width=0.25)+
geom_point(stat="summary", color="blue", size=3)+ geom_point(stat="summary", color="blue", size=3)+
theme(axis.text.x = element_text(angle=90, hjust=1, vjust=0.5)) theme(axis.text.x = element_text(angle=90, hjust=1, vjust=0.5))
}else{ }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)+
geom_jitter(width=0.25, aes(color=sex))+ geom_jitter(width=0.25, aes(color=sex))+
geom_point(stat="summary", color="blue", size=3)+ geom_point(stat="summary", color="blue", size=3)+
@@ -249,7 +287,7 @@ server <- function(input, output) {
ggplot(df_def, aes(sex, Volume))+ ggplot(df_def, aes(sex, Volume))+
geom_boxplot(outlier.alpha = F)+ geom_boxplot(outlier.alpha = F)+
geom_quasirandom(width=0.3), geom_quasirandom(width=0.3),
ggplot(df_def, aes(group, fill=sex))+ ggplot(df_def, aes(Group, fill=sex))+
geom_bar(stat="count", color="black", position="dodge")+ geom_bar(stat="count", color="black", position="dodge")+
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)),
@@ -269,8 +307,8 @@ server <- function(input, output) {
observeEvent(dades$db, {}) observeEvent(dades$db, {})
if (!is.null(dades$db)){ if (!is.null(dades$db)){
df<-dades$db df<-dades$db
df_sum<-dcast(df, group~., value.var = "Volume", fun.aggregate = mean, na.rm=T) %>% rename("Mean"=".") df_sum<-dcast(df, Group~., value.var = "Volume", fun.aggregate = mean, na.rm=T) %>% rename("Mean"=".")
df_sum["SEM"]<-dcast(df, group~., value.var = "Volume", fun.aggregate = std.error, na.rm=T) %>% pull(`.`) df_sum["SEM"]<-dcast(df, Group~., value.var = "Volume", fun.aggregate = std.error, na.rm=T) %>% pull(`.`)
df_sum df_sum
} }
}) })
@@ -278,7 +316,7 @@ server <- function(input, output) {
observeEvent(dades$db, {}) observeEvent(dades$db, {})
if (!is.null(dades$db)){ if (!is.null(dades$db)){
df<-dades$db df<-dades$db
df %>% arrange(group) df %>% arrange(Group)
} }
}) })
@@ -294,31 +332,15 @@ server <- function(input, output) {
# timepoint<-c(7,10,13,16,19,22,25) # timepoint<-c(7,10,13,16,19,22,25)
if (!is.null(input$file_sizes)){ if (!is.null(input$file_sizes)){
# dtemplate<-dades$db %>% select(-Volume,-sex) template<-dades$db %>%
# dtemplate<-melt(dtemplate, id=c("Cage", "ID animal", "ID tumor", "group"), variable.name = "DPV", value.name = "0") %>% rename("Group"="group") select(Animal, Group) %>% unique()
# dtemplate<-dtemplate[,c("Cage", "ID animal", "ID tumor", "Group", "DPV", "0")] %>% arrange(`ID animal`, `ID tumor`) dtemplate<-merge(dades$taula %>% select(-Group), template) %>%
# template<-expand.grid(dades$db$MouseID, timepoint) arrange(DayPostInoc, Animal, Side) %>%
# colnames(template)<-c("MouseID", "Timepoint") select(Animal, Date, DayPostInoc, Group, Side,
# template<-template[order(template$Timepoint, template$MouseID),] Weight, Long, Wide, Volume, Observations)
# template<-merge(template, dades$db[c("MouseID", "group")]) if ("Abs" %in% colnames(read.xlsx(input$file_sizes$datapath, sheet = 1, check.names = F, sep.names = " ", detectDates = T,cols=1:11))){
# if (input$measure_sys == "L-W-D"){ dtemplate<-rename(dtemplate, "Abs"="Volume")
# template<-rbind(template, template, template) }
# template<-template[order(template$Timepoint, template$MouseID),]
# template["TS"]<-rep(c("TS-Length", "TS-Width", "TS-Deep"), nrow(template)/3)
# dtemplate<-dcast(template, MouseID+group+TS~Timepoint)
# dtemplate<-dtemplate[mixedorder(as.character(dtemplate$MouseID)),]
# }
# if (input$measure_sys == "Min-Max"){
# template<-rbind(template, template)
# template<-template[order(template$Timepoint, template$MouseID),]
# template["DPV"]<-rep(c("Major", "Minor"), nrow(template)/2)
# dtemplate<-dcast(template, MouseID+group+DPV~Timepoint)
# dtemplate<-dtemplate[mixedorder(as.character(dtemplate$MouseID)),]
# }
# dtemplate<-dtemplate %>% add_column(.after="MouseID", "ID tumor"=dtemplate$MouseID)%>% rename(`ID animal`=MouseID)
# dtemplate["ID tumor"]<-gsub("[[:digit:]]","",dtemplate$`ID tumor`)
# dtemplate["ID animal"]<-gsub("[LR]","",dtemplate$`ID animal`)
# dtemplate[,5:ncol(dtemplate)]<-""
}else{ }else{
template<-data.frame( template<-data.frame(
@@ -334,29 +356,47 @@ server <- function(input, output) {
Volume="", Volume="",
Observations="" Observations=""
) )
template<-template %>% mutate(Animal=paste0(Cage,Animal)) %>% select(-Cage)
dtemplate<-template dtemplate<-template
} }
write.xlsx(list("Measures"=dtemplate, "Groups"=NULL,"Sex"=NULL), file) write.xlsx(list("Measures"=dtemplate, "Groups"=NULL,"Sex"=NULL), file)
} }
) )
# Análisis
# Análisis ----------------------------------------------------------------
analysis<-reactiveValues() analysis<-reactiveValues()
analysis$taula<-NULL analysis$taula<-NULL
analysis$taula_def<-NULL analysis$taula_def<-NULL
analysis$taula_vol<-NULL analysis$taula_vol<-NULL
observe({ observe({
if (!is.null(input$file_analy)){ if (!is.null(input$file_analy)){
table<-read.xlsx(input$file_analy$datapath, sheet = 1, check.names = F, sep.names = " ", detectDates = T) table<-read.xlsx(input$file_analy$datapath, sheet = 1, check.names = F, sep.names = " ", detectDates = T,cols=1:11)
if("ID.animal" %in% colnames(table)){
table<-table %>%
rename(Animal=`ID.animal`, Side=`ID.tumor`)
table<-table %>% gather(DayPostInoc, Value, which(!is.na(as.numeric(colnames(table))))) %>%
relocate(DayPostInoc, .before = Group) %>% spread(DPV, Value) %>%
rename(Long=Major, Wide=Minor) %>%
add_column(Date="", .after = "Animal") %>%
add_column(Weight="", .after="Group") %>%
add_column(Volume="",Observations="") %>%
relocate(Side, .after = "Group")
table$DayPostInoc<-as.numeric(table$DayPostInoc)
}
table$Date<-format(table$Date, format="%d/%m/%Y") table$Date<-format(table$Date, format="%d/%m/%Y")
if ("sex" %in% colnames(table)){table<-select(table, -sex)} if ("sex" %in% colnames(table)){table<-select(table, -sex)}
table$Long<-gsub(",",".", table$Long)
table$Wide<-gsub(",",".", table$Wide)
for (i in 1:nrow(table)){ for (i in 1:nrow(table)){
long<-as.numeric(strsplit(table[i,"Long"],"+", fixed = T)[[1]]) long<-as.numeric(gsub(",",".",strsplit(as.character(table[i,"Long"]),"+", fixed = T)[[1]]))
wide<-as.numeric(strsplit(table[i,"Wide"],"+", fixed = T)[[1]]) wide<-as.numeric(gsub(",",".",strsplit(as.character(table[i,"Wide"]),"+", fixed = T)[[1]]))
table[i,"Volume"]<-sum(sapply(1:length(long), function(x) (long[x]*wide[x]*wide[x])*(pi/6))) table[i,"Volume"]<-sum(sapply(1:length(long), function(x) (long[x]*wide[x]*wide[x])*(pi/6)))
} }
table$Volume<-as.numeric(table$Volume)
if ("Cage" %in% colnames(table)){
table$Animal<-paste0(table$Cage, table$Animal)
table<-table[,-which(colnames(table) == "Cage")]
}
## Autocompletado de grupo ## Autocompletado de grupo
table_group<-merge( table_group<-merge(
@@ -367,7 +407,28 @@ server <- function(input, output) {
table<-merge( table<-merge(
table %>% select(-Group), table %>% select(-Group),
table_group table_group
) %>% relocate(Group, .after = DayPostInoc) %>% arrange(DayPostInoc, Animal, Side) ) %>% relocate(Group, .after = DayPostInoc) %>%
arrange(DayPostInoc, Animal, Side)
if("Groups" %in% readxl::excel_sheets(input$file_analy$datapath)){
levels<-read.xlsx(input$file_analy$datapath, sheet = "Groups", colNames=F)[,1]
table$Group<-factor(table$Group, levels=levels)
table<-filter(table, !is.na(Group))
}else(table$Group<-factor(table$Group))
if (input$increase_volume){
cols<-colnames(table)
timepoints<-unique(table$DayPostInoc)
table_old<-select(table, -Volume)
table_vols<-table %>%
select(-Weight, -Date, -Long, -Wide,-Observations) %>%
spread(DayPostInoc, Volume) %>%
mutate(across(all_of(as.character(timepoints)), function(x){(x*100/`0`)-100})) %>%
gather(DayPostInoc, Volume, all_of(as.character(timepoints))) %>%
mutate(Volume=case_when(Volume < 0 ~ 0, T~Volume))
table<-merge(table_old, table_vols)[,cols]
}
analysis$taula<-table analysis$taula<-table
} }
@@ -376,7 +437,6 @@ server <- function(input, output) {
if (!is.null(analysis$taula)){ if (!is.null(analysis$taula)){
observeEvent(analysis$taula, {}) observeEvent(analysis$taula, {})
max_val<-max(analysis$taula$Volume, na.rm = T) max_val<-max(analysis$taula$Volume, na.rm = T)
# print(max_val)
sliderInput("cutoff", "Cutoff para Survival", min=0, max=round(max_val, digits=2), step=round(max_val, digits=2)/200, value=max_val) sliderInput("cutoff", "Cutoff para Survival", min=0, max=round(max_val, digits=2), step=round(max_val, digits=2)/200, value=max_val)
} }
}) })
@@ -388,17 +448,10 @@ server <- function(input, output) {
table<-analysis$taula table<-analysis$taula
table<-table %>% filter(!is.na(Group)) table<-table %>% filter(!is.na(Group))
if (input$increase_volume){
timepoints<-unique(table$Timepoint)
table<-table %>% select(-Major, -Minor) %>%
spread(Timepoint, Volume) %>%
mutate(across(all_of(timepoints), function(x){(x*100/`0`)-100})) %>%
gather(Timepoint, Volume, -Cage, -`ID animal`, -`ID tumor`, -Group) %>%
mutate(Volume=case_when(Volume < 0 ~ 0, T~Volume))
}
table %>% group_by(Group, DayPostInoc, Side) %>% count() %>% spread(DayPostInoc, n) table %>% group_by(Group, DayPostInoc, Side) %>% count() %>% spread(DayPostInoc, n)
} }
}) })
output$cin_group<-renderPlot({ output$cin_group<-renderPlot({
if (!is.null(input$file_analy) & !is.null(analysis$taula)){ if (!is.null(input$file_analy) & !is.null(analysis$taula)){
observeEvent(analysis$taula, {}) observeEvent(analysis$taula, {})
@@ -408,7 +461,6 @@ server <- function(input, output) {
sides<-unique(table$Side) sides<-unique(table$Side)
groups<-table %>% select(Animal, Group) %>% unique() %>% pull(Group) groups<-table %>% select(Animal, Group) %>% unique() %>% pull(Group)
basal<-data.frame( basal<-data.frame(
Cage="",
Animal=rep(animals, each=length(sides)), Animal=rep(animals, each=length(sides)),
Date="", Date="",
DayPostInoc=0, DayPostInoc=0,
@@ -420,8 +472,27 @@ server <- function(input, output) {
Volume=0, Volume=0,
Observations="" Observations=""
) )
table<-rbind(table, basal) if (!(0 %in% table$DayPostInoc) | sum(table[table$DayPostInoc == 0,"Volume"],na.rm = T) == 0){
table<-rbind(table, basal)
}
if (input$vacc == "Sí"){ if (input$vacc == "Sí"){
firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
select(DayPostInoc, Side) %>% unique() %>%
group_by(Side) %>% summarise(FirstOper=min(DayPostInoc))
deadmice<-filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "+") %>%
pull(Animal)
if (input$operated == TRUE & nrow(firstoper) > 0){
for (i in 1:nrow(firstoper)){
table<-table %>% filter(DayPostInoc < firstoper$FirstOper[i] | Side != firstoper$Side[i])
}
}else{
if(input$dead == TRUE){
table<-table %>% filter(!Animal %in% deadmice)
}
}
ggplot(table, aes(DayPostInoc, Volume, color=Group, group=Group))+ ggplot(table, aes(DayPostInoc, Volume, color=Group, group=Group))+
geom_errorbar(stat="summary", width=0.05)+ geom_errorbar(stat="summary", width=0.05)+
geom_line(stat="summary")+ geom_line(stat="summary")+
@@ -432,6 +503,21 @@ server <- function(input, output) {
scale_x_continuous(expand = expansion(mult = c(0,0.05)), limits = c(0, (round(max(table$DayPostInoc) / 5)+1)*5))+ scale_x_continuous(expand = expansion(mult = c(0,0.05)), limits = c(0, (round(max(table$DayPostInoc) / 5)+1)*5))+
theme_bw() theme_bw()
}else{ }else{
firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
pull(DayPostInoc) %>% min(na.rm = T)
if (firstoper == Inf){firstoper<-c()}
if (input$operated == TRUE & length(firstoper) > 0){
table<-table %>% filter(DayPostInoc < firstoper)
}else{
deadmice<-filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "+") %>%
pull(Animal)
if(input$dead == TRUE){
table<-table %>% filter(!Animal %in% deadmice)
}
}
ggplot(table, aes(DayPostInoc, Volume, color=Group, group=Group))+ ggplot(table, aes(DayPostInoc, Volume, color=Group, group=Group))+
geom_errorbar(stat="summary",width=0.05)+ geom_errorbar(stat="summary",width=0.05)+
geom_line(stat="summary")+ geom_line(stat="summary")+
@@ -453,7 +539,6 @@ server <- function(input, output) {
sides<-unique(table$Side) sides<-unique(table$Side)
groups<-table %>% select(Animal, Group) %>% unique() %>% pull(Group) groups<-table %>% select(Animal, Group) %>% unique() %>% pull(Group)
basal<-data.frame( basal<-data.frame(
Cage="",
Animal=rep(animals, each=length(sides)), Animal=rep(animals, each=length(sides)),
Date="", Date="",
DayPostInoc=0, DayPostInoc=0,
@@ -465,9 +550,25 @@ server <- function(input, output) {
Volume=0, Volume=0,
Observations="" Observations=""
) )
table<-rbind(table, basal) if (!(0 %in% table$DayPostInoc) | sum(table[table$DayPostInoc == 0,"Volume"],na.rm = T) == 0){
table<-rbind(table, basal)
}
if (input$vacc == "Sí"){ if (input$vacc == "Sí"){
firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
select(DayPostInoc, Side) %>% unique() %>%
group_by(Side) %>% summarise(FirstOper=min(DayPostInoc))
if (input$operated == TRUE & nrow(firstoper) > 0){
for (i in 1:nrow(firstoper)){
table<-table %>% filter(DayPostInoc < firstoper$FirstOper[i] | Side != firstoper$Side[i])
}
}else{
if(input$dead == TRUE){
deadmice<-filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "+") %>%
pull(Animal)
table<-table %>% filter(!Animal %in% deadmice)
}
}
ggplot(table, aes(DayPostInoc, Volume, color=Group, group=Animal))+ ggplot(table, aes(DayPostInoc, Volume, color=Group, group=Animal))+
# geom_errorbar(stat="summary", width=0.05)+ # geom_errorbar(stat="summary", width=0.05)+
geom_line()+ geom_line()+
@@ -478,6 +579,19 @@ server <- function(input, output) {
labs(x="Days after tumor inoculation")+ labs(x="Days after tumor inoculation")+
theme_bw() theme_bw()
}else{ }else{
firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
pull(DayPostInoc) %>% min(na.rm = T)
if (firstoper == Inf){firstoper<-c()}
if (input$operated == TRUE & length(firstoper) > 0){
table<-table %>% filter(DayPostInoc < firstoper)
}else{
deadmice<-filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "+") %>%
pull(Animal)
if(input$dead == TRUE){
table<-table %>% filter(!Animal %in% deadmice)
}
}
ggplot(table, aes(DayPostInoc, Volume, color=Group, group=paste0(Animal, Side)))+ ggplot(table, aes(DayPostInoc, Volume, color=Group, group=paste0(Animal, Side)))+
# geom_errorbar(stat="summary", width=0.05)+ # geom_errorbar(stat="summary", width=0.05)+
geom_line()+ geom_line()+
@@ -497,14 +611,29 @@ server <- function(input, output) {
observeEvent(analysis$taula, {}) observeEvent(analysis$taula, {})
table<-analysis$taula table<-analysis$taula
if (input$vacc == "Sí"){ if (input$vacc == "Sí"){
firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
select(DayPostInoc, Side) %>% unique() %>%
if (firstoper == Inf){firstoper<-c()}
if (input$operated == TRUE & length(firstoper) > 0){
for (i in 1:nrow(firstoper)){
table<-table %>% filter(DayPostInoc < firstoper$FirstOper[i] | Side != firstoper$Side[i])
}
}else{
if(input$dead == TRUE){
deadmice<-filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "+") %>%
pull(Animal)
table<-table %>% filter(!Animal %in% deadmice)
}
}
g<-list() g<-list()
for (side in c("L","R")){ for (side in c("L","R")){
tableR<-filter(table, Side == side) %>% filter(!is.na(Volume)) tableR<-filter(table, Side == side) %>% filter(!is.na(Volume))
endtime<-dcast(tableR %>% filter(Volume < input$cutoff), Cage+Animal+Side+Group~., value.var = "DayPostInoc", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% rename("end"=".") endtime<-dcast(tableR %>% filter(Volume < input$cutoff), Animal+Side+Group~., value.var = "DayPostInoc", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% rename("end"=".")
endtime["Dead"]<-dcast(tableR, Cage+Animal+Side+Group~., value.var = "Volume", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% pull(".") > input$cutoff endtime["Dead"]<-dcast(tableR, Animal+Side+Group~., value.var = "Volume", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% pull(".") > input$cutoff
table_tumor<<-endtime table_tumor<<-endtime
g[side]<-ggsurvplot(survfit(Surv(table_tumor$end, table_tumor$Dead) ~ table_tumor$Group, data=table_tumor), g[side]<-ggsurvplot(survfit(Surv(end, Dead) ~ Group, data=table_tumor),
pval = T, pval.method = T, pval = T, pval.method = T,
title = side, title = side,
# legend.labs = paste(c("< median", ">= median"), "MICA"), # legend.labs = paste(c("< median", ">= median"), "MICA"),
@@ -523,13 +652,27 @@ server <- function(input, output) {
do.call(grid.arrange, g) do.call(grid.arrange, g)
}else{ }else{
firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
pull(DayPostInoc) %>% min(na.rm = T)
if (firstoper == Inf){firstoper<-c()}
if (input$operated == TRUE & length(firstoper) > 0){
table<-table %>% filter(DayPostInoc < firstoper)
}else{
deadmice<-filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "+") %>%
pull(Animal)
if(input$dead == TRUE){
table<-table %>% filter(!Animal %in% deadmice)
}
}
tableR<-table %>% filter(!is.na(Volume)) tableR<-table %>% filter(!is.na(Volume))
endtime<-dcast(if(length(unique(tableR$DayPostInoc)) > 1){tableR %>% filter(Volume < input$cutoff)}else{tableR}, Animal+Side+Group~., endtime<-dcast(if(length(unique(tableR$DayPostInoc)) > 1){tableR %>% filter(Volume < input$cutoff)}else{tableR}, Animal+Side+Group~.,
value.var = "DayPostInoc", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% rename("end"=".") value.var = "DayPostInoc", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% rename("end"=".")
endtime["Dead"]<-dcast(tableR, Animal+Side+Group~., value.var = "Volume", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% pull(".") >= input$cutoff endtime["Dead"]<-dcast(tableR, Animal+Side+Group~., value.var = "Volume", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% pull(".") >= input$cutoff
table_tumor<<-endtime table_tumor<<-endtime
g<-ggsurvplot(survfit(Surv(table_tumor$end, table_tumor$Dead) ~ table_tumor$Group, data=table_tumor), g<-ggsurvplot(survfit(Surv(end, Dead) ~ Group, data=table_tumor),
pval = T, pval.method = T, pval = T, pval.method = T,
# legend.labs = paste(c("< median", ">= median"), "MICA"), # legend.labs = paste(c("< median", ">= median"), "MICA"),
ggtheme=theme_classic(base_size=15) ggtheme=theme_classic(base_size=15)
@@ -553,9 +696,6 @@ server <- function(input, output) {
for (side in c("L","R")){ for (side in c("L","R")){
tableR<-filter(table, Side == side) %>% filter(!is.na(Volume)) tableR<-filter(table, Side == side) %>% filter(!is.na(Volume))
if (length(unique(tableR$Volume)) > 1 & length(unique(tableR$DayPostInoc)) > 1){ if (length(unique(tableR$Volume)) > 1 & length(unique(tableR$DayPostInoc)) > 1){
print(paste0("Side: ",side))
# print(summary(aov(Volume~Group+DayPostInoc+Error(paste0(Animal,Cage)), data=tableR)))
print(summary(aov(Volume~Group+DayPostInoc+Error(Animal), data=tableR)))
} }
} }
} }
@@ -615,11 +755,13 @@ server <- function(input, output) {
}, },
content = function(file){ content = function(file){
dtemplate<-analysis$taula dtemplate<-analysis$taula
write.xlsx(dtemplate,file) write.xlsx(dtemplate,file, )
} }
) )
##Exportar
# Exportar ----------------------------------------------------------------
output$expPlotUI<- renderUI({ output$expPlotUI<- renderUI({
observeEvent(analysis$taula, {}) observeEvent(analysis$taula, {})
if (!is.null(input$file_analy) & !is.null(analysis$taula)){ if (!is.null(input$file_analy) & !is.null(analysis$taula)){
@@ -631,11 +773,11 @@ server <- function(input, output) {
observeEvent(analysis$taula, {}) observeEvent(analysis$taula, {})
if (!is.null(input$file_analy) & !is.null(analysis$taula)){ if (!is.null(input$file_analy) & !is.null(analysis$taula)){
table<-analysis$taula table<-analysis$taula
table$Volume<-table$Volume*as.numeric(input$unit_fact)
animals<-unique(table$Animal) animals<-unique(table$Animal)
sides<-unique(table$Side) sides<-unique(table$Side)
groups<-table %>% select(Animal, Group) %>% unique() %>% pull(Group) groups<-table %>% select(Animal, Group) %>% unique() %>% pull(Group)
basal<-data.frame( basal<-data.frame(
Cage="",
Animal=rep(animals, each=length(sides)), Animal=rep(animals, each=length(sides)),
Date="", Date="",
DayPostInoc=0, DayPostInoc=0,
@@ -647,10 +789,27 @@ server <- function(input, output) {
Volume=0, Volume=0,
Observations="" Observations=""
) )
table<-rbind(table, basal) if (!(0 %in% table$DayPostInoc) | sum(table[table$DayPostInoc == 0,"Volume"],na.rm = T) == 0){
table<-rbind(table, basal)
}
if (input$fig_id %in% c("Cinética Grupo", "Cinética Individual")){ if (input$fig_id %in% c("Cinética Grupo", "Cinética Individual")){
if (input$fig_id == "Cinética Grupo"){ if (input$fig_id == "Cinética Grupo"){
if (input$vacc == "Sí"){ if (input$vacc == "Sí"){
firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
select(DayPostInoc, Side) %>% unique() %>%
group_by(Side) %>% summarise(FirstOper=min(DayPostInoc))
if (input$operated == TRUE){
for (i in 1:nrow(firstoper)){
table<-table %>% filter(DayPostInoc < firstoper$FirstOper[i] | Side != firstoper$Side[i])
}
}else{
if(input$dead == TRUE){
deadmice<-filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "+") %>%
pull(Animal)
table<-table %>% filter(!Animal %in% deadmice)
}
}
std<-function(x, na.rm=T){sd(x, na.rm=na.rm)/sqrt(length(x))} std<-function(x, na.rm=T){sd(x, na.rm=na.rm)/sqrt(length(x))}
errbar<-table %>% group_by(Group,Side,DayPostInoc) %>% errbar<-table %>% group_by(Group,Side,DayPostInoc) %>%
summarise(mean=mean(Volume, na.rm=T), std=std(Volume)) %>% summarise(mean=mean(Volume, na.rm=T), std=std(Volume)) %>%
@@ -670,6 +829,19 @@ server <- function(input, output) {
geom_segment(data=errbar, aes(y=mean+std, yend=mean+std, geom_segment(data=errbar, aes(y=mean+std, yend=mean+std,
x=x,xend=xend)) x=x,xend=xend))
}else{ }else{
firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
pull(DayPostInoc) %>% min(na.rm = T)
if (input$operated == TRUE){
table<-table %>% filter(DayPostInoc < firstoper)
}else{
deadmice<-filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "+") %>%
pull(Animal)
if(input$dead == TRUE){
table<-table %>% filter(!Animal %in% deadmice)
}
}
std<-function(x, na.rm=T){sd(x, na.rm=na.rm)/sqrt(length(x))} std<-function(x, na.rm=T){sd(x, na.rm=na.rm)/sqrt(length(x))}
errbar<-table %>% group_by(Group, DayPostInoc) %>% errbar<-table %>% group_by(Group, DayPostInoc) %>%
summarise(mean=mean(Volume, na.rm=T), std=std(Volume)) %>% summarise(mean=mean(Volume, na.rm=T), std=std(Volume)) %>%
@@ -691,6 +863,22 @@ server <- function(input, output) {
} }
if (input$fig_id == "Cinética Individual"){ if (input$fig_id == "Cinética Individual"){
if (input$vacc == "Sí"){ if (input$vacc == "Sí"){
firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
select(DayPostInoc, Side) %>% unique() %>%
group_by(Side) %>% summarise(FirstOper=min(DayPostInoc))
if (input$operated == TRUE){
for (i in 1:nrow(firstoper)){
table<-table %>% filter(DayPostInoc < firstoper$FirstOper[i] | Side != firstoper$Side[i])
}
}else{
if(input$dead == TRUE){
deadmice<-filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "+") %>%
pull(Animal)
table<-table %>% filter(!Animal %in% deadmice)
}
}
g<-ggplot(table, aes(as.numeric(as.character(DayPostInoc)), Volume, color=Group, group=Animal))+ g<-ggplot(table, aes(as.numeric(as.character(DayPostInoc)), Volume, color=Group, group=Animal))+
scale_x_continuous(expand = expansion(mult = c(0,0.0)), scale_x_continuous(expand = expansion(mult = c(0,0.0)),
breaks=sort(unique(as.numeric(as.character(table$DayPostInoc)))), breaks=sort(unique(as.numeric(as.character(table$DayPostInoc)))),
@@ -698,7 +886,20 @@ server <- function(input, output) {
facet_grid(factor(Side, labels = c("Vaccination", "Rechallenge"))~Group, scale="free_y")+ facet_grid(factor(Side, labels = c("Vaccination", "Rechallenge"))~Group, scale="free_y")+
theme_bw() theme_bw()
}else{ }else{
g<-ggplot(table, aes(as.numeric(as.character(DayPostInoc)), Volume, color=Group, group=Animal))+ firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
pull(DayPostInoc) %>% min(na.rm = T)
if (input$operated == TRUE){
table<-table %>% filter(DayPostInoc < firstoper)
}else{
deadmice<-filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "+") %>%
pull(Animal)
if(input$dead == TRUE){
table<-table %>% filter(!Animal %in% deadmice)
}
}
g<-ggplot(table, aes(as.numeric(as.character(DayPostInoc)), Volume, color=Group, group=paste0(Animal,Side)))+
scale_x_continuous(expand = expansion(mult = c(0,0.0)), scale_x_continuous(expand = expansion(mult = c(0,0.0)),
breaks=sort(unique(as.numeric(as.character(table$DayPostInoc)))), breaks=sort(unique(as.numeric(as.character(table$DayPostInoc)))),
limits = c(0,max(as.numeric(as.character(table$DayPostInoc)))*1.1))+ limits = c(0,max(as.numeric(as.character(table$DayPostInoc)))*1.1))+
@@ -746,23 +947,38 @@ server <- function(input, output) {
hues <- seq(15, 375, length=n+1) hues <- seq(15, 375, length=n+1)
hcl(h=hues, l=l, c=100)[1:n] hcl(h=hues, l=l, c=100)[1:n]
} }
if (input$vacc == "Sí"){ if (input$vacc == "Sí"){
firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
select(DayPostInoc, Side) %>% unique() %>%
group_by(Side) %>% summarise(FirstOper=min(DayPostInoc))
if (input$operated == TRUE){
for (i in 1:nrow(firstoper)){
table<-table %>% filter(DayPostInoc < firstoper$FirstOper[i] | Side != firstoper$Side[i])
}
}else{
if(input$dead == TRUE){
deadmice<-filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "+") %>%
pull(Animal)
table<-table %>% filter(!Animal %in% deadmice)
}
}
g<-list() g<-list()
count<-1 count<-1
for (side in c("L","R")){ for (side in c("L","R")){
tableR<-filter(table, Side == side) %>% filter(!is.na(Volume)) tableR<-filter(table, Side == side) %>% filter(!is.na(Volume))
endtime<-dcast(tableR %>% filter(Volume < input$cutoff), Cage+Animal+Side+Group~., value.var = "DayPostInoc", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% rename("end"=".") endtime<-dcast(tableR %>% filter(Volume < (input$cutoff*as.numeric(input$unit_fact))), Animal+Side+Group~., value.var = "DayPostInoc", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% rename("end"=".")
endtime["Dead"]<-dcast(tableR, Cage+Animal+Side+Group~., value.var = "Volume", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% pull(".") > input$cutoff endtime["Dead"]<-dcast(tableR, Animal+Side+Group~., value.var = "Volume", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% pull(".") > (input$cutoff*as.numeric(input$unit_fact))
table_tumor<-endtime table_tumor<-endtime
if (input$colors != ""){ if (input$colors != ""){
col<-input$colors col<-strsplit(input$colors, ",")[[1]]
}else{ }else{
col<-gg_color_hue(length(unique(endtime$Group))) col<-gg_color_hue(length(unique(endtime$Group)))
} }
g[[count]]<-ggsurvplot(survfit(Surv(table_tumor$end, table_tumor$Dead) ~ table_tumor$Group, data=table_tumor), table_tumor$Group<-factor(table_tumor$Group, levels = levels(analysis$taula$Group))
g[[count]]<-ggsurvplot(survfit(Surv(end, Dead) ~ Group, data=table_tumor),
pval = T, pval.method = T, pval = T, pval.method = T,
title = side, title = side,
# legend.labs = paste(c("< median", ">= median"), "MICA"),
ggtheme=theme_classic(base_size=input$`font-size`), ggtheme=theme_classic(base_size=input$`font-size`),
palette = col palette = col
) )
@@ -771,19 +987,31 @@ server <- function(input, output) {
g_surv_vacc<-g g_surv_vacc<-g
}else{ }else{
firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
pull(DayPostInoc) %>% min(na.rm = T)
if (input$operated == TRUE){
table<-table %>% filter(DayPostInoc < firstoper)
}else{
deadmice<-filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "+") %>%
pull(Animal)
if(input$dead == TRUE){
table<-table %>% filter(!Animal %in% deadmice)
}
}
tableR<-table %>% filter(!is.na(Volume)) tableR<-table %>% filter(!is.na(Volume))
endtime<-dcast(tableR %>% filter(Volume < input$cutoff), Animal+Group~., value.var = "DayPostInoc", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% rename("end"=".") endtime<-dcast(tableR %>% filter(Volume < (input$cutoff*as.numeric(input$unit_fact))), Animal+Group~., value.var = "DayPostInoc", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% rename("end"=".")
endtime["Dead"]<-dcast(tableR, Animal+Group~., value.var = "Volume", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% pull(".") > input$cutoff endtime["Dead"]<-dcast(tableR, Animal+Group~., value.var = "Volume", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% pull(".") > (input$cutoff*as.numeric(input$unit_fact))
table_tumor<-endtime table_tumor<-endtime
if (input$colors != ""){ if (input$colors != ""){
col<-input$colors col<-strsplit(input$colors, ",")[[1]]
}else{ }else{
col<-gg_color_hue(length(unique(table_tumor$Group))) col<-gg_color_hue(length(unique(table_tumor$Group)))
} }
g<-ggsurvplot(survfit(Surv(table_tumor$end, table_tumor$Dead) ~ table_tumor$Group, data=table_tumor), table_tumor$Group<-factor(table_tumor$Group, levels = levels(analysis$taula$Group))
g<-ggsurvplot(survfit(Surv(end, Dead) ~ Group, data=table_tumor),
pval = T, pval.method = T, pval = T, pval.method = T,
# legend.labs = paste(c("< median", ">= median"), "MICA"), # ggtheme=theme_classic(base_size=input$`font-size`),
ggtheme=theme_classic(base_size=input$`font-size`),
palette = col palette = col
) )
} }