Skip to content

Commit

Permalink
renamed ms_tidy_msdial and fixed bug, v0.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanbass committed Sep 2, 2023
1 parent 23651e6 commit 49cc3ee
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 23 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-6175-6739"))
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
9 changes: 7 additions & 2 deletions R/normalization.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
42 changes: 35 additions & 7 deletions R/tidy_msdial.R
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.")
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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).
4 changes: 2 additions & 2 deletions inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -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)."
)
)
4 changes: 2 additions & 2 deletions man/ms_normalize_itsd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ms_normalize_pqn.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions man/ms_normalize_tsn.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions man/ms_reshape_peaktable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/ms_tidy_msdial.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 49cc3ee

Please sign in to comment.