| Title: | Creation, Reading and Validation of 'mzqc' Files |
|---|---|
| Description: | Reads, writes and validates 'mzQC' files. The 'mzQC' format is a standardized file format for the exchange, transmission, and archiving of quality metrics derived from biological mass spectrometry data, as defined by the HUPO-PSI (Human Proteome Organisation - Proteomics Standards Initiative) Quality Control working group. See <https://hupo-psi.github.io/mzQC/> for details. |
| Authors: | Chris Bielow [aut, cre] (ORCID: <https://orcid.org/0000-0001-5756-3988>), David Jimenez-Morales [rev, ctb] (ORCID: <https://orcid.org/0000-0003-4356-6461>), Jeremi Maciejewski [ctb] |
| Maintainer: | Chris Bielow <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.7.0 |
| Built: | 2026-05-17 08:15:27 UTC |
| Source: | https://github.com/ms-quality-hub/rmzqc |
Checks the value's class type, which should match at least of the types given in any_expected_class_types.
check_type(value, any_expected_class_types, expected_length = 0)check_type(value, any_expected_class_types, expected_length = 0)
value |
A certain value (e.g. a single value, data.frame etc) |
any_expected_class_types |
A vector of valid class types, any of which the @p value should have |
expected_length |
The expected length of value (usually to check if its a single value); 0 (default) indicates that length can be ignored |
check_type(1, "numeric", 1) # TRUE check_type("1", "numeric", 1) # FALSE check_type(1, "numeric", 2) # FALSE check_type("ABC", "character", 1) # TRUE check_type("ABC", "character") # TRUE check_type("ABC", "character", 2) # FALSE check_type(c("ABC", "DEF"), "character", 2) # TRUE check_type(1.1, c("numeric", "double")) # TRUE check_type(1.1, c("numeric", "double"), 1) # TRUE check_type(matrix(1:9, nrow=3), "matrix") # TRUE check_type(data.frame(a=1:3, b=4:6), c("something", "data.frame")) # TRUEcheck_type(1, "numeric", 1) # TRUE check_type("1", "numeric", 1) # FALSE check_type(1, "numeric", 2) # FALSE check_type("ABC", "character", 1) # TRUE check_type("ABC", "character") # TRUE check_type("ABC", "character", 2) # FALSE check_type(c("ABC", "DEF"), "character", 2) # TRUE check_type(1.1, c("numeric", "double")) # TRUE check_type(1.1, c("numeric", "double"), 1) # TRUE check_type(matrix(1:9, nrow=3), "matrix") # TRUE check_type(data.frame(a=1:3, b=4:6), c("something", "data.frame")) # TRUE
Define a Singleton class which can hold a CV dictionary (so we do not have to load the .obo files over and over again)
Get the full data by calling the 'getData()' function (which returns a list containing a 'CV', 'URI' and 'version'),
or 'getCV()' which is a shorthand for 'getData()$CV'.
You can set your own custom CV by calling 'setData()'. By default, the latest release of the PSI-MS-CV (see getCVDictionary).
Wherever you need this data, simply re-grab the singleton using 'CV_$new()' (or use the convenience function getCVSingleton() from outside the package)
R6P::Singleton -> CV_
ensureHasData()
Make sure that the CV data is loaded
CV_$ensureHasData()
byID()
A function to retrieve a CV entry using its ID
CV_$byID(id)
idA CV accession, e.g. 'MS:1000560'
A CV term, or NULL if the ID is unknown
setData()
Set a user-defined object (= a list of 'CV', 'URI' and 'version'), as obtained from getCVDictionary
CV_$setData(cv_data)
cv_dataThe result of a call to getCVDictionary
getData()
Gets the underlying data (CV, URI and version)
CV_$getData()
getCV()
A shorthand for 'getData()$CV', i.e. the CV data.frame.
CV_$getCV()
## Not run: cv_dict = CV_$new() ## uses 'getCVDictionary()' to populate the singleton cv_2 = CV_$new() ## uses the same data without parsing again cv_2$setData(getCVDictionary("custom", "https://my.com/custom.obo")) ## End(Not run)## Not run: cv_dict = CV_$new() ## uses 'getCVDictionary()' to populate the singleton cv_2 = CV_$new() ## uses the same data without parsing again cv_2$setData(getCVDictionary("custom", "https://my.com/custom.obo")) ## End(Not run)
The following mapping is currently known: .raw : MS:1000563 ! Thermo RAW format .mzML : MS:1000584 ! mzML format .mzData : MS:1000564 ! PSI mzData format .wiff : MS:1000562 ! ABI WIFF format .pkl : MS:1000565 ! Micromass PKL format .mzXML : MS:1000566 ! ISB mzXML format .yep : MS:1000567 ! Bruker/Agilent YEP format .dta : MS:1000613 ! Sequest DTA format .mzMLb : MS:1002838 ! mzMLb format
filenameToCV(filepath)filenameToCV(filepath)
filepath |
A filename (with optional path) |
Falls back to 'MS:1000560 ! mass spectrometer file format' if no match could be found.
Upper/lowercase is ignored, i.e. "mzML == mzml".
A CV term accession as string, e.g. 'MS:1000584'
filenameToCV("test.mZmL") # MS:1000584 filenameToCV("test.raw") # MS:1000563 filenameToCV(c("test.raw", "bla.mzML"))filenameToCV("test.mZmL") # MS:1000584 filenameToCV("test.raw") # MS:1000563 filenameToCV(c("test.raw", "bla.mzML"))
Allow conversion of plain named lists of R objects (from jSON) to mzQC objects
fromDatatoMzQC(mzqc_class, data, context = NULL)fromDatatoMzQC(mzqc_class, data, context = NULL)
mzqc_class |
Prototype of the class to convert 'data' into |
data |
A list of: A datastructure of R lists/arrays as obtained by 'jsonlite::fromJSON()' |
context |
A trace through the mzQC object tree to aid users in case of errors |
data = rmzqc::MzQCcvParameter$new("acc", "myName", "value") data_recovered = rmzqc::fromDatatoMzQC(rmzqc::MzQCcvParameter, list(jsonlite::fromJSON(jsonlite::toJSON(data))))data = rmzqc::MzQCcvParameter$new("acc", "myName", "value") data_recovered = rmzqc::fromDatatoMzQC(rmzqc::MzQCcvParameter, list(jsonlite::fromJSON(jsonlite::toJSON(data))))
If you have a list of elements, call fromDatatoMzQC.
fromDatatoMzQCobj(mzqc_class, data, context = NULL)fromDatatoMzQCobj(mzqc_class, data, context = NULL)
mzqc_class |
Prototype of the class to convert 'data' into |
data |
A datastructure of R lists/arrays as obtained by 'jsonlite::fromJSON()' |
context |
A trace through the mzQC object tree to aid users in case of errors |
data = MzQCcvParameter$new("acc", "myName", "value") data_recovered = fromDatatoMzQCobj(MzQCcvParameter, jsonlite::fromJSON(jsonlite::toJSON(data))) data_recovereddata = MzQCcvParameter$new("acc", "myName", "value") data_recovered = fromDatatoMzQCobj(MzQCcvParameter, jsonlite::fromJSON(jsonlite::toJSON(data))) data_recovered
If use_local_fallback is TRUE, this function will never fail. Otherwise, it may fail if the internet connection
is flawed or internal URLs related to GitHubs API become stale.
getCVDictionary( source = c("latest", "local", "custom"), custom_uri = NULL, use_local_fallback = TRUE )getCVDictionary( source = c("latest", "local", "custom"), custom_uri = NULL, use_local_fallback = TRUE )
source |
Where to get the PSI-MS CV from: - 'latest' will download 'psi-ms.obo' from https://api.github.com/repos/HUPO-PSI/psi-ms-CV/releases/latest - 'local' will use rmzqc/cv/psi-ms.obo' (which might be outdated, if you need the latest terms) - 'custom' uses a user-defined URI in 'custom_uri' |
custom_uri |
Used when 'source' is set to 'custom'. The URI can be local or remote, e.g. 'c:/obo/my.obo' or 'https://www.abc.com/my.obo' |
use_local_fallback |
When downloading a file from a URI fails, should we fall back to the local psi-ms.obo shipped with rmzqc? |
A 'pato.obo', and 'uo.obo' from the 'rmzqc/cv/' folder are automatically merged into the result.
See CV_ class to use this function efficiently.
A list with 'CV', 'URI' and 'version', where 'CV' is a data.frame with columns 'id', 'name', 'def', 'parents', 'children' (and many more) which contains the CV entries
MzQCcontrolledVocabulary for the currently used CV (see getCVSingleton)
using getCVSingleton()$getData()$URI and $version.Returns an MzQCcontrolledVocabulary for the currently used CV (see getCVSingleton)
using getCVSingleton()$getData()$URI and $version.
getCVInfo()getCVInfo()
CV_.Returns the CV singleton. See CV_.
getCVSingleton()getCVSingleton()
Fills a MzQCcvParameter object with id(accession) and name. The value (if any) needs to be set afterwards.
getCVTemplate(accession, CV = getCVSingleton())getCVTemplate(accession, CV = getCVSingleton())
accession |
The ID (=accession) of the term in the CV |
CV |
A CV dictionary, as obtained by getCVDictionary(); defaults to the global singleton, which is populated automatically |
An instance of MzQCcvParameter
getCVSingleton)Returns an MzQCcontrolledVocabulary for the currently used CV (see getCVSingleton)
getDefaultCV()getDefaultCV()
This function will be deprecated soon. Use getCVInfo instead.
This may fail (e.g. if no internet connection is available, or URLs became invalid) then 'NULL' will be returned instead of an URL. A warning may be emitted, if the URL is out of date (i.e. the GitHub API changed).
getLatest_PSICV_URL()getLatest_PSICV_URL()
Obtains the 'data-version' from a local (i.e. non-url) PSI-MS-CV
getLocal_CV_Version(local_PSIMS_obo_file)getLocal_CV_Version(local_PSIMS_obo_file)
local_PSIMS_obo_file |
A path to a local file, e.g. 'c:/temp/my.obo' |
getLocal_CV_Version(system.file("./cv/psi-ms.obo", package="rmzqc")) # "4.1.95"getLocal_CV_Version(system.file("./cv/psi-ms.obo", package="rmzqc")) # "4.1.95"
The accession must be valid (or allow_unknown_id must be TRUE)
getQualityMetricTemplate( accession, CV = getCVSingleton(), allow_unknown_id = FALSE )getQualityMetricTemplate( accession, CV = getCVSingleton(), allow_unknown_id = FALSE )
accession |
The ID (=accession) of the term in the CV |
CV |
A CV dictionary, as obtained by getCVDictionary(); defaults to the global singleton, which is populated automatically |
allow_unknown_id |
Allows invalid accession; if 'FALSE' this function errors if accession is unknown |
An instance of MzQCqualityMetric
Get a syntax validator for mzQC
getSyntaxValidator()getSyntaxValidator()
Checks if filepath ends in suffix (ignoring lower/upper case differences). If suffix does not start with a '.' it is prepended automatically.
hasFileSuffix(filepath, suffix)hasFileSuffix(filepath, suffix)
filepath |
A relative or absolute path to a file, whose suffix is checked |
suffix |
This is the suffix we expect (the '.' is prepended internally if missing) |
TRUE if yes, FALSE otherwise
hasFileSuffix("bla.txt", "txt") # TRUE hasFileSuffix("bla.txt", ".txt") # TRUE hasFileSuffix("bla.txt", ".TXT") # TRUE hasFileSuffix("foo", "") # TRUE hasFileSuffix("", "") # TRUE hasFileSuffix("bla.txt", "doc") # FALSE hasFileSuffix("bla.txt", ".doc") # FALSE hasFileSuffix("fo", ".doc") # FALSE hasFileSuffix("", ".doc") # FALSEhasFileSuffix("bla.txt", "txt") # TRUE hasFileSuffix("bla.txt", ".txt") # TRUE hasFileSuffix("bla.txt", ".TXT") # TRUE hasFileSuffix("foo", "") # TRUE hasFileSuffix("", "") # TRUE hasFileSuffix("bla.txt", "doc") # FALSE hasFileSuffix("bla.txt", ".doc") # FALSE hasFileSuffix("fo", ".doc") # FALSE hasFileSuffix("", ".doc") # FALSE
You can pass multiple variable, which are all checked. If any of them is undefined, the function returns TRUE
isUndefined(s, ..., verbose = TRUE, context = NULL)isUndefined(s, ..., verbose = TRUE, context = NULL)
s |
A variable to be checked for NA/NULL |
... |
More variable to be checked |
verbose |
If TRUE and 's' is NULL/NA, will print the name of the variable which was passed in |
context |
An optional string will be using within a warning message, to ease tracking of where in the mzQC structure the undefined value occurs |
isUndefined(NA) ## TRUE isUndefined(NULL) ## TRUE isUndefined(NA, NULL) ## TRUE isUndefined("") ## FALSE isUndefined(list(1,2,3)) ## FALSE isUndefined("", NA) ## TRUE isUndefined(NA, "") ## TRUE isUndefined(1) ## FALSE myVar = NA isUndefined(myVar) ## TRUE, with warning "Variable 'myVar' is NA/NULL!"isUndefined(NA) ## TRUE isUndefined(NULL) ## TRUE isUndefined(NA, NULL) ## TRUE isUndefined("") ## FALSE isUndefined(list(1,2,3)) ## FALSE isUndefined("", NA) ## TRUE isUndefined(NA, "") ## TRUE isUndefined(1) ## FALSE myVar = NA isUndefined(myVar) ## TRUE, with warning "Variable 'myVar' is NA/NULL!"
Note: Returns TRUE for empty lists!
isValidMzQC(x, parent_context = NULL)isValidMzQC(x, parent_context = NULL)
x |
An mzQC R6 class (or list of them), which will be subjected to validation |
parent_context |
Internal parameter used to track the path in nested validations |
This function checks if an mzQC object or a list of mzQC objects is valid. For lists, all elements need to be valid for the function to return TRUE. The function provides detailed error messages that include the path to the invalid field, making it easier to identify validation issues in complex nested structures.
isValidMzQC(MzQCcvParameter$new("MS:4000059")) # FALSE isValidMzQC(MzQCcvParameter$new("MS:4000059", "Number of MS1 spectra")) # TRUE isValidMzQC(list(MzQCcvParameter$new("MS:4000059"))) # FALSE isValidMzQC(list(MzQCcvParameter$new("MS:4000059", "Number of MS1 spectra"))) # TRUEisValidMzQC(MzQCcvParameter$new("MS:4000059")) # FALSE isValidMzQC(MzQCcvParameter$new("MS:4000059", "Number of MS1 spectra")) # TRUE isValidMzQC(list(MzQCcvParameter$new("MS:4000059"))) # FALSE isValidMzQC(list(MzQCcvParameter$new("MS:4000059", "Number of MS1 spectra"))) # TRUE
Relative filenames are made absolute. Backslashes as path separators are replaced by forward slashes (as commonly seen on Windows).
localFileToURI(local_filename, must_exist = TRUE)localFileToURI(local_filename, must_exist = TRUE)
local_filename |
Path to a file (can be relative to current getwd(); or absolute) |
must_exist |
Require the file to exist |
A URI starting with "file:///" followed by an absolute path
Details of the software used to create the QC metrics
Details of the software used to create the QC metrics
accessionAccession number identifying the term within its controlled vocabulary.
nameName of the controlled vocabulary term describing the software tool.
versionVersion number of the software tool.
uriPublicly accessible URI of the software tool or documentation.
description(optional) Definition of the controlled vocabulary term.
value(optional) Name of the software tool.
new()
Constructor
MzQCanalysisSoftware$new( accession = NA_character_, name = NA_character_, version = NA_character_, uri = NA_character_, description = NA_character_, value = NA_character_ )
accessionString value for initialization of field accession
nameString value for initialization of field name
versionString value for initialization of field version
uriOptional string value for initialization of field uri
descriptionOptional string value for initialization of field description
valueOptional string value for initialization of field value
isValid()
Verifies validity of the object
MzQCanalysisSoftware$isValid(context = "MzQCanalysisSoftware")
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
toJSON()
Creates JSON file from this object.
MzQCanalysisSoftware$toJSON(...)
...Optional parameters for jsonlite:::asJSON()
fromData()
Sets data for this object from plain named lists of R objects
MzQCanalysisSoftware$fromData(data, context = "MzQCanalysisSoftware")
dataA datastructure of R lists/arrays as obtained by 'jsonlite::fromJSON()'
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
clone()
The objects of this class are cloneable with this method.
MzQCanalysisSoftware$clone(deep = FALSE)
deepWhether to make a deep clone.
Base class of runQuality/setQuality
Base class of runQuality/setQuality
metadataThe metadata for this run/setQuality
qualityMetricsArray of MzQCqualityMetric objects
new()
Constructor
MzQCbaseQuality$new(metadata = MzQCmetadata$new(), qualityMetrics = list())
metadataOptional MzQCmetadata value for initialization of field metadata
qualityMetricsOptional list value for initialization of field qualityMetrics
isValid()
Verifies validity of the object
MzQCbaseQuality$isValid(context = "MzQCbaseQuality")
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
getMetric()
Fetches metrics which match specified accession or name from the object.
MzQCbaseQuality$getMetric(accession = NULL, name = NULL)
accessionSearch by accession
nameSearch by name
toJSON()
Creates JSON file from this object.
MzQCbaseQuality$toJSON(...)
...Optional parameters for jsonlite:::asJSON()
fromData()
Sets data for this object from plain named lists of R objects
MzQCbaseQuality$fromData(mdata, context = "MzQCbaseQuality")
mdataA datastructure of R lists/arrays as obtained by 'jsonlite::fromJSON()'
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
clone()
The objects of this class are cloneable with this method.
MzQCbaseQuality$clone(deep = FALSE)
deepWhether to make a deep clone.
You must provide either the accession or the name of the metric, but not both.
accession |
Accession of the MzQCqualityMetric |
name |
Name of the MzQCqualityMetric (less stable than accession) |
Usually there should be only one MzQCqualityMetric which matches, however, this function will return all matches.
Note: this function will stop() if not results are found
A list of MzQCqualityMetric's which match.
A controlled vocabulary document, usually pointing to an .obo file
A controlled vocabulary document, usually pointing to an .obo file
nameFull name of the controlled vocabulary.
uriPublicly accessible URI of the controlled vocabulary.
version(optional) Version of the controlled vocabulary.
new()
Constructor
MzQCcontrolledVocabulary$new( name = NA_character_, uri = NA_character_, version = NA_character_ )
nameString value for initialization of field name
uriString value for initialization of field uri
versionOptional string value for initialization of field version
isValid()
Verifies validity of the object
MzQCcontrolledVocabulary$isValid(context = "MzQCcontrolledVocabulary")
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
toJSON()
Creates JSON file from this object.
MzQCcontrolledVocabulary$toJSON(...)
...Optional parameters for jsonlite:::asJSON()
fromData()
Sets data for this object from plain named lists of R objects
MzQCcontrolledVocabulary$fromData(data, context = "MzQCcontrolledVocabulary")
dataA datastructure of R lists/arrays as obtained by 'jsonlite::fromJSON()'
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
clone()
The objects of this class are cloneable with this method.
MzQCcontrolledVocabulary$clone(deep = FALSE)
deepWhether to make a deep clone.
MzQCcontrolledVocabulary$new( "Proteomics Standards Initiative Quality Control Ontology", "https://github.com/HUPO-PSI/psi-ms-CV/releases/download/v4.1.129/psi-ms.obo", "4.1.129")MzQCcontrolledVocabulary$new( "Proteomics Standards Initiative Quality Control Ontology", "https://github.com/HUPO-PSI/psi-ms-CV/releases/download/v4.1.129/psi-ms.obo", "4.1.129")
A controlled vocabulary parameter, as detailed in the OBO file
A controlled vocabulary parameter, as detailed in the OBO file
accessionAccession number identifying the term within its controlled vocabulary.
nameName of the controlled vocabulary term describing the parameter.
value(optional) Value of the parameter.
description(optional) Definition of the controlled vocabulary term.
new()
Constructor
MzQCcvParameter$new( accession = NA_character_, name = NA_character_, value = NA, description = NA_character_ )
accessionString value for initialization of field accession
nameString value for initialization of field name
valueOptional value for initialization of field value
descriptionOptional string value for initialization of field description
isValid()
Verifies validity of the object
MzQCcvParameter$isValid(context = "MzQCcvParameter")
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
toJSON()
Creates JSON file from this object.
MzQCcvParameter$toJSON(...)
...Optional parameters for jsonlite:::asJSON()
fromData()
Sets data for this object from plain named lists of R objects
MzQCcvParameter$fromData(data, context = "MzQCcvParameter")
dataA datastructure of R lists/arrays as obtained by 'jsonlite::fromJSON()'
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
clone()
The objects of this class are cloneable with this method.
MzQCcvParameter$clone(deep = FALSE)
deepWhether to make a deep clone.
MzQCcvParameter$new("MS:4000070", "retention time acquisition range", c(0.2959, 5969.8172)) isValidMzQC(MzQCcvParameter$new("MS:0000000"))MzQCcvParameter$new("MS:4000070", "retention time acquisition range", c(0.2959, 5969.8172)) isValidMzQC(MzQCcvParameter$new("MS:0000000"))
An mzQC-formatted date+time in ISO8601 format, as required by the mzQC spec doc.
An mzQC-formatted date+time in ISO8601 format, as required by the mzQC spec doc.
The format is "%Y-%m-%dT%H:%M:%S".
datetimeA correctly formatted date time (use as read-only)
new()
Constructor
MzQCDateTime$new(date = as.character(Sys.time()))
dateOptional POSIXct value for initialization of field datetime. Defaults to Sys.time()
set()
Sets datetime value
MzQCDateTime$set(date)
dateNew date-time
isValid()
Verifies validity of the object
MzQCDateTime$isValid(context = "MzQCDateTime")
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
toJSON()
Creates JSON file from this object.
MzQCDateTime$toJSON(...)
...Optional parameters for jsonlite:::asJSON()
fromData()
Sets data for this object from plain named lists of R objects
MzQCDateTime$fromData(data, context = "MzQCDateTime")
dataA datastructure of R lists/arrays as obtained by 'jsonlite::fromJSON()'
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
clone()
The objects of this class are cloneable with this method.
MzQCDateTime$clone(deep = FALSE)
deepWhether to make a deep clone.
dt1 = MzQCDateTime$new("1900-01-01") ## yields "1900-01-01T00:00:00Z" dt2 = MzQCDateTime$new(Sys.time()) ## test faulty input ## errors with 'character string is not in a standard unambiguous format' try(MzQCDateTime$new('lala'), silent=TRUE) ## test roundtrip conversion from/to JSON dt2$fromData(jsonlite::fromJSON(jsonlite::toJSON(dt1)))dt1 = MzQCDateTime$new("1900-01-01") ## yields "1900-01-01T00:00:00Z" dt2 = MzQCDateTime$new(Sys.time()) ## test faulty input ## errors with 'character string is not in a standard unambiguous format' try(MzQCDateTime$new('lala'), silent=TRUE) ## test roundtrip conversion from/to JSON dt2$fromData(jsonlite::fromJSON(jsonlite::toJSON(dt1)))
An inputfile within metadata for a run/setQuality
An inputfile within metadata for a run/setQuality
nameThe name MUST uniquely match to a location (specified below) listed in the mzQC file.
locationUnique file location, REQUIRED to be specified as a URI. The file URI is RECOMMENDED to be publicly accessible.
fileFormatAn MzQCcvParameter with 'accession' and 'name'.
filePropertiesAn array of MzQCcvParameter, usually with 'accession', 'name' and 'value'. Recommended are at least two entries: a) Completion time of the input file (MS:1000747) and b) Checksum of the input file (any child of: MS:1000561 ! data file checksum type).
new()
Constructor
MzQCinputFile$new( name = NA_character_, location = NA_character_, fileFormat = MzQCcvParameter$new(), fileProperties = list() )
nameString value for initialization of field name
locationString value for initialization of field location
fileFormatOptional MzQCcvParameter value for initialization of field fileFormat
filePropertiesOptional list value for initialization of field fileProperties
isValid()
Verifies validity of the object
MzQCinputFile$isValid(context = "MzQCinputFile")
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
toJSON()
Creates JSON file from this object.
MzQCinputFile$toJSON(...)
...Optional parameters for jsonlite:::asJSON()
fromData()
Sets data for this object from plain named lists of R objects
MzQCinputFile$fromData(data, context = "MzQCinputFile")
dataA datastructure of R lists/arrays as obtained by 'jsonlite::fromJSON()'
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
clone()
The objects of this class are cloneable with this method.
MzQCinputFile$clone(deep = FALSE)
deepWhether to make a deep clone.
The metadata for a run/setQuality
The metadata for a run/setQuality
labelUnique name for the run (for runQuality) or set (for setQuality).
inputFilesArray/list of MzQCinputFile objects
analysisSoftwareArray/list of MzQCanalysisSoftware objects
cvParameters(optional) Array of cvParameters objects
new()
Constructor
MzQCmetadata$new( label = NA_character_, inputFiles = list(), analysisSoftware = list(), cvParameters = list() )
labelString value for initialization of field label
inputFilesOptional list value for initialization of field inputFiles
analysisSoftwareOptonal list value for initialization of field analysisSoftware
cvParametersOptional list value for initialization of field cvParameters
isValid()
Verifies validity of the object
MzQCmetadata$isValid(context = "MzQCmetadata")
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
toJSON()
Creates JSON file from this object.
MzQCmetadata$toJSON(...)
...Optional parameters for jsonlite:::asJSON()
fromData()
Sets data for this object from plain named lists of R objects
MzQCmetadata$fromData(data, context = "MzQCmetadata")
dataA datastructure of R lists/arrays as obtained by 'jsonlite::fromJSON()'
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
clone()
The objects of this class are cloneable with this method.
MzQCmetadata$clone(deep = FALSE)
deepWhether to make a deep clone.
Root element of an mzQC document
Root element of an mzQC document
At least one of runQualities or setQualities MUST be present.
versionVersion of the mzQC format.
creationDateCreation date of the mzQC file.
contactNameName of the operator/creator of this mzQC file.
contactAddressContact address (mail/e-mail or phone)
descriptionDescription and comments about the mzQC file contents.
runQualitiesArray of MzQCrunQuality;
setQualitiesArray of MzQCsetQuality
controlledVocabulariesArray of CV domains used (obo files)
new()
Constructor
MzQCmzQC$new( version = NA_character_, creationDate = MzQCDateTime$new(), contactName = NA_character_, contactAddress = NA_character_, description = NA_character_, runQualities = list(), setQualities = list(), controlledVocabularies = list() )
versionString value for initialization of field version
creationDateMzQCDateTime value for initialization of field creationDate
contactNameOptional string value for initialization of field contactName
contactAddressOptional string value for initialization of field contactAddress
descriptionOptional string value for initialization of field description
runQualitiesOptional list value for initialization of field runQualities
setQualitiesOptional list value for initialization of field setQualities
controlledVocabulariesOptional list value for initialization of field controlledVocabularies
isValid()
Verifies validity of the object
MzQCmzQC$isValid(context = "MzQCmzQC")
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
toJSON()
Creates JSON file from this object.
MzQCmzQC$toJSON(...)
...Optional parameters for jsonlite:::asJSON()
fromData()
Sets data for this object from plain named lists of R objects
MzQCmzQC$fromData(data, context = "MzQCmzQC")
dataA datastructure of R lists/arrays as obtained by 'jsonlite::fromJSON()'
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
clone()
The objects of this class are cloneable with this method.
MzQCmzQC$clone(deep = FALSE)
deepWhether to make a deep clone.
The central class to store QC information
The central class to store QC information
accessionAccession number identifying the term within its controlled vocabulary.
nameName of the controlled vocabulary element describing the metric.
description(optional) Definition of the controlled vocabulary term.
value(optional) Value of the metric (single value, n-tuple, table, matrix).
The structure is not checked by our mzQC implementation and must be handled by the caller, see toQCMetric.
unit(optional) Array of unit(s), stored as MzQcvParameter
new()
Constructor
MzQCqualityMetric$new( accession = NA_character_, name = NA_character_, description = NA_character_, value = NA, unit = list() )
accessionString value for initialization of field accession
nameString value for initialization of field name
descriptionOptional string value for initialization of field description
valueOptional value for initialization of field value
unitOptional unit value for initialization of field unit
isValid()
Verifies validity of the object
MzQCqualityMetric$isValid(context = "MzQCqualityMetric")
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
toJSON()
Creates JSON file from this object.
MzQCqualityMetric$toJSON(...)
...Optional parameters for jsonlite:::asJSON()
fromData()
Sets data for this object from plain named lists of R objects
MzQCqualityMetric$fromData(data, context = "MzQCqualityMetric")
dataA datastructure of R lists/arrays as obtained by 'jsonlite::fromJSON()'
contextOptional string describing location in mzQC structure that is used for more informative warning texts.
clone()
The objects of this class are cloneable with this method.
MzQCqualityMetric$clone(deep = FALSE)
deepWhether to make a deep clone.
The object is an alias for MzQCbaseQuality.
rmzqc::MzQCbaseQuality -> MzQCrunQuality
clone()
The objects of this class are cloneable with this method.
MzQCrunQuality$clone(deep = FALSE)
deepWhether to make a deep clone.
The object is an alias for MzQCbaseQuality.
rmzqc::MzQCbaseQuality -> MzQCsetQuality
clone()
The objects of this class are cloneable with this method.
MzQCsetQuality$clone(deep = FALSE)
deepWhether to make a deep clone.
This is useful for missing list elements (which returns NULL), but when the missing element in refClass should be NA_character_ (and NULL would return an error)
NULL_to_charNA(char_or_NULL)NULL_to_charNA(char_or_NULL)
char_or_NULL |
A string or NULL |
NULL_to_charNA(NA) ## NA NULL_to_charNA(NULL) ## NA_character_ NULL_to_charNA("hi") ## "hi"NULL_to_charNA(NA) ## NA NULL_to_charNA(NULL) ## NA_character_ NULL_to_charNA("hi") ## "hi"
This is useful for missing list elements (which returns NULL), but when the missing element in refClass should be NA (and NULL would return an error)
NULL_to_NA(var_or_NULL)NULL_to_NA(var_or_NULL)
var_or_NULL |
A variable of any kind or NULL |
NULL_to_NA(NA) ## NA NULL_to_NA(NULL) ## NA NULL_to_NA("hi") ## "hi"NULL_to_NA(NA) ## NA NULL_to_NA(NULL) ## NA NULL_to_NA("hi") ## "hi"
Get the information of each CV term from an obo file.
parseOBO(cv_obo_file)parseOBO(cv_obo_file)
cv_obo_file |
A local path to an .obo file |
A data.frame containing CV term information
Read a JSON file in mzQC format into an MzQCmzQC root object
readMZQC(filepath)readMZQC(filepath)
filepath |
A filename (with path) to read from. |
An MzQCmzQC root object from which all the data can be extracted/manipulated
Read a JSON object in mzQC format into an MzQCmzQC root object
readMZQCFromJSON(json_obj)readMZQCFromJSON(json_obj)
json_obj |
A generic R object (list of lists...) |
An MzQCmzQC root object from which all the data can be extracted/manipulated
Removes the last suffix (including the last dot) from a filename. If no dot exists, the full string is returned.
removeFileSuffix(filepath)removeFileSuffix(filepath)
filepath |
A filename (with optional path – which is retained) |
The input with removed suffix
removeFileSuffix("test.tar.gz") # --> 'test.tar' removeFileSuffix("test.mzML") # --> 'test' removeFileSuffix("/path/to/test.mzML") # --> '/path/to/test' removeFileSuffix("test_no_dot") # --> 'test_no_dot'removeFileSuffix("test.tar.gz") # --> 'test.tar' removeFileSuffix("test.mzML") # --> 'test' removeFileSuffix("/path/to/test.mzML") # --> '/path/to/test' removeFileSuffix("test_no_dot") # --> 'test_no_dot'
Remove a file, if it exists (useful for temporary files which may or may not have been created)
removeIfExists(tmp_filename)removeIfExists(tmp_filename)
tmp_filename |
A path to a local file |
NULL if file is missing, otherwise TRUE/FALSE depening on successful removal
From an ID, e.g. "MS:1003162" (for PTX-QC), and some additional information, create an 'analysisSoftware' node for mzQC
toAnalysisSoftware(id, version = "unknown", uri = NULL, value = NA_character_)toAnalysisSoftware(id, version = "unknown", uri = NULL, value = NA_character_)
id |
The CV accession |
version |
The version of the tool which created the metric/mzQC |
uri |
URI to the homepage, or if NULL (default), will be extracted from the definition in the PSI MS-CV (if possible) |
value |
An optional name for the software (if different from the CV's name) |
An MzQCanalysisSoftware object
# use 'version = packageVersion("PTXQC")' if the package is installed toAnalysisSoftware(id = "MS:1003162", version = "1.0.12")# use 'version = packageVersion("PTXQC")' if the package is installed toAnalysisSoftware(id = "MS:1003162", version = "1.0.12")
Create an 'MzQCqualityMetric' object from two inputs (id and value).
toQCMetric( id, value, on_violation = c("error", "warn"), allow_unknown_id = FALSE )toQCMetric( id, value, on_violation = c("error", "warn"), allow_unknown_id = FALSE )
id |
The CV accession |
value |
The data, as computed by some QC software in the required format. |
on_violation |
What to do when 'value' is not of the correct type (according to the given 'id')? Default: "error"; or "warn" |
allow_unknown_id |
Allows invalid accession, and also does not check the value type; if 'FALSE' this function errors |
The inputs are:
an ID of a QC metric, e.g. "MS:4000059" (number of MS1 spectra)
a value
The value must be in the correct format depending on the metric. The value type (see below) is checked (a warning/error is given if mismatching): The following requirements for values apply:
single value: R single value; the unit is deduced from the CVs 'has_units'
n-tuple: an R vector, e.g. using c(1,2,3), i.e. all values have the same type; the unit is deduced from the CVs 'has_units'
table: an R list(); all columns defined using CVs 'has_column' must be present (a warning/error is given otherwise)
matrix: an R matrix, i.e. all values have the same type; the unit is deduced from the CVs 'has_units'
Upon violation of the value type (e.g. data.frame instead of single value), an error or a warning is emitted (see @p on_violation):
toQCMetric(id = "MS:4000059", value = data.frame(n = 1)) # errors: wrong value format
An MzQCanalysisSoftware object
## single value toQCMetric(id = "MS:4000059", value = 13405) # number of MS1 spectra ## n-tuple toQCMetric(id = "MS:4000051", value = c(31.3, 35.99, 38.44)) # XIC-FWHM quantiles ## table toQCMetric(id = "MS:4000063", # MS2 known precursor charges fractions value = list("MS:1000041" = 1:3, "UO:0000191" = c(0.7, 0.6, 0.8))) ## test an invalid CV accession/id toQCMetric(id = "MS:0000", value = "ID_is_not_valid", allow_unknown_id = TRUE) ## matrix (MS:4000006): there is no example in the CV yet, so this cannot be tested) #toQCMetric(id = "MS:400000?", value = matrix(1:12, nrow = 3, ncol = 4)) # ??? # does not work since the 'id' is not derived from a valid value type #toQCMetric(id = "MS:0000000", value = "ID_is_not_valid") # does not work, since the ID is unknown and 'allow_unknown_id' is FALSE by default #toQCMetric(id = "MS:0000", value = "ID_is_not_valid")## single value toQCMetric(id = "MS:4000059", value = 13405) # number of MS1 spectra ## n-tuple toQCMetric(id = "MS:4000051", value = c(31.3, 35.99, 38.44)) # XIC-FWHM quantiles ## table toQCMetric(id = "MS:4000063", # MS2 known precursor charges fractions value = list("MS:1000041" = 1:3, "UO:0000191" = c(0.7, 0.6, 0.8))) ## test an invalid CV accession/id toQCMetric(id = "MS:0000", value = "ID_is_not_valid", allow_unknown_id = TRUE) ## matrix (MS:4000006): there is no example in the CV yet, so this cannot be tested) #toQCMetric(id = "MS:400000?", value = matrix(1:12, nrow = 3, ncol = 4)) # ??? # does not work since the 'id' is not derived from a valid value type #toQCMetric(id = "MS:0000000", value = "ID_is_not_valid") # does not work, since the ID is unknown and 'allow_unknown_id' is FALSE by default #toQCMetric(id = "MS:0000", value = "ID_is_not_valid")
The returned TRUE/FALSE has additional attributes in case of errors. Use attributes(result) to access them.
validateFromFile(filepath, verbose = TRUE)validateFromFile(filepath, verbose = TRUE)
filepath |
A path to a file (e.g. "c:/my.mzQC", or "test.mzQC") |
verbose |
Show extra information if validation fails |
TRUE/FALSE if validation was successful/failed
This method is less performant than validateFromString, because it needs to convert the R object to a JSON string first.
validateFromObj(mzqc_root, verbose = TRUE)validateFromObj(mzqc_root, verbose = TRUE)
mzqc_root |
An mzQC root object |
verbose |
Show extra information if validation fails |
The returned TRUE/FALSE has additional attributes in case of errors. Use attributes(result) to access them.
TRUE/FALSE if validation was successful/failed
If the string object passed into this function contains multiple elements (length > 1). then they will be concatenated using '\n' before validation.
validateFromString(JSON_string, verbose = TRUE)validateFromString(JSON_string, verbose = TRUE)
JSON_string |
A string which contains JSON (multiple lines allowed) |
verbose |
Show extra information if validation fails |
The returned TRUE/FALSE has additional attributes in case of errors. Use attributes(result) to access them.
TRUE/FALSE if validation was successful/failed
You can in theory also provide any mzQC subelement, but the resulting mzQC file will not validate since its incomplete.
writeMZQC(filepath, mzqc_obj)writeMZQC(filepath, mzqc_obj)
filepath |
A filename (with optional path) to write to. |
mzqc_obj |
An MzQCmzQC root object, which is serialized to JSON and then written to disk |
The filename should have '.mzQC' (case sensitive) as suffix. There will be a warning otherwise.