Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
chi-raag committed Jul 5, 2024
2 parents 2b1bd03 + 0625234 commit cf52db6
Show file tree
Hide file tree
Showing 21 changed files with 945 additions and 520 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
massSight.wiki/
.Rproj.user
.Rhistory
.RData
Expand All @@ -6,11 +7,12 @@
.httr-oauth
.DS_Store
.vscode/
.lintr
README_cache/
*.csv
*.xlsx

log/
data/
inst/doc
eval/
massSight-benchmarking/
5 changes: 4 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
linters: linters_with_defaults() # see vignette("lintr")
linters: linters_with_defaults(
line_length_linter = NULL, # Disable line length linter
object_name_linter = object_name_linter(),
object_usage_linter = object_usage_linter())
encoding: "UTF-8"
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: massSight
Title: Batch Alignment and Scaling for LC-MS Data
Version: 0.2.0
Version: 0.2.1
Authors@R: c(
person("Chiraag", "Gohel", , "chiraaggohel@gwu.edu", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-4446-9380")),
Expand All @@ -21,6 +21,7 @@ Imports:
caret,
checkmate,
cowplot,
data.table,
dbscan,
dplyr,
GauPro,
Expand All @@ -39,6 +40,7 @@ Imports:
tidyr,
utils
Suggests:
jsonlite,
knitr,
rmarkdown,
spelling,
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# massSight 0.2.1

* Fixed bug in `final_plots()` that prevented the display of all matched metabolites
* Removed pre-isolation matching from `auto_combine()`

# massSight 0.2.0

* Added more robust plotting features
Expand Down
101 changes: 81 additions & 20 deletions R/auto_combine.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#' @param weights A numeric vector indicating the weights to be used for
#' the alignment.
#' @param keep_features A logical vector indicating whether or not to
#' @param log A character indicating the name of the log file.
#' @param output A character indicating the directory to save the output. If NULL,
#' the output will be saved in the current working directory.
#'
#' @return A `MergedMSObject` containing the combined data.
setGeneric("auto_combine", function(ms1,
Expand All @@ -50,7 +53,8 @@ setGeneric("auto_combine", function(ms1,
smooth_method = "gam",
weights = c(1, 1, 1),
keep_features = c(F, F),
log = F) {
log = NULL,
output = NULL) {
standardGeneric("auto_combine")
})

Expand All @@ -71,12 +75,27 @@ setMethod(
match_method = "unsupervised",
smooth_method = "gam",
weights = c(1, 1, 1),
keep_features = c(F, F),
log = F) {
call <- modify_call(match.call(expand.dots = TRUE))
if (log) {
initialize_log(call)
keep_features = c(FALSE, FALSE),
log = "log.json",
output = NULL) {
if (!is.null(log)) {
time_start <- Sys.time()
check_jsonlite()
log_params <- match.call(expand.dots = TRUE) |>
modify_call() |>
as.list() |>
(\(x) x[-1])() |>
lapply(\(x) {
if (is.language(x)) {
return(deparse(x))
} else {
return(x)
}
})
log_r <- R.Version()
log_date <- Sys.time()
}

validate_parameters(iso_method, match_method, smooth_method, minimum_intensity)

if (match_method == "unsupervised") {
Expand Down Expand Up @@ -108,12 +127,12 @@ setMethod(
ms1(align_obj) <- ms1
ms2(align_obj) <- ms2
align_obj <- align_obj |>
align_pre_isolated_compounds(
rt_minus = rt_lower,
rt_plus = rt_upper,
mz_minus = mz_lower,
mz_plus = mz_upper
) |>
# align_pre_isolated_compounds(
# rt_minus = rt_lower,
# rt_plus = rt_upper,
# mz_minus = mz_lower,
# mz_plus = mz_upper
# ) |>
align_isolated_compounds(
match_method = match_method,
rt_minus = rt_lower,
Expand All @@ -130,16 +149,58 @@ setMethod(
weights = weights
)

if (log) {
logr::log_print(
paste0(
"Numbers of matched/kept features: ",
nrow(all_matched(align_obj))
),
console = T
if (!is.null(log)) {
final_results <- all_matched(align_obj)
compound_id_1 <- paste("Compound_ID", name(ms1), sep = "_")
compound_id_2 <- paste("Compound_ID", name(ms2), sep = "_")
n1 <- final_results |>
dplyr::filter(!is.na(!!rlang::sym(compound_id_1)) &
is.na(!!rlang::sym(compound_id_2))) |>
nrow()
n2 <- final_results |>
dplyr::filter(is.na(!!rlang::sym(compound_id_1)) &
!is.na(!!rlang::sym(compound_id_2))) |>
nrow()
n12 <- final_results |>
dplyr::filter(!is.na(!!rlang::sym(compound_id_1)) &
!is.na(!!rlang::sym(compound_id_2))) |>
nrow()

metabolite_1 <- paste("Metabolite", name(ms1), sep = "_")
metabolite_2 <- paste("Metabolite", name(ms2), sep = "_")
m_correct <- final_results |>
dplyr::filter(!!rlang::sym(metabolite_1) == !!rlang::sym(metabolite_2)) |>
nrow()
m_total <- final_results |>
dplyr::filter(!is.na(!!rlang::sym(metabolite_1)) &
!is.na(!!rlang::sym(metabolite_2))) |>
nrow()

log_results <- list(
"Dataset 1 Unmatched" = n1,
"Dataset 2 Unmatched" = n2,
"Matched" = n12,
"Correct Matched Annotated Metabolites" = m_correct,
"Total Matched Annotated Metabolites" = m_total,
"Percentage Correct Matched Annotated Metabolites" = m_correct / m_total
)

time_end <- Sys.time()
time <- time_end - time_start
date$runtime <- time

log_file <- list(
date = log_date,
r_version = log_r,
parameters = log_params,
results = log_results
)
log_file <-
jsonlite::toJSON(log_file, auto_unbox = TRUE, pretty = TRUE)

writeLines(log_file, log)

logr::log_close()
return(align_obj)
}
return(align_obj)
}
Expand Down
Loading

0 comments on commit cf52db6

Please sign in to comment.