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

validate-metadata --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,
    metadataType: MetadataValidatorType,
    idField: str = None
)  Union[BiosourcePropertiesValidator, FileManifestValidator]

Initialize and return a metadata validator.

Args:

  • file (str): metadata file name
  • schema (str): JSONschema file name
  • metadataType (MetadataValidatorType): type of metadata to be validated
  • idField (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,
    metadataType: str,
    idField: str = None,
    failOnError: bool = False
)

Run validation.

Validator initialization fully encapsulated. Returns validation result.

Args:

  • file (str): metadata file name
  • schema (str): JSONschema file name
  • metadataType (MetadataValidatorType): type of metadata to be validated
  • idField (str, optional): biosource id field in the metadata file; required for BIOSOURCE_PROPERTIES valdiatoin. Defaults to None.
  • failOnError (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"

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.0.tar.gz (27.9 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.0-py3-none-any.whl (37.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for niagads_metadata_validator-0.2.0.tar.gz
Algorithm Hash digest
SHA256 de7960e16d9b862971adb009161041ffabf5a127e30393f2c5cac2ffc6328006
MD5 c32795e79e38cc27fd10b8f5026b1dd7
BLAKE2b-256 835fe7bb7530b8aa32e186ca3fcd2d2d03685d80d973193f35876d6140441745

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for niagads_metadata_validator-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3cd9a06138afe686f4c01ad5d300a0c028a55800008d007a627e8b918418c83f
MD5 bdb222a9b99e32891acfef0955c66965
BLAKE2b-256 692f27ea2249da3d402a4363095695dd7170f2e0f9ca195072e21a8b9c8d1ceb

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