Skip to content

Commit

Permalink
2023-12-03
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhang503 committed Dec 3, 2023
1 parent add0966 commit 676c56e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 25 deletions.
8 changes: 5 additions & 3 deletions R/ms2frames.R
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ hpair_mgths <- function (ms1_offset = 0, notch = NULL, mgfs, n_modules,
else {
mgfs <- make_dia_mgfs(mgfs = mgfs, mgf_path = mgf_path, quant = quant,
min_mass = min_mass, ppm_ms1_bin = ppm_ms1_bin)
mgfs <- mgfs[names(mgfs) != "-Inf"] # unknown precursors
}

# to chunks: each chunk has multiple frames: each frame multiple precursors
Expand Down Expand Up @@ -265,13 +266,14 @@ make_dia_mgfs <- function (mgfs, mgf_path, quant = "none", min_mass = 200L,
data_ms2 <- data_ms2[seqs, ]
mgfs <- dplyr::bind_cols(datalist, dataflat, data_ms2)

# rm(list = c("datalist", "dataflat", "scans", "data_ms2",
# "col_nms", "cols_list", "cols_flat", "cols_ms2"))

ord <- order(mgfs$ms1_mass)
mgfs <- mgfs[ord, ]
ms1_bins <- ceiling(log(mgfs$ms1_mass/min_mass)/log(1+ppm_ms1_bin/1e6))

# ms1_bins can be -Inf or NA since
# (1) ms1_moverz can be NA because not yet determined by the current algorithm
# (2) ms1_mass can also be NA due to ms1_charge being NA
# (3) ms1_charge can be zero since undetermined
mgfs <- split(mgfs, ms1_bins)
}

Expand Down
5 changes: 3 additions & 2 deletions R/msmsmatches2.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,13 @@ ms2match <- function (mgf_path, aa_masses_all, out_path, .path_bin,

delete_files(
out_path,
ignores = c(mgf_path, "\\.[Rr]$", "\\.(mgf|MGF)$", "\\.(mzML|mzml)$",
ignores = c("\\.[Rr]$", "\\.(mgf|MGF)$", "\\.(mzML|mzml)$",
"\\.xlsx$", "\\.xls$", "\\.csv$", "\\.txt$", "\\.pars$",
"^mgf$", "^mgfs$", "^mzML$", "^mzMLs$",
"Calls", "^PSM$", "^Peptide$", "^Protein$",
"fraction_scheme.rda", "label_scheme.rda",
"label_scheme_full.rda"))
"label_scheme_full.rda"),
paths_excluded = mgf_path)

# pairs expts and theos
files_a <- list.files(mgf_path, pattern = "^expttheo_", full.names = TRUE)
Expand Down
38 changes: 19 additions & 19 deletions R/utils_os.R
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,9 @@ match_calltime <- function (path = "~/mzion/.MSearches/Cache/Calls",
#'
#' @param path A file path.
#' @param ignores The file extensions to be ignored.
#' @param paths_excluded The path to be ignored.
#' @param ... Arguments for file.remove.
delete_files <- function (path, ignores = NULL, ...)
delete_files <- function (path, ignores = NULL, paths_excluded = NULL, ...)
{

# Hadley Ch.19 Quasiquotation, note 97
Expand All @@ -577,27 +578,26 @@ delete_files <- function (path, ignores = NULL, ...)

nms <- do.call(list.files, args)

if (!is.null(ignores)) {
nms <- local({
dirs <- list.dirs(path, full.names = FALSE, recursive = recursive)
dirs <- dirs[dirs != ""]
if (length(nms) && length(paths_excluded)) {
ignore_case <- if (Sys.info()['sysname'] == "Windows") TRUE else FALSE

for (i in seq_along(paths_excluded))
nms <- nms[!grepl(paths_excluded[[i]], nms, ignore.case = ignore_case)]
}

idxes_kept <- purrr::map_lgl(dirs, function (x) any(grepl(x, ignores)))
nms_kept <- list.files(path = file.path(path, dirs[idxes_kept]),
recursive = TRUE, full.names = TRUE)
nms[! nms %in% nms_kept]
})
if (!is.null(ignores)) {
dirs <- list.dirs(path, full.names = FALSE, recursive = recursive)
dirs <- dirs[dirs != ""]
oks <- purrr::map_lgl(dirs, function (x) any(grepl(x, ignores)))
nms_oks <- list.files(path = file.path(path, dirs[oks]),recursive = TRUE,
full.names = TRUE)
nms <- nms[!nms %in% nms_oks]

nms <- local({
exts <- gsub("^.*(\\.[^.]*)$", "\\1", nms)
idxes_kept <- purrr::map_lgl(exts, function (x) any(grepl(x, ignores)))

nms[!idxes_kept]
})
exts <- gsub("^.*(\\.[^.]*)$", "\\1", nms)
oks <- purrr::map_lgl(exts, function (x) any(grepl(x, ignores)))
nms <- nms[!oks]
}

if (length(nms))
suppressMessages(file.remove(file.path(nms)))

Expand Down
4 changes: 3 additions & 1 deletion man/delete_files.Rd

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

0 comments on commit 676c56e

Please sign in to comment.