fgcz / rawDiag

Brings Orbitrap mass spectrometry data to life; multi-platform, fast and colorful R package
https://bioconductor.org/packages/rawDiag
36 stars 11 forks source link

implement a read.raw.info method #49

Closed cpanse closed 5 years ago

cpanse commented 5 years ago
.read.raw.info <- function(file,
     mono = if(Sys.info()['sysname'] %in% c("Darwin", "Linux")) TRUE else FALSE,
     exe = file.path(path.package(package = "rawDiag"), "exec", "fgcz_raw.exe"),
     mono_path = "",
     argv = "info",
     system2_call = TRUE,
     method = "thermo"){

  if(system2_call && method == 'thermo'){

    tf <- tempfile(fileext = '.tsv')
    tf.err <- tempfile(fileext = '.tsv')

    message(paste("system2 is writting to tempfile ", tf, "..."))

    if (mono){
      rvs <- system2("mono", args = c(exe, shQuote(file), argv),
                     stdout = tf)
    }else{
      rvs <- system2(exe, args = c(shQuote(file), argv),
                     stderr = tf.err,
                     stdout = tf)
    }

    if (rvs == 0){
      rv <- read.csv(tf,  sep = ":",   stringsAsFactors = TRUE, header = FALSE,
                     col.names = c('attribute', 'value'))

      message(paste("unlinking", tf, "..."))

      unlink(tf)
      # unlink(tfstdout)
      return(rv)
    }
  }
  NULL
}
cpanse commented 5 years ago

https://github.com/fgcz/rawDiag/blob/c50ff4079aad823aa94ffae8639bbc2d7c91ddb0/R/rawDiag.R#L524

witszymanski commented 5 years ago

It works! Confirmed! Thanks for the great piece of code. Witold Szymanski

cpanse commented 5 years ago

Screenshot 2019-05-28 at 09 09 11

@kaniawave since version 0.0.34 there is a rawDiag::read.raw.info function.

(rawfile <- file.path(path.package(package = 'rawDiag'), 'extdata', 'sample.raw'))
Y <- read.raw.info(rawfile)