knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(rmzTabM) library(kableExtra)
You can read an mzTab-M file in tab separated format into a data frame structure as follows:
testfile <- system.file("testdata", c("lipidomics-example.mzTab"), package="rmzTabM") mzTabTable <- readMzTab(testfile) kable(head(mzTabTable[,1:3])) %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", font_size = 7)) %>% scroll_box(width = "800px", height = "200px")
You can extract the individual section tables from this one as follows:
mtdTable <- extractMetadata(mzTabTable) smlTable <- extractSmallMoleculeSummary(mzTabTable) smfTable <- extractSmallMoleculeFeatures(mzTabTable) smeTable <- extractSmallMoleculeEvidence(mzTabTable) knitr::kable(head(smlTable)) %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", font_size = 7)) %>% scroll_box(width = "800px", height = "200px") knitr::kable(head(smfTable)) %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", font_size = 7)) %>% scroll_box(width = "800px", height = "200px") knitr::kable(head(smeTable)) %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", font_size = 7)) %>% scroll_box(width = "800px", height = "200px")
To turn these tables into objects, use the R6 class constructor method new()
:
mzTabObject <- MzTab$new()$fromDataFrame(mzTabTable)
You can then access sections like Metadata as object members:
# this is an R6 object metadata <- mzTabObject$metadata # these are lists smallMoleculeSummaryEntries <- mzTabObject$smallMoleculeSummary smallMoleculeFeatureEntries <- mzTabObject$smallMoleculeFeature smallMoleculeEvidenceEntries <- mzTabObject$smallMoleculeEvidence
Extracting values is possible from either representation, depending on whether you prefer a tabular style or an object oriented style, however, there may be type differences:
# this is the SmallMoleculeSummary list first entry id smallMoleculeSummaryEntries[[1]]$sml_id # and this is the same with the data frame as.numeric(smlTable$SML_ID)
If you have an mzTab-M data frame, you can write it as follows:
utils::write.table( mzTabTable, file = file.path(tempdir(check=TRUE), "mzTabWrite1.mztab"), row.names = FALSE, col.names = FALSE, quote = FALSE, sep = "\t", na = "", fileEncoding = "UTF8" )
For an MzTab object, you can write to the tab separated format:
writeMzTab(mzTabObject, file.path(tempdir(check=TRUE), "mzTabWrite2.mztab"))
Or to JSON format:
writeMzTabJSON(mzTabObject, file.path(tempdir(check=TRUE), "mzTabWrite3.mztab.json"))
To validate an mzTab-M file, you can access the mzTab Validator web application at https://apps.lifs-tools.org/mztabvalidator
You can set the validationLevel
to one of info
, warning
or error
. If you enable semanticValidation
, CV parameters present in your file will be checked against the default recommended mapping file.
In order to validate an mzTab-M file without needing to parse it locally, use the following call, which should return an empty list:
validatePlainFile <- system.file("testdata", c("lipidomics-example.mzTab"),package="rmzTabM") mzTabString <- readChar(validatePlainFile, file.info(testfile)$size) validationMessages2 <- validateMzTab( mzTabString, validationMode = "plain", validationLevel = "info", maxErrors = 100, semanticValidation = FALSE ) if(length(validationMessages2)==0) { print("No validation messages") } else { validationMessages2 }
Alternatively, to run the validation with semantic checks of the used CV parameters against the default mapping file, which will give you hints on how to improve your file:
validationMessages2 <- validateMzTab( mzTabString, validationMode = "plain", validationLevel = "info", maxErrors = 100, semanticValidation = TRUE ) dfList<-lapply(validationMessages2, function(x) { data.frame("Category"=x$category, "Message"=x$code) }) vmdf <- do.call("rbind", dfList) knitr::kable(vmdf) %>% kable_styling(bootstrap_options = c("striped", "hover", "condensed", font_size = 7)) %>% scroll_box(width = "800px", height = "1000px")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.