Last active
November 25, 2019 18:37
-
-
Save chasemc/489cc798655c1b4c815a1649b6045ece to your computer and use it in GitHub Desktop.
Run msconvert in parallel from R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Requires IDBac function findMSconvert() | |
parallel_msconvert <- function(directory){ | |
# File paths | |
raw_path <- file.path(directory) | |
raw_files <- list.files(raw_path, | |
full.names = TRUE) | |
mzml_dir <- file.path(dirname(raw_path), | |
"mzml") | |
dir.create(mzml_dir) | |
# Run msconvert in parallel | |
msconvert_location <- normalizePath(IDBacApp::findMSconvert(), | |
winslash = "/") | |
msconvert_cmd <- lapply(raw_files, | |
function(raw_files){ | |
paste0(shQuote(msconvert_location), | |
" ", | |
shQuote(raw_files), | |
" ", | |
"--mzML", | |
" ", | |
'--filter "peakPicking true 1-" --filter "threshold count 100 most-intense"', | |
" ", | |
"-o", | |
" ", | |
shQuote(mzml_dir)) | |
}) | |
numCores <- parallel::detectCores() | |
numCores <- ifelse(numCores > 2, | |
numCores - 1, | |
1) | |
cl <- parallel::makeCluster(numCores) | |
functionTOrunMSCONVERTonCMDline <- function(x){ | |
system(command = x, | |
invisible = T, | |
wait = TRUE) | |
} | |
parallel::parLapply(cl, | |
msconvert_cmd, | |
functionTOrunMSCONVERTonCMDline) | |
parallel::stopCluster(cl) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment