mzqc package

Submodules

mzqc.MZQCFile module

class mzqc.MZQCFile.AnalysisSoftware(accession: str = '', name: str = '', description: str = '', value: str = '', unit: str = '', version: str = '', uri: str = '')

Bases: CvParameter

AnalysisSoftware Object representation for mzQC schema type AnalysisSoftware

class mzqc.MZQCFile.BaseQuality(metadata: MetaDataParameters = None, qualityMetrics: List[QualityMetric] = None)

Bases: jsonobject

BaseQuality Object representation for mzQC schema type BaseQuality

class mzqc.MZQCFile.ControlledVocabulary(name: str = '', uri: str = '', version: str = '')

Bases: jsonobject

ControlledVocabulary Object representation for mzQC schema type ControlledVocabulary

class mzqc.MZQCFile.CvParameter(accession: str = '', name: str = '', description: str = '', value: Optional[Union[int, str, float, List[int], List[str], List[float], List[List[int]], List[List[str]], List[List[float]], Dict[str, List]]] = None, unit: str = '')

Bases: jsonobject

CvParameter Object representation for mzQC schema type CvParameter

class mzqc.MZQCFile.InputFile(location: str = '', name: str = '', fileFormat: CvParameter = None, fileProperties: List[CvParameter] = None)

Bases: jsonobject

InputFile Object representation for mzQC schema type InputFile

class mzqc.MZQCFile.JsonSerialisable

Bases: object

JsonSerialisable Main structure template for mzQC objects

Sets the foundation for a mzQC object to be readily (de-)serialisable with standard python json handling code. Facilitates reading and writing of complex objects.

classmethod FromJson(json_str, complete=False)

FromJson Main method for deserialisation

Accounts for neccessary object rectification due to same-attribute class footprints. N.B.: for this to work the class init variables must be same name as the corresponding member attributes (self).

Parameters
  • classself (self) – The objects class self

  • json_str (str) – The JSON string to be deserialised

  • complete (bool, optional) – Flag to indicate if the whole JSON is to be returned deserialised, or just the mzQC entry (default).

Returns

The deserialised JSON string

Return type

MzQcFile object

classmethod ToJson(obj, readability=0, complete=True)

ToJson Main method for serialisation

Parameters
  • classself (self) – The objects class self

  • obj (object) – The object to be serialised

  • readability (int, optional) – The indentation level, by default 0 (=no indentation, 1=minor indentation on MZQC objects, >1 heavy indentation for max. human readability)

  • complete (bool, optional) – Flag to indicate if the object is to be left without the enclosing mzQC key or if the JSON is to be amended to full schema compliance (default).

Returns

The serialisation result

Return type

str

classmethod class_mapper(d)

class_mapper Maps incoming objects to their respective definition

Allows every registered object to ‘know’ its type map incuding recursing into its attributes. Can be used as object_hook in the json load process.

Parameters
  • classself (self) – The objects class self

  • d (dict) – The dictionary mapping attributes

Returns

Returns an object of the ‘outer-most’ class

Return type

class object

Raises

ValueError – If expected date strings are invalid.

classmethod complex_handler(obj)

complex_handler Handles the in-depth serialisations necessary

Facilitates the correct serialisation for each type of object (within the registered mzQC JsonSerialisable context) through possible serialisation specialisation by way of object type. If objects behave like dictionaries, but are complex classes (like all pymzqc obj), the dict needs to be returned as classical dict in order to serialise.

Parameters
  • classself (self) – The objects class self

  • obj (object) – The object to be deserialised

Returns

The correct object deconstruction into its deserialisable bits

Return type

obj

Raises

TypeError – In case a given object cannot be serialised with the given set of functionalities.

