Commit e61bebce authored by Amine  GHOZLANE's avatar Amine GHOZLANE
Browse files

Change some if else and add multiple selection for the tree

parent 528f77ca
......@@ -82,8 +82,8 @@ CheckTaxoTable <- function(taxo,counts, MGSTable=FALSE, taxoCreated=FALSE)
Warning = NULL
if(taxoCreated){Warning = "No taxonomy table has been uploaded, the analysis can only be done at the OTU/gene level"}
if(ncol(taxo)<1 && is.null(Error)){Error = "The number of columns of the taxonomy table must be at least 1" }
if(nrow(taxo)<=1 && is.null(Error)){Error = "The number of rows if the taxonomy table must be at least 2" }
if(TRUE%in%is.numeric(taxo) && is.null(Error) ){Error = "The taxonomy table must contain only character" }
else if(nrow(taxo)<=1 && is.null(Error)){Error = "The number of rows if the taxonomy table must be at least 2" }
if(is.numeric(taxo) && is.null(Error) ){Error = "The taxonomy table must contain only character" }
if(is.null(Error))
{
......@@ -93,7 +93,9 @@ CheckTaxoTable <- function(taxo,counts, MGSTable=FALSE, taxoCreated=FALSE)
nb = length(level)
if(nb==1 && level=="NA"){ Error = "At least one column contains only NA"}
}
if(MGSTable && length(which(toupper(colnames(taxo))%in%"MGS")) != 1){Error="The taxonomy table must contain a column named MGS providing the MGS association of each gene"}
if(MGSTable && length(which(toupper(colnames(taxo))%in%"MGS")) != 1){
Error="The taxonomy table must contain a column named MGS providing the MGS association of each gene"
}
}
## Annotated features without counts
......
......@@ -107,20 +107,26 @@ HCPlot <- function (input,dds,group,type.trans,counts,CT,tree,col = c("lightblue
nb = length(unique((group)))
## Get the dendrogram
if(input$DistClust!="sere" && input$DistClust!="Unifrac") dist = vegdist(t(counts), method = input$DistClust)
if(input$DistClust=="sere") dist = as.dist(SEREcoef(counts))
if(input$DistClust=="Unifrac") {
if(input$DistClust=="sere") dist.counts.norm = as.dist(SEREcoef(counts.norm))
else if(input$DistClust=="Unifrac"){
tmp = UniFracDist(CT,tree)
if(is.null(tree) || is.null(tmp)) dist = NULL
if(!is.null(tree)) {dist = switch(input$DistClustUnifrac,
"WU" = as.dist(tmp[, , "d_1"]),
"UWU" = as.dist(tmp[, , "d_UW"]),
"VAWU" = as.dist(tmp[, , "d_VAW"])
)
if(is.null(tree) || is.null(tmp)) dist.counts.norm = NULL
else
{
dist.counts.norm = switch(input$DistClustUnifrac,
"WU" = as.dist(tmp[, , "d_1"]),
"UWU" = as.dist(tmp[, , "d_UW"]),
"VAWU" = as.dist(tmp[, , "d_VAW"]))
}
}
else if(input$DistClust %in% getDistMethods()){
dist = as.dist(distance(t(sweep(counts.norm,2,colSums(counts.norm),`/`)), method=input$DistClust))
dist[is.na(dist)]=0.0
dist.counts.norm = dist
}
else dist.counts.norm = vegdist(t(counts.norm), method = input$DistClust)
if(!is.null(dist))
{
hc <- hclust(dist, method = "ward.D")
......@@ -137,7 +143,7 @@ HCPlot <- function (input,dds,group,type.trans,counts,CT,tree,col = c("lightblue
par(cex=input$cexTitleDiag,mar=c(6,6,4,5))
res = plot(dend, main = "Cluster dendrogram",xlab = paste(input$DistClust,"distance, Ward criterion",sep=" "),cex=input$cexLabelDiag)
}
if(type!="hori")
else
{
par(cex=input$cexTitleDiag,mar=c(6,6,4,5))
res = circlize_dendrogram(dend, labels_track_height = 0.2, dend_track_height = .3, main = "Cluster dendrogram",xlab = paste(input$DistClust,"distance, Ward criterion",sep=" "))
......@@ -413,15 +419,19 @@ PCoAPlot_meta <-function (input, dds, group_init, CT,tree,col = c("SpringGreen",
## Get the distance
if(input$DistClust=="sere") dist.counts.norm = as.dist(SEREcoef(counts.norm))
else if(input$DistClust=="Unifrac"){
tmp = UniFracDist(CT,tree)
saveRDS(counts.norm,file="/home/aghozlan/workspace/shaman/count_matrix.rds")
saveRDS(tree,file="/home/aghozlan/workspace/shaman/tree.rds")
print(counts.norm)
print(tree)
#tmp = UniFracDist(CT,tree)
tmp = UniFracDist(counts.norm,tree)
if(is.null(tree) || is.null(tmp)) dist.counts.norm = NULL
if(!is.null(tree))
else
{
dist.counts.norm = switch(input$DistClustUnifrac,
"WU" = as.dist(tmp[, , "d_1"]),
"UWU" = as.dist(tmp[, , "d_UW"]),
"VAWU" = as.dist(tmp[, , "d_VAW"])
)
"VAWU" = as.dist(tmp[, , "d_VAW"]))
}
}
......@@ -678,13 +688,13 @@ Get_pcoa_table <-function (input, dds, group_init,CT,tree)
## Get the distance
if(input$DistClust=="sere") dist.counts.norm = as.dist(SEREcoef(counts.norm))
else if(input$DistClust=="Unifrac") {
tmp = UniFracDist(CT,tree)
tmp = UniFracDist(counts.norm,tree)
if(is.null(tree) || is.null(tmp)) dist.counts.norm = NULL
if(!is.null(tree)) {dist.counts.norm = switch(input$DistClustUnifrac,
else{
dist.counts.norm = switch(input$DistClustUnifrac,
"WU" = as.dist(tmp[, , "d_1"]),
"UWU" = as.dist(tmp[, , "d_UW"]),
"VAWU" = as.dist(tmp[, , "d_VAW"])
)
"VAWU" = as.dist(tmp[, , "d_VAW"]))
}
}
else if(input$DistClust %in% getDistMethods()){
......@@ -907,9 +917,8 @@ NMDSPlot <-function (input, dds, group_init, CT,tree,col = c("SpringGreen","dodg
)
title(main= "Non-metric multidimensional scaling",cex.main=1.5)
par(font.main=3)
if(input$DistClust!="Unifrac") title(main=paste("\n","\n",input$DistClust,"distance",sep=" "),cex.main=1)
if(input$DistClust=="Unifrac") title(main=paste("\n","\n",input$DistClustUnifrac,"distance",sep=" "),cex.main=1)
else title(main=paste("\n","\n",input$DistClust,"distance",sep=" "),cex.main=1)
abline(h = 0, v = 0, lty = 2, col = "lightgray")
text(proj[,as.numeric(gsub("PC","",input$PCaxe1))] - ifelse(proj[,as.numeric(gsub("PC","",input$PCaxe1))] > 0, abs, -abs), proj[,as.numeric(gsub("PC","",input$PCaxe2))] - ifelse(proj[,as.numeric(gsub("PC","",input$PCaxe2))] > 0, ord, -ord), colnames(counts.norm), col = col[indgrp],cex=input$cexLabelDiag)
}
......
......@@ -19,7 +19,7 @@ Plot_Visu_Barplot <- function(input,resDiff)
SamplesNames = tmp_combined$namesCounts
if(nbKept>1) namesTax = colnames(counts_tmp_combined)
if(nbKept==1) namesTax = ind_taxo
else if(nbKept==1) namesTax = ind_taxo
dataNull = data.frame(x=c(0,0),y=c(1,2))
......@@ -63,7 +63,7 @@ Plot_Visu_Barplot <- function(input,resDiff)
colnames(dataBarPlot_mat) = c("Taxonomy","Proportions","AllVar")
dataBarPlot_mat[,2] = tmp_counts
if(input$SensPlotVisu == "Vertical") Sens = "multiBarChart"
if(input$SensPlotVisu == "Horizontal") Sens = "multiBarHorizontalChart"
else Sens = "multiBarHorizontalChart"
XRotate = input$rotateXLabel
......@@ -655,7 +655,7 @@ CreateTableTree <- function(input,resDiff,CT_Norm_OTU,taxo_table,VarInt,ind_taxo
rownames(targetInt)=rownames(target)
## Combining the Varint
if(length(VarInt)>1){targetInt$AllVar = apply(targetInt,1,paste, collapse = "-"); targetInt$AllVar = factor(targetInt$AllVar,levels = expand.grid2.list(list.val))}
if(length(VarInt)<=1){targetInt$AllVar = target[,VarInt]; targetInt$AllVar = factor(targetInt$AllVar,levels = val)}
else{targetInt$AllVar = target[,VarInt]; targetInt$AllVar = factor(targetInt$AllVar,levels = val)}
colnames(targetInt) = c(VarInt,"AllVar")
## Keep only the selected modalities
......@@ -707,7 +707,6 @@ CreateTableTree <- function(input,resDiff,CT_Norm_OTU,taxo_table,VarInt,ind_taxo
Plot_Visu_Tree <- function(input,resDiff,CT_Norm_OTU,taxo_table)
{
res = NULL
## Get Input for BarPlot
VarInt = input$VisuVarInt
......@@ -722,21 +721,16 @@ Plot_Visu_Tree <- function(input,resDiff,CT_Norm_OTU,taxo_table)
{
tmp = CreateTableTree(input,resDiff,CT_Norm_OTU,taxo_table,VarInt)
if(nrow(tmp$counts)>0 && !is.null(tmp$counts) && !is.null(input$TaxoTree))
if(nrow(tmp$counts)>0 && !is.null(tmp$counts))
{
#save(tmp,taxo_table,nodeFind,file="testTree.RData")
merge_dat = merge(taxo_table,round(t(tmp$counts)),by="row.names")
colnames(merge_dat)[1] = "OTU"
levels <- c("OTU", colnames(taxo_table))
conditions <- rownames(tmp$counts)
nodeFind = input$TaxoTree
if(input$TaxoTree=="...") nodeFind = NULL
#nodeFind = input$TaxoTree
nodeFind =input$selectTaxoPlot
if(length(input$selectTaxoPlot) == 0) nodeFind = NULL
res = treeWeightD3(merge_dat,conditions,levels,nodeFind=nodeFind, height =input$heightVisu+10, width=if(input$modifwidthVisu){input$widthVisu})
}
}
......
......@@ -104,11 +104,7 @@ shinyServer(function(input, output,session) {
if (is.null(inFile)) return(NULL)
try(read.tree(inFile$datapath)->data,silent=T)
CheckTree = CheckTreeFile(data)
data = CheckTree$tree
print(CheckTree$Error)
print(CheckTree$Warning)
print(data)
return(list(data=data,Error = CheckTree$Error,Warning = CheckTree$Warning))
})
......@@ -1561,7 +1557,7 @@ shinyServer(function(input, output,session) {
"SERE"="sere", dist_phyl))),selected="bray")
## Add the unifrac distance
if(!is.null(tree) && !is.null(input$fileTree) && is.null(ErrorTree) && TaxoSelect == "OTU/Gene")
if(!is.null(tree) && !is.null(input$fileTree) && is.null(ErrorTree) && TaxoSelect %in% c("OTU/Gene", "MGS"))
{
res = selectInput("DistClust","Distance",unique(sort(c("altGower", "binomial", "bray", "canberra", "cao", "chao", "euclidean","gower", "horn",
"jaccard","kulczynski", "mahalanobis", "morisita", "mountford", "raup",
......@@ -2341,27 +2337,27 @@ shinyServer(function(input, output,session) {
})
output$VarIntVisuTree <- renderUI({
target=values$TargetWorking
data = dataInput()$data
taxo = input$TaxoSelect
resDiff = ResDiffAnal()
res = NULL
if(!is.null(data$counts) && !is.null(data$taxo) && nrow(data$counts)>0 && nrow(data$taxo)>0 && !is.null(taxo) && taxo!="..." && !is.null(target))
{
counts = dataMergeCounts()$counts
Available_x = sort(rownames(counts))
res = selectizeInput("TaxoTree",h6(strong(paste("Select a specific",taxo,sep=" "))),c("...",Available_x),multiple = FALSE)
}
return(res)
})
# output$VarIntVisuTree <- renderUI({
#
# target=values$TargetWorking
# data = dataInput()$data
# taxo = input$TaxoSelect
# resDiff = ResDiffAnal()
# res = NULL
#
# if(!is.null(data$counts) && !is.null(data$taxo) && nrow(data$counts)>0 && nrow(data$taxo)>0 && !is.null(taxo) && taxo!="..." && !is.null(target))
# {
# counts = dataMergeCounts()$counts
#
# Available_x = sort(rownames(counts))
#
# res = selectizeInput("TaxoTree",h6(strong(paste("Select a specific",taxo,sep=" "))),c("...",Available_x),multiple = TRUE)
#
# }
#
# return(res)
#
# })
#####################################################
##
......
......@@ -650,7 +650,6 @@ body <- dashboardBody(
column(width=3,
box(title = "Select your plot", width = NULL, status = "primary", solidHeader = TRUE,collapsible = FALSE,collapsed= FALSE,
selectizeInput("PlotVisuSelect","",c("Barplot"="Barplot","Heatmap"="Heatmap","Boxplot"="Boxplot","Tree"="Tree","Scatterplot"="Scatterplot","Diversity"="Diversity","Rarefaction"="Rarefaction"),selected = "Barplot")
#selectizeInput("PlotVisuSelect","",c("Barplot"="Barplot","Heatmap"="Heatmap","Boxplot"="Boxplot","Scatterplot"="Scatterplot","Diversity"="Diversity","Rarefaction"="Rarefaction"),selected = "Barplot")
),
......@@ -663,28 +662,28 @@ body <- dashboardBody(
conditionalPanel(condition="input.PlotVisuSelect",
radioButtons("NormOrRaw",label = h5(strong("Type of counts")), c("Normalized" = "norm", "Raw" = "raw"),inline=TRUE)
),
conditionalPanel(condition="input.PlotVisuSelect!='Rarefaction' && input.PlotVisuSelect!='Scatterplot' ",
conditionalPanel(condition="input.PlotVisuSelect!='Rarefaction' && input.PlotVisuSelect!='Scatterplot' && input.PlotVisuSelect!='Tree'",
uiOutput("VarIntVisu"),
h5(strong("Select the modalities")),
uiOutput("ModVisu")
),
conditionalPanel(condition="input.PlotVisuSelect=='Tree' ",
uiOutput("VarIntVisuTree")),
conditionalPanel(condition="input.PlotVisuSelect=='Scatterplot' ",
# conditionalPanel(condition="input.PlotVisuSelect=='Tree'",
# uiOutput("VarIntVisuTree")),
conditionalPanel(condition="input.PlotVisuSelect=='Scatterplot'",
uiOutput("VarIntVisuScatter"),
radioButtons("TransDataScatter","Data transformation",c("Log2 +1" = "log2","None" = "none"),inline=TRUE),
hr(),
radioButtons("CorMeth","Correlation method",c("Pearson" = "pearson","Spearman" = "spearman"),inline=TRUE),
radioButtons("CorMeth","Correlation method",c("Pearson" = "pearson", "Spearman" = "spearman"),inline=TRUE),
checkboxInput("AddRegScatter","Add regression line",FALSE)
),
conditionalPanel(condition="input.PlotVisuSelect!='Rarefaction' && input.PlotVisuSelect!='Diversity' && input.PlotVisuSelect!='Scatterplot' && input.PlotVisuSelect!='Tree'",
conditionalPanel(condition="input.PlotVisuSelect!='Rarefaction' && input.PlotVisuSelect!='Diversity' && input.PlotVisuSelect!='Scatterplot'",
radioButtons("SelectSpecifTaxo","Select the features",c("Most abundant"="Most","All"="All", "Differential features" = "Diff", "Non differential features" = "NoDiff"))
),
conditionalPanel(condition="input.PlotVisuSelect!='Rarefaction' && input.PlotVisuSelect!='Diversity' && input.PlotVisuSelect!='Scatterplot' && input.PlotVisuSelect!='Tree' && (input.SelectSpecifTaxo=='Diff' || input.SelectSpecifTaxo=='NoDiff') ",
conditionalPanel(condition="input.PlotVisuSelect!='Rarefaction' && input.PlotVisuSelect!='Diversity' && input.PlotVisuSelect!='Scatterplot' && (input.SelectSpecifTaxo=='Diff' || input.SelectSpecifTaxo=='NoDiff') ",
selectizeInput("ContrastList_table_Visu","",choices = "", multiple = TRUE),
radioButtons("UnionInterContrasts","Union or intersection ?",c("Union"="Union","Intersection"="Inter"),inline = TRUE)
),
conditionalPanel(condition="input.PlotVisuSelect!='Rarefaction' && input.PlotVisuSelect!='Diversity' && input.PlotVisuSelect!='Scatterplot' && input.PlotVisuSelect!='Tree'",
conditionalPanel(condition="input.PlotVisuSelect!='Rarefaction' && input.PlotVisuSelect!='Diversity' && input.PlotVisuSelect!='Scatterplot'",
uiOutput("TaxoToPlotVisu")
),
......@@ -789,7 +788,7 @@ body <- dashboardBody(
##################
## ALL
##################
conditionalPanel(condition="input.PlotVisuSelect!='Rarefaction' && input.PlotVisuSelect!='Scatterplot' && input.PlotVisuSelect!='Tree'",
conditionalPanel(condition="input.PlotVisuSelect!='Rarefaction' && input.PlotVisuSelect!='Scatterplot'",
radioButtons(inputId = "SensPlotVisu",label = h6(strong("Orientation")),choices = c("Vertical" = "Vertical", "Horizontal" = "Horizontal"),selected = "Vertical",inline = TRUE)
)
),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment