Skip to main content

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:

  • dict: validation errors, separated by frequency of occurrence into file (affecting every row, such as missing required column), recurring: occuring in 5 or more rows and row_specific

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.

Metadata

Release files for niagads-metadata-validator 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for niagads-metadata-validator 0.3.2
File Size Uploaded Provenance Actions
niagads_metadata_validator-0.3.2.tar.gz 66.4 kB Without provenance Details for niagads_metadata_validator-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for niagads-metadata-validator 0.3.2
File Interpreter ABI Platform Actions
niagads_metadata_validator-0.3.2-py3-none-any.whl Python 3 none any Details for niagads_metadata_validator-0.3.2-py3-none-any.whl

Total release size: 157.8 kB

Release files / niagads_metadata_validator-0.3.2.tar.gz

Download URL niagads_metadata_validator-0.3.2.tar.gz
Size 66.4 kB
Tags Source
SHA-256 checksum
How to use checksums
89a8129dcbf0132e7e62b612f3e32fae09cf6b3c3731ac3ff54cde8a8b7c5b54
BLAKE2b-256 checksum
How to use checksums
0665be9b013def7f3333c241544981c4c130d3c003b0529ee422e9a91b0f8193
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.4 CPython/3.12.3 Linux/6.18.33.2-microsoft-standard-WSL2

Release files / niagads_metadata_validator-0.3.2-py3-none-any.whl

Download URL niagads_metadata_validator-0.3.2-py3-none-any.whl
Size 91.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c076c475c1b5ab1d922bbe6f43d098a4628ec92a9d84be1fe5b16f05497f948
BLAKE2b-256 checksum
How to use checksums
76874d8df16f2d1c2ea2d78d86f6c677da5bc8d9153509a6225eb755a4ea4671
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.4 CPython/3.12.3 Linux/6.18.33.2-microsoft-standard-WSL2

Security for niagads-metadata-validator 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page