Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document validation with linkml-validate and navigating the schema with schemaview #2281

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ nav:
- Schema element deprecation guide: schema_element_deprecation_guide.md
- v10 vs v11 (Berkeley schema) retrospective: v10-vs-v11-retrospective.md
- Visualizations: visualizations.md
- Data Validation: validation.md
- SchemaView: schemaview.md


site_url: https://microbiomedata.github.io/nmdc-schema
Expand Down
18 changes: 18 additions & 0 deletions src/docs/schemaview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Using LinkML SchemaView in NMDC

## Introduction

Please see LinkML SchemaView documentation for general information.
It has several good examples of how to use this module in a python script or from the command line.
https://linkml.io/linkml/developers/schemaview.html#schemaview

There are also several notebooks that demonstrate SchemaView usage in the LinkML-runtime repository:
https://github.com/linkml/linkml-runtime/tree/main/notebooks

Finally, the Biolink Model Toolkit is a helper wrapper around SchemaView for use with the Biolink Model and it
has many examples of customizing SchemaView output for Biolink Model specific use cases. Similar customizations
may be helpful for NMDC.
https://biolink.github.io/biolink-model-toolkit/
https://github.com/biolink/biolink-model-toolkit/blob/master/examples/bmt-tutorial.ipynb


50 changes: 50 additions & 0 deletions src/docs/validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Validating nmdc-schema data against the schema

## Introduction

Please see LinkML Validation documentation for general information on validation with LinkML.
It has several good examples of how to use linkml-validate in a python script or from the command line.
https://linkml.io/linkml/data/validating-data.html


Using the examples in src/docs/examples, we can validate the data against the schema in python:

```python
from linkml.validator import validate

instance = {
"id": "nmdc:bsm-99-dtTMNb",
"associated_studies": ["nmdc:study-00-abc123"],
"env_broad_scale": {
"has_raw_value": "ENVO:00002030",
"term": {
"id": "ENVO:00002030"
}
},
"env_local_scale": {
"has_raw_value": "ENVO:00002169",
"term": {
"id": "ENVO:00002169"
}
},
"env_medium": {
"has_raw_value": "ENVO:00005792",
"term": {
"id": "ENVO:00005792"
}
},
"type": "nmdc:Biosample",
"analysis_type": [
"amplicon sequencing assay",
"metagenomics"
]
}

report = validate(instance, "nmdc.yaml", "Biosample")

if not report.results:
print('The instance is valid!')
else:
for result in report.results:
print(result.message)
```