Compare commits

..

3 Commits

+54 -46
View File
@@ -374,30 +374,7 @@ server <- function(input, output) {
oneside<-"" oneside<-""
table<-analysis$taula table<-analysis$taula
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","Code", "Cage","Group", "ID.animal","ID animal", "ID.tumor", "ID tumor", "TS","DPV", "Absorbance")
if (length(grep(0, colnames(table)[!colnames(table) %in% col_nodays])) == 0 & input$vacc == "Sí"){
table["0"]<-0
}
table<-melt(table, id=colnames(table)[colnames(table) %in% col_nodays], variable.name = "Timepoint")
table$Timepoint<-gsub("[A-Za-z ]","",table$Timepoint)
# print(table)
if ("DPV" %in% colnames(table)){
table<-dcast(table, Cage+`ID animal`+`ID tumor`+Group+Timepoint~DPV, value.var = "value")
table$Major<-table$Major
table$Minor<-table$Minor
table["Volume"]<-((table$Major*table$Minor*table$Minor)*(pi/6))
}
if ("TS" %in% colnames(table)){
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
}
if (!"Volume" %in% colnames(table)){table<-rename(table, "Volume"=value)}
table<-table %>% filter(!is.na(Group)) table<-table %>% filter(!is.na(Group))
table$Timepoint<-factor(table$Timepoint, levels=mixedsort(as.numeric(as.character(unique(table$Timepoint)))))
if (input$increase_volume){ if (input$increase_volume){
timepoints<-unique(table$Timepoint) timepoints<-unique(table$Timepoint)
table<-table %>% select(-Major, -Minor) %>% table<-table %>% select(-Major, -Minor) %>%
@@ -406,30 +383,43 @@ server <- function(input, output) {
gather(Timepoint, Volume, -Cage, -`ID animal`, -`ID tumor`, -Group) %>% gather(Timepoint, Volume, -Cage, -`ID animal`, -`ID tumor`, -Group) %>%
mutate(Volume=case_when(Volume < 0 ~ 0, T~Volume)) mutate(Volume=case_when(Volume < 0 ~ 0, T~Volume))
} }
table$Timepoint<-factor(table$Timepoint, levels=mixedsort(as.numeric(as.character(unique(table$Timepoint))))) table %>% group_by(Group, DayPostInoc, Side) %>% count() %>% spread(DayPostInoc, n)
analysis$taula_def<-table
analysis$taula_vol<-dcast(table, Cage+`ID animal`+`ID tumor`~Timepoint,value.var = "Volume")
table_plot<-dcast(dcast(table %>% filter(!is.na(Volume)), `ID animal`+Group+Timepoint~., value.var = "Volume", fun.aggregate = mean), Group~Timepoint)
table_plot
} }
}) })
output$cin_group<-renderPlot({ output$cin_group<-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
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$vacc == "Sí"){ if (input$vacc == "Sí"){
ggplot(table, aes(as.numeric(as.character(Timepoint)), 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")+
geom_point(stat="summary")+ 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 challenge")+ labs(x="Days after tumor inoculation")+
scale_y_continuous(expand = expansion(mult = c(0,0.05)))+ 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))+ 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{
ggplot(table, aes(Timepoint, 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")+
geom_point(stat="summary")+ geom_point(stat="summary")+
@@ -442,29 +432,47 @@ server <- function(input, output) {
} }
}) })
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)){
observeEvent(analysis$taula_def, {}) observeEvent(analysis$taula, {})
table<-analysis$taula_def table<-analysis$taula
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,
Group=rep(groups, each=length(sides)),
Side=rep(sides, length(animals)),
Weight="",
Long="",
Wide="",
Volume=0,
Observations=""
)
table<-rbind(table, basal)
if (input$vacc == "Sí"){ if (input$vacc == "Sí"){
ggplot(table, aes(as.numeric(as.character(Timepoint)), Volume, color=Group, group=`ID 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()+
geom_point()+ geom_point()+
scale_y_continuous(expand = expansion(mult = c(0,0.05)))+ 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))+ scale_x_continuous(expand = expansion(mult = c(0,0.05)), limits = c(0, (round(max(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")+
labs(x="Days after tumor challenge")+ labs(x="Days after tumor inoculation")+
theme_bw() theme_bw()
}else{ }else{
ggplot(table, aes(Timepoint, Volume, color=Group, group=paste0(`ID animal`, `ID tumor`)))+ 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()+
geom_point()+ geom_point()+
scale_y_continuous(expand = expansion(mult = c(0,0.05)))+ 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))+ # 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)+ facet_wrap(.~Group)+
labs(x="Days after tumor challenge")+ labs(x="Days after tumor inoculation")+
theme_bw()+ theme_bw()+
theme(axis.text.x=element_text(angle=45, hjust=1)) theme(axis.text.x=element_text(angle=45, hjust=1))
} }