Browse Source

"Añadir análisis no vacunación"

master
marcelcosta 4 years ago
parent
commit
5019fab020
1 changed files with 88 additions and 42 deletions
  1. +88
    -42
      invivos/app.R

+ 88
- 42
invivos/app.R

@ -213,7 +213,7 @@ server <- function(input, output) {
analysis$taula_def<-NULL analysis$taula_def<-NULL
observe({ observe({
if (!is.null(input$file_analy)){ if (!is.null(input$file_analy)){
analysis$taula<-read.xlsx(input$file_analy$datapath, sheet = 1)
analysis$taula<-read.xlsx(input$file_analy$datapath, sheet = 1, check.names = F, sep.names = " ")
} }
}) })
output$ntable<-renderTable({ output$ntable<-renderTable({
@ -224,23 +224,28 @@ server <- function(input, output) {
cutoff<-750 cutoff<-750
table<-analysis$taula table<-analysis$taula
table<- table %>% add_column("0"=0, .before="12")
table[table$ID.tumor == "R","0"]<-NA
table<-melt(table, id=colnames(table)[1:6], variable.name = "Timepoint")
if ("ID.animal" %in% colnames(table)){table<-rename(table, "ID animal"=`ID.animal`)}
if ("ID" %in% colnames(table)){table<-rename(table, "ID animal"=ID)}
if ("ID.tumor" %in% colnames(table)){table<-rename(table, "ID tumor"=`ID.tumor`)}
# table[table$ID.tumor == "R","0"]<-NA
col_nodays<-c("ID", "Cage","Group", "ID.animal","ID animal", "ID.tumor", "ID tumor", "TS","DPV", "Absorbance")
table<-melt(table, id=colnames(table)[colnames(table) %in% col_nodays], variable.name = "Timepoint")
table$Timepoint<-gsub("[A-Za-z ]","",table$Timepoint)
table$Timepoint<-factor(table$Timepoint, levels=mixedsort(as.numeric(as.character(unique(table$Timepoint)))))
if ("DPV" %in% colnames(table)){ if ("DPV" %in% colnames(table)){
table<-dcast(table, Cage+ID.animal+ID.tumor+Group+Timepoint~DPV, value.var = "value")
table<-dcast(table, Cage+`ID animal`+`ID tumor`+Group+Timepoint~DPV, value.var = "value")
table$Major<-table$Major/1000 table$Major<-table$Major/1000
table$Minor<-table$Minor/1000 table$Minor<-table$Minor/1000
table["Volume"]<-((table$Major*table$Minor*table$Minor)*(pi/6))*1000 table["Volume"]<-((table$Major*table$Minor*table$Minor)*(pi/6))*1000
} }
if ("TS" %in% colnames(table)){ if ("TS" %in% colnames(table)){
table<-dcast(table, Cage+ID.animal+ID.tumor+Group+Timepoint~TS, value.var = "value")
table<-dcast(table, Cage+`ID animal`+`ID tumor`+Group+Timepoint~TS, value.var = "value")
table["Volume"]<-table$`TS-Deep`*table$`TS-Length`*table$`TS-Width`*pi/6 table["Volume"]<-table$`TS-Deep`*table$`TS-Length`*table$`TS-Width`*pi/6
} }
if (!"Volume" %in% colnames(table)){table<-rename(table, "Volume"=value)}
table<-table %>% filter(!is.na(Group)) table<-table %>% filter(!is.na(Group))
analysis$taula_def<-table analysis$taula_def<-table
table_plot<-dcast(dcast(table %>% filter(!is.na(Volume)), Cage+`ID.animal`+Group+Timepoint~., value.var = "Volume", fun.aggregate = mean), Group~Timepoint)
table_plot<-dcast(dcast(table %>% filter(!is.na(Volume)), `ID animal`+Group+Timepoint~., value.var = "Volume", fun.aggregate = mean), Group~Timepoint)
table_plot table_plot
} }
}) })
@ -248,30 +253,55 @@ server <- function(input, output) {
if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){ if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){
observeEvent(analysis$taula_def, {}) observeEvent(analysis$taula_def, {})
table<-analysis$taula_def table<-analysis$taula_def
ggplot(table, aes(as.numeric(as.character(Timepoint)), Volume, color=Group, group=Group))+
geom_errorbar(stat="summary", width=0.05)+
geom_line(stat="summary")+
geom_point(stat="summary")+
facet_grid(factor(ID.tumor, labels = c("Vaccination", "Rechallenge"))~., scale="free_y")+
labs(x="Days after tumor challenge")+
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(as.numeric(as.character(table$Timepoint))) / 5)+1)*5))+
theme_bw()
if (input$vacc == "Sí"){
ggplot(table, aes(as.numeric(as.character(Timepoint)), Volume, color=Group, group=Group))+
geom_errorbar(stat="summary", width=0.05)+
geom_line(stat="summary")+
geom_point(stat="summary")+
facet_grid(factor(`ID tumor`, labels = c("Vaccination", "Rechallenge"))~., scale="free_y")+
labs(x="Days after tumor challenge")+
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(as.numeric(as.character(table$Timepoint))) / 5)+1)*5))+
theme_bw()
}else{
ggplot(table, aes(Timepoint, Volume, color=Group, group=Group))+
geom_errorbar(stat="summary",width=0.05)+
geom_line(stat="summary")+
geom_point(stat="summary")+
labs(x="Days after tumor challenge")+
scale_y_continuous(expand = expansion(mult = c(0,0.05)))+
theme_bw()+
theme(axis.text.x=element_text(angle=45, hjust=1))
}
} }
}) })
output$cin_indiv<-renderPlot({ output$cin_indiv<-renderPlot({
if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){ if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){
observeEvent(analysis$taula_def, {}) observeEvent(analysis$taula_def, {})
table<-analysis$taula_def table<-analysis$taula_def
ggplot(table, aes(as.numeric(as.character(Timepoint)), Volume, color=Group, group=paste0(Cage,ID.animal)))+
# geom_errorbar(stat="summary", width=0.05)+
geom_line()+
geom_point()+
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(as.numeric(as.character(table$Timepoint))) / 5)+1)*5))+
facet_grid(factor(ID.tumor, labels = c("Vaccination", "Rechallenge"))~Group, scale="free_y")+
labs(x="Days after tumor challenge")+
theme_bw()
if (input$vacc == "Sí"){
ggplot(table, aes(as.numeric(as.character(Timepoint)), Volume, color=Group, group=`ID animal`))+
# geom_errorbar(stat="summary", width=0.05)+
geom_line()+
geom_point()+
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(as.numeric(as.character(table$Timepoint))) / 5)+1)*5))+
facet_grid(factor(`ID tumor`, labels = c("Vaccination", "Rechallenge"))~Group, scale="free_y")+
labs(x="Days after tumor challenge")+
theme_bw()
}else{
ggplot(table, aes(Timepoint, Volume, color=Group, group=`ID animal`))+
# geom_errorbar(stat="summary", width=0.05)+
geom_line()+
geom_point()+
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(as.numeric(as.character(table$Timepoint))) / 5)+1)*5))+
facet_wrap(.~Group)+
labs(x="Days after tumor challenge")+
theme_bw()+
theme(axis.text.x=element_text(angle=45, hjust=1))
}
} }
}) })
output$stats<-renderPrint({ output$stats<-renderPrint({
@ -281,16 +311,16 @@ server <- function(input, output) {
if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){ if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){
observeEvent(analysis$taula_def, {}) observeEvent(analysis$taula_def, {})
table<-analysis$taula_def table<-analysis$taula_def
if (oneside != ""){
tableR<-filter(table, ID.tumor == rechallenge) %>% filter(!is.na(Volume))
summary(aov(Volume~Group+Timepoint+Error(ID.animal), data=table[table$ID.tumor == oneside,]))
if (input$vacc == "No"){
table<-filter(table, !is.na(Volume))
summary(aov(Volume~Group+Timepoint+Error(`ID animal`), 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, `ID tumor` == 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$Timepoint)) > 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+Timepoint+Error(ID.animal), data=tableR)))
# print(summary(aov(Volume~Group+Timepoint+Error(paste0(ID animal,Cage)), data=tableR)))
print(summary(aov(Volume~Group+Timepoint+Error(`ID animal`), data=tableR)))
} }
} }
} }
@ -303,20 +333,37 @@ server <- function(input, output) {
if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){ if (!is.null(input$file_analy) & !is.null(analysis$taula_def)){
table<-analysis$taula_def table<-analysis$taula_def
table_stats<-list() table_stats<-list()
for (side in c("L","R")){
tableR<-filter(table, ID.tumor == side) %>% filter(!is.na(Volume))
if (length(unique(tableR$Volume)) > 1){
table_stats[[side]]<-multi_stats(tableR, "Volume", "Timepoint", "Group", stat.test=stattest)
if (input$vacc == "No"){
table<-table%>%filter(!is.na(Volume))
if (length(unique(table$Volume)) > 1){
table_stats<-multi_stats(table, "Volume", "Timepoint", "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)){
len_group<-length(unique(tableR %>% filter(Timepoint == point) %>% pull(Group)))
for (point in unique(table$Timepoint)){
len_group<-length(unique(table %>% filter(Timepoint == 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(table %>% filter(Timepoint == point) %>% pull(Volume), table %>% filter(Timepoint == point) %>% pull(Group))[3][[1]]))
} }
} }
colnames(table_kw)<-c("Timepoint", "KW-p.val") colnames(table_kw)<-c("Timepoint", "KW-p.val")
table_stats[[side]]<-merge(table_stats[[side]], table_kw)
table_stats<-merge(table_stats, table_kw)
}else{
for (side in c("L","R")){
tableR<-filter(table, `ID tumor` == side) %>% filter(!is.na(Volume))
if (length(unique(tableR$Volume)) > 1){
table_stats[[side]]<-multi_stats(tableR, "Volume", "Timepoint", "Group", stat.test=stattest)
}
table_kw<-as.data.frame(matrix(nrow=0, ncol=2))
for (point in unique(tableR$Timepoint)){
len_group<-length(unique(tableR %>% filter(Timepoint == point) %>% pull(Group)))
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]]))
}
}
colnames(table_kw)<-c("Timepoint", "KW-p.val")
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 = "ID tumor")
if (input$filter_stats == T){ if (input$filter_stats == T){
@ -329,5 +376,4 @@ server <- function(input, output) {
} }
# Run the application # Run the application
shinyApp(ui = ui, server = server)
shinyApp(ui = ui, server = server)

Loading…
Cancel
Save