Compare commits

..

18 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
+207 -50
View File
@@ -48,6 +48,7 @@ ui <- fluidPage(
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("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(
@@ -120,12 +121,22 @@ server <- function(input, output) {
} }
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)}
for (i in 1:nrow(table)){ if ("Abs" %in% colnames(table)){
long<-as.numeric(gsub(",",".",strsplit(as.character(table[i,"Long"]),"+", fixed = T)[[1]])) table<-rename(table, "Volume"="Abs")
wide<-as.numeric(gsub(",",".",strsplit(as.character(table[i,"Wide"]),"+", fixed = T)[[1]])) }else{
table[i,"Volume"]<-sum(sapply(1:length(long), function(x) (long[x]*wide[x]*wide[x])*(pi/6))) 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)
} }
table$Volume<-as.numeric(table$Volume)
if ("Cage" %in% colnames(table)){
table$Animal<-paste0(table$Cage, table$Animal)
table<-table[,-which(colnames(table) == "Cage")]
}
dades$taula<-table dades$taula<-table
dades$groups<-read.xlsx(input$file_sizes$datapath, sheet = "Groups", colNames=F)[,1] 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){
@@ -187,8 +198,8 @@ server <- function(input, output) {
grafic<-eventReactive(input$goButton,{ grafic<-eventReactive(input$goButton,{
df<-dades$taula %>% filter(DayPostInoc == input$day_vol) df<-dades$taula %>% filter(DayPostInoc == input$day_vol)
print(df)
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
@@ -217,7 +228,6 @@ server <- function(input, output) {
while(interr == T){ while(interr == T){
ind<-sample(rep(dades$groups, each=ceiling(length(unique(df_sex$Animal))/ngroup)), length(unique(df_sex$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("Animal", "Side","Volume")], data.frame("Animal"=unique(df_sex$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))
print(df_sex)
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{
@@ -238,20 +248,21 @@ 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( df_def<-merge(
if(!is.null(dades$sex)){merge(dades$taula %>% filter(DayPostInoc == input$day_vol), dades$sex)}else{ 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), dades$taula %>% filter(DayPostInoc == input$day_vol) %>% add_column(sex="undefined")} %>% select(-Group),
df_def[,c("Animal", "group")] %>% unique, all=T, by="Animal") %>% rename(Group=group) df_def[,c("Animal", "group")] %>% unique, all=T, by="Animal")
df_def<-select(df_def, Cage, Animal, Date, DayPostInoc, Group, Side, Weight, Long, Wide, Volume, Observations) 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("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))} # 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))}
@@ -321,12 +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)){
template<-dades$db %>% filter(!is.na(Group)) %>% template<-dades$db %>%
select(Animal, Group) %>% unique() select(Animal, Group) %>% unique()
dtemplate<-merge(dades$taula %>% select(-Group), template) %>% dtemplate<-merge(dades$taula %>% select(-Group), template) %>%
arrange(DayPostInoc, Animal, Side) %>% arrange(DayPostInoc, Animal, Side) %>%
select(Cage, Animal, Date, DayPostInoc, Group, Side, select(Animal, Date, DayPostInoc, Group, Side,
Weight, Long, Wide, Volume, Observations) Weight, Long, Wide, Volume, Observations)
if ("Abs" %in% colnames(read.xlsx(input$file_sizes$datapath, sheet = 1, check.names = F, sep.names = " ", detectDates = T,cols=1:11))){
dtemplate<-rename(dtemplate, "Abs"="Volume")
}
}else{ }else{
template<-data.frame( template<-data.frame(
@@ -342,6 +356,7 @@ 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)
@@ -378,6 +393,10 @@ server <- function(input, output) {
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) 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(
@@ -389,16 +408,28 @@ server <- function(input, output) {
table %>% select(-Group), table %>% select(-Group),
table_group table_group
) %>% relocate(Group, .after = DayPostInoc) %>% ) %>% relocate(Group, .after = DayPostInoc) %>%
relocate(Cage, .before = Animal) %>%
arrange(DayPostInoc, Animal, Side) arrange(DayPostInoc, Animal, Side)
if("Groups" %in% readxl::excel_sheets(input$file_analy$datapath)){ if("Groups" %in% readxl::excel_sheets(input$file_analy$datapath)){
levels<-read.xlsx(input$file_analy$datapath, sheet = "Groups", colNames=F)[,1] levels<-read.xlsx(input$file_analy$datapath, sheet = "Groups", colNames=F)[,1]
print(levels)
table$Group<-factor(table$Group, levels=levels) table$Group<-factor(table$Group, levels=levels)
table<-filter(table, !is.na(Group)) table<-filter(table, !is.na(Group))
}else(table$Group<-factor(table$Group)) }else(table$Group<-factor(table$Group))
print(str(table))
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
} }
}) })
@@ -406,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)
} }
}) })
@@ -418,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, {})
@@ -438,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,
@@ -450,17 +472,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) == "*") %>% firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
select(DayPostInoc, Side) %>% unique() %>% select(DayPostInoc, Side) %>% unique() %>%
group_by(Side) %>% summarise(FirstOper=min(DayPostInoc)) 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){ if (input$operated == TRUE & nrow(firstoper) > 0){
for (i in 1:nrow(firstoper)){ for (i in 1:nrow(firstoper)){
table<-table %>% filter(DayPostInoc < firstoper$FirstOper[i] | Side != firstoper$Side[i]) 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))+
@@ -476,10 +506,16 @@ server <- function(input, output) {
firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>% firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
pull(DayPostInoc) %>% min(na.rm = T) pull(DayPostInoc) %>% min(na.rm = T)
print(firstoper) if (firstoper == Inf){firstoper<-c()}
if (input$operated == TRUE){ if (input$operated == TRUE & length(firstoper) > 0){
table<-table %>% filter(DayPostInoc < firstoper) 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))+
@@ -503,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,
@@ -515,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()+
@@ -528,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()+
@@ -547,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"),
@@ -573,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)
@@ -603,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)))
} }
} }
} }
@@ -665,7 +755,6 @@ server <- function(input, output) {
}, },
content = function(file){ content = function(file){
dtemplate<-analysis$taula dtemplate<-analysis$taula
# print(str(dtemplate))
write.xlsx(dtemplate,file, ) write.xlsx(dtemplate,file, )
} }
) )
@@ -689,7 +778,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,
@@ -701,7 +789,9 @@ 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í"){
@@ -713,6 +803,12 @@ server <- function(input, output) {
for (i in 1:nrow(firstoper)){ for (i in 1:nrow(firstoper)){
table<-table %>% filter(DayPostInoc < firstoper$FirstOper[i] | Side != firstoper$Side[i]) 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) %>%
@@ -735,11 +831,17 @@ server <- function(input, output) {
}else{ }else{
firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>% firstoper<- filter(table, !is.na(substr(Observations,1,1)) & substr(Observations,1,1) == "*") %>%
pull(DayPostInoc) %>% min(na.rm = T) pull(DayPostInoc) %>% min(na.rm = T)
print(firstoper)
if (input$operated == TRUE){ if (input$operated == TRUE){
table<-table %>% filter(DayPostInoc < firstoper) 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)) %>%
@@ -761,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)))),
@@ -768,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))+
@@ -818,12 +949,26 @@ server <- function(input, output) {
} }
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*as.numeric(input$unit_fact))), 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*as.numeric(input$unit_fact)) 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<-strsplit(input$colors, ",")[[1]] col<-strsplit(input$colors, ",")[[1]]
@@ -831,7 +976,7 @@ server <- function(input, output) {
col<-gg_color_hue(length(unique(endtime$Group))) col<-gg_color_hue(length(unique(endtime$Group)))
} }
table_tumor$Group<-factor(table_tumor$Group, levels = levels(analysis$taula$Group)) table_tumor$Group<-factor(table_tumor$Group, levels = levels(analysis$taula$Group))
g[[count]]<-ggsurvplot(survfit(Surv(table_tumor$end, table_tumor$Dead) ~ Group, data=table_tumor), 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,
ggtheme=theme_classic(base_size=input$`font-size`), ggtheme=theme_classic(base_size=input$`font-size`),
@@ -842,6 +987,18 @@ 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*as.numeric(input$unit_fact))), 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*as.numeric(input$unit_fact)) 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))
@@ -852,7 +1009,7 @@ server <- function(input, output) {
col<-gg_color_hue(length(unique(table_tumor$Group))) col<-gg_color_hue(length(unique(table_tumor$Group)))
} }
table_tumor$Group<-factor(table_tumor$Group, levels = levels(analysis$taula$Group)) table_tumor$Group<-factor(table_tumor$Group, levels = levels(analysis$taula$Group))
g<-ggsurvplot(survfit(Surv(table_tumor$end, table_tumor$Dead) ~ Group, data=table_tumor), g<-ggsurvplot(survfit(Surv(end, Dead) ~ Group, data=table_tumor),
pval = T, pval.method = T, pval = T, pval.method = T,
# ggtheme=theme_classic(base_size=input$`font-size`), # ggtheme=theme_classic(base_size=input$`font-size`),
palette = col palette = col