From 092a788125195c76823cc8accbf6b24ee53f4be2 Mon Sep 17 00:00:00 2001 From: marcelcosta Date: Tue, 12 Dec 2023 17:12:05 +0100 Subject: [PATCH] =?UTF-8?q?Eliminar=20la=20columna=20Cage=20manteniendo=20?= =?UTF-8?q?la=20compatibilidad=20con=20hojas=20de=20c=C3=A1lculo=20antigua?= =?UTF-8?q?s.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- invivos/app.R | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/invivos/app.R b/invivos/app.R index 61772a7..4091f45 100755 --- a/invivos/app.R +++ b/invivos/app.R @@ -127,6 +127,11 @@ server <- function(input, output) { 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")] + } + 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){ @@ -252,7 +257,7 @@ server <- function(input, output) { if(!is.null(dades$sex)){merge(dades$taula %>% filter(DayPostInoc == input$day_vol), dades$sex)}else{ 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<-select(df_def, Cage, Animal, Date, DayPostInoc, Group, Side, Weight, Long, Wide, Volume, Observations) + df_def<-select(df_def, Animal, 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))} @@ -326,7 +331,7 @@ server <- function(input, output) { select(Animal, Group) %>% unique() dtemplate<-merge(dades$taula %>% select(-Group), template) %>% arrange(DayPostInoc, Animal, Side) %>% - select(Cage, Animal, Date, DayPostInoc, Group, Side, + select(Animal, Date, DayPostInoc, Group, Side, Weight, Long, Wide, Volume, Observations) }else{ @@ -343,6 +348,7 @@ server <- function(input, output) { Volume="", Observations="" ) + template<-template %>% mutate(Animal=paste0(Cage,Animal)) %>% select(-Cage) dtemplate<-template } write.xlsx(list("Measures"=dtemplate, "Groups"=NULL,"Sex"=NULL), file) @@ -379,7 +385,10 @@ server <- function(input, output) { 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$Animal<-paste0(table$Cage, table$Animal) + if ("Cage" %in% colnames(table)){ + table$Animal<-paste0(table$Cage, table$Animal) + table<-table[,-which(colnames(table) == "Cage")] + } ## Autocompletado de grupo table_group<-merge( @@ -391,7 +400,6 @@ server <- function(input, output) { table %>% select(-Group), table_group ) %>% relocate(Group, .after = DayPostInoc) %>% - relocate(Cage, .before = Animal) %>% arrange(DayPostInoc, Animal, Side) if("Groups" %in% readxl::excel_sheets(input$file_analy$datapath)){ @@ -425,7 +433,7 @@ server <- function(input, output) { 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) %>% + gather(Timepoint, Volume, -`ID animal`, -`ID tumor`, -Group) %>% mutate(Volume=case_when(Volume < 0 ~ 0, T~Volume)) } table %>% group_by(Group, DayPostInoc, Side) %>% count() %>% spread(DayPostInoc, n) @@ -436,13 +444,11 @@ server <- function(input, output) { observeEvent(analysis$taula, {}) table<-analysis$taula - table$Animal<-paste0(table$Cage, table$Animal) print(table) animals<-unique(table$Animal) sides<-unique(table$Side) groups<-table %>% select(Animal, Group) %>% unique() %>% pull(Group) basal<-data.frame( - Cage="", Animal=rep(animals, each=length(sides)), Date="", DayPostInoc=0, @@ -515,12 +521,10 @@ server <- function(input, output) { observeEvent(analysis$taula, {}) table<-analysis$taula - table$Animal<-paste0(table$Cage, table$Animal) animals<-unique(table$Animal) sides<-unique(table$Side) groups<-table %>% select(Animal, Group) %>% unique() %>% pull(Group) basal<-data.frame( - Cage="", Animal=rep(animals, each=length(sides)), Date="", DayPostInoc=0, @@ -608,8 +612,8 @@ server <- function(input, output) { g<-list() for (side in c("L","R")){ 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["Dead"]<-dcast(tableR, Cage+Animal+Side+Group~., value.var = "Volume", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% pull(".") > input$cutoff + 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, Animal+Side+Group~., value.var = "Volume", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% pull(".") > input$cutoff table_tumor<<-endtime g[side]<-ggsurvplot(survfit(Surv(end, Dead) ~ Group, data=table_tumor), @@ -676,7 +680,6 @@ server <- function(input, output) { tableR<-filter(table, Side == side) %>% filter(!is.na(Volume)) 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))) } } @@ -761,7 +764,6 @@ server <- function(input, output) { sides<-unique(table$Side) groups<-table %>% select(Animal, Group) %>% unique() %>% pull(Group) basal<-data.frame( - Cage="", Animal=rep(animals, each=length(sides)), Date="", DayPostInoc=0, @@ -951,8 +953,8 @@ server <- function(input, output) { count<-1 for (side in c("L","R")){ 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["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<-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, 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 if (input$colors != ""){ col<-strsplit(input$colors, ",")[[1]]