Commit 1341b3fc authored by Amine  GHOZLANE's avatar Amine GHOZLANE
Browse files

Include Stevenn modification for project number from upload your data section

parent 12721cab
......@@ -574,6 +574,7 @@ GetCountsMerge <- function(input,dataInput,taxoSelect,target,design)
normFactors = NULL
FeatureSize = NULL
CT_Norm = NULL
Error = NULL
## Counts and taxo tables
CT = dataInput$counts
......@@ -607,13 +608,15 @@ GetCountsMerge <- function(input,dataInput,taxoSelect,target,design)
CT=CT_int
} else CT = CT[,ind]
print("start order")
## Order CT according to the target
CT = OrderCounts(counts=CT,labels=labels)$CountsOrder
CT_noNorm = CT
RowProd = sum(apply(CT_noNorm,1,prod))
print("end order")
merged_table = merge(CT, taxo, by="row.names")
save(merged_table, file = "/tmp/wtf.rdata")
print("end merged")
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]])
......@@ -622,96 +625,99 @@ GetCountsMerge <- function(input,dataInput,taxoSelect,target,design)
colnames(taxo) = namesTaxo
#ordOTU = order(rownames(taxo))
counts_annot = CT
## Create the dds object
dds <- DESeqDataSetFromMatrix(countData=CT, colData=target, design=design,ignoreRank=TRUE)
#save(dds,file="testdds.RData")
if(is.null(VarNorm)){
## Counts normalisation
## Normalisation with or without 0
if(input$AccountForNA=="NonNull" || RowProd==0) dds = estimateSizeFactors(dds,locfunc=eval(as.name(input$locfunc)),geoMeans=GeoMeansCT(CT))
if(input$AccountForNA=="All" && RowProd!=0) dds = estimateSizeFactors(dds,locfunc=eval(as.name(input$locfunc)))
if(input$AccountForNA=="Weighted" && input$AccountForNA!="NonNull" ) {dds = estimateSizeFactors(dds,locfunc=eval(as.name(input$locfunc)),geoMeans=GeoMeansCT(CT)); sizeFactors(dds) = w.sizefactor(CT)}
if(input$AccountForNA=="Total counts") { sizeFactors(dds) = colSums(CT)/mean(colSums(CT))}
normFactors = sizeFactors(dds)
} else{
group = as.data.frame(target[,VarNorm])
group = apply(group,1,paste, collapse = "-")
normFactors = c()
mod = unique(group)
## At least 2 samples are needed for the normalization
if(min(table(group))>1){
for(i in unique(group))
{
indgrp = which(group==i)
CT_tmp = CT[,indgrp]
CT_tmp = removeNulCounts(CT_tmp)
target_tmp = data.frame(labels = rownames(target)[indgrp])
dds_tmp <- DESeqDataSetFromMatrix(countData=CT_tmp, colData=target_tmp, design=~labels,ignoreRank=TRUE)
if(input$AccountForNA=="NonNull") {dds_tmp = estimateSizeFactors(dds_tmp,locfunc=eval(as.name(input$locfunc)),geoMeans=GeoMeansCT(CT_tmp)); normFactors[indgrp] = sizeFactors(dds_tmp)}
if(input$AccountForNA=="All") {dds_tmp = estimateSizeFactors(dds_tmp,locfunc=eval(as.name(input$locfunc))); normFactors[indgrp] = sizeFactors(dds_tmp)}
if(input$AccountForNA=="Weighted" && input$AccountForNA!="NonNull" ) {dds_tmp = estimateSizeFactors(dds_tmp,locfunc=eval(as.name(input$locfunc)),geoMeans=GeoMeansCT(CT_tmp)); normFactors[indgrp] = w.sizefactor(CT_tmp)}
if(input$AccountForNA=="Total counts") { normFactors[indgrp] = colSums(CT_tmp)/mean(colSums(CT_tmp))}
}
} else{
if(0%in%colSums(counts_annot)){Error = "At least one of the column of the counts table is 0" }
else{
print("DDS start")
## Create the dds object
dds <- DESeqDataSetFromMatrix(countData=CT, colData=target, design=design,ignoreRank=TRUE)
print("DDS end")
#save(dds,file="testdds.RData")
if(is.null(VarNorm)){
## Counts normalisation
## Normalisation with or without 0
if(input$AccountForNA=="NonNull" || RowProd==0) dds = estimateSizeFactors(dds,locfunc=eval(as.name(input$locfunc)),geoMeans=GeoMeansCT(CT))
if(input$AccountForNA=="All" && RowProd!=0) dds = estimateSizeFactors(dds,locfunc=eval(as.name(input$locfunc)))
if(input$AccountForNA=="Weighted" && input$AccountForNA!="NonNull" ) {dds = estimateSizeFactors(dds,locfunc=eval(as.name(input$locfunc)),geoMeans=GeoMeansCT(CT)); sizeFactors(dds) = w.sizefactor(CT)}
if(input$AccountForNA=="Total counts") { sizeFactors(dds) = colSums(CT)/mean(colSums(CT))}
normFactors = sizeFactors(dds)
} else{
group = as.data.frame(target[,VarNorm])
group = apply(group,1,paste, collapse = "-")
normFactors = c()
mod = unique(group)
## At least 2 samples are needed for the normalization
if(min(table(group))>1){
for(i in unique(group))
{
indgrp = which(group==i)
CT_tmp = CT[,indgrp]
CT_tmp = removeNulCounts(CT_tmp)
target_tmp = data.frame(labels = rownames(target)[indgrp])
dds_tmp <- DESeqDataSetFromMatrix(countData=CT_tmp, colData=target_tmp, design=~labels,ignoreRank=TRUE)
if(input$AccountForNA=="NonNull") {dds_tmp = estimateSizeFactors(dds_tmp,locfunc=eval(as.name(input$locfunc)),geoMeans=GeoMeansCT(CT_tmp)); normFactors[indgrp] = sizeFactors(dds_tmp)}
if(input$AccountForNA=="All") {dds_tmp = estimateSizeFactors(dds_tmp,locfunc=eval(as.name(input$locfunc))); normFactors[indgrp] = sizeFactors(dds_tmp)}
if(input$AccountForNA=="Weighted" && input$AccountForNA!="NonNull" ) {dds_tmp = estimateSizeFactors(dds_tmp,locfunc=eval(as.name(input$locfunc)),geoMeans=GeoMeansCT(CT_tmp)); normFactors[indgrp] = w.sizefactor(CT_tmp)}
if(input$AccountForNA=="Total counts") { normFactors[indgrp] = colSums(CT_tmp)/mean(colSums(CT_tmp))}
}
} else{
if(input$AccountForNA=="NonNull" || RowProd==0) dds = estimateSizeFactors(dds,locfunc=eval(as.name(input$locfunc)),geoMeans=GeoMeansCT(CT))
if(input$AccountForNA=="All" && RowProd!=0) dds = estimateSizeFactors(dds,locfunc=eval(as.name(input$locfunc)))
if(input$AccountForNA=="Weighted" && input$AccountForNA!="NonNull" ) {dds = estimateSizeFactors(dds,locfunc=eval(as.name(input$locfunc)),geoMeans=GeoMeansCT(CT)); sizeFactors(dds) = w.sizefactor(CT)}
if(input$AccountForNA=="Total counts") { sizeFactors(dds) = colSums(CT)/mean(colSums(CT))}
normFactors = sizeFactors(dds)
}
sizeFactors(dds) = normFactors
}
sizeFactors(dds) = normFactors
}
## Keep normalized OTU table
CT_Norm = counts(dds, normalized=TRUE)
# Only interesting OTU
# merged_table = merge(CT, taxo[order(rownames(CT)),], by="row.names")
# merged_table = merge(CT, taxo, by="row.names")
# 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]
# #ordOTU = order(rownames(taxo))
# counts_annot = CT
# ordOTU = order(rownames(taxo))
# indOTU_annot = which(rownames(CT)%in%rownames(taxo))
# counts_annot = CT[indOTU_annot[ordOTU],]
## Aggregate matrix
if(taxoSelect=="OTU/Gene") counts = counts_annot
else{
if(input$TypeTable == "MGS" && input$FileFormat!="fileBiom"){
MGS_taxocol = which(toupper(colnames(taxo))%in%"MGS")
taxoS = taxo[,MGS_taxocol]
counts = aggregate(counts_annot,by=list(Taxonomy = taxoS),mean)
rownames(counts)=counts[,1]
counts=counts[,-1]
counts_int=t(apply(counts,1,as.integer))
rownames(counts_int)=rownames(counts)
colnames(counts_int)=colnames(counts)
counts=counts_int
}
if(taxoSelect != "MGS" || input$FileFormat=="fileBiom"){
#taxoS = taxo[ordOTU,taxoSelect]
taxoS = taxo[,taxoSelect]
counts = aggregate(counts_annot,by=list(Taxonomy = taxoS),sum)
rownames(counts)=counts[,1];counts=counts[,-1]
## Keep normalized OTU table
CT_Norm = counts(dds, normalized=TRUE)
# Only interesting OTU
# merged_table = merge(CT, taxo[order(rownames(CT)),], by="row.names")
# merged_table = merge(CT, taxo, by="row.names")
# 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]
# #ordOTU = order(rownames(taxo))
# counts_annot = CT
# ordOTU = order(rownames(taxo))
# indOTU_annot = which(rownames(CT)%in%rownames(taxo))
# counts_annot = CT[indOTU_annot[ordOTU],]
## Aggregate matrix
if(taxoSelect=="OTU/Gene") counts = counts_annot
else{
if(input$TypeTable == "MGS" && input$FileFormat!="fileBiom"){
MGS_taxocol = which(toupper(colnames(taxo))%in%"MGS")
taxoS = taxo[,MGS_taxocol]
counts = aggregate(counts_annot,by=list(Taxonomy = taxoS),mean)
rownames(counts)=counts[,1]
counts=counts[,-1]
counts_int=t(apply(counts,1,as.integer))
rownames(counts_int)=rownames(counts)
colnames(counts_int)=colnames(counts)
counts=counts_int
}
if(taxoSelect != "MGS" || input$FileFormat=="fileBiom"){
#taxoS = taxo[ordOTU,taxoSelect]
taxoS = taxo[,taxoSelect]
counts = aggregate(counts_annot,by=list(Taxonomy = taxoS),sum)
rownames(counts)=counts[,1];counts=counts[,-1]
}
}
## Ordering the counts table according to the target labels
tmpOrder = OrderCounts(counts,normFactors,labels)
counts = tmpOrder$CountsOrder
normFactors = tmpOrder$normFactorsOrder
CheckTarget = TRUE
}
## Ordering the counts table according to the target labels
tmpOrder = OrderCounts(counts,normFactors,labels)
counts = tmpOrder$CountsOrder
normFactors = tmpOrder$normFactorsOrder
CheckTarget = TRUE
}
return(list(counts=counts,CheckTarget=CheckTarget,normFactors=normFactors, CT_noNorm=CT_noNorm, CT_Norm =CT_Norm))
return(list(counts=counts,CheckTarget=CheckTarget,normFactors=normFactors, CT_noNorm=CT_noNorm, CT_Norm =CT_Norm, Error = Error))
#return(list(counts=counts,target=target[ind,],labeled=labeled,normFactors=normFactors, CT_noNorm=CT_noNorm))
}
......
This diff is collapsed.
......@@ -109,8 +109,8 @@ body <- dashboardBody(
tabPanel("Introduction",
p("First check out our user guide:"),
tags$ul(
tags$li(a("User's guide", href="Userguide.pdf")),
tags$li(a("Writing a target file for the experimental design", href="experimental_design_guide.pdf"))
tags$li(a("User's guide",target="_blank", href="Userguide.pdf")),
tags$li(a("Writing a target file for the experimental design",target="_blank", href="experimental_design_guide.pdf"))
),
p(" You can test SHAMAN with the dataset from", a("[Tap et al. 2015]",href="http://www.ncbi.nlm.nih.gov/pubmed/26235304"),
", which is available", a("here",target="_blank",href="Alimintest.zip"),"."),
......@@ -487,10 +487,20 @@ body <- dashboardBody(
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","Saved project"="fileRData"),selected="fileCounts"),
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","Project number"="projnum"),selected="fileCounts"),
conditionalPanel(condition="input.FileFormat=='fileCounts'",
checkboxInput("NoTaxoFile","No taxonomy table",value=FALSE)
),
conditionalPanel(condition="input.FileFormat=='projnum'",
inlineCSS(list(.pwdGREEN = "background-color: #DDF0B3",.pwdRED = "background-color: #F0B2AD")),
textInput("password_home","Enter the key",value = NULL),
div(style = "text-align:right;",
actionButton("Check_project_home", "Check project number",icon=icon("check-circle")),
tags$style(type='text/css', "#Check_project_home {margin-top: 15px;}")
)
)
),
conditionalPanel(condition="input.FileFormat=='fileCounts'",
......@@ -527,18 +537,24 @@ body <- dashboardBody(
)
),
box(title="Load phylogenetic tree (optional)",width = 3, status = "primary", solidHeader = TRUE,collapsible = TRUE,collapsed = TRUE,
fileInput('fileTree', h6(strong('Select your file (tree)')),width="100%"),
tags$script('$( "#fileTree" ).on( "click", function() { this.value = null; });')
conditionalPanel(condition="input.FileFormat=='projnum'",
uiOutput("Project_box_home")
),
conditionalPanel(condition="input.FileFormat!='projnum'",
box(title="Load phylogenetic tree (optional)",width = 3, status = "primary", solidHeader = TRUE,collapsible = TRUE,collapsed = TRUE,
fileInput('fileTree', h6(strong('Select your file (tree)')),width="100%"),
tags$script('$( "#fileTree" ).on( "click", function() { this.value = null; });')
)
),
fluidRow(column(width=3,
uiOutput("InfoCountsFile"),
uiOutput("InfoTaxoFile"),
uiOutput("InfoBIOM")
)
)
)
),
column(id="tabboxdata_col",width=12,uiOutput("TabBoxData")),
......
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