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 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,
metadataType: MetadataValidatorType,
idField: str = None
) → Union[BiosourcePropertiesValidator, FileManifestValidator]
Initialize and return a metadata validator.
Args:
file(str): metadata file nameschema(str): JSONschema file namemetadataType(MetadataValidatorType): type of metadata to be validatedidField(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,
metadataType: str,
idField: str = None,
failOnError: bool = False,
)
Run validation.
Validator initialization fully encapsulated. Returns validation result.
Args:
file(str): metadata file nameschema(str): JSONschema file namemetadataType(MetadataValidatorType): type of metadata to be validatedidField(str, optional): biosource id field in the metadata file; required forBIOSOURCE_PROPERTIESvaldiatoin. 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file niagads_metadata_validator-0.2.1.tar.gz.
File metadata
- Download URL: niagads_metadata_validator-0.2.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdf3f9768457412ca7f2af4e42918056bb48beaa8ee3be1d3c5f61e64c91beba
|
|
| MD5 |
3d310358c481739c34053479e292651b
|
|
| BLAKE2b-256 |
4b605326028da6716a4a3c3ac5d16cb81b38ca2a5774494abbe01cbfd744cbfa
|
File details
Details for the file niagads_metadata_validator-0.2.1-py3-none-any.whl.
File metadata
- Download URL: niagads_metadata_validator-0.2.1-py3-none-any.whl
- Upload date:
- Size: 39.7 kB
- Tags: Python 3
- 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82eb05a96a8bd1211f62180f690a0ced622ee7f1a8b4d541e73f0d46f6c06d7f
|
|
| MD5 |
c1e89dd5d760740aeb125b1420e4be9f
|
|
| BLAKE2b-256 |
47c7197fcbb9d7430a7e86ce831b2b9f30ed5d97235735c251464e1241d54ea4
|