Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce usage of default argument values #168

Merged
merged 14 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- exported functions in NAMESPACE [#154](https://github.com/RECETOX/recetox-aplcms/pull/154)
- docstrings and documentation files for refactored functions [#160](https://github.com/RECETOX/recetox-aplcms/pull/160)
- refactored parameter names to keep them more harmonized [#167](https://github.com/RECETOX/recetox-aplcms/pull/167)
- moved some utility functions to a more suitable locations [#164](https://github.com/RECETOX/recetox-aplcms/pull/160)
- moved some utility functions to a more suitable locations [#164](https://github.com/RECETOX/recetox-aplcms/pull/164)
### Removed
- `extract_features` and `feature.align` [#154](https://github.com/RECETOX/recetox-aplcms/pull/154)
- improper usage of `@examples` [#160](https://github.com/RECETOX/recetox-aplcms/pull/160)
- several obsolete utility functions [#164](https://github.com/RECETOX/recetox-aplcms/pull/160)
- several obsolete utility functions [#164](https://github.com/RECETOX/recetox-aplcms/pull/164)
- several outdated `.Rd` files [#168](https://github.com/RECETOX/recetox-aplcms/pull/168)
- default argument values from low-level functions [#168](https://github.com/RECETOX/recetox-aplcms/pull/168)

## [0.9.4] - 2022-05-10

Expand Down
2 changes: 1 addition & 1 deletion R/adaptive.bin.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ adaptive.bin <- function(features,
min_pres,
mz_tol,
baseline_correct,
intensity_weighted = FALSE) {
intensity_weighted) {
# order inputs after mz values
features <- features |> dplyr::arrange_at("mz")

Expand Down
9 changes: 8 additions & 1 deletion R/compute_clusters.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ compute_clusters <- function(feature_tables,
mz_tol_absolute,
mz_max_diff,
rt_tol_relative,
do.plot = FALSE,
do.plot,
hechth marked this conversation as resolved.
Show resolved Hide resolved
sample_names = NA) {
number_of_samples <- length(feature_tables)
all <- concatenate_feature_tables(feature_tables, sample_names)
Expand All @@ -34,6 +34,9 @@ compute_clusters <- function(feature_tables,
mz_tol_relative <- find.tol(
all$mz,
mz_max_diff = mz_max_diff,
aver.bin.size = 4000,
min.bins = 50,
max.bins = 200,
do.plot = do.plot
)
if (length(mz_tol_relative) == 0) {
Expand All @@ -60,7 +63,11 @@ compute_clusters <- function(feature_tables,
number_of_samples = number_of_samples,
mz_tol_relative = mz_tol_relative,
rt_tol_relative = rt_tol_relative,
aver.bin.size = 200,
min.bins = 50,
max.bins = 100,
mz_tol_absolute = mz_tol_absolute,
max.num.segments = 10000,
do.plot = do.plot
)

Expand Down
2 changes: 1 addition & 1 deletion R/find.match.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param a A matrix of distances.
#' @param unacceptable A distance larger than which cannot be accepted as pairs.
#' @return A matrix the same dimension as the input matrix, with matched position taking value 1, and all other positions taking value 0.
find.match <- function(a, unacceptable=4) {
find.match <- function(a, unacceptable) {
find.min.pos<-function(d)
{
pos<-which(d==min(d))[1]
Expand Down
10 changes: 5 additions & 5 deletions R/find.tol.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ NULL
#' @return The tolerance level is returned.
#' @export
find.tol <- function(mz,
mz_max_diff = 1e-4,
aver.bin.size = 4000,
min.bins = 50,
max.bins = 200,
do.plot = TRUE) {
mz_max_diff,
hechth marked this conversation as resolved.
Show resolved Hide resolved
aver.bin.size,
min.bins,
max.bins,
do.plot) {
mz <- mz[order(mz)]
l <- length(mz)
# pairwise m/z difference divided by their average, filtered outside of tolerance limit
Expand Down
16 changes: 8 additions & 8 deletions R/find.tol.time.R
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ compute_rt_tol_relative <- function(breaks,
#' spectrum label, and peak group label. The rows are ordered by the median m/z of each peak group, and with each peak group the rows are ordered
find.tol.time <- function(features,
number_of_samples,
mz_tol_relative = 2e-5,
rt_tol_relative = NA,
aver.bin.size = 200,
min.bins = 50,
max.bins = 100,
mz_tol_absolute = 0.01,
max.num.segments = 10000,
do.plot = TRUE) {
mz_tol_relative,
rt_tol_relative,
aver.bin.size,
min.bins,
max.bins,
mz_tol_absolute,
max.num.segments,
do.plot) {
features <- dplyr::arrange_at(features, "mz")

min_mz_tol <- compute_min_mz_tolerance(
Expand Down
16 changes: 11 additions & 5 deletions R/hybrid.R
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ augment_known_table <- function(
#' @param use_observed_range If the value is TRUE, the actual range of the observed locations of the feature in all the spectra will be used.
#' @param recover_min_count Minimum number of raw data points to support a recovery.
#' @param intensity_weighted Whether to use intensity to weight mass density estimation.
#' @param do.plot Indicates whether plot should be drawn.
#' @param cluster The number of CPU cores to be used
#' @export
hybrid <- function(
Expand Down Expand Up @@ -326,6 +327,7 @@ hybrid <- function(
use_observed_range = TRUE,
recover_min_count = 3,
intensity_weighted = FALSE,
do_plot = FALSE,
cluster = 4
) {
if (!is(cluster, 'cluster')) {
Expand All @@ -351,7 +353,7 @@ hybrid <- function(
baseline_correct = baseline_correct,
baseline_correct_noise_percentile = baseline_correct_noise_percentile,
intensity_weighted = intensity_weighted,
do.plot = FALSE,
do.plot = do_plot,
cache = FALSE
)
})
Expand All @@ -369,7 +371,7 @@ hybrid <- function(
component_eliminate = component_eliminate,
moment_power = moment_power,
BIC_factor = BIC_factor,
do.plot = FALSE
do.plot = do_plot
)
})

Expand All @@ -380,6 +382,7 @@ hybrid <- function(
mz_tol_absolute = mz_tol_absolute,
mz_max_diff = 10 * mz_tol,
rt_tol_relative = rt_tol_relative,
do.plot = do_plot,
sample_names = sample_names
)

Expand All @@ -401,7 +404,8 @@ hybrid <- function(
mz_tol_relative = extracted_clusters$mz_tol_relative,
mz_tol_absolute = extracted_clusters$rt_tol_relative,
mz_max_diff = 10 * mz_tol,
rt_tol_relative = rt_tol_relative
rt_tol_relative = rt_tol_relative,
do.plot = do_plot
)

message("**** feature alignment ****")
Expand Down Expand Up @@ -455,7 +459,8 @@ hybrid <- function(
mz_tol_relative = mz_tol_relative,
mz_tol_absolute = mz_tol_absolute,
mz_max_diff = 10 * mz_tol,
rt_tol_relative = rt_tol_relative
rt_tol_relative = rt_tol_relative,
do.plot = do_plot
)

message("**** computing template ****")
Expand All @@ -476,7 +481,8 @@ hybrid <- function(
mz_tol_relative = recovered_clusters$mz_tol_relative,
mz_tol_absolute = recovered_clusters$rt_tol_relative,
mz_max_diff = 10 * mz_tol,
rt_tol_relative = rt_tol_relative
rt_tol_relative = rt_tol_relative,
do.plot = do_plot
)

message("**** second feature alignment ****")
Expand Down
16 changes: 8 additions & 8 deletions R/proc.cdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ load_data <- function(filename,
#' @return A matrix with four columns: m/z value, retention time, intensity, and group number.
#' @export
proc.cdf <- function(filename,
min_pres = 0.5,
min_run = 12,
mz_tol = 1e-05,
baseline_correct = 0.0,
baseline_correct_noise_percentile = 0.05,
intensity_weighted = FALSE,
do.plot = FALSE,
cache = FALSE) {
min_pres,
min_run,
mz_tol,
baseline_correct,
baseline_correct_noise_percentile,
intensity_weighted,
do.plot,
cache) {
raw.prof <- load_data(
filename,
cache,
Expand Down
22 changes: 11 additions & 11 deletions R/prof.to.features.R
Original file line number Diff line number Diff line change
Expand Up @@ -826,17 +826,17 @@ normix.bic <- function(x, y, moment_power = 2, do.plot = FALSE, bw = c(15, 30, 6
#' curve), and estimated total signal strength (total area of the estimated normal curve).
#' @export
prof.to.features <- function(profile,
bandwidth = 0.5,
min_bandwidth = NA,
max_bandwidth = NA,
sd_cut = c(0.01, 500),
sigma_ratio_lim = c(0.01, 100),
shape_model = "bi-Gaussian",
peak_estim_method = "moment",
moment_power = 1,
component_eliminate = 0.01,
BIC_factor = 2,
do.plot = TRUE) {
bandwidth,
min_bandwidth,
max_bandwidth,
sd_cut,
sigma_ratio_lim,
shape_model,
peak_estim_method,
moment_power,
component_eliminate,
BIC_factor,
do.plot) {
validate_inputs(shape_model, peak_estim_method)

profile <- preprocess_profile(profile)
Expand Down
18 changes: 9 additions & 9 deletions R/recover.weaker.R
Original file line number Diff line number Diff line change
Expand Up @@ -659,15 +659,15 @@ recover.weaker <- function(filename,
rt_tol_relative,
extracted_features,
adjusted_features,
recover_mz_range = NA,
recover_rt_range = NA,
use_observed_range = TRUE,
mz_tol = 1e-5,
min_bandwidth = NA,
max_bandwidth = NA,
bandwidth = .5,
recover_min_count = 3,
intensity_weighted = FALSE) {
recover_mz_range,
recover_rt_range,
use_observed_range,
mz_tol,
min_bandwidth,
max_bandwidth,
bandwidth,
recover_min_count,
intensity_weighted) {
# load raw data
data_table <- load_file(filename) |> dplyr::arrange_at("mz")
times <- sort(unique(data_table$rt))
Expand Down
8 changes: 4 additions & 4 deletions R/run_filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' @param profile The matrix containing m/z, retention time, intensity, and EIC label as columns.
#' @return unique_grp.
#' @export
compute_uniq_grp <- function(profile, min_count_run, min_pres = 0.6) {
compute_uniq_grp <- function(profile, min_count_run, min_pres) {
grps <- profile
ttt <- table(grps)
ttt <- ttt[ttt >= max(min_count_run * min_pres, 2)]
Expand All @@ -18,7 +18,7 @@ compute_uniq_grp <- function(profile, min_count_run, min_pres = 0.6) {
#' @param times. Retention times vector.
#' @return predicted rt.
#' @export
predict_smoothed_rt <- function(min_run = 5, times) {
predict_smoothed_rt <- function(min_run, times) {
# ksmooth(x, y, kernel, bandwidth, range, n.points, x.points)
smooth <- ksmooth(
seq(-min_run + 1, length(times) + min_run),
Expand Down Expand Up @@ -78,8 +78,8 @@ label_val_to_keep <- function(min_run, timeline, min_pres, this_times, times) {
#' @return A list is returned. new_rec - The matrix containing m/z, retention time, intensity, and EIC label as columns after applying the run filter.
#' @export
run_filter <- function(newprof,
min_pres = 0.6,
min_run = 5) {
min_pres,
min_run) {

newprof <- tibble::tibble(mz = newprof[,1], rt = newprof[,2], intensi = newprof[,3], grps = newprof[,4])

Expand Down
4 changes: 2 additions & 2 deletions R/semi.sup.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ semi.sup <- function(
that.name<-paste(strsplit(tolower(files[j]),"\\.")[[1]][1],suf.prof,".profile",sep="_")

processable<-"goodgood"
processable<-try(this.prof<-proc.cdf(files[j], min.pres=min.pres, min.run=min.run, tol=mz.tol, baseline.correct=baseline.correct, baseline.correct.noise.percentile=baseline.correct.noise.percentile, do.plot=FALSE, intensity.weighted=intensity.weighted))
processable<-try(this.prof<-proc.cdf(files[j], min_pres=min.pres, min_run=min.run, mz_tol=mz.tol, baseline_correct=baseline.correct, baseline_correct_noise_percentile=baseline.correct.noise.percentile, do.plot=FALSE, intensity_weighted=intensity.weighted, cache=FALSE))
if(substr(processable,1,5)=="Error")
{
file.copy(from=files[j], to="error_files")
Expand All @@ -156,7 +156,7 @@ semi.sup <- function(
if(substr(processable,1,5)!="Error")
{
processable.2<-"goodgood"
processable.2<-try(this.feature<-prof.to.features(this.prof, min.bw=min.bw, max.bw=max.bw, sd.cut=sd.cut, shape.model=shape.model, estim.method=peak.estim.method, do.plot=FALSE, component.eliminate=component.eliminate, power=moment.power, BIC.factor=BIC.factor))
processable.2<-try(this.feature<-prof.to.features(profile, bandwidth = 0.5, min_bandwidth=min.bw, max_bandwidth=max.bw, sd_cut=sd.cut, sigma_ratio_lim = c(0.01, 100), shape_model=shape.model, peak_estim_method=peak.estim.method, do.plot=FALSE, component_eliminate=component.eliminate, moment_power=moment.power, BIC_factor=BIC.factor))

if(substr(processable.2,1,5)=="Error")
{
Expand Down
13 changes: 9 additions & 4 deletions R/unsupervised.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ get_sample_name <- function(filename) {
#' the spectra will be used.
#' @param recover_min_count Minimum number of raw data points to support a recovery.
#' @param intensity_weighted Whether to use intensity to weight mass density estimation.
#' @param do.plot Indicates whether plot should be drawn.
#' @param cluster The number of CPU cores to be used
#' @export
unsupervised <- function(
Expand Down Expand Up @@ -116,6 +117,7 @@ unsupervised <- function(
use_observed_range = TRUE,
recover_min_count = 3,
intensity_weighted = FALSE,
do_plot = FALSE,
cluster = 4
) {
if (!is(cluster, 'cluster')) {
Expand All @@ -141,7 +143,7 @@ unsupervised <- function(
baseline_correct = baseline_correct,
baseline_correct_noise_percentile = baseline_correct_noise_percentile,
intensity_weighted = intensity_weighted,
do.plot = FALSE,
do.plot = do_plot,
cache = FALSE
)
})
Expand All @@ -159,7 +161,7 @@ unsupervised <- function(
component_eliminate = component_eliminate,
moment_power = moment_power,
BIC_factor = BIC_factor,
do.plot = FALSE
do.plot = do_plot
)
})

Expand All @@ -170,6 +172,7 @@ unsupervised <- function(
mz_tol_absolute = mz_tol_absolute,
mz_max_diff = 10 * mz_tol,
rt_tol_relative = rt_tol_relative,
do.plot = do_plot,
sample_names = sample_names
)

Expand All @@ -191,7 +194,8 @@ unsupervised <- function(
mz_tol_relative = extracted_clusters$mz_tol_relative,
mz_tol_absolute = extracted_clusters$rt_tol_relative,
mz_max_diff = 10 * mz_tol,
rt_tol_relative = rt_tol_relative
rt_tol_relative = rt_tol_relative,
do.plot = do_plot
)

message("**** feature alignment ****")
Expand Down Expand Up @@ -235,7 +239,8 @@ unsupervised <- function(
mz_tol_relative = adjusted_clusters$mz_tol_relative,
mz_tol_absolute = adjusted_clusters$rt_tol_relative,
mz_max_diff = 10 * mz_tol,
rt_tol_relative = rt_tol_relative
rt_tol_relative = rt_tol_relative,
do.plot = do_plot
)

message("**** feature alignment ****")
Expand Down
2 changes: 1 addition & 1 deletion man/adaptive.bin.Rd

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

21 changes: 0 additions & 21 deletions man/aligned.Rd

This file was deleted.

Loading