schematron¶
Validation of SBGN documents against the schematron rules of libsbgn.
The SBGN specifications define rules which the SBGN-ML schema cannot express,
e.g., that a consumption arc starts at an entity pool node and ends at a
process. libsbgn implements them as
schematron rules, one file per map language. validate_schematron checks a
document against them and reports every broken rule as an Issue, the results
are the ones of the Java library.
from pathlib import Path
from libsbgnpy import validate_schematron
for issue in validate_schematron(Path("map.sbgn")):
print(issue.rule_id, issue.element_id)
print(f" {issue.message}")
The rules are packaged in libsbgnpy/schema/, see the README.md there for
their origin and the changes which let lxml run them with XSLT 1.0.
Issue
dataclass
¶
A rule of the SBGN specifications which a map breaks.
Attributes:
| Name | Type | Description |
|---|---|---|
severity |
str
|
the role of the rule, |
rule_id |
str
|
id of the rule, e.g., |
message |
str
|
what the rule requires. |
element_id |
str | None
|
id of the glyph or arc which breaks the rule, None if the rule does not name it. |
validate_schematron
¶
Validate an SBGN file against the schematron rules of libsbgn.
The file is read like validate_xsd
reads it: decoded with the encoding of its XML declaration and upconverted
from SBGN-ML 0.1 and 0.2. Every map is checked on its own with the rules of
its language, which is taken from its version or else its language, see
language_of; a map of an unknown
language is not checked. As in the Java library, the basic phase of the
rules is checked.
The rules do not check the structure of the document, a document without
maps, e.g., another XML document, has no issues; validate it with
validate_xsd first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
Path
|
path of the SBGN file |
required |
Returns:
| Type | Description |
|---|---|
list[Issue]
|
The broken rules, in the order of the maps and of the rules; empty if the document breaks none. |
Raises:
| Type | Description |
|---|---|
OSError
|
if the file cannot be read |
XMLSyntaxError
|
if the file is no well-formed XML |