motbxtools Python package#

The motbxtools package provides classes and methods to read, write, validate, or summarise MOTBX resources. It is available in the directory src/motbxtools.

Module motbxschema#

This module contains classes for the Multi-omics Toolbox (MOTBX) JSON schema, the MOTBX resource (single YAML file), and the MOTBX collection (all YAML files in a directory that describe resources).

class motbxschema.MotbxCollection(collection_dir, schema_json_path)#

This class collects all MOTBX resources in a directory.

__init__(collection_dir, schema_json_path)#

Initialise MOTBX collection object.

Parameters:

collection_dir (str) – Path to directory containing MOTBX resources

get_info(fields=None)#

Retrieve information about values present in given field(s) for MOTBX resources in directory.

Parameters:

fields (list) – List with field names or tuples of fieldnames to retrieve

summarise(summary_csv_path, validate=True, exclude_invalid=False, old_summary_csv_path=None, changelog_path=None, validationlog_path=None, verbose=True)#

Summarise all MOTBX resources in folder and write to CSV file.

Parameters:
  • summary_csv_path (str) – Path to CSV file summarising resources of latest MOTBX version

  • validate (bool) – Validate resource against JSON schema if True

  • verbose (bool) – Print processed resource IDs if True

  • old_summary_csv_path (str) – Path to CSV file summarising resources of previous MOTBX version

  • changelog_path (str) – Path to CSV file summarising changes

  • validationlog_path (str) – Path to CSV file summarising failed validations

class motbxschema.MotbxResource(yaml_path, resource=None)#

This class stores a MOTBX resource as a dictionary.

__init__(yaml_path, resource=None)#

Initialise MOTBX resource object.

Parameters:
  • yaml_path (str) – Path to YAML file containing a MOTBX resource

  • resource (dict) – A MOTBX resource

flatten(fieldnames)#

Iterate through nested dictionary (from JSON) and return dictionary with single level for writing CSV file. Keep only keys present in fieldnames.

Parameters:

fieldnames (list) – CSV column names (fieldnames) of a DictWriter instance

Returns:

A row for writerow()

Return type:

dict

load()#

Load a MOTBX resource from a YAML file.

save()#

Save the MOTBX resource to a YAML file.

validate(motbx_schema)#

Validate MOTBX resource with JSON schema and confirm that URL is valid and live.

Parameters:

motbx_schema (MotbxSchema) – A JSON schema defining structure of MOTBX resource

Raises:

Exception – Validation of URL fails

class motbxschema.MotbxSchema(json_path)#

This class stores a JSON Schema as a dictionary.

__init__(json_path)#
validate()#

Validate schema against metaschema JSON schema draft 2020-12.

Unit testing#

The directory tests/test_motbxtools contains unit tests for the motbxtools package. The tests directory additionally contains MOTBX resource YAML files used by the tests. Unit tests can be run using the GitHub action defined in .github/workflows/tests.yml via actions. This action is triggered by changes to files in src, schema, or tests.