From 5fcb854b17c8016f4e20b267dcf7e2f00db6935f Mon Sep 17 00:00:00 2001 From: Ethan Bass Date: Thu, 16 Nov 2023 15:40:41 -0500 Subject: [PATCH] change name of alignment class to `ms_alignment` --- NAMESPACE | 12 ++++----- NEWS.md | 2 ++ R/attach_metadata.R | 8 +++--- R/ms_search_gadget.R | 2 +- R/normalization.R | 28 +++++++++---------- R/plot_spectrum.R | 8 +++--- R/read_alignment.R | 16 +++++------ R/search_spectra.R | 27 +++++++++++-------- R/utils.R | 4 +-- man/ms_attach_metadata.Rd | 6 ++--- man/ms_calculate_RIs.Rd | 2 +- man/ms_filter_alignment.Rd | 2 +- man/ms_find_peak.Rd | 2 +- man/ms_get_spectrum.Rd | 2 +- man/ms_mirror_plot.Rd | 6 ++--- man/ms_normalize_itsd.Rd | 4 +-- man/ms_normalize_pqn.Rd | 4 +-- man/ms_normalize_tsn.Rd | 4 +-- man/ms_read_alignment.Rd | 2 +- man/ms_search_gadget.Rd | 2 +- man/ms_search_spectra.Rd | 13 ++++----- man/ms_subtract_blanks.Rd | 4 +-- man/spectral_similarity.Rd | 55 ++++++++++++++++++++++++++++++++++++++ 23 files changed, 139 insertions(+), 76 deletions(-) create mode 100644 man/spectral_similarity.Rd diff --git a/NAMESPACE b/NAMESPACE index ff5635e..a3726bc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,12 +1,12 @@ # Generated by roxygen2: do not edit by hand -S3method(dim,msdial_alignment) -S3method(head,msdial_alignment) +S3method(dim,ms_alignment) +S3method(head,ms_alignment) S3method(ms_mirror_plot,data.frame) -S3method(ms_mirror_plot,msdial_alignment) -S3method(print,msdial_alignment) -S3method(row.names,msdial_alignment) -S3method(tail,msdial_alignment) +S3method(ms_mirror_plot,ms_alignment) +S3method(print,ms_alignment) +S3method(row.names,ms_alignment) +S3method(tail,ms_alignment) export(ms_attach_metadata) export(ms_calculate_RIs) export(ms_call_msdial) diff --git a/NEWS.md b/NEWS.md index 4877a50..3684fa2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ * Updated `ms_filter_alignment` so it filters matches when removing columns from the peak table. * Added titles to mass spectra plots with peak name and retention index or time. * Fixed bug in retention index matching algorithm for `ms_search_spectra` function. +* Added `fixed_levels` argument to `ms_reshape_peaktable` so features can be automatically plotted in the order they are provided by the user. +* Changed the name of the `mzinspectr` alignment object from `msdial_alignment` to `ms_alignment`. # msdialreadr 0.3.3 diff --git a/R/attach_metadata.R b/R/attach_metadata.R index 8e43001..a1505ce 100644 --- a/R/attach_metadata.R +++ b/R/attach_metadata.R @@ -1,13 +1,13 @@ #' Attach experimental metadata #' -#' Attaches experimental metadata to `MSDIAL_alignment` object. One of the columns in +#' Attaches experimental metadata to `ms_alignment` object. One of the columns in #' the supplied metadata must match exactly the row names of the peak table. #' #' @aliases attach_metadata -#' @param x An `MSDIAL_alignment` object. +#' @param x A \code{ms_alignment} object. #' @param metadata A `data.frame` containing the sample metadata. #' @param col The name of the column containing the sample names. -#' @return A \code{MSDIAL_alignment} object with attached metadata in the \code{ +#' @return A \code{ms_alignment} object with attached metadata in the \code{ #' $sample_meta} slot. #' @author Ethan Bass #' @export @@ -24,7 +24,7 @@ ms_attach_metadata <- function(x, metadata, col){ if (sum((duplicated(metadata[,col]))) > 0) stop(paste("Sample names must be unique. Please check column", sQuote(col), "for duplicates.")) - if (!inherits(x,"msdial_alignment")) + if (!inherits(x,"ms_alignment")) stop(paste("Provided peak table object must be of class 'x'.")) meta <- data.frame(rownames(x$tab)) names(meta) <- col diff --git a/R/ms_search_gadget.R b/R/ms_search_gadget.R index 75d7ed3..b5cc069 100644 --- a/R/ms_search_gadget.R +++ b/R/ms_search_gadget.R @@ -1,7 +1,7 @@ #' Launch MS search gadget for interactive viewing of spectral matches. #' @name ms_search_gadget #' @importFrom graphics rasterImage par plot.new -#' @param data An \code{msdial_alignment} object. +#' @param data An \code{ms_alignment} object. #' @export ms_search_gadget <- function(data){ diff --git a/R/normalization.R b/R/normalization.R index 5e9adf9..7dcc848 100644 --- a/R/normalization.R +++ b/R/normalization.R @@ -2,14 +2,14 @@ #' #' @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 x An \code{ms_alignment} object or matrix with rows as samples and features as columns. #' @param ref Reference for normalization: either \code{median} (default) to use #' the overall median of variables as the reference, or \code{mean} to use the #' overall average of variables as the reference. #' @param QC vector of number(s) to specify samples which average to use as reference #' (e.g. QC samples) #' -#' @return A normalized \code{msdial_alignment} object or \code{matrix}, +#' @return A normalized \code{ms_alignment} object or \code{matrix}, #' according to the input. #' #' @importFrom stats median @@ -26,7 +26,7 @@ ms_normalize_pqn <- function(x, ref = c("median", "mean"), QC = NULL) { ref <- match.arg(ref, c("median","mean")) - if (inherits(x, what = "msdial_alignment")){ + if (inherits(x, what = "ms_alignment")){ X <- x$tab } else if (class(x) %in% c("data.frame","matrix")){ X <- x @@ -61,7 +61,7 @@ ms_normalize_pqn <- function(x, ref = c("median", "mean"), QC = NULL) { X.norm <- as.data.frame(X.norm) - if (inherits(x, what = "msdial_alignment")){ + if (inherits(x, what = "ms_alignment")){ x$tab <- X.norm } else{ x <- X.norm @@ -73,13 +73,13 @@ ms_normalize_pqn <- function(x, ref = c("median", "mean"), QC = NULL) { #' #' 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}, +#' @param x An \code{ms_alignment} object or matrix with rows as samples and features as columns. +#' @return A normalized \code{ms_alignment} object or \code{matrix}, #' according to the input. #' @export ms_normalize_tsn <- function(x) { - if (inherits(x, what = "msdial_alignment")){ + if (inherits(x, what = "ms_alignment")){ X <- x$tab } else if (class(x) %in% c("data.frame","matrix")){ X <- x @@ -92,7 +92,7 @@ ms_normalize_tsn <- function(x) { X.norm <- as.data.frame(X.norm) - if (inherits(x, what = "msdial_alignment")){ + if (inherits(x, what = "ms_alignment")){ x$tab <- X.norm } else{ x <- X.norm @@ -104,18 +104,18 @@ ms_normalize_tsn <- function(x) { #' #' Normalize by internal standard. #' -#' @param x An \code{msdial_alignment} object or matrix with rows as samples and +#' @param x An \code{ms_alignment} object or matrix with rows as samples and #' features as columns. #' @param idx Column index of internal standard. #' @param plot_it Logical. Whether to plot ITSD against total peak area. #' @importFrom graphics abline legend plot #' @importFrom stats lm #' @author Ethan Bass -#' @return A normalized \code{msdial_alignment} object or \code{matrix}, +#' @return A normalized \code{ms_alignment} object or \code{matrix}, #' according to the input. #' @export ms_normalize_itsd <- function(x, idx, plot_it = FALSE) { - if (inherits(x, what = "msdial_alignment")){ + if (inherits(x, what = "ms_alignment")){ X <- x$tab } else if (class(x) %in% c("data.frame","matrix")){ X <- x @@ -141,7 +141,7 @@ ms_normalize_itsd <- function(x, idx, plot_it = FALSE) { X.norm <- as.data.frame(X.norm) - if (inherits(x, what = "msdial_alignment")){ + if (inherits(x, what = "ms_alignment")){ x$tab <- X.norm } else{ x <- X.norm @@ -150,12 +150,12 @@ ms_normalize_itsd <- function(x, idx, plot_it = FALSE) { } #' Subtract blanks -#' @param x A \code{msdial_alignment} object. +#' @param x A \code{ms_alignment} object. #' @param blanks.idx Indices of blank samples #' @param blanks.pattern A string that uniquely identifies blank samples by name #' @param what Whether to subtract the mean or median value #' @param drop Logical. Whether to drop columns containing only zeros. Defaults to TRUE. -#' @return A \code{msdial_alignment} object with the mean or median of the blanks +#' @return A \code{ms_alignment} object with the mean or median of the blanks #' subtracted from each peak. #' @export diff --git a/R/plot_spectrum.R b/R/plot_spectrum.R index e8da201..82f08dc 100644 --- a/R/plot_spectrum.R +++ b/R/plot_spectrum.R @@ -20,7 +20,7 @@ ms_plot_spectrum <- function(x, col, plot_labels = TRUE, lab_int = 0.2, title = TRUE, type = c("plotly", "base"), scale = FALSE, bar_width = 1, digits = 1, ...){ - if (inherits(x,"msdial_alignment")){ + if (inherits(x,"ms_alignment")){ xx <- x$peak_meta } else if (inherits(x, "data.frame") && "EI.spectrum" %in% colnames(x)){ xx <- x @@ -152,7 +152,7 @@ ms_mirror_plot.data.frame <- function(x, y, plot_labels = TRUE, type = c("plotly } #' Plot two spectra as a mirror plot. -#' @param x A \code{msdial_alignment} object. +#' @param x A \code{ms_alignment} object. #' @param cols One or more columns in the peak table \code{tab} to plot. #' @param ref A row in the matches slot corresponding to the provided column. #' @param type What kind of plot to produce. Either base R (\code{base}) or @@ -165,10 +165,10 @@ ms_mirror_plot.data.frame <- function(x, y, plot_labels = TRUE, type = c("plotly #' @param bar_width Width of bars. #' @param match_score Logical. Whether to plot match score or not. #' @rdname ms_mirror_plot -#' @method ms_mirror_plot msdial_alignment +#' @method ms_mirror_plot ms_alignment #' @export -ms_mirror_plot.msdial_alignment <- function(x, cols, ref, type=c("plotly", "base"), +ms_mirror_plot.ms_alignment <- function(x, cols, ref, type=c("plotly", "base"), scale = TRUE, plot_labels = TRUE, lab_int = 0.2, digits = 1, bar_width = 1, match_score = TRUE, ...){ diff --git a/R/read_alignment.R b/R/read_alignment.R index 1de34e8..6c2d41d 100644 --- a/R/read_alignment.R +++ b/R/read_alignment.R @@ -3,7 +3,7 @@ #' @param format The format of the provided alignment file. Currently, only #' MS-DIAL '.txt' files are supported (\code{msdial}). #' @importFrom utils read.csv -#' @return Returns \code{msdial_alignment} object. A list of 3 data.frames, +#' @return Returns \code{ms_alignment} object. A list of 3 data.frames, #' containing peak data (\code{tab}), peak metadata (\code{peak_meta}) and #' sample metadata (\code{sample_meta}). #' @export @@ -27,12 +27,12 @@ ms_read_alignment <- function(path, format = c("msdial")){ structure(.Data = list(tab = tab, peak_meta = peak_meta, sample_meta = data.frame(full.name = rownames(tab))), - class = "msdial_alignment") + class = "ms_alignment") } #' Filter alignment by provided indices. -#' @param x An \code{msdial_alignment} object or matrix with rows as samples and features as columns. +#' @param x An \code{ms_alignment} object or matrix with rows as samples and features as columns. #' @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}). @@ -60,32 +60,32 @@ ms_filter_alignment <- function(x, idx, what=c("rows","cols"), inverse = FALSE){ #' @importFrom utils head #' @noRd #' @export -head.msdial_alignment <- function(x,...){ +head.ms_alignment <- function(x,...){ head(x$tab) } #' @importFrom utils tail #' @noRd #' @export -tail.msdial_alignment <- function(x,...){ +tail.ms_alignment <- function(x,...){ tail(x$tab) } #' @noRd #' @export -print.msdial_alignment <- function(x, ...){ +print.ms_alignment <- function(x, ...){ print(x$tab) } #' @noRd #' @export -dim.msdial_alignment <- function(x){ +dim.ms_alignment <- function(x){ dim(x$tab) } #' @noRd #' @export -row.names.msdial_alignment <- function(x){ +row.names.ms_alignment <- function(x){ row.names(x$tab) } diff --git a/R/search_spectra.R b/R/search_spectra.R index afe05d1..9eeb26f 100644 --- a/R/search_spectra.R +++ b/R/search_spectra.R @@ -1,4 +1,4 @@ -#' Search spectra in MSDIAL alignment against database +#' Search spectra in MS alignment against database #' #' This function can be used to identify peaks in a peak table by matching them #' to a spectral database (\code{db}). It takes several arguments that can @@ -11,7 +11,7 @@ #' index similarity) when calculating the the total similarity score, which is #' used to rank matches. #' -#' @param x An \code{msdial_alignment} object. +#' @param x An \code{ms_alignment} object. #' @param db MSP database. The provided object should be a nested list, where the #' sublists contain the following elements: retention indices in an element named #' \code{RI} and mass spectra in an element called \code{Spectra}. All other elements @@ -32,7 +32,7 @@ #' @param progress_bar Logical. Whether to display progress bar or not. #' @note See \href{https://github.com/QizhiSu/mspcompiler}{mspcompiler} for help compiling #' an msp database. -#' @return Returns a modified \code{msdial_alignment} object with database matches +#' @return Returns a modified \code{ms_alignment} object with database matches #' in the \code{matches} slot as a list of data frames. Each \code{data.frame} #' will contain the database matches as rows and columns corresponding to the #' elements of the database entry (e.g. "Name", "InChIKey", etc.) as well as @@ -86,7 +86,7 @@ ms_search_spectra <- function(x, db, cols, ..., ri_thresh = 100, spectral_weight } #' Get spectrum from MSDIAL alignment object -#' @param x An \code{msdial_alignment} object or matrix with rows as samples and features as columns. +#' @param x An \code{ms_alignment} object or matrix with rows as samples and features as columns. #' @param col Index of the feature (column). #' @return Returns spectrum as a data.frame with two columns: "mz" and "intensity". #' @author Ethan Bass @@ -105,7 +105,7 @@ ms_get_spectrum <- function(x, col){ #' @param parallel Logical. Whether to use parallel processing. (This feature #' does not work on Windows). #' @param mc.cores How many cores to use for parallel processing? Defaults to 2. -#' @param what What kind of object to return. Either \code{msdial_alignment} object, +#' @param what What kind of object to return. Either \code{ms_alignment} object, #' (\code{msd}), or \code{data.frame} (\code{df}). #' @param progress_bar Logical. Whether to display progress bar or not. #' @importFrom pbapply pblapply @@ -151,9 +151,9 @@ msp_to_dataframe <- function(db){ } #' Calculate spectral similarity between two peaks -#' This function is adapted from the \code{SpectrumSimilarity} function in -#' [OrgMassSpecR](https://orgmassspec.github.io/) where it is licensed under -#' BSD-2 (© 2011-2017, Nathan Dodder). The function was refactored here for +#' This function is slightly adapted from the \code{SpectrumSimilarity} function +#' in [OrgMassSpecR](https://orgmassspec.github.io/) where it is licensed under +#' BSD-2 (© 2011-2017, Nathan Dodder). The function was re-factored here for #' increased speed. #' @param spec.top data frame containing the experimental spectrum's peak list #' with the m/z values in the first column and corresponding intensities in the @@ -167,11 +167,18 @@ msp_to_dataframe <- function(db){ #' identification. Expressed as a percent of the maximum intensity. #' @param xlim numeric vector of length 2, defining the beginning and ending #' values of the x-axis. -#' @param x.threshold +#' @param x.threshold numeric value of length 1 specifying the m/z threshold +#' used for the similarity score calculation. Only peaks with m/z values above +#' the threshold are used in the calculation. This can be used to exclude noise +#' and/or non-specific ions at the low end of the spectrum. By default all ions +#' are used. #' @author Nathan G. Dodder #' @author Ethan Bass spectral_similarity <- function(spec.top, spec.bottom, t = 0.25, b = 10, xlim = c(50, 1200), x.threshold = 0){ + if (x.threshold < 0){ + stop("x.threshold argument must be zero or a positive number") + } colnames(spec.top) <- c("mz", "intensity") spec.top$normalized <- round((spec.top$intensity/max(spec.top$intensity)) * 100) spec.top <- spec.top[which(spec.top$mz >= xlim[1] & spec.top$mz <= xlim[2]),] @@ -192,8 +199,6 @@ spectral_similarity <- function(spec.top, spec.bottom, t = 0.25, b = 10, alignment[, c(2, 3)][is.na(alignment[, c(2, 3)])] <- 0 names(alignment) <- c("mz", "intensity.top", "intensity.bottom") - if (x.threshold < 0) - stop("x.threshold argument must be zero or a positive number") alignment <- alignment[alignment[, 1] >= x.threshold, ] u <- alignment[, 2] v <- alignment[, 3] diff --git a/R/utils.R b/R/utils.R index 8c1fa45..07ffb3c 100644 --- a/R/utils.R +++ b/R/utils.R @@ -19,7 +19,7 @@ condense_eispectrum <- function(x){ } #' Find peak based on retention time and/or mass -#' @param x An \code{msdial_alignment} object +#' @param x An \code{ms_alignment} object #' @param rt Retention time #' @param mz Quant.mass #' @param rt.tol Tolerance for matching retention time @@ -98,7 +98,7 @@ ms_rt_to_ri <- function(rts, RIs){ } #' Convert retention times to retention indices in alignment object. -#' @param x An \code{msdial_alignment} object. +#' @param x An \code{ms_alignment} object. #' @param Ris A matrix or data.frame containing retention times in column one #' and retention indices in column two. #' @export diff --git a/man/ms_attach_metadata.Rd b/man/ms_attach_metadata.Rd index 12435fa..7c8638a 100644 --- a/man/ms_attach_metadata.Rd +++ b/man/ms_attach_metadata.Rd @@ -8,18 +8,18 @@ ms_attach_metadata(x, metadata, col) } \arguments{ -\item{x}{An `MSDIAL_alignment` object.} +\item{x}{A \code{ms_alignment} object.} \item{metadata}{A `data.frame` containing the sample metadata.} \item{col}{The name of the column containing the sample names.} } \value{ -A \code{MSDIAL_alignment} object with attached metadata in the \code{ +A \code{ms_alignment} object with attached metadata in the \code{ $sample_meta} slot. } \description{ -Attaches experimental metadata to `MSDIAL_alignment` object. One of the columns in +Attaches experimental metadata to `ms_alignment` object. One of the columns in the supplied metadata must match exactly the row names of the peak table. } \author{ diff --git a/man/ms_calculate_RIs.Rd b/man/ms_calculate_RIs.Rd index 773ff39..e7cba14 100644 --- a/man/ms_calculate_RIs.Rd +++ b/man/ms_calculate_RIs.Rd @@ -7,7 +7,7 @@ ms_calculate_RIs(x, Ris) } \arguments{ -\item{x}{An \code{msdial_alignment} object.} +\item{x}{An \code{ms_alignment} object.} \item{Ris}{A matrix or data.frame containing retention times in column one and retention indices in column two.} diff --git a/man/ms_filter_alignment.Rd b/man/ms_filter_alignment.Rd index 3c7bf68..4ceae08 100644 --- a/man/ms_filter_alignment.Rd +++ b/man/ms_filter_alignment.Rd @@ -7,7 +7,7 @@ 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{x}{An \code{ms_alignment} object or matrix with rows as samples and features as columns.} \item{idx}{Indices to be retained or excluded according to the value of \code{inverse}.} diff --git a/man/ms_find_peak.Rd b/man/ms_find_peak.Rd index 18fde13..17240d1 100644 --- a/man/ms_find_peak.Rd +++ b/man/ms_find_peak.Rd @@ -7,7 +7,7 @@ ms_find_peak(x, rt, mz, rt.tol = 0.01, mz.tol = 0.05, plot_it = TRUE) } \arguments{ -\item{x}{An \code{msdial_alignment} object} +\item{x}{An \code{ms_alignment} object} \item{rt}{Retention time} diff --git a/man/ms_get_spectrum.Rd b/man/ms_get_spectrum.Rd index 39f75fc..cbf05d6 100644 --- a/man/ms_get_spectrum.Rd +++ b/man/ms_get_spectrum.Rd @@ -7,7 +7,7 @@ ms_get_spectrum(x, col) } \arguments{ -\item{x}{An \code{msdial_alignment} object or matrix with rows as samples and features as columns.} +\item{x}{An \code{ms_alignment} object or matrix with rows as samples and features as columns.} \item{col}{Index of the feature (column).} } diff --git a/man/ms_mirror_plot.Rd b/man/ms_mirror_plot.Rd index 4e77d37..1540416 100644 --- a/man/ms_mirror_plot.Rd +++ b/man/ms_mirror_plot.Rd @@ -3,7 +3,7 @@ \name{ms_mirror_plot} \alias{ms_mirror_plot} \alias{ms_mirror_plot.data.frame} -\alias{ms_mirror_plot.msdial_alignment} +\alias{ms_mirror_plot.ms_alignment} \title{Mirror plot function} \usage{ ms_mirror_plot(x, ...) @@ -21,7 +21,7 @@ ms_mirror_plot(x, ...) ... ) -\method{ms_mirror_plot}{msdial_alignment}( +\method{ms_mirror_plot}{ms_alignment}( x, cols, ref, @@ -36,7 +36,7 @@ ms_mirror_plot(x, ...) ) } \arguments{ -\item{x}{A \code{msdial_alignment} object.} +\item{x}{A \code{ms_alignment} object.} \item{...}{Additional arguments} diff --git a/man/ms_normalize_itsd.Rd b/man/ms_normalize_itsd.Rd index ff1ed27..1c6b770 100644 --- a/man/ms_normalize_itsd.Rd +++ b/man/ms_normalize_itsd.Rd @@ -7,7 +7,7 @@ ms_normalize_itsd(x, idx, plot_it = FALSE) } \arguments{ -\item{x}{An \code{msdial_alignment} object or matrix with rows as samples and +\item{x}{An \code{ms_alignment} object or matrix with rows as samples and features as columns.} \item{idx}{Column index of internal standard.} @@ -15,7 +15,7 @@ features as columns.} \item{plot_it}{Logical. Whether to plot ITSD against total peak area.} } \value{ -A normalized \code{msdial_alignment} object or \code{matrix}, +A normalized \code{ms_alignment} object or \code{matrix}, according to the input. } \description{ diff --git a/man/ms_normalize_pqn.Rd b/man/ms_normalize_pqn.Rd index 6540e5d..08f5813 100644 --- a/man/ms_normalize_pqn.Rd +++ b/man/ms_normalize_pqn.Rd @@ -7,7 +7,7 @@ ms_normalize_pqn(x, ref = c("median", "mean"), QC = NULL) } \arguments{ -\item{x}{An \code{msdial_alignment} object or matrix with rows as samples and features as columns.} +\item{x}{An \code{ms_alignment} object or matrix with rows as samples and features as columns.} \item{ref}{Reference for normalization: either \code{median} (default) to use the overall median of variables as the reference, or \code{mean} to use the @@ -17,7 +17,7 @@ overall average of variables as the reference.} (e.g. QC samples)} } \value{ -A normalized \code{msdial_alignment} object or \code{matrix}, +A normalized \code{ms_alignment} object or \code{matrix}, according to the input. } \description{ diff --git a/man/ms_normalize_tsn.Rd b/man/ms_normalize_tsn.Rd index 766277e..ccfd036 100644 --- a/man/ms_normalize_tsn.Rd +++ b/man/ms_normalize_tsn.Rd @@ -7,10 +7,10 @@ ms_normalize_tsn(x) } \arguments{ -\item{x}{An \code{msdial_alignment} object or matrix with rows as samples and features as columns.} +\item{x}{An \code{ms_alignment} object or matrix with rows as samples and features as columns.} } \value{ -A normalized \code{msdial_alignment} object or \code{matrix}, +A normalized \code{ms_alignment} object or \code{matrix}, according to the input. } \description{ diff --git a/man/ms_read_alignment.Rd b/man/ms_read_alignment.Rd index 2dc07d7..5f3492a 100644 --- a/man/ms_read_alignment.Rd +++ b/man/ms_read_alignment.Rd @@ -13,7 +13,7 @@ ms_read_alignment(path, format = c("msdial")) MS-DIAL '.txt' files are supported (\code{msdial}).} } \value{ -Returns \code{msdial_alignment} object. A list of 3 data.frames, +Returns \code{ms_alignment} object. A list of 3 data.frames, containing peak data (\code{tab}), peak metadata (\code{peak_meta}) and sample metadata (\code{sample_meta}). } diff --git a/man/ms_search_gadget.Rd b/man/ms_search_gadget.Rd index d55eb8e..8dcdfaa 100644 --- a/man/ms_search_gadget.Rd +++ b/man/ms_search_gadget.Rd @@ -7,7 +7,7 @@ ms_search_gadget(data) } \arguments{ -\item{data}{An \code{msdial_alignment} object.} +\item{data}{An \code{ms_alignment} object.} } \description{ Launch MS search gadget for interactive viewing of spectral matches. diff --git a/man/ms_search_spectra.Rd b/man/ms_search_spectra.Rd index 95346b8..f76f389 100644 --- a/man/ms_search_spectra.Rd +++ b/man/ms_search_spectra.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/search_spectra.R \name{ms_search_spectra} \alias{ms_search_spectra} -\title{Search spectra in MSDIAL alignment against database} +\title{Search spectra in MS alignment against database} \usage{ ms_search_spectra( x, @@ -19,7 +19,7 @@ ms_search_spectra( ) } \arguments{ -\item{x}{An \code{msdial_alignment} object.} +\item{x}{An \code{ms_alignment} object.} \item{db}{MSP database. The provided object should be a nested list, where the sublists contain the following elements: retention indices in an element named @@ -50,7 +50,7 @@ to FALSE.} \item{progress_bar}{Logical. Whether to display progress bar or not.} } \value{ -Returns a modified \code{msdial_alignment} object with database matches +Returns a modified \code{ms_alignment} object with database matches in the \code{matches} slot as a list of data frames. Each \code{data.frame} will contain the database matches as rows and columns corresponding to the elements of the database entry (e.g. "Name", "InChIKey", etc.) as well as @@ -58,15 +58,16 @@ match scores for spectral similarity (\code{spectral_match}), retention index similarity (\code{ri_match}) and the total similarity score (\code{total_score}). } \description{ -This function can be used to identify peaks in your peaktable by matching them +This function can be used to identify peaks in a peak table by matching them to a spectral database (\code{db}). It takes several arguments that can be used to customize the matching algorithm, including \code{ri_thresh}, \code{spectral weight}, \code{n_results}. The retention index threshold (\code{ri_thresh}) is used to subset the provided database, which greatly improves the search speed. Only database entries with a retention index falling within the specified threshold will be considered. The spectral -weight affects the weight given to spectral similarity when calculating the -the total similarity score, which is used to rank matches. +weight affects the weight given to spectral similarity (versus retention +index similarity) when calculating the the total similarity score, which is +used to rank matches. } \note{ See \href{https://github.com/QizhiSu/mspcompiler}{mspcompiler} for help compiling diff --git a/man/ms_subtract_blanks.Rd b/man/ms_subtract_blanks.Rd index 24c4b0d..e087ae9 100644 --- a/man/ms_subtract_blanks.Rd +++ b/man/ms_subtract_blanks.Rd @@ -13,7 +13,7 @@ ms_subtract_blanks( ) } \arguments{ -\item{x}{A \code{msdial_alignment} object.} +\item{x}{A \code{ms_alignment} object.} \item{blanks.idx}{Indices of blank samples} @@ -24,7 +24,7 @@ ms_subtract_blanks( \item{drop}{Logical. Whether to drop columns containing only zeros. Defaults to TRUE.} } \value{ -A \code{msdial_alignment} object with the mean or median of the blanks +A \code{ms_alignment} object with the mean or median of the blanks subtracted from each peak. } \description{ diff --git a/man/spectral_similarity.Rd b/man/spectral_similarity.Rd new file mode 100644 index 0000000..48b0b39 --- /dev/null +++ b/man/spectral_similarity.Rd @@ -0,0 +1,55 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/search_spectra.R +\name{spectral_similarity} +\alias{spectral_similarity} +\title{Calculate spectral similarity between two peaks +This function is slightly adapted from the \code{SpectrumSimilarity} function +in [OrgMassSpecR](https://orgmassspec.github.io/) where it is licensed under +BSD-2 (© 2011-2017, Nathan Dodder). The function was re-factored here for +increased speed.} +\usage{ +spectral_similarity( + spec.top, + spec.bottom, + t = 0.25, + b = 10, + xlim = c(50, 1200), + x.threshold = 0 +) +} +\arguments{ +\item{spec.top}{data frame containing the experimental spectrum's peak list +with the m/z values in the first column and corresponding intensities in the +second.} + +\item{spec.bottom}{data frame containing the reference spectrum's peak list +with the m/z values in the first column and corresponding intensities in the +second.} + +\item{t}{numeric value specifying the tolerance used to align the m/z values +of the two spectra.} + +\item{b}{numeric value specifying the baseline threshold for peak +identification. Expressed as a percent of the maximum intensity.} + +\item{xlim}{numeric vector of length 2, defining the beginning and ending +values of the x-axis.} + +\item{x.threshold}{numeric value of length 1 specifying the m/z threshold +used for the similarity score calculation. Only peaks with m/z values above +the threshold are used in the calculation. This can be used to exclude noise +and/or non-specific ions at the low end of the spectrum. By default all ions +are used.} +} +\description{ +Calculate spectral similarity between two peaks +This function is slightly adapted from the \code{SpectrumSimilarity} function +in [OrgMassSpecR](https://orgmassspec.github.io/) where it is licensed under +BSD-2 (© 2011-2017, Nathan Dodder). The function was re-factored here for +increased speed. +} +\author{ +Nathan G. Dodder + +Ethan Bass +}