Commit 978f4414 authored by Amine  GHOZLANE's avatar Amine GHOZLANE
Browse files

Add more distance

parent 2b5bd3f5
......@@ -412,35 +412,26 @@ PCoAPlot_meta <-function (input, dds, group_init, CT,tree,col = c("SpringGreen",
# print(head(counts.norm))
## Get the distance
if(input$DistClust=="sere") dist.counts.norm = as.dist(SEREcoef(counts.norm))
else if(input$DistClust=="jsd"){
#dist_jsd = JSD(sweep(counts.norm,2,colSums(counts.norm)))
dist_jsd = JSD(t(sweep(counts.norm,2,colSums(counts.norm),`/`)))
dist_jsd[is.na(dist_jsd)]=0
dist.counts.norm = as.dist(dist_jsd)
}
else if(input$DistClust=="kl"){
dist_kl = KL(t(sweep(counts.norm,2,colSums(counts.norm),`/`)))
dist_kl[is.na(dist_kl)]=0
dist.counts.norm = as.dist(dist_kl)
}
else if(input$DistClust=="Unifrac")
{
else if(input$DistClust=="Unifrac"){
tmp = UniFracDist(CT,tree)
if(is.null(tree) || is.null(tmp)) dist.counts.norm = NULL
if(!is.null(tree))
{
dist.counts.norm = switch(input$DistClustUnifrac,
"WU" = as.dist(tmp[, , "d_1"]),
"UWU" = as.dist(tmp[, , "d_UW"]),
"VAWU" = as.dist(tmp[, , "d_VAW"])
)
"WU" = as.dist(tmp[, , "d_1"]),
"UWU" = as.dist(tmp[, , "d_UW"]),
"VAWU" = as.dist(tmp[, , "d_VAW"])
)
}
}
else{
dist.counts.norm = vegdist(t(counts.norm), method = input$DistClust)
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)
#"additive_symm"
if(!is.null(dist.counts.norm))
{
## Do PCoA
......@@ -486,8 +477,8 @@ PCoAPlot_meta <-function (input, dds, group_init, CT,tree,col = c("SpringGreen",
title(main='Principal Coordinates Analysis ',cex.main=1.5)
## Add a subtitle
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)
# Set different shapes
if(input$labelPCOA == "Group"){
......@@ -649,7 +640,7 @@ Get_pcoa_table <-function (input, dds, group_init,CT,tree)
time_set = 0
# Set of shape
shape=c(19,17,15,18)
## Var of interest
VarInt = input$VarInt
......@@ -686,16 +677,6 @@ 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=="jsd"){
dist_jsd = JSD(t(sweep(counts.norm,2,colSums(counts.norm),`/`)))
dist_jsd[is.na(dist_jsd)]=0.0
dist.counts.norm = as.dist(dist_jsd)
}
else if(input$DistClust=="kl"){
dist_kl = KL(t(sweep(counts.norm,2,colSums(counts.norm),`/`)))
dist_kl[is.na(dist_kl)]=0.0
dist.counts.norm = as.dist(dist_kl)
}
else if(input$DistClust=="Unifrac") {
tmp = UniFracDist(CT,tree)
if(is.null(tree) || is.null(tmp)) dist.counts.norm = NULL
......@@ -706,6 +687,11 @@ Get_pcoa_table <-function (input, dds, group_init,CT,tree)
)
}
}
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)
}
......
......@@ -1551,16 +1551,19 @@ shinyServer(function(input, output,session) {
ErrorTree = dataInputTree()$Error
TaxoSelect = input$TaxoSelect
res = selectInput("DistClust","Distance", c("altGower", "binomial", "bray", "canberra", "cao", "chao", "euclidean","gower", "horn",
"jaccard","jsd","kl", "kulczynski", "mahalanobis", "morisita", "mountford","raup",
"SERE"="sere"),selected="bray")
dist_phyl = getDistMethods()[!getDistMethods() %in% c("additive_symm", "jensen-shannon", "jensen_difference", "minkowski", "topsoe")]
res = selectInput("DistClust","Distance", unique(sort(c("altGower", "binomial", "bray", "canberra", "cao", "chao", "euclidean","gower", "horn",
"jaccard", "kulczynski", "mahalanobis", "morisita", "mountford","raup",
"SERE"="sere", dist_phyl))),selected="bray")
## Add the unifrac distance
if(!is.null(tree) && !is.null(input$fileTree) && is.null(ErrorTree) && TaxoSelect == "OTU/Gene")
{
res = selectInput("DistClust","Distance",c("altGower", "binomial", "bray", "canberra", "cao", "chao", "euclidean","gower", "horn",
"jaccard","jsd","kl", "kulczynski", "mahalanobis", "morisita", "mountford","raup",
"SERE"="sere","Unifrac"),selected="bray")
res = selectInput("DistClust","Distance",unique(sort(c("altGower", "binomial", "bray", "canberra", "cao", "chao", "euclidean","gower", "horn",
"jaccard","kulczynski", "mahalanobis", "morisita", "mountford", "raup",
"SERE"="sere","Unifrac", dist_phyl))),selected="bray")
}
return(res)
......
Supports Markdown
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