diff --git a/R/FEAST.R b/R/FEAST.R index 149be09..1782291 100644 --- a/R/FEAST.R +++ b/R/FEAST.R @@ -41,8 +41,7 @@ #' } #' #' @export -FEAST <- function(C, metadata, EM_iterations = 1000, COVERAGE = NULL ,different_sources_flag, - dir_path, outfile){ +FEAST <- function(C, metadata, EM_iterations = 1000, COVERAGE = NULL ,different_sources_flag, dir_path = NULL, outfile = NULL){ ###1. Parse metadata and check it has the correct hearer (i.e., Env, SourceSink, id) if(sum(colnames(metadata)=='Env')==0) stop("The metadata file must contain an 'Env' column naming the source environment for each sample.") @@ -143,9 +142,11 @@ FEAST <- function(C, metadata, EM_iterations = 1000, COVERAGE = NULL ,different_ colnames(proportions_mat) <- c(envs_sources, "Unknown") rownames(proportions_mat) <- envs_sink # proportions_mat[is.na(proportions_mat)] <- 999 + if(!is.null(dir_path)){ + setwd(dir_path) + write.table(proportions_mat, file = paste0(outfile,"_source_contributions_matrix.txt"), sep = "\t") + } - setwd(dir_path) - write.table(proportions_mat, file = paste0(outfile,"_source_contributions_matrix.txt"), sep = "\t") return(proportions_mat) } diff --git a/R/Infer_LatentVariables.R b/R/Infer_LatentVariables.R index 82943c7..30f3001 100644 --- a/R/Infer_LatentVariables.R +++ b/R/Infer_LatentVariables.R @@ -129,7 +129,6 @@ unknown_initialize_1 <- function(sources, sink, n_sources){ sources_sum <- apply(sources, 2 ,sum) - unknown_source <- c() if(n_sources > 1){ @@ -169,7 +168,7 @@ unknown_initialize_1 <- function(sources, sink, n_sources){ if(length(ind_cor_all) > 1){ cor_abundance <- round(apply(sources[,ind_cor_all], 2, min)/2) #take the min abundnace of the 'cor' - unknown_source[ind_cor_all] <- 0 + unknown_source[ind_cor_all] <- cor_abundance } diff --git a/R/utils.R b/R/utils.R index d346034..1228cfc 100644 --- a/R/utils.R +++ b/R/utils.R @@ -44,7 +44,7 @@ FEAST_rarefy <- function(x,maxdepth){ if(is.null(maxdepth)) return(x) - if(!is.element(class(x), c('matrix', 'data.frame','array'))) + if(!any(is.element(class(x), c('matrix', 'data.frame','array')))) x <- matrix(x,nrow=nrow(x)) nr <- nrow(x) nc <- ncol(x)