Commit 15f8df15 authored by Etienne Rifa's avatar Etienne Rifa
Browse files

allow to generate and work without taxonomy, for filtering before assignation

parent 426505d9
......@@ -272,7 +272,12 @@ decontam_fun <- function(data = data, domain = "Bacteria", output = "./decontam_
TABf=cbind.data.frame( TABtest_filt, TABf )
names(TABf)[1] = names(TF)[j]
}
TABff <- cbind(as.matrix(TABf), as.matrix(data_no_filtering@tax_table[row.names(TABf),]))
if(!is.null(data@tax_table)){
TABff <- cbind(as.matrix(TABf), as.matrix(data_no_filtering@tax_table[row.names(TABf),]))
}else{
TABff <- as.matrix(TABf)
}
write.table(TABff, file = paste(output,'/Exclu_out.csv',sep=''), sep = "\t", col.names=NA)
......@@ -312,11 +317,25 @@ decontam_fun <- function(data = data, domain = "Bacteria", output = "./decontam_
flog.info(paste("AFTER FILTERING: ",nsamples(data), "samples and", ntaxa(data),"ASVs in otu table") )
flog.info('Writing raw tables.')
write.table(cbind(otu_table(data),"Consensus Lineage" = apply(tax_table(data), 1, paste, collapse = ";"), "sequences"=as.data.frame(refseq(data)) ), paste(output,"/raw_otu-table.csv",sep=''), sep="\t", row.names=TRUE, col.names=NA, quote=FALSE)
if(!is.null(data@tax_table)){
write.table(cbind(otu_table(data),"Consensus Lineage" = apply(tax_table(data), 1, paste, collapse = ";"), "sequences"=as.data.frame(refseq(data)) ), paste(output,"/raw_otu-table.csv",sep=''), sep="\t", row.names=TRUE, col.names=NA, quote=FALSE)
}else{
write.table(cbind(otu_table(data), "sequences"=as.data.frame(refseq(data)) ), paste(output,"/raw_otu-table.csv",sep=''), sep="\t", row.names=TRUE, col.names=NA, quote=FALSE)
}
flog.info('Writing relative tables.')
data_rel <- transform_sample_counts(data, function(x) x / sum(x) )
write.table(cbind(otu_table(data_rel),"Consensus Lineage" = apply(tax_table(data_rel), 1, paste, collapse = ";"), "sequences"=as.data.frame(refseq(data_rel))),paste(output,"/relative_otu-table.csv",sep=''), sep="\t", row.names=TRUE, col.names=NA, quote=FALSE)
if(!is.null(data@tax_table)){
write.table(cbind(otu_table(data_rel),"Consensus Lineage" = apply(tax_table(data_rel), 1, paste, collapse = ";"), "sequences"=as.data.frame(refseq(data_rel))),paste(output,"/relative_otu-table.csv",sep=''), sep="\t", row.names=TRUE, col.names=NA, quote=FALSE)
}else{
write.table(cbind(otu_table(data_rel), "sequences"=as.data.frame(refseq(data_rel))),paste(output,"/relative_otu-table.csv",sep=''), sep="\t", row.names=TRUE, col.names=NA, quote=FALSE)
}
flog.info('Saving R objects.')
save(data, file=paste(output,'/robjects.Rdata',sep=''))
......
......@@ -42,8 +42,16 @@ generate_phyloseq_fun <- function(dada_res = dada_res, tax.table = tax.table, tr
flog.info('Done.')
if(length(setdiff(colnames(dada_res$otu.table), sampledata$sample.id)) > 0){
flog.info(setdiff(colnames(dada_res$otu.table), sampledata$sample.id))
stop("ERROR: number of samples in metadata differ from otu table.")
message("ERROR: sample names in otu table differs from sample metadata.")
print(setdiff(colnames(dada_res$otu.table), sampledata$sample.id))
stop("Please check metadata table.",call. = FALSE)
}
if(length(setdiff(sampledata$sample.id, colnames(dada_res$otu.table))) > 0){
message("WARNING: One or more samples in metadata are not present in otu table:")
print(setdiff(sampledata$sample.id, colnames(dada_res$otu.table)))
sample.metadata <- sample.metadata[colnames(dada_res$otu.table),]
}
flog.info("Sequences..")
......@@ -51,13 +59,31 @@ generate_phyloseq_fun <- function(dada_res = dada_res, tax.table = tax.table, tr
flog.debug('Generate MD5 ids...')
names(sequences) <- sapply(sequences,digest,algo='md5')
if(is.null(tree)){
flog.info('Building phyloseq object without tree...')
data <- phyloseq(dada_res$otu.table[,row.names(sample.metadata)], tax_table(as.matrix(tax.table)), sample.metadata, DNAStringSet(sequences))
} else{
flog.info('Building phyloseq object with tree...')
data <- phyloseq(dada_res$otu.table[,row.names(sample.metadata)], tax_table(as.matrix(tax.table)), sample.metadata, phy_tree(tree), DNAStringSet(sequences))
if(!is.null(tax.table)){
if(is.null(tree)){
flog.info('Building phyloseq object without tree...')
data <- phyloseq(dada_res$otu.table[,row.names(sample.metadata)], tax_table(as.matrix(tax.table)), sample.metadata, DNAStringSet(sequences))
} else{
flog.info('Building phyloseq object with tree...')
data <- phyloseq(dada_res$otu.table[,row.names(sample.metadata)], tax_table(as.matrix(tax.table)), sample.metadata, phy_tree(tree), DNAStringSet(sequences))
}
}else{
if(is.null(tree)){
flog.info('Building phyloseq object without tree...')
data <- phyloseq(dada_res$otu.table[,row.names(sample.metadata)], sample.metadata, DNAStringSet(sequences))
} else{
flog.info('Building phyloseq object with tree...')
data <- phyloseq(dada_res$otu.table[,row.names(sample.metadata)], sample.metadata, phy_tree(tree), DNAStringSet(sequences))
}
}
flog.info('Done.')
data_rel <- transform_sample_counts(data, function(x) x / sum(x) )
......
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