Commit 877518ae authored by svolant's avatar svolant
Browse files

Check input file + biom

parent de934b49
......@@ -48,10 +48,10 @@ if (!require(devtools)) {
install.packages('devtools')
library(devtools)
}
if(!require(treeWeightD3)){
devtools::install_git('https://gitlab.pasteur.fr/plechat/treeWeightD3')
library(treeWeightD3)
}
# if(!require(treeWeightD3)){
# devtools::install_git('https://gitlab.pasteur.fr/plechat/treeWeightD3')
# library(treeWeightD3)
# }
if (!require(BiocInstaller)){
source("https://bioconductor.org/biocLite.R")
biocLite("BiocInstaller")
......
......@@ -52,39 +52,51 @@ CheckCountsTable <- function(counts)
{
Error = NULL
Warning = NULL
numTest = FALSE%in%sapply(counts,is.numeric)
if(ncol(counts)<=1){Error = "The number of columns of the counts table must be at least 2" }
if(nrow(counts)<=1){Error = "The number of rows of the counts table must be at least 2" }
if(numTest){Error = "The counts table must contain only numeric values" }
if(!numTest)
if(is.null(counts) && is.null(Error)){Error = "There is no counts table" }
if(ncol(counts)<=1 && is.null(Error)){Error = "The number of columns of the counts table must be at least 2" }
if(nrow(counts)<=1 && is.null(Error)){Error = "The number of rows of the counts table must be at least 2" }
if(is.null(Error))
{
if(0%in%colSums(counts)){Error = "At least one of the column of the counts table is 0" }
if(min(counts)<0){Error = "The counts table must contain only positive values" }
numTest = FALSE%in%sapply(counts,is.numeric)
if(numTest) Error = "The counts table must contain only numeric values"
if(!numTest)
{
if(0%in%colSums(counts)){Error = "At least one of the column of the counts table is 0" }
if(min(counts)<0){Error = "The counts table must contain only positive values" }
}
}
if(TRUE%in%sapply(counts,is.na)){Warning = "NA values are considered as 0 is the counts table"; counts[sapply(counts,is.na)]=0}
if(TRUE%in%sapply(counts,is.na) && is.null(Error)){Warning = "NA values are considered as 0 is the counts table"; counts[sapply(counts,is.na)]=0}
return(list(Error=Error,Warning=Warning,counts=counts))
}
## Check the format of the taxonomy table
CheckTaxoTable <- function(taxo,counts)
CheckTaxoTable <- function(taxo,counts,taxoCreated = FALSE)
{
Error = NULL
Warning = NULL
if(ncol(taxo)<1){Error = "The number of columns of the taxonomy table must be at least 1" }
if(nrow(taxo)<=1){Error = "The number of rows if the taxonomy table must be at least 2" }
if(TRUE%in%is.numeric(taxo)){Error = "The taxonomy table must contain only character" }
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" }
for(i in 1:ncol(taxo))
if(is.null(Error))
{
level = levels(taxo[,i])
nb = length(level)
if(nb==1 && level=="NA"){ Error = "At least one column contains only NA"}
for(i in 1:ncol(taxo))
{
level = levels(taxo[,i])
nb = length(level)
if(nb==1 && level=="NA"){ Error = "At least one column contains only NA"}
}
}
## Annotated features without counts
if(!any(rownames(taxo)%in%rownames(counts))){ Error = "Some annotated features are not in the count table"}
if(!any(rownames(taxo)%in%rownames(counts)) && is.null(Error)){ Error = "Some annotated features are not in the count table"}
return(list(Error=Error,Warning=Warning))
}
......@@ -172,28 +184,41 @@ PercentAnnot <- function(counts,taxo)
## Get the counts and the taxo tables from the BIOM format file.
GetDataFromBIOM <-function(dataBIOM)
{
taxo = NULL
counts = NULL
taxoCreated = FALSE
## Counts table
counts = biom_data(dataBIOM)
counts = as.matrix(counts)
## Change of - to . is risky
colnames(counts) = gsub("-",".",colnames(counts))
counts = as.data.frame(counts)
if(!is.null(counts))
{
counts = as.matrix(counts)
## Change of - to . is risky
colnames(counts) = gsub("-",".",colnames(counts))
counts = as.data.frame(counts)
}
CheckCounts = CheckCountsTable(counts)
counts = CheckCounts$counts
## Taxonomy table
taxo = as.data.frame(observation_metadata(dataBIOM))
OTUnames = rownames(taxo)
## Modif taxo table (remove p__,... and change the colnames)
taxo = as.data.frame(sapply(taxo,gsub,pattern="^.*__",replacement=""))
colnames(taxo) = c("Kingdom", "Phylum","Class","Order","Family","Genus","Species")
rownames(taxo) = OTUnames
## Remove empty row
taxo[taxo==""] = NA
taxo[taxo=="Unassigned"] = NA
taxo=taxo[rowSums(is.na(taxo))!=dim(taxo)[2], ]
tmp = observation_metadata(dataBIOM)
if(!is.null(tmp))
{
if(is.data.frame(tmp)) taxo = as.data.frame(tmp)
if(!is.data.frame(tmp)) taxo = as.data.frame(t(sapply(observation_metadata(dataBIOM),FUN=function(x){x[1:7]})))
OTUnames = rownames(taxo)
## Modif taxo table (remove p__,... and change the colnames)
taxo = as.data.frame(sapply(taxo,gsub,pattern="^.*__",replacement=""))
colnames(taxo) = c("Kingdom", "Phylum","Class","Order","Family","Genus","Species")
rownames(taxo) = OTUnames
## Remove empty row
taxo[taxo==""] = NA
taxo[taxo=="Unassigned"] = NA
taxo=taxo[rowSums(is.na(taxo))!=dim(taxo)[2], ]
}
if(is.null(tmp) && !is.null(counts)) {taxo = data.frame(rownames(counts),row.names = rownames(counts));names(taxo)=NA; taxoCreated = TRUE}
CheckTaxo = CheckTaxoTable(taxo,counts)
CheckTaxo = CheckTaxoTable(taxo,counts,taxoCreated)
## Pourcentage of annotation
tmp = PercentAnnot(counts,taxo)
......@@ -209,6 +234,8 @@ GetDataFromCT <-function(dataC,dataT)
counts = dataC
CheckCounts = CheckCountsTable(counts)
counts = CheckCounts$counts
## Taxonomy table
taxo = as.data.frame(dataT)
CheckTaxo = CheckTaxoTable(taxo,counts)
......@@ -316,8 +343,8 @@ GetCountsMerge <- function(input,dataInput,taxoSelect,target,design)
# merged_table = merge(CT, taxo[order(rownames(CT)),], by="row.names")
merged_table = merge(CT, taxo, by="row.names")
CT = merged_table[,2: (dim(CT)[2]+1)]
taxo = merged_table[,(dim(CT)[2]+2):dim(merged_table)[2]]
CT = as.data.frame(merged_table[,2: (dim(CT)[2]+1)])
taxo = as.data.frame(merged_table[,(dim(CT)[2]+2):dim(merged_table)[2]])
rownames(CT) = merged_table[,1]
rownames(taxo) = merged_table[,1]
......
......@@ -25,16 +25,19 @@ shinyServer(function(input, output,session) {
## Counts file
dataInputCounts <-reactive({
data = NULL
inFile <- input$fileCounts
if (is.null(inFile)) return(NULL)
data = read.csv(inFile$datapath,sep=input$sepcount,header=TRUE,check.names=FALSE)
colnames(data) = gsub("-",".",colnames(data))
## Rownames
if(!TRUE%in%duplicated(data[,1])) rownames(data)=data[,1];data=data[,-1]
try(read.csv(inFile$datapath,sep=input$sepcount,header=TRUE,check.names=FALSE)->data,silent=T)
if(!is.null(data)){
colnames(data) = gsub("-",".",colnames(data))
## Rownames
if(!TRUE%in%duplicated(data[,1])) rownames(data)=data[,1];data=data[,-1]
}
return(as.data.frame(data))
})
......@@ -49,15 +52,18 @@ shinyServer(function(input, output,session) {
if(input$TypeTaxo=="Table")
{
data = read.csv(inFile$datapath,sep=input$septaxo,header=TRUE)
try(read.csv(inFile$datapath,sep=input$septaxo,header=TRUE)->data,silent=T)
## Rownames
if(!TRUE%in%duplicated(data[,1])){
DataNames=data[,1]
colNames=colnames(data)[-1]
data=as.matrix(data[,-1])
rownames(data)=DataNames
colnames(data) = colNames
if(!is.null(data))
{
if(!TRUE%in%duplicated(data[,1])){
DataNames=data[,1]
colNames=colnames(data)[-1]
data=as.matrix(data[,-1])
rownames(data)=DataNames
colnames(data) = colNames
}
}
}
......@@ -78,10 +84,11 @@ shinyServer(function(input, output,session) {
## BIOM File
dataInputBiom <-reactive({
data = NULL
inFile <- input$fileBiom
if (is.null(inFile)) return(NULL)
data = read_biom(inFile$datapath)
try(read_biom(inFile$datapath)->data,silent=T)
return(data)
})
......@@ -94,11 +101,14 @@ shinyServer(function(input, output,session) {
data = NULL
check = NULL
percent = NULL
Taxo = NULL
Counts = NULL
if(input$FileFormat=="fileCounts")
{
Counts = dataInputCounts()
Taxo = dataInputTaxo()
if(!input$NoTaxoFile) Taxo = dataInputTaxo()
if(!is.null(Counts) && input$NoTaxoFile) {Taxo = data.frame(rownames(Counts),row.names = rownames(Counts));names(Taxo)=NA}
if(!is.null(Counts) && !is.null(Taxo))
{
tmp = GetDataFromCT(Counts,Taxo)
......@@ -243,7 +253,7 @@ shinyServer(function(input, output,session) {
data = tmp$data
check = tmp$check
cond = (!is.null(data$taxo) && nrow(data$taxo)>0)
res =infoBox(h6(strong("Taxonomy table")), subtitle = h6("Load the taxonomy table") ,color = "light-blue",width=NULL,fill=TRUE, icon = icon("upload"))
res = infoBox(h6(strong("Taxonomy table")), subtitle = h6("Load the taxonomy table") ,color = "light-blue",width=NULL,fill=TRUE, icon = icon("upload"))
if(cond)
{
......@@ -252,6 +262,7 @@ shinyServer(function(input, output,session) {
if(is.null(check$CheckTaxo$Error) && is.null(check$CheckTaxo$Warning)) res = infoBox(h6(strong("Taxonomy table")), subtitle = h6(paste("Format of the taxonomy table seems to be OK")), icon = icon("thumbs-o-up"),color = "green",width=NULL,fill=TRUE)
}
if(input$NoTaxoFile && input$FileFormat=="fileCounts") res = infoBox(h6(strong("Taxonomy table")), subtitle = h6("No taxonomy table has been uploaded, the analysis can only be done at the OTU/gene level"), icon = icon("warning"),color = "orange",width=NULL,fill=TRUE)
return(res)
})
......@@ -264,7 +275,7 @@ shinyServer(function(input, output,session) {
check = tmp$check
cond = (!is.null(data$counts) && nrow(data$counts)>0 && !is.null(data$taxo) && nrow(data$taxo)>0)
res = valueBox(paste0(0, "%"),h6(strong("Annotated features")), color = "light-blue",width=NULL,icon = icon("list"))
if(cond)
{
percent = round(100*tmp$percent,2)
......@@ -348,7 +359,6 @@ shinyServer(function(input, output,session) {
## Check error in the counts and taxonomy table
CheckOK = (is.null(check$CheckCounts$Error) && is.null(check$CheckTaxo$Error) && is.null(check$CheckPercent))
if(!is.null(data$counts) && !is.null(data$taxo) && nrow(data$counts)>0 && nrow(data$taxo)>0 && CheckOK)
{
......@@ -365,7 +375,7 @@ shinyServer(function(input, output,session) {
tabName = "Visu"),
menuItem("Perspective plots", icon = icon("pie-chart"), tabName = "Krona")
)
}
} else{ sidebarMenu(id = "side",NULL)}
})
......@@ -1120,6 +1130,8 @@ shinyServer(function(input, output,session) {
if(!is.null(data$taxo) && nrow(data$taxo)>0)
{
tmp = colnames(data$taxo)
ind = which(is.na(tmp))
if(length(ind)>0) tmp = tmp[-which(is.na(tmp))]
selectInput("TaxoSelect",h6(strong("Select the taxonomy level")),c("...",tmp,"OTU/Gene"))
}
else selectInput("TaxoSelect",h6(strong("Select the taxonomy level")),c("..."))
......@@ -1204,6 +1216,61 @@ shinyServer(function(input, output,session) {
})
output$InfoBIOM<- renderUI({
if(input$FileFormat=="fileBiom")
{
inFile <- input$fileBiom
tmpBIOM = dataInputBiom()
if(!is.null(inFile) && is.null(tmpBIOM)) {
box(title = "Error", status = "danger",width = 3,
h5(strong("This file can not be loaded.")),br(),
em("The loaded file is not in the biom format or its format is not currently supported by SHAMAN software")
)
}
}
})
output$InfoCountsFile<- renderUI({
if(input$FileFormat=="fileCounts")
{
inFile <- input$fileCounts
Counts = dataInputCounts()
if(!is.null(inFile) && is.null(Counts)) {
box(title = "Error", status = "danger",width = 3,
h5(strong("This file can not be loaded.")),br(),
em("The count table file is not in the correct format for SHAMAN software")
)
}
}
})
output$InfoTaxoFile<- renderUI({
if(input$FileFormat=="fileCounts")
{
inFile <- input$fileTaxo
Taxo = dataInputTaxo()
if(!is.null(inFile) && !input$NoTaxoFile && is.null(Taxo)) {
box(title = "Error", status = "danger",width = 3,
h5(strong("This file can not be loaded.")),br(),
em("The taxonomy table file is not in the correct format for SHAMAN software")
)
}
}
})
#####################################################
##
......@@ -1596,16 +1663,16 @@ shinyServer(function(input, output,session) {
##
#####################################################
output$PlotVisuTree <- renderTreeWeightD3({
resDiff = ResDiffAnal()
taxo_table = dataInput()$data$taxo
CT_Norm_OTU = dataMergeCounts()$CT_Norm
res = NULL
if(!is.null(resDiff$dds) && length(input$VisuVarInt)>=1) res = Plot_Visu_Tree(input,resDiff,CT_Norm_OTU,taxo_table)
return(res)
})
# output$PlotVisuTree <- renderTreeWeightD3({
# resDiff = ResDiffAnal()
# taxo_table = dataInput()$data$taxo
# CT_Norm_OTU = dataMergeCounts()$CT_Norm
# res = NULL
# if(!is.null(resDiff$dds) && length(input$VisuVarInt)>=1) res = Plot_Visu_Tree(input,resDiff,CT_Norm_OTU,taxo_table)
# return(res)
#
# })
#
output$PlotVisuBar <- renderChart({
resDiff = ResDiffAnal()
......@@ -1797,7 +1864,7 @@ shinyServer(function(input, output,session) {
if(input$PlotVisuSelect=="Barplot") res = showOutput("PlotVisuBar")
if(input$PlotVisuSelect=="Heatmap") res = d3heatmapOutput("heatmap", height = input$heightVisu+10)
if(input$PlotVisuSelect=="Boxplot") res = plotOutput("Boxplot", height = input$heightVisu+10)
if(input$PlotVisuSelect=="Tree") res = treeWeightD3Output('PlotVisuTree', height = input$heightVisu+10,width="100%")
# if(input$PlotVisuSelect=="Tree") res = treeWeightD3Output('PlotVisuTree', height = input$heightVisu+10,width="100%")
if(input$PlotVisuSelect=="Scatterplot" && !input$AddRegScatter) res = scatterD3Output("ScatterplotD3", height = input$heightVisu+10)
if(input$PlotVisuSelect=="Scatterplot" && input$AddRegScatter) res = plotOutput("Scatterplotgg", height = input$heightVisu+10)
......@@ -2041,28 +2108,28 @@ shinyServer(function(input, output,session) {
})
output$VarIntVisuTree <- renderUI({
target=dataInputTarget()$target
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=dataInputTarget()$target
# 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)
#
# })
#
#####################################################
##
## KRONA
......
......@@ -5,10 +5,10 @@ if (!require(devtools)) {
install.packages('devtools')
library(devtools)
}
if(!require(treeWeightD3)){
devtools::install_git('https://gitlab.pasteur.fr/plechat/treeWeightD3.git')
library(treeWeightD3)
}
# if(!require(treeWeightD3)){
# devtools::install_git('https://gitlab.pasteur.fr/plechat/treeWeightD3.git')
# library(treeWeightD3)
# }
if (!require(scatterD3)) {
devtools::install_github('aghozlane/scatterD3')
library(scatterD3)
......@@ -254,7 +254,10 @@ body <- dashboardBody(
br(),
fluidRow(
box(title="Select your file format",width = 3,status = "success", solidHeader = TRUE,collapsible = FALSE,
selectInput("FileFormat","",c("Count table & taxonomy (*.csv or *.tsv)"="fileCounts","BIOM file"="fileBiom"),selected="fileCounts")
selectInput("FileFormat","",c("Count table & taxonomy (*.csv or *.tsv)"="fileCounts","BIOM file"="fileBiom"),selected="fileCounts"),
conditionalPanel(condition="input.FileFormat=='fileCounts'",
checkboxInput("NoTaxoFile","No taxonomy table",value=FALSE)
)
),
conditionalPanel(condition="input.FileFormat=='fileCounts'",
box(title="Load the count table",width = 3,height = "260px", status = "primary", solidHeader = TRUE,collapsible = FALSE,
......@@ -264,27 +267,33 @@ body <- dashboardBody(
),
fileInput('fileCounts', h6(strong('Select your file')),width="100%")
),
box(title="Load the taxonomy file",width = 3,height = "260px", status = "primary", solidHeader = TRUE,collapsible = FALSE,
fluidRow(
column(width=6,radioButtons("TypeTaxo",h6(strong("Format:")),c("Table"="Table","RDP"="RDP"))),
column(width=6,
conditionalPanel(condition="input.TypeTaxo=='RDP'",numericInput("RDP_th",h6(strong("Threshold:")),0.5,step=0.01,min=0.01,max=1))
conditionalPanel(condition="!input.NoTaxoFile",
box(title="Load the taxonomy file",width = 3,height = "260px", status = "primary", solidHeader = TRUE,collapsible = FALSE,
fluidRow(
column(width=6,radioButtons("TypeTaxo",h6(strong("Format:")),c("Table"="Table","RDP"="RDP"))),
column(width=6,
conditionalPanel(condition="input.TypeTaxo=='RDP'",numericInput("RDP_th",h6(strong("Threshold:")),0.5,step=0.01,min=0.01,max=1))
),
column(width=6,
conditionalPanel(condition="input.TypeTaxo=='Table'",selectInput("septaxo", h6(strong("Separator:")),
c("Tab" = "\t", "Comma" = ",", "Semicolon" = ";")))
)
),
column(width=6,
conditionalPanel(condition="input.TypeTaxo=='Table'",selectInput("septaxo", h6(strong("Separator:")),
c("Tab" = "\t", "Comma" = ",", "Semicolon" = ";")))
)
),
fileInput('fileTaxo', h6(strong('Select your file')),width="100%")
fileInput('fileTaxo', h6(strong('Select your file')),width="100%")
)
),
fluidRow(column(width=3,
uiOutput("InfoCountsFile"),
uiOutput("InfoTaxoFile")
)
)
),
conditionalPanel(condition="input.FileFormat=='fileBiom'",
box(title="Load the BIOM file",width = 3, status = "primary", solidHeader = TRUE,collapsible = FALSE,
fileInput('fileBiom', h5(strong('Select your file')),width="100%")
)
),
fluidRow(uiOutput("InfoBIOM"))
)
),
column(12,uiOutput("TabBoxData"))
......@@ -612,8 +621,8 @@ body <- dashboardBody(
h5(strong("Select the modalities")),
uiOutput("ModVisu")
),
conditionalPanel(condition="input.PlotVisuSelect=='Tree' ",
uiOutput("VarIntVisuTree")),
# 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),
......
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