Skip to content

Commit c8ed5ef

Browse files
annotation validator
1 parent c186ffc commit c8ed5ef

File tree

5 files changed

+1518
-1
lines changed

5 files changed

+1518
-1
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ keywords = [
3434
"computational modeling",
3535
]
3636
dependencies = [
37-
"pymetadata>=0.5.6",
37+
"pymetadata>=0.5.7",
3838
"depinfo",
3939
"rich",
4040
"lxml",

release-notes/0.9.5.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Release notes for sbmlutils 0.9.5
2+
![sbmlutils](https://github.com/matthiaskoenig/sbmlutils/raw/develop/docs_builder/images/sbmlutils-logo-60.png)
3+
4+
We are pleased to release the next version of sbmlutils including the
5+
following changes:
6+
7+
# Features
8+
- annotation validation functionality
9+
10+
Your sbmlutils team
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from pathlib import Path
2+
from typing import Union
3+
4+
import libsbml
5+
import pandas as pd
6+
from pymetadata.identifiers.miriam import BQB
7+
8+
from sbmlutils.console import console
9+
from sbmlutils.io.sbml import read_sbml
10+
from sbmlutils.log import get_logger
11+
from pymetadata.core.annotation import RDFAnnotation
12+
13+
14+
logger = get_logger(__name__)
15+
16+
17+
def validate_sbml_annotations(source: Union[Path, str]) -> pd.DataFrame:
18+
"""Validate annotations in a given SBML file.
19+
20+
:param source: SBML to check
21+
:return: DataFrame of invalid annotations
22+
"""
23+
doc: libsbml.SBMLDocument = read_sbml(source=source)
24+
console.rule(style="white")
25+
console.print(f"Validate annotations: {source}", style="white bold")
26+
console.rule(style="white")
27+
28+
elements = doc.getListOfAllElements()
29+
element: libsbml.SBase
30+
invalid_annotations: list = []
31+
for element in elements:
32+
if element.isSetAnnotation():
33+
cvterm: libsbml.CVTerm
34+
cvterms = element.getCVTerms()
35+
36+
# console.rule(f"id='{element.id}' | {type(element)} | '{element.name}'", align="left", style="bold white")
37+
for cvterm in cvterms:
38+
qualifier_type = cvterm.getQualifierType()
39+
for k in range(cvterm.getNumResources()):
40+
41+
resource_uri = cvterm.getResourceURI(k)
42+
# console.print(f"{qualifier_type} | {resource_uri}")
43+
annotation = RDFAnnotation(qualifier=BQB.IS, resource=resource_uri, validate=False)
44+
valid: bool = annotation.validate()
45+
if not valid:
46+
console.print(
47+
f"id='{element.id}' | {type(element).__name__} | '{element.name}' | {resource_uri}",
48+
style="warning"
49+
)
50+
invalid_annotations.append(
51+
{
52+
"id": element.id,
53+
"object": type(element).__name__,
54+
"resource": resource_uri,
55+
}
56+
)
57+
df = pd.DataFrame(invalid_annotations)
58+
if len(invalid_annotations) == 0:
59+
console.print("All annotations valid", style="success")
60+
else:
61+
console.print(df.to_string())
62+
console.print("Invalid annotations", style="error")
63+
console.rule(style="white")
64+
return df
65+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import pandas as pd
2+
3+
from sbmlutils.console import console
4+
from sbmlutils.resources import MODELS_DIR
5+
from sbmlutils.metadata.validator import validate_sbml_annotations
6+
7+
if __name__ == "__main__":
8+
sbml_faure2006 = MODELS_DIR / "qual" / "Faure2006_MammalianCellCycle.sbml"
9+
results: pd.DataFrame = validate_sbml_annotations(sbml_faure2006)

0 commit comments

Comments
 (0)