From 36bdbdab9e0cc8181edefeba8394048103af812e Mon Sep 17 00:00:00 2001 From: Ethan Bass Date: Tue, 14 Nov 2023 19:27:29 -0500 Subject: [PATCH] feat: filter matches with ms_filter_alignment --- NEWS.md | 1 + R/read_alignment.R | 10 +++++++--- man/ms_filter_alignment.Rd | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index f4cdf9b..1a097af 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # mzinspectr 0.4.0 * Changed name of package to "mzinspectr". +* Updated `ms_filter_alignment` so it filters matches if columns are removed from the peak table. # msdialreadr 0.3.3 diff --git a/R/read_alignment.R b/R/read_alignment.R index a31b961..1f3623b 100644 --- a/R/read_alignment.R +++ b/R/read_alignment.R @@ -30,13 +30,14 @@ ms_read_alignment <- function(path){ #' Filter alignment by provided indices. #' @param x An \code{msdial_alignment} object or matrix with rows as samples and features as columns. -#' @param idx Indices to be retained -#' @param what Which dimension to filter on. Either \code{rows} or columns (\code{cols}). +#' @param idx Indices to be retained or excluded according to the value of \code{inverse}. +#' @param what Which dimension to filter on. Either (\code{rows}) or columns +#' (\code{cols}). #' @param inverse Whether to retain (default) or remove the specified columns. #' @author Ethan Bass #' @export ms_filter_alignment <- function(x, idx, what=c("rows","cols"), inverse = FALSE){ - what <- match.arg(what, c("rows","cols")) + what <- match.arg(what, c("rows", "cols")) if (inverse){ idx <- -idx } @@ -46,6 +47,9 @@ ms_filter_alignment <- function(x, idx, what=c("rows","cols"), inverse = FALSE){ } else if (what == "cols"){ x$tab <- x$tab[,idx] x$peak_meta <- x$peak_meta[idx,] + if (!is.null(x$matches)){ + x$matches <- x$matches[idx] + } } x } diff --git a/man/ms_filter_alignment.Rd b/man/ms_filter_alignment.Rd index 2a45eff..3c7bf68 100644 --- a/man/ms_filter_alignment.Rd +++ b/man/ms_filter_alignment.Rd @@ -9,9 +9,10 @@ ms_filter_alignment(x, idx, what = c("rows", "cols"), inverse = FALSE) \arguments{ \item{x}{An \code{msdial_alignment} object or matrix with rows as samples and features as columns.} -\item{idx}{Indices to be retained} +\item{idx}{Indices to be retained or excluded according to the value of \code{inverse}.} -\item{what}{Which dimension to filter on. Either \code{rows} or columns (\code{cols}).} +\item{what}{Which dimension to filter on. Either (\code{rows}) or columns +(\code{cols}).} \item{inverse}{Whether to retain (default) or remove the specified columns.} }