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 filetemplate(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 nameextensions(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 nameschema(str): JSONschema file namemetadata_type(MetadataValidatorType): type of metadata to be validatedcase_insensitive(bool, optional): allow case-insensitive matching against enums. Defaults to False.id_field(str, optional): biosource id field in the metadata file; required forBIOSOURCE_PROPERTIESvalidation. Defaults to None.
Raises:
RuntimeError: ifmetadataType == 'BIOSOURCE_PROPERTIES'and noidFieldwas providedValueError: if invalidmetadataTypeis 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 nameschema(str): JSONschema file namemetadata_type(MetadataValidatorType): type of metadata to be validatedid_field(str, optional): biosource id field in the metadata file; required forBIOSOURCE_PROPERTIESvaldiatoin. 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 intofile(affecting every row, such as missing required column),recurring: occuring in 5 or more rows androw_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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| niagads_metadata_validator-0.3.1.tar.gz | 63.4 kB | Without provenance | Details for niagads_metadata_validator-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| niagads_metadata_validator-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for niagads_metadata_validator-0.3.1-py3-none-any.whl |
Total release size: 151.7 kB
Release files / niagads_metadata_validator-0.3.1.tar.gz
| Download URL | niagads_metadata_validator-0.3.1.tar.gz |
|---|---|
| Size | 63.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
996729079a1bda65b29a371197a583d2e18a900d0007f9308a200b70d6e1d763
|
|
BLAKE2b-256 checksum How to use checksums |
e694d8ac011e9615e0207811ae6efe5aae2b0d7f77ff1c8f806e30bb69ea48d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.4 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2
|
Release files / niagads_metadata_validator-0.3.1-py3-none-any.whl
| Download URL | niagads_metadata_validator-0.3.1-py3-none-any.whl |
|---|---|
| Size | 88.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
774ebc0430049313aa35bc884c2ab3bbf7c306c115b64b04c96d390f0d6a3c14
|
|
BLAKE2b-256 checksum How to use checksums |
bfe9b368e0cdc965bbbad533f25246e02d88d7ac77b79f891ae9e8af595156eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.4 CPython/3.12.3 Linux/5.15.167.4-microsoft-standard-WSL2
|
Security for niagads-metadata-validator 0.3.1
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.