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

support open file standards through Bioconductor mzR package - make it PSI friendly #9

Closed cpanse closed 6 years ago

cpanse commented 6 years ago

to benefit from to the fantastic PSI world.

wolski commented 6 years ago

Map columns from RawDiag to CV terms.

c("filename", "scanNumber", "StartTime", "BasePeakMass", "BasePeakIntensity", "TIC", "ScanType", "CycleNumber", "MSOrder", "MassAnalyzer", "PrecursorMass", "ChargeState", "IonInjectionTimems", "FTResolution", "MasterScanNumber", "LMCorrection", "ElapsedScanTimesec", "transient", "AGC", "AGCMode", "PrescanMode")

https://raw.githubusercontent.com/HUPO-PSI/psi-ms-CV/master/psi-ms.obo

tobiasko commented 6 years ago

I will most likely not manage to do this before 15th of May (application deadline).

cpanse commented 6 years ago

the code snippet below should do the job

#' mzR reader method
#'
#' @param object an mzR object
#'
#' @return an \code{\link{rawDiag}} object
#' @author Christian Panse <cp@fgcz.ethz.ch>, Witold E.Wolski <wew@fgcz.ethz.ch>
#' @example 
#' 
#' library(mzR)
#' mzmlFilename <- "PXD006932/Exp3A/20161213_NGHF_DBJ_SA_Exp3A_HeLa_1ug_15min_15000_01.mzML"
#' S <- as.rawDiag.mzR(openMSfile(mzmlFilename))
#' 
as.rawDiag.mzR <- function(object){
  #time.start <- Sys.time()
  runInfo <- runInfo(object)
  rv <- lapply(1:runInfo$scanCount, 
               function(x){data.frame(header(object, x))})
  rv <- bind_rows(rv)

  #time.end <- Sys.time()
  #message(time.start - time.end)

  rv <- rv[, c('acquisitionNum', 'retentionTime', 'basePeakMZ',
               'basePeakIntensity', 'totIonCurrent', 'msLevel', 'precursorMZ',
               'precursorCharge')]

  colnames(rv) <- c('scanNumber', 'StartTime', 'BasePeakMass',
                    'BasePeakIntensity', 'TIC', 'MSOrder', 'PrecursorMass',
                    'ChargeState')

  rv$filename <- basename(fileName(object))
  as.rawDiag(rv)
}