Skip to content

Instantly share code, notes, and snippets.

@chasemc
Last active November 25, 2019 18:37
Show Gist options
  • Save chasemc/489cc798655c1b4c815a1649b6045ece to your computer and use it in GitHub Desktop.
Save chasemc/489cc798655c1b4c815a1649b6045ece to your computer and use it in GitHub Desktop.
Run msconvert in parallel from R
# 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