mappings: Dict[str, Any] = {frozenset({'name', 'uri', 'version'}): <class 'mzqc.MZQCFile.ControlledVocabulary'>, frozenset({'accession', 'description', 'name', 'unit', 'value'}): <class 'mzqc.MZQCFile.QualityMetric'>, frozenset({'accession', 'description', 'name', 'unit', 'uri', 'value', 'version'}): <class 'mzqc.MZQCFile.AnalysisSoftware'>, frozenset({'fileFormat', 'fileProperties', 'location', 'name'}): <class 'mzqc.MZQCFile.InputFile'>, frozenset({'analysisSoftware', 'inputFiles', 'label'}): <class 'mzqc.MZQCFile.MetaDataParameters'>, frozenset({'metadata', 'qualityMetrics'}): <class 'mzqc.MZQCFile.SetQuality'>, frozenset({'contactAddress', 'contactName', 'controlledVocabularies', 'creationDate', 'description', 'runQualities', 'setQualities', 'version'}): <class 'mzqc.MZQCFile.MzQcFile'>}
classmethod register(cls)

register The method for class registration in the class mapping process

Each registered class gets mapped.

Parameters
  • classself (self) – the objects class self

  • cls (object) – the class type

Returns

the class type

Return type

cls

static time_helper(da: str) datetime

time_helper Helper method for ISO8601 string of various length consumption

Used on JSON datetime object string representation will handle length and return python datetime objects. JSON-schema actually follows https://www.rfc-editor.org/rfc/rfc3339.html#section-5.6 which is a little more stringent subset of ISO8601.

Parameters

da (str) – JSON datetime object string representation

Returns

Python datetime object including the same amount detail provided

Return type

datetime

class mzqc.MZQCFile.MetaDataParameters(label: str = '', inputFiles: List[InputFile] = None, analysisSoftware: List[AnalysisSoftware] = None)

Bases: jsonobject

MetaDataParameters Object representation for mzQC schema type MetaDataParameters

class mzqc.MZQCFile.MzQcFile(creationDate: Union[datetime, str] = datetime.datetime(2024, 1, 25, 16, 18, 16), version: str = '1.0.0', contactName: str = '', contactAddress: str = '', description: str = '', runQualities: List[RunQuality] = None, setQualities: List[SetQuality] = None, controlledVocabularies: List[ControlledVocabulary] = None)

Bases: jsonobject

MzQcFile Object representation for mzQC schema type MzQcFile

class mzqc.MZQCFile.MzqcJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)

Bases: JSONEncoder

MzqcJSONEncoder The encoder used to facilitate indented encoding

Handles the string encoding and formatting of the serialised objects.

iterencode(o, _one_shot=False)

Encode the given object and yield each string representation as available.

For example:

for chunk in JSONEncoder().iterencode(bigobject):
    mysocket.write(chunk)
class mzqc.MZQCFile.QualityMetric(accession: str = '', name: str = '', description: str = '', value: Optional[Union[int, str, float, List[int], List[str], List[float], List[List[int]], List[List[str]], List[List[float]], Dict[str, List]]] = None, unit: str = '')

Bases: CvParameter

QualityMetric Object representation is passed for its more concrete derivatives

class mzqc.MZQCFile.RunQuality(metadata: MetaDataParameters = None, qualityMetrics: List[QualityMetric] = None)

Bases: BaseQuality

QualityMetric Object representation is passed for its more general basis

class mzqc.MZQCFile.SetQuality(metadata: MetaDataParameters = None, qualityMetrics: List[QualityMetric] = None)

Bases: BaseQuality

SetQuality Object representation is passed for its more general basis

class mzqc.MZQCFile.jsonobject

Bases: object

jsonobject Proxy object for better integration of mzQC objects

Useful for testing and validity checks as __eq__ is overridden to compare all attributes as well.

mzqc.MZQCFile.rectify(obj)

rectify Rectifies objects according to their position in the local hierarchy

Carries out the neccessary object rectification due to same-attribute class footprints. Rectification depends on the object position in the local object hierarchy.

Parameters

obj (object) – The object to be rectified

Returns

The rectified object

Return type

object

mzqc.SemanticCheck module

class mzqc.SemanticCheck.SemanticCheck(mzqc_obj: MzQcFile, version: str = '', file_path: str = '')

Bases: UserDict

Class for keeping track of all instances of SemanticIssues arising during semantic validation.

