diff --git a/R/exportInteractive.R b/R/exportInteractive.R index aec4ec9..06dbc79 100644 --- a/R/exportInteractive.R +++ b/R/exportInteractive.R @@ -9,11 +9,18 @@ #' @param calcko calculate KO abundance #' @param calctree calculate consensus tree #' @param species candidate species, default to all the species +#' @param dataset_name dataset name #' @export #' @return output the results to specified directory exportInteractive <- function(stana, out=".", db="uhgg", calcko=TRUE, - calctree=TRUE, + calctree=TRUE, dataset_name=NULL, species=NULL) { + if (is.null(dataset_name)) { + dataset_name <- gsub(":", "-", gsub(" ", "-", as.character(Sys.time()))) + } + dir.create(paste0(out,"/data")) + dir.create(paste0(out,"/data/",dataset_name)) + if (stana@type!="MIDAS2") {stop("This feature is for MIDAS2 only")} if (is.null(species)) { species <- stana@ids @@ -57,22 +64,22 @@ exportInteractive <- function(stana, out=".", db="uhgg", calcko=TRUE, if (!dir.exists(out)) { dir.create(out) } - dir.create(paste0(out,"/tree")) + dir.create(paste0(out,"/data/",dataset_name,"/tree")) for (i in names(stana@treeList)) { if (i %in% species) { tre <- stana@treeList[[i]] if (!is.null(tre)) { - ape::write.tree(tre, paste0(out,"/tree/",i,".cons.tree")) + ape::write.tree(tre, paste0(out,"/data/",dataset_name,"/tree/",i,".cons.tree")) } } } - dir.create(paste0(out,"/KOs")) + dir.create(paste0(out,"/data/",dataset_name,"/KOs")) for (i in names(stana@kos)) { if (i %in% species) { ko <- stana@kos[[i]] - write.table(ko, paste0(out, "/KOs/", i, ".txt"), sep="\t", quote=FALSE) + write.table(ko, ppaste0(out,"/data/",dataset_name,"/KOs/", i, ".txt"), sep="\t", quote=FALSE) } } - write.table(meta, paste0(out, "metadata.tsv"), sep="\t", quote=FALSE) + write.table(meta, paste0(out,"/data/",dataset_name,"/metadata.tsv"), sep="\t", quote=FALSE) return(stana) } \ No newline at end of file diff --git a/man/exportInteractive.Rd b/man/exportInteractive.Rd index 1fb78cb..a9c97a7 100644 --- a/man/exportInteractive.Rd +++ b/man/exportInteractive.Rd @@ -10,15 +10,14 @@ exportInteractive( db = "uhgg", calcko = TRUE, calctree = TRUE, + dataset_name = NULL, species = NULL ) } \arguments{ -\item{stana}{stana object} +\item{stana}{stana object of type MIDAS2} -\item{out}{output directory -export the stana results for the inspection in interactive -application} +\item{out}{output directory} \item{db}{db used to profile 'uhgg' or 'gtdb'} @@ -26,11 +25,14 @@ application} \item{calctree}{calculate consensus tree} -\item{species}{calk} +\item{dataset_name}{dataset name} + +\item{species}{candidate species, default to all the species} } \value{ output the results to specified directory } \description{ -exportInteractive +export the current stana object to interactive application +for the convenient analysis and visualization }