Skip to content

Commit

Permalink
deprecate code to save spectra to RDS after processing
Browse files Browse the repository at this point in the history
Remove/deprecate `rds_suffix` argument

This fixes #38
  • Loading branch information
cpauvert committed Dec 6, 2023
1 parent bed180e commit d8dfaa9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 30 deletions.
25 changes: 11 additions & 14 deletions R/process_spectra.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#'
#' @param spectra_list A list of [MALDIquant::MassSpectrum] objects.
#' @param spectra_names A [tibble::tibble] (or [data.frame]) of sanitized spectra names by default from [get_spectra_names]. If provided manually, the column `sanitized_name` will be used to name the spectra.
#' @param rds_prefix A character indicating the prefix for the `.RDS` output files to be written in the `processed` directory. By default, no prefix are given and thus no files are written.
#' @param rds_prefix `r lifecycle::badge('deprecated')` Writing to disk as RDS is no longer supported. A character indicating the prefix for the `.RDS` output files to be written in the `processed` directory. By default, no prefix are given and thus no files are written.
#'
#' @return A named list of three objects:
#' * `spectra`: a list the length of the spectra list of [MALDIquant::MassSpectrum] objects.
Expand Down Expand Up @@ -48,9 +48,16 @@
#' processed$metadata
process_spectra <- function(spectra_list,
spectra_names = get_spectra_names(spectra_list),
rds_prefix = NULL) {
rds_prefix = deprecated()) {
# It returns the list and write it for future processing as an RDS file.

if (lifecycle::is_present(rds_prefix)) {
lifecycle::deprecate_warn(
when = "1.2.9000",
what = "process_spectra(rds_prefix)",
details = "Ability to write processed spectra to disk as RDS files will be dropped in next release."
)
}
# 1. SQRT transformation
# 2. Mass range trimming
# 3. Signal smoothing
Expand Down Expand Up @@ -85,14 +92,14 @@ process_spectra <- function(spectra_list,
)

# Add the spectra identifiers to all objects
if(! "sanitized_name" %in% colnames(spectra_names)){
if (!"sanitized_name" %in% colnames(spectra_names)) {
stop(
"Missing 'sanitized_name' column in the provided 'spectra_names' tibble!",
"\n\nTip: Use the `get_spectra_names()` for default and compliant names."
)
}
rownames(metadata) <- names(spectra) <- names(peaks) <- spectra_names[["sanitized_name"]]

# Aggregate the objects to a list
processed_list <- list(
"spectra" = spectra,
Expand All @@ -101,15 +108,5 @@ process_spectra <- function(spectra_list,
"metadata" = tibble::as_tibble(metadata, rownames = "name")
)

# Optional: writing objects to RDS files
if (!is.null(rds_prefix)) {
if (!dir.exists("processed")) {
dir.create("processed")
}
saveRDS(processed_list,
version = 2, compress = FALSE,
file = paste0("processed/", rds_prefix, ".RDS")
)
}
return(processed_list)
}
25 changes: 11 additions & 14 deletions dev/dereplicate-spectra.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ The full procedure is illustrated in the example below. While in this case, all
#'
#' @param spectra_list A list of [MALDIquant::MassSpectrum] objects.
#' @param spectra_names A [tibble::tibble] (or [data.frame]) of sanitized spectra names by default from [get_spectra_names]. If provided manually, the column `sanitized_name` will be used to name the spectra.
#' @param rds_prefix A character indicating the prefix for the `.RDS` output files to be written in the `processed` directory. By default, no prefix are given and thus no files are written.
#' @param rds_prefix `r lifecycle::badge('deprecated')` Writing to disk as RDS is no longer supported. A character indicating the prefix for the `.RDS` output files to be written in the `processed` directory. By default, no prefix are given and thus no files are written.
#'
#' @return A named list of three objects:
#' * `spectra`: a list the length of the spectra list of [MALDIquant::MassSpectrum] objects.
Expand All @@ -73,9 +73,16 @@ The full procedure is illustrated in the example below. While in this case, all
#' @examples
process_spectra <- function(spectra_list,
spectra_names = get_spectra_names(spectra_list),
rds_prefix = NULL) {
rds_prefix = deprecated()) {
# It returns the list and write it for future processing as an RDS file.
if (lifecycle::is_present(rds_prefix)) {
lifecycle::deprecate_warn(
when = "1.2.9000",
what = "process_spectra(rds_prefix)",
details = "Ability to write processed spectra to disk as RDS files will be dropped in next release."
)
}
# 1. SQRT transformation
# 2. Mass range trimming
# 3. Signal smoothing
Expand Down Expand Up @@ -110,14 +117,14 @@ process_spectra <- function(spectra_list,
)
# Add the spectra identifiers to all objects
if(! "sanitized_name" %in% colnames(spectra_names)){
if (!"sanitized_name" %in% colnames(spectra_names)) {
stop(
"Missing 'sanitized_name' column in the provided 'spectra_names' tibble!",
"\n\nTip: Use the `get_spectra_names()` for default and compliant names."
)
}
rownames(metadata) <- names(spectra) <- names(peaks) <- spectra_names[["sanitized_name"]]
# Aggregate the objects to a list
processed_list <- list(
"spectra" = spectra,
Expand All @@ -126,16 +133,6 @@ process_spectra <- function(spectra_list,
"metadata" = tibble::as_tibble(metadata, rownames = "name")
)
# Optional: writing objects to RDS files
if (!is.null(rds_prefix)) {
if (!dir.exists("processed")) {
dir.create("processed")
}
saveRDS(processed_list,
version = 2, compress = FALSE,
file = paste0("processed/", rds_prefix, ".RDS")
)
}
return(processed_list)
}
```
Expand Down
21 changes: 21 additions & 0 deletions man/figures/lifecycle-deprecated.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions man/process_spectra.Rd

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

0 comments on commit d8dfaa9

Please sign in to comment.