Skip to content

Commit

Permalink
Fixed running examples
Browse files Browse the repository at this point in the history
  • Loading branch information
hechth committed Sep 21, 2022
1 parent 1e4f54b commit 6bf9bfb
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 79 deletions.
20 changes: 7 additions & 13 deletions R/adjust.time.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ compute_template <- function(extracted_features) {
template <- which.max(num.ftrs)
message(paste("the template is sample", template))

candi <- extracted_features[[template]] |> dplyr::select(c(mz, rt))
candi <- tibble::as_tibble(extracted_features[[template]]) |> dplyr::select(c(mz, rt))
template_features <- dplyr::bind_cols(candi, sample_id = rep(template, nrow(candi)))
return(tibble::as_tibble(template_features))
}
Expand Down Expand Up @@ -120,28 +120,22 @@ correct_time <- function(this.feature, template_features, mz_tol_relative, rt_to
#' This function adjusts the retention time in each LC/MS profile to achieve better between-profile agreement.
#'
#' @param extracted_features A list object. Each component is a matrix which is the output from compute_clusters
#' @param mz_tol_relative The m/z tolerance level for peak alignment. The default is NA, which allows the
#' program to search for the tolerance level based on the data. This value is expressed as the
#' @param mz_tol_relative The m/z tolerance level for peak alignment. This value is expressed as the
#' percentage of the m/z value. This value, multiplied by the m/z value, becomes the cutoff level.
#' @param rt_tol_relative The retention time tolerance level for peak alignment. The default is NA, which
#' allows the program to search for the tolerance level based on the data.
#' @param rt_tol_relative The retention time tolerance level for peak alignment.
#' @param colors The vector of colors to be used for the line plots of time adjustments. The default is NA,
#' in which case the program uses a set of default color set.
#' @param mz_max_diff Argument passed to find.tol(). Consider only m/z diffs smaller than this value.
#' This is only used when the mz_tol_relative is NA.
#' @param mz_tol_absolute As the m/z tolerance is expressed in relative terms (ppm), it may not be suitable
#' when the m/z range is wide. This parameter limits the tolerance in absolute terms. It mostly
#' influences feature matching in higher m/z range.
#' @param do.plot Indicates whether plot should be drawn.
#' @return A list object with the exact same structure as the input object features, i.e. one matrix per profile
#' being processed. The only difference this output object has with the input object is that the retention time
#' column in each of the matrices is changed to new adjusted values.
#' @export
#' @examples
#' adjust.time(extracted_features, mz_max_diff = 10 * 1e-05, do.plot = FALSE)
#' data(extracted)
#' adjust.time(extracted, 10e-06, 5, do.plot = FALSE)
adjust.time <- function(extracted_features,
mz_tol_relative = NA,
rt_tol_relative = NA,
mz_tol_relative,
rt_tol_relative,
colors = NA,
do.plot = TRUE) {
number_of_samples <- length(extracted_features)
Expand Down
13 changes: 7 additions & 6 deletions R/feature.align.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

create_empty_tibble <- function(number_of_samples, metadata_colnames, intensity_colnames, rt_colnames) {
features <- new("list")
features$metadata <- as_tibble(matrix(nrow = 0, ncol = length(metadata_colnames)), .name_repair = ~ metadata_colnames)
features$intensity <- as_tibble(matrix(nrow = 0, ncol = length(intensity_colnames)), .name_repair = ~ intensity_colnames)
features$rt <- as_tibble(matrix(nrow = 0, ncol = length(rt_colnames)), .name_repair = ~ rt_colnames)
features$metadata <- tibble::as_tibble(matrix(nrow = 0, ncol = length(metadata_colnames)), .name_repair = ~ metadata_colnames)
features$intensity <- tibble::as_tibble(matrix(nrow = 0, ncol = length(intensity_colnames)), .name_repair = ~ intensity_colnames)
features$rt <- tibble::as_tibble(matrix(nrow = 0, ncol = length(rt_colnames)), .name_repair = ~ rt_colnames)
return(features)
}


add_row <- function(df, data, i, column_names) {
row <- matrix(c(i, data), nrow=1)
colnames(row) <- column_names
return(bind_rows(df, as_tibble(row)))
return(dplyr::bind_rows(df, tibble::as_tibble(row)))
}


Expand Down Expand Up @@ -101,7 +101,7 @@ create_rows <- function(features,
gc()
} # call Garbage Collection for performance improvement?

sample <- filter(features, cluster == sel.labels[i])
sample <- dplyr::filter(features, cluster == sel.labels[i])
if (nrow(sample) > 1) {
if (validate_contents(sample, min_occurrence)) {
return(select_mz(sample, mz_tol_relative, rt_tol_relative, min_occurrence, number_of_samples))
Expand Down Expand Up @@ -177,7 +177,8 @@ create_aligned_feature_table <- function(all_table,
#' }
#' @export
#' @examples
#' feature.align(features, mz_max_diff = 10 * 1e-05, do.plot = FALSE)
#' data(extracted)
#' feature.align(extracted, mz_max_diff = 10 * 1e-05, do.plot = FALSE)
feature.align <- function(features,
min_occurrence = 2,
mz_tol_relative = NA,
Expand Down
1 change: 1 addition & 0 deletions data/datalist
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
adduct.table
aligned
extracted
features.learn
features
features2.learn
Expand Down
Binary file added data/extracted.rda
Binary file not shown.
56 changes: 29 additions & 27 deletions man/adjust.time.Rd

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

76 changes: 43 additions & 33 deletions man/feature.align.Rd

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

0 comments on commit 6bf9bfb

Please sign in to comment.