Chapter 2 File converter

The script 1.Pipeline_extension_format_converter.R is available under the folder of J:\CBMR\SUN-CBMR-Metabolomics\Workflow\Script\modules

2.1 Source paths on the server

source("H:/From_SUND/Scripts/utils/utils_MS2_set_up/set_up_paths.R")

2.2 Specify the polarity πŸ•΅

polarity <- "POS" #other options "NEG", "c("POS", "NEG")"

2.3 Path of application of openms πŸ•΅

path_openms <- "C:/Program Files/OpenMS-2.8.0/bin"

2.4 Path of storing files (.mzML) exported from dataanalysis for each polarity πŸ•΅

path_files_from_DA <- "H:/From_SUND/Scripts/test/MS2pos_untarget"

2.5 Conduct

2.5.1 Add extension (if not available) to files exported from dataanalysis

files_from_DA <- list.files(path_files_from_DA, full.names = TRUE)
id_not_ext <- setdiff(1:length(files_from_DA), 
                      grep("\\.mzML$|\\.d$", basename(files_from_DA)))


if (length(id_not_ext) != 0) {
  

  file.rename(files_from_DA[id_not_ext],
              paste0(files_from_DA[id_not_ext], ".mzML")
             )
}

2.5.2 File converter for adapting to run XCMS

source(paste0(path_func, "/file-conversion.R"))

#Create a sibling folder for storing files from openms
path_files_from_openms <- paste0(dirname(path_files_from_DA), "/mzML_openms_MS2_", polarity)
if (!dir.exists(file.path(path_files_from_openms))) dir.create(path_files_from_openms, showWarnings = FALSE, recursive = TRUE)

#conduct converting  
mapply(function(x, y) file_conversion(x,y, path_openms, ".mzML", ".mzML"), path_files_from_openms, path_files_from_DA)