Skip to main content

JSON Schema based validation of dataset metadata developed to support submissions to the NIAGADS Data Sharing Service

Project description

NIAGADS JSON Schema based metadata validation tools

This tool allows the user to perform JSON Schema-based validation of a sample or file manifest metadata file arranged in tabular format (with a header row that has field names matching the validation schema).

The tool works for delimited text files (.tab, .csv., .txt) as well as excel (.xls, .xlsx) files.

This tool can be run as a script or can also be imported as a module. When run as a script, results are piped to STDOUT unless the --log option is specified.

Requirements

  • Python: >3.12,<4.0

Usage

command-line

Run with the --help option to get full USAGE information

metadata-validator --help

module

Import package into your python script.

import niagads.metadata_validator_tool.core as mv_tool

Use mv_tool.initialize_validator to initialize and retrieve a validator object for further manipulation. Use mv_tool.run to initialize and run a validation with default configuration. See validator documentation for more information about validator properties and member functions.

Example code, with schema and metadata files are availble in the code repostory: examples/niagads-metadata-validator.


API Reference


function get_templated_schema_file

get_templated_schema_file(dir: str, template: str)  str

Verify that templated schema file {schemaDir}/{vType}.json exists.

Args:

  • path (str): path to directory containing schema file
  • template (str): template name

Raises:

  • FileExistsError: if the schema file does not exist

Returns:

  • str: schema file name

function get_templated_metadata_file

get_templated_metadata_file(
    prefix: str,
    template: str,
    extensions: List[str] = ['xlsx', 'xls', 'txt', 'csv', 'tab']
)  str

Find metadata file based on templated name {prefix}{validator_type}.{ext}.

Args:

  • path (str): file path; may include prefix/file pattern to match (e.g. /files/study1/experiment1-)
  • template (str): template name
  • extensions (List[str], optional): allowable file extensions. Defaults to ["xlsx", "xls", "txt", "csv", "tab"].

Raises:

  • FileNotFoundError: if metadata file does not exist

Returns:

  • str: metadata file name

function initialize_validator

initialize_validator(
    file: str,
    schema: str,
    metadata_type: MetadataValidatorType,
    case_insensitive: bool = False,
    id_field: str = None
)  Union[BiosourcePropertiesValidator, FileManifestValidator]

Initialize and return a metadata validator.

Args:

  • file (str): metadata file name
  • schema (str): JSONschema file name
  • metadata_type (MetadataValidatorType): type of metadata to be validated
  • case_insensitive (bool, optional): allow case-insensitive matching against enums. Defaults to False.
  • id_field (str, optional): biosource id field in the metadata file; required for BIOSOURCE_PROPERTIES validation. Defaults to None.

Raises:

  • RuntimeError: if metadataType == 'BIOSOURCE_PROPERTIES' and no idField was provided
  • ValueError: if invalid metadataType is specified

Returns:

  • Union[BiosourcePropertiesValidator, FileManifestValidator]: the validator object

function run

run(
    file: str,
    schema: str,
    metadata_type: str,
    id_field: str = None,
    case_insensitive: bool = False,
    fail_on_error: bool = False
)

Run validation.

Validator initialization fully encapsulated. Returns validation result.

Args:

  • file (str): metadata file name
  • schema (str): JSONschema file name
  • metadata_type (MetadataValidatorType): type of metadata to be validated
  • id_field (str, optional): biosource id field in the metadata file; required for BIOSOURCE_PROPERTIES valdiatoin. Defaults to None.
  • case_insensitive (bool, optional): allow case-insensitive matching against enums. Defaults to False.
  • fail_on_error (bool, optional): raise an exception on validation error if true, otherwise returns list of validation errors. Defaults to False.

Returns:

  • list: list of validation errors

class MetadataValidatorType

Enum defining types of supported tabular metadata files.

BIOSOURCE_PROPERTIES = '''biosource properties file;
a file that maps a sample or participant to descriptive properties
(e.g., phenotype or material) or a ISA-TAB-like sample file'''

FILE_MANIFEST = "file manifest or a sample-data-relationship (SDRF) file"

class MetadataFileFormatError

Exception raised when metadata file parsing fails due to inconsistency in file format or data quality issues (e.g., malformed content) that the user must resolve by providing a properly formatted file.


This file was automatically generated via lazydocs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

niagads_metadata_validator-0.2.3.tar.gz (34.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

niagads_metadata_validator-0.2.3-py3-none-any.whl (46.4 kB view details)

Uploaded Python 3

File details

Details for the file niagads_metadata_validator-0.2.3.tar.gz.

File metadata

  • Download URL: niagads_metadata_validator-0.2.3.tar.gz
  • Upload date:
  • Size: 34.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2

File hashes

Hashes for niagads_metadata_validator-0.2.3.tar.gz
Algorithm Hash digest
SHA256 c36680b630472e314fd8e6737dd3d1d2b2bfedc44991073b629c4054bcf57f73
MD5 5181b8ce1da5ff630bfec0f3291cbb0c
BLAKE2b-256 bc6aabd034b1bbc0eab63bf6c189ecd6d3b18d37e2fdc3f9c7f079e07b19de05

See more details on using hashes here.

File details

Details for the file niagads_metadata_validator-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for niagads_metadata_validator-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 82416a49f4df7ab686983a848acf39d41a83402e9984f76f7529abadf9e37d83
MD5 5ef8aa5beb6943c33a07afd5dcd94609
BLAKE2b-256 c989d7f8bb25b82c4ed066d57a22f9dd429b53efa02929c3292b8291d99073b3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page