From 49cc3ee08f95ebc5da30c94083f103dc67d0dac5 Mon Sep 17 00:00:00 2001 From: Ethan Bass Date: Sat, 2 Sep 2023 16:01:13 -0400 Subject: [PATCH] renamed ms_tidy_msdial and fixed bug, v0.3.3 --- DESCRIPTION | 2 +- NAMESPACE | 1 + NEWS.md | 6 ++++++ R/normalization.R | 9 ++++++-- R/tidy_msdial.R | 42 ++++++++++++++++++++++++++++++------- README.md | 4 ++-- inst/CITATION | 4 ++-- man/ms_normalize_itsd.Rd | 4 ++-- man/ms_normalize_pqn.Rd | 2 +- man/ms_normalize_tsn.Rd | 4 +--- man/ms_reshape_peaktable.Rd | 31 +++++++++++++++++++++++++++ man/ms_tidy_msdial.Rd | 7 ++++--- 12 files changed, 93 insertions(+), 23 deletions(-) create mode 100644 man/ms_reshape_peaktable.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 2ef019f..5fed57d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: msdialreadr Type: Package Title: Read and Analyze MS-DIAL Alignment Files -Version: 0.3.2 +Version: 0.3.3 Authors@R: person("Ethan", "Bass", , "ethanbass@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6175-6739")) diff --git a/NAMESPACE b/NAMESPACE index 053cd49..ff5635e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,6 +19,7 @@ export(ms_normalize_pqn) export(ms_normalize_tsn) export(ms_plot_spectrum) export(ms_read_alignment) +export(ms_reshape_peaktable) export(ms_rt_to_ri) export(ms_search_gadget) export(ms_search_spectra) diff --git a/NEWS.md b/NEWS.md index 579b9ad..c9e00a5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# msdialreadr 0.3.3 + +* Fixed bug `ms_tidy_msdial` when renaming peaks that are out of order. +* Renamed `ms_tidy_msdial` to `ms_reshape_peaktable`. The old function name is now deprecated. +* Made some improvements to documentation. + # msdialreadr 0.3.2 * Added option to for renaming peaks via `ms_tidy_msdial` by providing a named character vector. diff --git a/R/normalization.R b/R/normalization.R index 8985c52..5e9adf9 100644 --- a/R/normalization.R +++ b/R/normalization.R @@ -1,6 +1,6 @@ #' @title Probabilistic Quotient Normalization #' -#' @description Performs Probabilistic Quotient Normalization +#' @description Performs Probabilistic Quotient Normalization on peak table. #' #' @param x An \code{msdial_alignment} object or matrix with rows as samples and features as columns. #' @param ref Reference for normalization: either \code{median} (default) to use @@ -70,7 +70,9 @@ ms_normalize_pqn <- function(x, ref = c("median", "mean"), QC = NULL) { } #' Total sum normalization +#' #' Divides each row by the sum of the features in that row. +#' #' @param x An \code{msdial_alignment} object or matrix with rows as samples and features as columns. #' @return A normalized \code{msdial_alignment} object or \code{matrix}, #' according to the input. @@ -98,7 +100,10 @@ ms_normalize_tsn <- function(x) { x } -#' Normalize by internal standard +#' Internal standard normalization +#' +#' Normalize by internal standard. +#' #' @param x An \code{msdial_alignment} object or matrix with rows as samples and #' features as columns. #' @param idx Column index of internal standard. diff --git a/R/tidy_msdial.R b/R/tidy_msdial.R index 5f0b428..33ceaf4 100644 --- a/R/tidy_msdial.R +++ b/R/tidy_msdial.R @@ -1,4 +1,7 @@ -#' Convert peak to tidy format for plotting +#' Reshape peak table +#' +#' Convert peak table to tidy format for plotting. +#' #' @param x An MS dial alignment object. #' @param peaks A character vector specifying the peaks to include in tidy output. #' If the character vector is named, the names of the vector elements will be @@ -14,8 +17,8 @@ #' @author Ethan Bass #' @export -ms_tidy_msdial <- function(x, peaks, metadata, treatments){ - if (!missing(treatments)){ +ms_reshape_peaktable <- function(x, peaks, metadata, treatments = NULL){ + if (!is.null(treatments)){ .Deprecated("metadata", package="msdialreadr", old = "treatments", msg="The `treatments` argument is deprecated as of msdialreadr v0.3.2. \t Please use the `metadata` argument instead.") @@ -27,13 +30,38 @@ ms_tidy_msdial <- function(x, peaks, metadata, treatments){ } x$tab <- x$tab[,which(colnames(x$tab) %in% peaks), drop = FALSE] if (!is.null(names(peaks))){ - colnames(x$tab) <- names(peaks) - peaks <- names(peaks) + colnames(x$tab) <- names(peaks)[match(colnames(x$tab), peaks)] + peaks <- colnames(x$tab) } - x} + } df <- as.data.frame(x$tab) df <- cbind(df, select(x$sample_meta, any_of(metadata))) df <- mutate(df, sample = row.names(x)) - df <- pivot_longer(df, cols = peaks, names_to="peak") + df <- pivot_longer(df, cols = peaks, names_to = "peak") df } + +#' Reshape peak table +#' +#' Converts peak table to tidy format for plotting. This function is deprecated +#' as of version \code{0.3.3}. Please use \code{\link{ms_reshape_peaktable}} instead. +#' +#' @param x An MS dial alignment object. +#' @param peaks A character vector specifying the peaks to include in tidy output. +#' If the character vector is named, the names of the vector elements will be +#' used in place of the original peak names. +#' @param metadata A character vector specifying the metadata to include in +#' the tidy output. +#' @param treatments This argument is deprecated as of version 0.3.2. It is +#' synonymous with the new metadata argument which should be used instead. +#' @importFrom dplyr select mutate any_of +#' @importFrom tidyr pivot_longer +#' @return If \code{export} is \code{TRUE}, returns spectrum as \code{data.frame}. +#' Otherwise, no return value. +#' @author Ethan Bass +#' @export + +ms_tidy_msdial <- function(x, peaks, metadata, treatments = NULL){ + .Deprecated("ms_reshape_peaktable", package = "tidy_msdial") + ms_reshape_peaktable(x=x, peaks = peaks, metadata = metadata, treatments = treatments) +} diff --git a/README.md b/README.md index 314748c..367c53a 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ There are currently several different options for feature normalization, includi ### Peak identification -There is preliminary support for peak identification by searching a user-provided mass-spectral database through the `ms_search_spectra` function. It takes several parameters, including an ms-dial alignment object (`x`), a spectral database (`db`), the column or columns to identify (`cols`), the maximum retention index shift to exclude a match from consideration (`ri_thresh`), the relative weight to give spectral similarity versus retention index similarity (`spectral_weight`), the number of results to return (`n_results`), and the number of cores to use for parallel processing (`mc.cores`). +There is preliminary support for peak identification by searching a user-provided mass-spectral database through the `ms_search_spectra` function. The database can be loaded into R from an MSP file using the It takes several parameters, including an ms-dial alignment object (`x`), a spectral database (`db`), the column or columns to identify (`cols`), the maximum retention index shift to exclude a match from consideration (`ri_thresh`), the relative weight to give spectral similarity versus retention index similarity (`spectral_weight`), the number of results to return (`n_results`), and the number of cores to use for parallel processing (`mc.cores`). To compile a mass spectral database, I recommend using [mspcompiler](https://github.com/QizhiSu/mspcompiler). @@ -52,4 +52,4 @@ Spectra can be plotted using either "base R" graphics or "plotly" graphics using If you use msdialreadr in published work, please cite it as follows: -Bass, E. (2023). msdialreadr: Read and Analyze MS-DIAL Alignment Files (version 0.3.2). +Bass, E. (2023). msdialreadr: Read and Analyze MS-DIAL Alignment Files (version 0.3.3). diff --git a/inst/CITATION b/inst/CITATION index cfd5848..3893f67 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -5,10 +5,10 @@ citEntry( title = "msdialreadr: Read and Analyze MS-DIAL Alignment Files", author = "Ethan Bass", year = "2023", - note = "version 0.3.2", + note = "version 0.3.3", url = "", doi = "", textVersion = paste("Bass, E. (2023).", - "msdialreadr: Read and Analyze MS-DIAL Alignment Files (version 0.3.2)." + "msdialreadr: Read and Analyze MS-DIAL Alignment Files (version 0.3.3)." ) ) diff --git a/man/ms_normalize_itsd.Rd b/man/ms_normalize_itsd.Rd index 415bf88..ff1ed27 100644 --- a/man/ms_normalize_itsd.Rd +++ b/man/ms_normalize_itsd.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/normalization.R \name{ms_normalize_itsd} \alias{ms_normalize_itsd} -\title{Normalize by internal standard} +\title{Internal standard normalization} \usage{ ms_normalize_itsd(x, idx, plot_it = FALSE) } @@ -19,7 +19,7 @@ A normalized \code{msdial_alignment} object or \code{matrix}, according to the input. } \description{ -Normalize by internal standard +Normalize by internal standard. } \author{ Ethan Bass diff --git a/man/ms_normalize_pqn.Rd b/man/ms_normalize_pqn.Rd index 89fc3c1..6540e5d 100644 --- a/man/ms_normalize_pqn.Rd +++ b/man/ms_normalize_pqn.Rd @@ -21,7 +21,7 @@ A normalized \code{msdial_alignment} object or \code{matrix}, according to the input. } \description{ -Performs Probabilistic Quotient Normalization +Performs Probabilistic Quotient Normalization on peak table. } \note{ Adapted from the \href{https://github.com/ricoderks/Rcpm}{Rcpm} package diff --git a/man/ms_normalize_tsn.Rd b/man/ms_normalize_tsn.Rd index a786b21..766277e 100644 --- a/man/ms_normalize_tsn.Rd +++ b/man/ms_normalize_tsn.Rd @@ -2,8 +2,7 @@ % Please edit documentation in R/normalization.R \name{ms_normalize_tsn} \alias{ms_normalize_tsn} -\title{Total sum normalization -Divides each row by the sum of the features in that row.} +\title{Total sum normalization} \usage{ ms_normalize_tsn(x) } @@ -15,6 +14,5 @@ A normalized \code{msdial_alignment} object or \code{matrix}, according to the input. } \description{ -Total sum normalization Divides each row by the sum of the features in that row. } diff --git a/man/ms_reshape_peaktable.Rd b/man/ms_reshape_peaktable.Rd new file mode 100644 index 0000000..b8bea28 --- /dev/null +++ b/man/ms_reshape_peaktable.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tidy_msdial.R +\name{ms_reshape_peaktable} +\alias{ms_reshape_peaktable} +\title{Reshape peak table} +\usage{ +ms_reshape_peaktable(x, peaks, metadata, treatments = NULL) +} +\arguments{ +\item{x}{An MS dial alignment object.} + +\item{peaks}{A character vector specifying the peaks to include in tidy output. +If the character vector is named, the names of the vector elements will be +used in place of the original peak names.} + +\item{metadata}{A character vector specifying the metadata to include in +the tidy output.} + +\item{treatments}{This argument is deprecated as of version 0.3.2. It is +synonymous with the new metadata argument which should be used instead.} +} +\value{ +If \code{export} is \code{TRUE}, returns spectrum as \code{data.frame}. +Otherwise, no return value. +} +\description{ +Convert peak table to tidy format for plotting. +} +\author{ +Ethan Bass +} diff --git a/man/ms_tidy_msdial.Rd b/man/ms_tidy_msdial.Rd index cb34a43..aeb3b4d 100644 --- a/man/ms_tidy_msdial.Rd +++ b/man/ms_tidy_msdial.Rd @@ -2,9 +2,9 @@ % Please edit documentation in R/tidy_msdial.R \name{ms_tidy_msdial} \alias{ms_tidy_msdial} -\title{Convert peak to tidy format for plotting} +\title{Reshape peak table} \usage{ -ms_tidy_msdial(x, peaks, metadata, treatments) +ms_tidy_msdial(x, peaks, metadata, treatments = NULL) } \arguments{ \item{x}{An MS dial alignment object.} @@ -24,7 +24,8 @@ If \code{export} is \code{TRUE}, returns spectrum as \code{data.frame}. Otherwise, no return value. } \description{ -Convert peak to tidy format for plotting +Converts peak table to tidy format for plotting. This function is deprecated +as of version \code{0.3.3}. Please use \code{\link{ms_reshape_peaktable}} instead. } \author{ Ethan Bass