Due to the design and nature of checks performed, it is recommended to use one object per loaded mzQC file. Thus, if you provide the file_path of a loaded mzQC object to the SemanticCheck class, you can directly document to which file (and not only which object) the validation belongs to. The validation results are directly accessible through the UserDict super class. Additional parameters on the validation call are kept, too. The validate function updates internal data attributes as max_error, the dict of SemanticIssues, and the mzqc_obj (see __init__). A wrapping function to add new-found validation issues with raising() helps keeping track of the number of issues during validation, which can be cut short in resource restrictive environments. Like so, the class objects can perform different modes of validation on the same mzqc. However, this makes the SemanticCheck object memory heavy. The class uses a number of internal functions to capsulate the validation process and access to the mzqc_object: clear, raising, and string_export which are present as convenience functions to the validator applications in the accessories of the project’s repository. See the validate function documentation for further details.

Parameters

UserDict (Dict[str,List[SemanticIssue]]) – keeps track of the issues during validation

clear() None

Substitute to the UserDict clear which clears the dict and resets _exceeded_errors

raising(category: str, issue: SemanticIssue)

Helper function to append new issues without circumventing the max_error mechanism or initialising new issue types or categories

Parameters
  • category (str) – issue type or category, key to __setitem__

  • issue (SemanticIssue) – A

string_export() Dict[str, List[str]]

Helper function to properly export the validation results

For easy compatibility with the validation apps from the repositories accessories.

Returns

dict of list of issues formatted as str

Return type

Dict[str,List[str]]

validate(max_errors: int = 0, load_local: bool = False, keep_issues: bool = False, _document_collected_issues: bool = False)

Validates the object given during class initialisation, considers a number of parameters

Note before adding new checks: create functions to check specific types of issues, name the group or select an existing group and add new SemanticIssues to self under that group’s name as key with the raising function. Also add a method for synthetic generation of these new issues given the _document_collected_issues flag. Like that, the name, severity level, and error message gets automatically documented, also in the validator apps of the accessories to the pymzqc repository. Should a new group name be introduced, it is also necessary to add this name to the issue_types_genreated to ensure proper auto_doc functionality.

The validation result is kept in the object itself, accessible through the UserDict and additional member attributes (see class doc). A convenience function to export the list of stringified dict of SemanticIssue lists, e.g. with the apps from the pymzqc’s repository accessories, is provided with string_export.

Parameters
  • max_errors (int, optional) – the maximum number of SemanticIssues detected before the validation will raise a ValidationIssue, by default 0 for no limit

  • load_local (bool, optional) – flag to indicate if referenced local files should be attempted to load, by default False does not make sense for online validation

  • keep_issues (bool, optional) – flag to indicate if any SemanticIssues from previous should _NOT_ be cleared, by default False

  • _document_collected_issues (bool, optional) – flag to indicate that every possible SemanticIssue is to be auto_doc generated, by default False

class mzqc.SemanticCheck.SemanticIssue(name: str, severity: int, message: str)

Bases: object

Class for keeping track of an instance of all the different issues during the

semantic validation for a particular dataset, collecting a few data members: name: name of the issue severity: value from 1-9, increasing severity, no checks performed, no guaranties. message: issue message

Added is a _to_string function to simplify serialisation. Note: ValidationError was too inflexible for development, hence the dataclass.

message: str
name: str
severity: int
mzqc.SemanticCheck.suppress_verbose_modules()

mzqc.SyntaxCheck module

class mzqc.SyntaxCheck.SyntaxCheck(version: str = 'main')

Bases: object

SyntaxCheck class for syntax validations of mzQC objects (after JSON dump)

Using member function validate of the SytnaxCheck class, mzQC objects can be checked for correct syntax in its built-in serialisation. The result dict object from schema validation is compatible with the result dict object from semantic validation of the SemanticCheck class.

validate(mzqc_str: str)

The validation function validates the given json string representation against the class objects set schema (see __init__) with jsonschema.validate and jsonschema.FormatChecker (default arguments).

Parameters

mzqc_str (str) – The json object to be validated in string representation.

Returns

Returns a dictionary with key ‘schema validation’, containing a truncated error message or in the absence of an error ‘success’, both string type.

Return type

dict

Module contents