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,
    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.2.tar.gz (28.4 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.2-py3-none-any.whl (39.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: niagads_metadata_validator-0.2.2.tar.gz
  • Upload date:
  • Size: 28.4 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.2.tar.gz
Algorithm Hash digest
SHA256 2e5e5b676e1db8cb2ae8640a8430f1be255c783f17cb24ca9f03605f07a2d2cf
MD5 2368166bd675f00bda03547299e437b3
BLAKE2b-256 17971256601323081283adcf43f0869bf1e32ceed5c70ab83122429fd14eacdd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for niagads_metadata_validator-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9926e3871dbac39c38b476870f7e750466c5a84f052d20a9198e74224ff4c4c0
MD5 003afca8cef7bd4a507ce4f6c595100e
BLAKE2b-256 01900c422db0656e6b9dab4de27b77288b792789256555b774eba1377d208773

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