Compare commits

...

5 Commits

+92 -72
View File
@@ -357,26 +357,25 @@ server <- function(input, output) {
wide<-as.numeric(strsplit(table[i,"Wide"],"+", fixed = T)[[1]]) wide<-as.numeric(strsplit(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)))
} }
## Autocompletado de grupo ## Autocompletado de grupo
table_group<-merge( table_group<-merge(
table %>% select(Animal, Group) %>% unique() %>% group_by(Animal) %>% count(), table %>% select(Animal, Group) %>% unique() %>% group_by(Animal) %>% count(),
table %>% select(Animal, Group) %>% unique() table %>% select(Animal, Group) %>% unique()
) %>% filter(n > 1 & (!is.na(Group) | Group != "")) %>% select(-n) ) %>% filter(!is.na(Group) | Group != "") %>% select(-n)
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)
analysis$taula<-table analysis$taula<-table
} }
}) })
output$cutoffUI<-renderUI({ output$cutoffUI<-renderUI({
if (!is.null(analysis$taula_def)){ if (!is.null(analysis$taula)){
observeEvent(analysis$taula_def, {}) observeEvent(analysis$taula, {})
max_val<-max(analysis$taula_def$Volume, na.rm = T) max_val<-max(analysis$taula$Volume, na.rm = T)
# print(max_val) # 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)
} }
@@ -494,15 +493,15 @@ server <- function(input, output) {
}) })
output$survival<-renderPlot({ output$survival<-renderPlot({
if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){ if (!is.null(input$file_analy) & !is.null(analysis$taula)){
observeEvent(analysis$taula_def, {}) observeEvent(analysis$taula, {})
table<-analysis$taula_def table<-analysis$taula
if (input$vacc == "Sí"){ if (input$vacc == "Sí"){
g<-list() g<-list()
for (side in c("L","R")){ for (side in c("L","R")){
tableR<-filter(table, `ID tumor` == side) %>% filter(!is.na(Volume)) tableR<-filter(table, Side == side) %>% filter(!is.na(Volume))
endtime<-dcast(tableR %>% filter(Volume < input$cutoff), Cage+`ID animal`+`ID tumor`+Group~., value.var = "Timepoint", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% rename("end"=".") 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+`ID animal`+`ID tumor`+Group~., value.var = "Volume", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% pull(".") > input$cutoff endtime["Dead"]<-dcast(tableR, Cage+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(table_tumor$end, table_tumor$Dead) ~ table_tumor$Group, data=table_tumor),
@@ -525,9 +524,9 @@ server <- function(input, output) {
}else{ }else{
tableR<-table %>% filter(!is.na(Volume)) tableR<-table %>% filter(!is.na(Volume))
endtime<-dcast(if(length(unique(tableR$Timepoint)) > 1){tableR %>% filter(Volume < input$cutoff)}else{tableR}, `ID animal`+`ID tumor`+Group~., endtime<-dcast(if(length(unique(tableR$DayPostInoc)) > 1){tableR %>% filter(Volume < input$cutoff)}else{tableR}, Animal+Side+Group~.,
value.var = "Timepoint", 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, `ID animal`+`ID tumor`+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(table_tumor$end, table_tumor$Dead) ~ table_tumor$Group, data=table_tumor),
@@ -544,19 +543,19 @@ server <- function(input, output) {
output$stats<-renderPrint({ output$stats<-renderPrint({
stattest<-"dunn" stattest<-"dunn"
oneside<-"" oneside<-""
if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){ if (!is.null(input$file_analy) & !is.null(analysis$taula)){
observeEvent(analysis$taula_def, {}) observeEvent(analysis$taula, {})
table<-analysis$taula_def table<-analysis$taula
if (input$vacc == "No"){ if (input$vacc == "No"){
table<-filter(table, !is.na(Volume)) table<-filter(table, !is.na(Volume))
summary(aov(Volume~Group+Timepoint+Error(`ID animal`+`ID tumor`), data=table)) summary(aov(Volume~Group+DayPostInoc+Error(Animal+Side), data=table))
}else{ }else{
for (side in c("L","R")){ for (side in c("L","R")){
tableR<-filter(table, `ID tumor` == side) %>% filter(!is.na(Volume)) tableR<-filter(table, Side == side) %>% filter(!is.na(Volume))
if (length(unique(tableR$Volume)) > 1 & length(unique(tableR$Timepoint)) > 1){ if (length(unique(tableR$Volume)) > 1 & length(unique(tableR$DayPostInoc)) > 1){
print(paste0("Side: ",side)) print(paste0("Side: ",side))
# print(summary(aov(Volume~Group+Timepoint+Error(paste0(ID animal,Cage)), data=tableR))) # print(summary(aov(Volume~Group+DayPostInoc+Error(paste0(Animal,Cage)), data=tableR)))
print(summary(aov(Volume~Group+Timepoint+Error(`ID animal`), data=tableR))) print(summary(aov(Volume~Group+DayPostInoc+Error(Animal), data=tableR)))
} }
} }
} }
@@ -565,42 +564,42 @@ server <- function(input, output) {
output$tab_stats<-renderTable({ output$tab_stats<-renderTable({
stattest<-"dunn" stattest<-"dunn"
oneside<-"" oneside<-""
if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){ if (!is.null(input$file_analy) & !is.null(analysis$taula)){
table<-analysis$taula_def table<-analysis$taula
table_stats<-list() table_stats<-list()
if (input$vacc == "No"){ if (input$vacc == "No"){
table<-table%>%filter(!is.na(Volume)) table<-table%>%filter(!is.na(Volume))
if (length(unique(table$Volume)) > 1){ if (length(unique(table$Volume)) > 1){
table_stats<-multi_stats(table, "Volume", "Timepoint", "Group", stat.test=stattest) table_stats<-multi_stats(table, "Volume", "DayPostInoc", "Group", stat.test=stattest)
} }
table_kw<-as.data.frame(matrix(nrow=0, ncol=2)) table_kw<-as.data.frame(matrix(nrow=0, ncol=2))
for (point in unique(table$Timepoint)){ for (point in unique(table$DayPostInoc)){
len_group<-length(unique(table %>% filter(Timepoint == point) %>% pull(Group))) len_group<-length(unique(table %>% filter(DayPostInoc == point) %>% pull(Group)))
if (len_group > 1){ if (len_group > 1){
table_kw<-rbind(table_kw, data.frame(point,kruskal.test(table %>% filter(Timepoint == point) %>% pull(Volume), table %>% filter(Timepoint == point) %>% pull(Group))[3][[1]])) table_kw<-rbind(table_kw, data.frame(point,kruskal.test(table %>% filter(DayPostInoc == point) %>% pull(Volume), table %>% filter(DayPostInoc == point) %>% pull(Group))[3][[1]]))
} }
} }
colnames(table_kw)<-c("Timepoint", "KW-p.val") colnames(table_kw)<-c("DayPostInoc", "KW-p.val")
table_stats<-merge(table_stats, table_kw) table_stats<-merge(table_stats, table_kw)
}else{ }else{
for (side in c("L","R")){ for (side in c("L","R")){
tableR<-filter(table, `ID tumor` == side) %>% filter(!is.na(Volume)) tableR<-filter(table, Side == side) %>% filter(!is.na(Volume))
if (length(unique(tableR$Volume)) > 1){ if (length(unique(tableR$Volume)) > 1){
table_stats[[side]]<-multi_stats(tableR, "Volume", "Timepoint", "Group", stat.test=stattest) table_stats[[side]]<-multi_stats(tableR, "Volume", "DayPostInoc", "Group", stat.test=stattest)
} }
table_kw<-as.data.frame(matrix(nrow=0, ncol=2)) table_kw<-as.data.frame(matrix(nrow=0, ncol=2))
for (point in unique(tableR$Timepoint)){ for (point in unique(tableR$DayPostInoc)){
len_group<-length(unique(tableR %>% filter(Timepoint == point) %>% pull(Group))) len_group<-length(unique(tableR %>% filter(DayPostInoc == point) %>% pull(Group)))
if (len_group > 1){ if (len_group > 1){
table_kw<-rbind(table_kw, data.frame(point,kruskal.test(tableR %>% filter(Timepoint == point) %>% pull(Volume), tableR %>% filter(Timepoint == point) %>% pull(Group))[3][[1]])) table_kw<-rbind(table_kw, data.frame(point,kruskal.test(tableR %>% filter(DayPostInoc == point) %>% pull(Volume), tableR %>% filter(DayPostInoc == point) %>% pull(Group))[3][[1]]))
} }
} }
colnames(table_kw)<-c("Timepoint", "KW-p.val") colnames(table_kw)<-c("DayPostInoc", "KW-p.val")
table_stats[[side]]<-merge(table_stats[[side]], table_kw) table_stats[[side]]<-merge(table_stats[[side]], table_kw)
} }
} }
table_stats_def<-bind_rows(table_stats, .id = "ID tumor") table_stats_def<-bind_rows(table_stats, .id = "Side")
if (input$filter_stats == T){ if (input$filter_stats == T){
table_stats_def %>% filter(p.adj < 0.05) table_stats_def %>% filter(p.adj < 0.05)
}else{ }else{
@@ -622,48 +621,69 @@ server <- function(input, output) {
##Exportar ##Exportar
output$expPlotUI<- renderUI({ output$expPlotUI<- renderUI({
observeEvent(analysis$taula_def, {}) observeEvent(analysis$taula, {})
if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){ if (!is.null(input$file_analy) & !is.null(analysis$taula)){
plotOutput("expPlot", width=paste0(input$width/10,"px"), height = paste0(input$height/10, "px")) plotOutput("expPlot", width=paste0(input$width/10,"px"), height = paste0(input$height/10, "px"))
} }
}) })
output$expPlot <- renderPlot({ output$expPlot <- renderPlot({
observeEvent(analysis$taula_def, {}) observeEvent(analysis$taula, {})
if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){ if (!is.null(input$file_analy) & !is.null(analysis$taula)){
table<-analysis$taula_def table<-analysis$taula
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,
Group=rep(groups, each=length(sides)),
Side=rep(sides, length(animals)),
Weight="",
Long="",
Wide="",
Volume=0,
Observations=""
)
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í"){
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,`ID tumor`, Timepoint) %>% 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)) %>%
mutate(Timepoint2=as.numeric(as.character(Timepoint))) %>% mutate(Timepoint2=as.numeric(as.character(DayPostInoc))) %>%
mutate(x=Timepoint2-input$`errorbar-width`, xend=Timepoint2+input$`errorbar-width`) mutate(x=Timepoint2-input$`errorbar-width`, xend=Timepoint2+input$`errorbar-width`)
g<-ggplot(table, aes(as.numeric(as.character(Timepoint)), Volume, color=Group, group=Group))+ g<-ggplot(table, aes(DayPostInoc, Volume, color=Group, group=Group))+
scale_x_continuous(expand = expansion(mult = c(0,0.0)), geom_errorbar(stat="summary", width=0.05)+
breaks=sort(unique(errbar$Timepoint2)), geom_line(stat="summary")+
limits = c(0,max(as.numeric(as.character(table$Timepoint)))*1.1))+ geom_point(stat="summary")+
facet_grid(factor(`ID tumor`, labels = c("Vaccination", "Rechallenge"))~., scale="free_y")+ facet_grid(factor(Side, labels = c("Vaccination", "Rechallenge"))~., scale="free_y")+
labs(x="Days after tumor inoculation")+
scale_y_continuous(expand = expansion(mult = c(0,0.05)))+
scale_x_continuous(expand = expansion(mult = c(0,0.05)), limits = c(0, (round(max(table$DayPostInoc) / 5)+1)*5))+
theme_bw()+ theme_bw()+
geom_segment(data=errbar, aes(y=mean, yend=mean+std, x=Timepoint2, xend=Timepoint2))+ geom_segment(data=errbar, aes(y=mean, yend=mean+std, x=Timepoint2, xend=Timepoint2))+
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{
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, Timepoint) %>% 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)) %>%
mutate(Timepoint2=as.numeric(as.character(Timepoint))) %>% mutate(Timepoint2=as.numeric(as.character(DayPostInoc))) %>%
mutate(x=Timepoint2-input$`errorbar-width`, xend=Timepoint2+input$`errorbar-width`) mutate(x=Timepoint2-input$`errorbar-width`, xend=Timepoint2+input$`errorbar-width`)
g<-ggplot(table, aes(as.numeric(as.character(Timepoint)), Volume, color=Group, group=Group))+ g<-ggplot(table, aes(DayPostInoc, Volume, color=Group, group=Group))+
scale_x_continuous(expand = expansion(mult = c(0,0.0)), geom_errorbar(stat="summary",width=0.05)+
breaks=sort(unique(errbar$Timepoint2)), geom_line(stat="summary")+
limits = c(0,max(as.numeric(as.character(table$Timepoint)))*1.1))+ geom_point(stat="summary")+
# limits = c(0, (round(max(as.numeric(as.character(table$Timepoint))) / 5)+1)*5))+ labs(x="Days after tumor challenge")+
scale_y_continuous(expand = expansion(mult = c(0,0.05)))+
theme_bw()+ theme_bw()+
theme(axis.text.x=element_text(angle=45, hjust=1))+
geom_segment(data=errbar, aes(y=mean, yend=mean+std, x=Timepoint2, xend=Timepoint2))+ geom_segment(data=errbar, aes(y=mean, yend=mean+std, x=Timepoint2, xend=Timepoint2))+
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))
@@ -671,17 +691,17 @@ 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í"){
g<-ggplot(table, aes(as.numeric(as.character(Timepoint)), Volume, color=Group, group=`ID 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$Timepoint)))), breaks=sort(unique(as.numeric(as.character(table$DayPostInoc)))),
limits = c(0, (round(max(as.numeric(as.character(table$Timepoint))) / 5)+1)*5))+ limits = c(0, (round(max(as.numeric(as.character(table$DayPostInoc))) / 5)+1)*5))+
facet_grid(factor(`ID tumor`, 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(Timepoint)), Volume, color=Group, group=`ID 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$Timepoint)))), breaks=sort(unique(as.numeric(as.character(table$DayPostInoc)))),
limits = c(0,max(as.numeric(as.character(table$Timepoint)))*1.1))+ limits = c(0,max(as.numeric(as.character(table$DayPostInoc)))*1.1))+
facet_wrap(.~Group)+ facet_wrap(.~Group)+
theme_bw() theme_bw()
} }
@@ -730,9 +750,9 @@ server <- function(input, output) {
g<-list() g<-list()
count<-1 count<-1
for (side in c("L","R")){ for (side in c("L","R")){
tableR<-filter(table, `ID tumor` == side) %>% filter(!is.na(Volume)) tableR<-filter(table, Side == side) %>% filter(!is.na(Volume))
endtime<-dcast(tableR %>% filter(Volume < input$cutoff), Cage+`ID animal`+`ID tumor`+Group~., value.var = "Timepoint", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% rename("end"=".") 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+`ID animal`+`ID tumor`+Group~., value.var = "Volume", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% pull(".") > input$cutoff endtime["Dead"]<-dcast(tableR, Cage+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
if (input$colors != ""){ if (input$colors != ""){
col<-input$colors col<-input$colors
@@ -752,8 +772,8 @@ server <- function(input, output) {
}else{ }else{
tableR<-table %>% filter(!is.na(Volume)) tableR<-table %>% filter(!is.na(Volume))
endtime<-dcast(tableR %>% filter(Volume < input$cutoff), `ID animal`+Group~., value.var = "Timepoint", fun.aggregate = function(x){max(as.numeric(as.character(x)))}) %>% rename("end"=".") 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["Dead"]<-dcast(tableR, `ID 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
table_tumor<-endtime table_tumor<-endtime
if (input$colors != ""){ if (input$colors != ""){
col<-input$colors col<-input$colors