From dabfb13d354804302e4b7d171a667f1178d5566a Mon Sep 17 00:00:00 2001 From: Daenarys8 Date: Thu, 24 Aug 2023 08:49:17 +0100 Subject: [PATCH 1/5] Issue 174: TreeSE support non-taxonomic ranks Signed-off-by: Daenarys8 --- R/ancombc_prep.R | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/R/ancombc_prep.R b/R/ancombc_prep.R index fad28c2..6ce80f9 100644 --- a/R/ancombc_prep.R +++ b/R/ancombc_prep.R @@ -30,7 +30,7 @@ tse_construct = function(data, assay_name, tax_level, phyloseq) { # Check if agglomeration should be performed if (is.null(tax_level)) { - tax_levels = mia::taxonomyRanks(tse) + tax_levels = union(mia::taxonomyRanks(tse), rownames(SummarizedExperiment::rowData(tse))) txt = sprintf(paste0("`tax_level` is not specified \n", "No agglomeration will be performed", "\n", @@ -41,7 +41,15 @@ tse_construct = function(data, assay_name, tax_level, phyloseq) { tax_level = "ASV" tse_alt = tse } else { - tse_alt = mia::agglomerateByRank(tse, tax_level) + # Check if tax_level parameter belongs to taxonomyRanks + if (is.character(tax_level) && length(tax_level) == 1 && tax_level %in% mia::taxonomyRanks(tse)) { + #Merge using agglomerateByRank + tse_alt <- mia::agglomerateByRank(tse, tax_level) + } else { + # Merge using mergeRows + tse_alt <- mia::mergeRows(tse, tax_level) + } + tse_alt } SingleCellExperiment::altExp(tse, tax_level) = tse_alt } else if (!is.null(phyloseq)) { @@ -57,7 +65,7 @@ tse_construct = function(data, assay_name, tax_level, phyloseq) { } if (is.null(tax_level)) { - tax_levels = mia::taxonomyRanks(tse) + tax_levels = union(mia::taxonomyRanks(tse), rownames(SummarizedExperiment::rowData(tse))) txt = sprintf(paste0("`tax_level` is not speficified \n", "No agglomeration will be performed", "\n", @@ -68,7 +76,15 @@ tse_construct = function(data, assay_name, tax_level, phyloseq) { tax_level = "ASV" tse_alt = tse } else { - tse_alt = mia::agglomerateByRank(tse, tax_level) + # Check if tax_level parameter belongs to taxonomyRanks + if (is.character(tax_level) && length(tax_level) == 1 && tax_level %in% mia::taxonomyRanks(tse)) { + #Merge using agglomerateByRank + tse_alt <- mia::agglomerateByRank(tse, tax_level) + } else { + # Merge using mergeRows + tse_alt <- mia::mergeRows(tse, tax_level) + } + tse_alt } SingleCellExperiment::altExp(tse, tax_level) = tse_alt } else { From f598412451d65879b1fb9e0c50d2c85542306971 Mon Sep 17 00:00:00 2001 From: Daenarys8 Date: Fri, 25 Aug 2023 07:52:24 +0100 Subject: [PATCH 2/5] Up Signed-off-by: Daenarys8 --- R/ancombc_prep.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/R/ancombc_prep.R b/R/ancombc_prep.R index 6ce80f9..99f1447 100644 --- a/R/ancombc_prep.R +++ b/R/ancombc_prep.R @@ -43,11 +43,11 @@ tse_construct = function(data, assay_name, tax_level, phyloseq) { } else { # Check if tax_level parameter belongs to taxonomyRanks if (is.character(tax_level) && length(tax_level) == 1 && tax_level %in% mia::taxonomyRanks(tse)) { - #Merge using agglomerateByRank - tse_alt <- mia::agglomerateByRank(tse, tax_level) + #Merge using mergeFeaturesByRank + tse_alt <- mia::mergeFeaturesByRank(tse, tax_level) } else { - # Merge using mergeRows - tse_alt <- mia::mergeRows(tse, tax_level) + # Merge using mergeFeatures + tse_alt <- mia::mergeFeatures(tse, tax_level) } tse_alt } @@ -78,11 +78,11 @@ tse_construct = function(data, assay_name, tax_level, phyloseq) { } else { # Check if tax_level parameter belongs to taxonomyRanks if (is.character(tax_level) && length(tax_level) == 1 && tax_level %in% mia::taxonomyRanks(tse)) { - #Merge using agglomerateByRank - tse_alt <- mia::agglomerateByRank(tse, tax_level) + #Merge using mergeFeaturesByRank + tse_alt <- mia::mergeFeaturesByRank(tse, tax_level) } else { - # Merge using mergeRows - tse_alt <- mia::mergeRows(tse, tax_level) + # Merge using mergeFeatures + tse_alt <- mia::mergeFeatures(tse, tax_level) } tse_alt } From 772dc6d74e5b574e4b98031ee2969707824e52b7 Mon Sep 17 00:00:00 2001 From: Daenarys8 Date: Fri, 25 Aug 2023 07:54:14 +0100 Subject: [PATCH 3/5] Up Signed-off-by: Daenarys8 --- R/ancombc_prep.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/ancombc_prep.R b/R/ancombc_prep.R index 99f1447..3c70440 100644 --- a/R/ancombc_prep.R +++ b/R/ancombc_prep.R @@ -30,7 +30,7 @@ tse_construct = function(data, assay_name, tax_level, phyloseq) { # Check if agglomeration should be performed if (is.null(tax_level)) { - tax_levels = union(mia::taxonomyRanks(tse), rownames(SummarizedExperiment::rowData(tse))) + tax_levels = union(mia::taxonomyRanks(tse), colnames(SummarizedExperiment::rowData(tse))) txt = sprintf(paste0("`tax_level` is not specified \n", "No agglomeration will be performed", "\n", @@ -65,7 +65,7 @@ tse_construct = function(data, assay_name, tax_level, phyloseq) { } if (is.null(tax_level)) { - tax_levels = union(mia::taxonomyRanks(tse), rownames(SummarizedExperiment::rowData(tse))) + tax_levels = union(mia::taxonomyRanks(tse), colnames(SummarizedExperiment::rowData(tse))) txt = sprintf(paste0("`tax_level` is not speficified \n", "No agglomeration will be performed", "\n", From 69e00782502c24eb0e00d353b7babb66aa857d3f Mon Sep 17 00:00:00 2001 From: Daenarys8 Date: Mon, 28 Aug 2023 17:21:57 +0100 Subject: [PATCH 4/5] Up Signed-off-by: Daenarys8 --- R/ancombc_prep.R | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/R/ancombc_prep.R b/R/ancombc_prep.R index 3c70440..d2cab70 100644 --- a/R/ancombc_prep.R +++ b/R/ancombc_prep.R @@ -41,15 +41,7 @@ tse_construct = function(data, assay_name, tax_level, phyloseq) { tax_level = "ASV" tse_alt = tse } else { - # Check if tax_level parameter belongs to taxonomyRanks - if (is.character(tax_level) && length(tax_level) == 1 && tax_level %in% mia::taxonomyRanks(tse)) { - #Merge using mergeFeaturesByRank - tse_alt <- mia::mergeFeaturesByRank(tse, tax_level) - } else { - # Merge using mergeFeatures - tse_alt <- mia::mergeFeatures(tse, tax_level) - } - tse_alt + tse_alt = mia:::.merge_features(tse, tax_level) } SingleCellExperiment::altExp(tse, tax_level) = tse_alt } else if (!is.null(phyloseq)) { @@ -76,15 +68,7 @@ tse_construct = function(data, assay_name, tax_level, phyloseq) { tax_level = "ASV" tse_alt = tse } else { - # Check if tax_level parameter belongs to taxonomyRanks - if (is.character(tax_level) && length(tax_level) == 1 && tax_level %in% mia::taxonomyRanks(tse)) { - #Merge using mergeFeaturesByRank - tse_alt <- mia::mergeFeaturesByRank(tse, tax_level) - } else { - # Merge using mergeFeatures - tse_alt <- mia::mergeFeatures(tse, tax_level) - } - tse_alt + tse_alt = mia:::.merge_features(tse, tax_level) } SingleCellExperiment::altExp(tse, tax_level) = tse_alt } else { From 73b99794c5d53cc2d21c8215806669aa4a54903c Mon Sep 17 00:00:00 2001 From: Daenarys8 Date: Thu, 14 Sep 2023 02:51:51 +0100 Subject: [PATCH 5/5] Up Signed-off-by: Daenarys8 --- R/ancombc2.R | 10 +++++----- R/ancombc_prep.R | 16 ---------------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/R/ancombc2.R b/R/ancombc2.R index 1365c6b..9b66ae0 100644 --- a/R/ancombc2.R +++ b/R/ancombc2.R @@ -81,13 +81,13 @@ #' (only applicable if data object is a \code{(Tree)SummarizedExperiment}). #' Default is "counts". #' See \code{?SummarizedExperiment::assay} for more details. -#' @param tax_level character. The taxonomic level of interest. The input data -#' can be analyzed at any taxonomic level without prior agglomeration. -#' Note that \code{tax_level} must be a value from \code{taxonomyRanks}, which -#' includes "Kingdom", "Phylum" "Class", "Order", "Family" "Genus" or "Species". +#' @param tax_level character. The taxonomic or non taxonomic(rowData) level of interest. The input data +#' can be analyzed at any taxonomic or rowData level without prior agglomeration. +#' Note that \code{tax_level} must be a value from \code{taxonomyRanks} or \code{rowData}, which +#' includes "Kingdom", "Phylum" "Class", "Order", "Family" "Genus" "Species" etc. #' See \code{?mia::taxonomyRanks} for more details. #' Default is NULL, i.e., do not perform agglomeration, and the -#' ANCOM-BC2 anlysis will be performed at the lowest taxonomic level of the +#' ANCOM-BC2 analysis will be performed at the lowest taxonomic level of the #' input \code{data}. #' @param fix_formula the character string expresses how the microbial absolute #' abundances for each taxon depend on the fixed effects in metadata. When diff --git a/R/ancombc_prep.R b/R/ancombc_prep.R index d2cab70..dfd6511 100644 --- a/R/ancombc_prep.R +++ b/R/ancombc_prep.R @@ -30,14 +30,6 @@ tse_construct = function(data, assay_name, tax_level, phyloseq) { # Check if agglomeration should be performed if (is.null(tax_level)) { - tax_levels = union(mia::taxonomyRanks(tse), colnames(SummarizedExperiment::rowData(tse))) - txt = sprintf(paste0("`tax_level` is not specified \n", - "No agglomeration will be performed", - "\n", - "Otherwise, please specify `tax_level` ", - "by one of the following: \n", - paste(tax_levels, collapse = ", "))) - message(txt) tax_level = "ASV" tse_alt = tse } else { @@ -57,14 +49,6 @@ tse_construct = function(data, assay_name, tax_level, phyloseq) { } if (is.null(tax_level)) { - tax_levels = union(mia::taxonomyRanks(tse), colnames(SummarizedExperiment::rowData(tse))) - txt = sprintf(paste0("`tax_level` is not speficified \n", - "No agglomeration will be performed", - "\n", - "Otherwise, please speficy `tax_level` ", - "by one of the following: \n", - paste(tax_levels, collapse = ", "))) - message(txt) tax_level = "ASV" tse_alt = tse } else {