Skip to contents

Create an 'MzQCqualityMetric' object from two inputs (id and value).

Usage

toQCMetric(
  id,
  value,
  on_violation = c("error", "warn"),
  allow_unknown_id = FALSE
)

Arguments

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

Value

An MzQCanalysisSoftware object

Details

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
 

Examples

   ## single value
   toQCMetric(id = "MS:4000059", value = 13405) # number of MS1 spectra
#> <MzQCqualityMetric>
#>   Public:
#>     accession: MS:4000059
#>     clone: function (deep = FALSE) 
#>     description: "The number of MS1 events in the run." [PSI:MS]
#>     fromData: function (data, context = "MzQCqualityMetric") 
#>     initialize: function (accession = NA_character_, name = NA_character_, description = NA_character_, 
#>     isValid: function (context = "MzQCqualityMetric") 
#>     name: number of MS1 spectra
#>     self: MzQCqualityMetric, R6
#>     toJSON: function (...) 
#>     unit: list
#>     value: 13405

   ## n-tuple
   toQCMetric(id = "MS:4000051", value = c(31.3, 35.99, 38.44)) # XIC-FWHM quantiles
#> <MzQCqualityMetric>
#>   Public:
#>     accession: MS:4000051
#>     clone: function (deep = FALSE) 
#>     description: "The first to n-th quantile of peak widths for XICs. A m ...
#>     fromData: function (data, context = "MzQCqualityMetric") 
#>     initialize: function (accession = NA_character_, name = NA_character_, description = NA_character_, 
#>     isValid: function (context = "MzQCqualityMetric") 
#>     name: XIC-FWHM quantiles
#>     self: MzQCqualityMetric, R6
#>     toJSON: function (...) 
#>     unit: list
#>     value: 31.3 35.99 38.44

   ## 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)))
#> <MzQCqualityMetric>
#>   Public:
#>     accession: MS:4000063
#>     clone: function (deep = FALSE) 
#>     description: "The fraction of MS/MS precursors of the corresponding c ...
#>     fromData: function (data, context = "MzQCqualityMetric") 
#>     initialize: function (accession = NA_character_, name = NA_character_, description = NA_character_, 
#>     isValid: function (context = "MzQCqualityMetric") 
#>     name: MS2 known precursor charges fractions
#>     self: MzQCqualityMetric, R6
#>     toJSON: function (...) 
#>     unit: list
#>     value: list

   ## test an invalid CV accession/id
   toQCMetric(id = "MS:0000", value = "ID_is_not_valid", allow_unknown_id = TRUE)
#> Warning: Could not find id 'MS:0000' in CV list (length: 6813)
#> <MzQCqualityMetric>
#>   Public:
#>     accession: MS:0000
#>     clone: function (deep = FALSE) 
#>     description: 
#>     fromData: function (data, context = "MzQCqualityMetric") 
#>     initialize: function (accession = NA_character_, name = NA_character_, description = NA_character_, 
#>     isValid: function (context = "MzQCqualityMetric") 
#>     name: 
#>     self: MzQCqualityMetric, R6
#>     toJSON: function (...) 
#>     unit: list
#>     value: ID_is_not_valid

   # \donttest{
   ## 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")
   # }