Corregir asignador de grupos
This commit is contained in:
+60
-39
@@ -84,14 +84,24 @@ server <- function(input, output) {
|
|||||||
dades$db<-NULL
|
dades$db<-NULL
|
||||||
observe({
|
observe({
|
||||||
if (!is.null(input$file_sizes)){
|
if (!is.null(input$file_sizes)){
|
||||||
dades$taula<-read.xlsx(input$file_sizes$datapath, sheet = 1)
|
taula<-read.xlsx(input$file_sizes$datapath, sheet = 1, sep.names = " ")
|
||||||
|
if ("DPV" %in% colnames(taula)){
|
||||||
|
taula<-dcast(taula, Cage+`ID animal`+`ID tumor`+Group~DPV, value.var = "0")
|
||||||
|
# taula$Major<-taula$Major/1000
|
||||||
|
# taula$Minor<-taula$Minor/1000
|
||||||
|
# taula["Volume"]<-((taula$Major*taula$Minor*taula$Minor)*(pi/6))*1000
|
||||||
|
taula$Major<-taula$Major
|
||||||
|
taula$Minor<-taula$Minor
|
||||||
|
taula["Volume"]<-((taula$Major*taula$Minor*taula$Minor)*(pi/6))
|
||||||
|
}
|
||||||
|
dades$taula<-taula
|
||||||
dades$groups<-read.xlsx(input$file_sizes$datapath, sheet = 2)[,1]
|
dades$groups<-read.xlsx(input$file_sizes$datapath, sheet = 2)[,1]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
output$firstPlot <- renderPlot({
|
output$firstPlot <- renderPlot({
|
||||||
observeEvent(dades$taula, {})
|
observeEvent(dades$taula, {})
|
||||||
if (!is.null(dades$taula)){
|
if (!is.null(dades$taula)){
|
||||||
ggplot(dades$taula, aes(x="1", y=Volumen))+geom_quasirandom(width=0.2)
|
ggplot(dades$taula, aes(x="1", y=Volume))+geom_quasirandom(width=0.2)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -124,13 +134,14 @@ server <- function(input, output) {
|
|||||||
df<-dades$taula
|
df<-dades$taula
|
||||||
up_cuttof<-input$upcut
|
up_cuttof<-input$upcut
|
||||||
low_cuttof<-input$lowcut
|
low_cuttof<-input$lowcut
|
||||||
df<-df[df$Volumen < up_cuttof & df$Volumen > low_cuttof,]
|
df<-df[df$Volume <= up_cuttof & df$Volume >= low_cuttof,]
|
||||||
df["Mouse"]<-gsub("[a-zA-Z]", "", df$MouseID)
|
|
||||||
|
|
||||||
s<-shapiro.test(df$Volumen)[[2]]
|
|
||||||
|
# df["Mouse"]<-gsub("[a-zA-Z]", "", df$MouseID)
|
||||||
|
print(df$Volume)
|
||||||
|
s<-shapiro.test(df$Volume)[[2]]
|
||||||
|
|
||||||
ngroup<-length(dades$groups)
|
ngroup<-length(dades$groups)
|
||||||
|
|
||||||
ind.list<-list()
|
ind.list<-list()
|
||||||
pval.list<-list()
|
pval.list<-list()
|
||||||
lvn.list<-list()
|
lvn.list<-list()
|
||||||
@@ -138,32 +149,39 @@ server <- function(input, output) {
|
|||||||
for (data in 1:input$iterations){
|
for (data in 1:input$iterations){
|
||||||
interr=T
|
interr=T
|
||||||
while(interr == T){
|
while(interr == T){
|
||||||
ind<-sample(rep(dades$groups, each=7), length(unique(df$Mouse)))
|
ind<-sample(rep(dades$groups, each=ceiling(length(unique(df$`ID animal`))/ngroup)), length(unique(df$`ID animal`)))
|
||||||
df_temp<-merge(df, data.frame("Mouse"=unique(df$Mouse), "group"=as.factor(ind)))
|
df_temp<-merge(df[,c("ID animal", "ID tumor","Volume")], data.frame("ID animal"=unique(df$`ID animal`), "group"=as.factor(ind),check.names=F))
|
||||||
interr<-any(table(df_temp$group) < floor(nrow(df_temp)/5) | table(df_temp$group) > ceiling(nrow(df_temp)/5))
|
if ((nrow(df_temp)/ngroup) %% 2 == 0){
|
||||||
|
interr<-any(table(df_temp$group) < floor(nrow(df_temp)/ngroup) | table(df_temp$group) > ceiling(nrow(df_temp)/ngroup))
|
||||||
|
}else{
|
||||||
|
interr<-any(table(df_temp$group) < (floor(nrow(df_temp)/ngroup)-1) | table(df_temp$group) > (ceiling(nrow(df_temp)/ngroup)+1))
|
||||||
}
|
}
|
||||||
ind.list[[data]]<-df_temp[,c("MouseID","group")]
|
}
|
||||||
lvn.list[data]<-leveneTest(Volumen ~ group, data = df_temp[,3:4])[[2]][1]
|
ind.list[[data]]<-df_temp[,c("ID animal", "ID tumor","group","Volume")]
|
||||||
|
lvn.list[data]<-leveneTest(Volume ~ group, data = df_temp[,3:4])[[2]][1]
|
||||||
if (s < 0.05){
|
if (s < 0.05){
|
||||||
k<-kruskal.test(df_temp$Volumen,df_temp$group)
|
k<-kruskal.test(df_temp$Volume,df_temp$group)
|
||||||
test.list[data]<-k[[1]][1]
|
test.list[data]<-k[[1]][1]
|
||||||
pval.list[data]<-k[[3]][1]
|
pval.list[data]<-k[[3]][1]
|
||||||
}else{
|
}else{
|
||||||
res.aov<-aov(Volumen~group, data=df_temp)
|
res.aov<-aov(Volume~group, data=df_temp)
|
||||||
pval.list[data]<-summary(res.aov)[[1]][[5]][1]
|
pval.list[data]<-summary(res.aov)[[1]][[5]][1]
|
||||||
test.list[data]<-summary(res.aov)[[1]][[4]][1]
|
test.list[data]<-summary(res.aov)[[1]][[4]][1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
index<-which(unlist(lvn.list) == min(unlist(lvn.list)[which(unlist(pval.list) %in% sort(unlist(pval.list), decreasing = T)[1:20])]))
|
index<-which(unlist(lvn.list) == min(unlist(lvn.list)[which(unlist(pval.list) %in% sort(unlist(pval.list), decreasing = T)[1:20])]))
|
||||||
df_def<-merge(df, ind.list[[index]])
|
df_def<-merge(df, ind.list[[index]])
|
||||||
|
if ("Group" %in% colnames(df_def)){
|
||||||
|
df_def<-df_def %>% select(-"Group")
|
||||||
|
}
|
||||||
dades$db<-df_def
|
dades$db<-df_def
|
||||||
|
print(df_def)
|
||||||
|
|
||||||
ggplot(df_def, aes(group, Volumen))+
|
ggplot(df_def, aes(group, Volume))+
|
||||||
geom_boxplot(outlier.alpha = F)+
|
geom_boxplot(outlier.alpha = F)+
|
||||||
geom_jitter(width=0.25)+
|
geom_jitter(width=0.25)+
|
||||||
geom_point(stat="summary", color="blue", size=3)+
|
geom_point(stat="summary", color="blue", size=3)
|
||||||
lims(y=c(0,max(df_def$Volumen)+10))
|
# lims(y=c(0,max(df_def$Volume)+10))
|
||||||
})
|
})
|
||||||
output$distPlot <- renderPlot({
|
output$distPlot <- renderPlot({
|
||||||
observeEvent(dades$taula, {})
|
observeEvent(dades$taula, {})
|
||||||
@@ -184,28 +202,31 @@ 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<-expand.grid(dades$db$MouseID, timepoint)
|
dtemplate<-df$db %>% select(-Volume)
|
||||||
colnames(template)<-c("MouseID", "Timepoint")
|
dtemplate<-melt(dtemplate, id=c("Cage", "ID animal", "ID tumor", "group"), variable.name = "DPV", value.name = "0") %>% rename("Group"="group")
|
||||||
template<-template[order(template$Timepoint, template$MouseID),]
|
dtemplate<-dtemplate[,c("Cage", "ID animal", "ID tumor", "Group", "DPV", "0")]
|
||||||
template<-merge(template, dades$db[c("MouseID", "group")])
|
# template<-expand.grid(dades$db$MouseID, timepoint)
|
||||||
if (input$measure_sys == "L-W-D"){
|
# colnames(template)<-c("MouseID", "Timepoint")
|
||||||
template<-rbind(template, template, template)
|
# template<-template[order(template$Timepoint, template$MouseID),]
|
||||||
template<-template[order(template$Timepoint, template$MouseID),]
|
# template<-merge(template, dades$db[c("MouseID", "group")])
|
||||||
template["TS"]<-rep(c("TS-Length", "TS-Width", "TS-Deep"), nrow(template)/3)
|
# if (input$measure_sys == "L-W-D"){
|
||||||
dtemplate<-dcast(template, MouseID+group+TS~Timepoint)
|
# template<-rbind(template, template, template)
|
||||||
dtemplate<-dtemplate[mixedorder(as.character(dtemplate$MouseID)),]
|
# template<-template[order(template$Timepoint, template$MouseID),]
|
||||||
}
|
# template["TS"]<-rep(c("TS-Length", "TS-Width", "TS-Deep"), nrow(template)/3)
|
||||||
if (input$measure_sys == "Min-Max"){
|
# dtemplate<-dcast(template, MouseID+group+TS~Timepoint)
|
||||||
template<-rbind(template, template)
|
# dtemplate<-dtemplate[mixedorder(as.character(dtemplate$MouseID)),]
|
||||||
template<-template[order(template$Timepoint, template$MouseID),]
|
# }
|
||||||
template["DPV"]<-rep(c("Major", "Minor"), nrow(template)/2)
|
# if (input$measure_sys == "Min-Max"){
|
||||||
dtemplate<-dcast(template, MouseID+group+DPV~Timepoint)
|
# template<-rbind(template, template)
|
||||||
dtemplate<-dtemplate[mixedorder(as.character(dtemplate$MouseID)),]
|
# template<-template[order(template$Timepoint, template$MouseID),]
|
||||||
}
|
# template["DPV"]<-rep(c("Major", "Minor"), nrow(template)/2)
|
||||||
dtemplate<-dtemplate %>% add_column(.after="MouseID", "ID tumor"=dtemplate$MouseID)%>% rename(`ID animal`=MouseID)
|
# dtemplate<-dcast(template, MouseID+group+DPV~Timepoint)
|
||||||
dtemplate["ID tumor"]<-gsub("[[:digit:]]","",dtemplate$`ID tumor`)
|
# dtemplate<-dtemplate[mixedorder(as.character(dtemplate$MouseID)),]
|
||||||
dtemplate["ID animal"]<-gsub("[LR]","",dtemplate$`ID animal`)
|
# }
|
||||||
dtemplate[,5:ncol(dtemplate)]<-""
|
# dtemplate<-dtemplate %>% add_column(.after="MouseID", "ID tumor"=dtemplate$MouseID)%>% rename(`ID animal`=MouseID)
|
||||||
|
# dtemplate["ID tumor"]<-gsub("[[:digit:]]","",dtemplate$`ID tumor`)
|
||||||
|
# dtemplate["ID animal"]<-gsub("[LR]","",dtemplate$`ID animal`)
|
||||||
|
# dtemplate[,5:ncol(dtemplate)]<-""
|
||||||
}else{
|
}else{
|
||||||
template<-expand.grid(LETTERS[1:ncages], 1:5, id_tumors, timepoint)[,-2]
|
template<-expand.grid(LETTERS[1:ncages], 1:5, id_tumors, timepoint)[,-2]
|
||||||
colnames(template)<-c("Cage", "ID tumor", "Timepoint")
|
colnames(template)<-c("Cage", "ID tumor", "Timepoint")
|
||||||
|
|||||||
Reference in New Issue
Block a user