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

OntologyClass metadata additions: alternative_names, alternative_identifiers, relations #2239

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
95 changes: 86 additions & 9 deletions nmdc_schema/nmdc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Auto generated from nmdc.yaml by pythongen.py version: 0.0.1
# Generation date: 2024-11-13T01:04:03

# Generation date: 2024-10-31T16:13:01
# Schema: NMDC
#
# id: https://w3id.org/nmdc/nmdc
Expand Down Expand Up @@ -113,6 +114,7 @@
NEON_IDENTIFIER = CurieNamespace('neon_identifier', 'http://example.org/neon/identifier/')
NEON_SCHEMA = CurieNamespace('neon_schema', 'http://example.org/neon/schema/')
NMDC = CurieNamespace('nmdc', 'https://w3id.org/nmdc/')
OWL = CurieNamespace('owl', 'http://www.w3.org/2002/07/owl#')
PROV = CurieNamespace('prov', 'http://www.w3.org/ns/prov#')
QUD = CurieNamespace('qud', 'http://qudt.org/1.1/schema/qudt#')
RDF = CurieNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
Expand Down Expand Up @@ -1349,6 +1351,9 @@ def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):

@dataclass(repr=False)
class OntologyClass(NamedThing):
"""
This class is used to represent ontology terms.
"""
_inherited_slots: ClassVar[List[str]] = []

class_class_uri: ClassVar[URIRef] = NMDC["OntologyClass"]
Expand All @@ -1358,13 +1363,27 @@ class OntologyClass(NamedThing):

id: Union[str, OntologyClassId] = None
type: Union[str, URIorCURIE] = None
alternative_names: Optional[Union[str, List[str]]] = empty_list()
definition: Optional[str] = None
relations: Optional[Union[Union[dict, "OntologyRelation"], List[Union[dict, "OntologyRelation"]]]] = empty_list()

def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
if self._is_empty(self.id):
self.MissingRequiredField("id")
if not isinstance(self.id, OntologyClassId):
self.id = OntologyClassId(self.id)

if not isinstance(self.alternative_names, list):
self.alternative_names = [self.alternative_names] if self.alternative_names is not None else []
self.alternative_names = [v if isinstance(v, str) else str(v) for v in self.alternative_names]

if self.definition is not None and not isinstance(self.definition, str):
self.definition = str(self.definition)

if not isinstance(self.relations, list):
self.relations = [self.relations] if self.relations is not None else []
self.relations = [v if isinstance(v, OntologyRelation) else OntologyRelation(**as_dict(v)) for v in self.relations]

super().__post_init__(**kwargs)
if self._is_empty(self.type):
self.MissingRequiredField("type")
Expand Down Expand Up @@ -1488,7 +1507,6 @@ class ChemicalEntity(OntologyClass):

id: Union[str, ChemicalEntityId] = None
type: Union[str, URIorCURIE] = None
alternative_names: Optional[Union[str, List[str]]] = empty_list()
chemical_formula: Optional[str] = None
inchi: Optional[str] = None
inchi_key: Optional[str] = None
Expand All @@ -1500,10 +1518,6 @@ def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
if not isinstance(self.id, ChemicalEntityId):
self.id = ChemicalEntityId(self.id)

if not isinstance(self.alternative_names, list):
self.alternative_names = [self.alternative_names] if self.alternative_names is not None else []
self.alternative_names = [v if isinstance(v, str) else str(v) for v in self.alternative_names]

if self.chemical_formula is not None and not isinstance(self.chemical_formula, str):
self.chemical_formula = str(self.chemical_formula)

Expand All @@ -1523,6 +1537,51 @@ def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
self.type = str(self.class_class_curie)


@dataclass(repr=False)
class OntologyRelation(YAMLRoot):
"""
A relationship between two ontology classes as specified either directly in the ontology in the form of axioms
(statements or assertions that defines rules or constraints in an ontology) or inferred via reasoning. The
association object is defined by two terms (the subject and the object) and the relationship between them (the
predicate). Because ontologies often have a plethora of relationships/axiom types and can have additional metadata
on the relationship itself, these kinds of relationships are structured as a class instead of a simple set of
slots on OntologyClass itself.
"""
_inherited_slots: ClassVar[List[str]] = []

class_class_uri: ClassVar[URIRef] = NMDC["OntologyRelation"]
class_class_curie: ClassVar[str] = "nmdc:OntologyRelation"
class_name: ClassVar[str] = "OntologyRelation"
class_model_uri: ClassVar[URIRef] = NMDC.OntologyRelation

type: Union[str, URIorCURIE] = None
subject: Union[str, OntologyClassId] = None
predicate: Union[str, OntologyClassId] = None
object: Union[str, OntologyClassId] = None

def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
if self._is_empty(self.type):
self.MissingRequiredField("type")
self.type = str(self.class_class_curie)

if self._is_empty(self.subject):
self.MissingRequiredField("subject")
if not isinstance(self.subject, OntologyClassId):
self.subject = OntologyClassId(self.subject)

if self._is_empty(self.predicate):
self.MissingRequiredField("predicate")
if not isinstance(self.predicate, OntologyClassId):
self.predicate = OntologyClassId(self.predicate)

if self._is_empty(self.object):
self.MissingRequiredField("object")
if not isinstance(self.object, OntologyClassId):
self.object = OntologyClassId(self.object)

super().__post_init__(**kwargs)


@dataclass(repr=False)
class FailureCategorization(YAMLRoot):
_inherited_slots: ClassVar[List[str]] = []
Expand Down Expand Up @@ -9881,6 +9940,9 @@ class slots:
slots.chemical_entity_set = Slot(uri=NMDC.chemical_entity_set, name="chemical_entity_set", curie=NMDC.curie('chemical_entity_set'),
model_uri=NMDC.chemical_entity_set, domain=None, range=Optional[Union[Dict[Union[str, ChemicalEntityId], Union[dict, ChemicalEntity]], List[Union[dict, ChemicalEntity]]]])

slots.ontology_class_set = Slot(uri=NMDC.ontology_class_set, name="ontology_class_set", curie=NMDC.curie('ontology_class_set'),
model_uri=NMDC.ontology_class_set, domain=None, range=Optional[Union[Dict[Union[str, OntologyClassId], Union[dict, OntologyClass]], List[Union[dict, OntologyClass]]]])

slots.biosample_set = Slot(uri=NMDC.biosample_set, name="biosample_set", curie=NMDC.curie('biosample_set'),
model_uri=NMDC.biosample_set, domain=None, range=Optional[Union[Dict[Union[str, BiosampleId], Union[dict, Biosample]], List[Union[dict, Biosample]]]])

Expand Down Expand Up @@ -10815,7 +10877,7 @@ class slots:

slots.alternative_identifiers = Slot(uri=NMDC.alternative_identifiers, name="alternative_identifiers", curie=NMDC.curie('alternative_identifiers'),
model_uri=NMDC.alternative_identifiers, domain=None, range=Optional[Union[Union[str, URIorCURIE], List[Union[str, URIorCURIE]]]],
pattern=re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_\.]+:[a-zA-Z0-9_][a-zA-Z0-9_\-\/\.,]*$'))
pattern=re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_\.]+:[a-zA-Z0-9_][a-zA-Z0-9_\-\/\.,\(\)\=\#]*$'))

slots.start_date = Slot(uri=NMDC.start_date, name="start_date", curie=NMDC.curie('start_date'),
model_uri=NMDC.start_date, domain=None, range=Optional[str])
Expand Down Expand Up @@ -12437,6 +12499,21 @@ class slots:
slots.sequencing_field = Slot(uri=MIXS.sequencing_field, name="sequencing field", curie=MIXS.curie('sequencing_field'),
model_uri=NMDC.sequencing_field, domain=None, range=Optional[str])

slots.ontologyClass__definition = Slot(uri=NMDC['basic_classes/definition'], name="ontologyClass__definition", curie=NMDC.curie('basic_classes/definition'),
model_uri=NMDC.ontologyClass__definition, domain=None, range=Optional[str])

slots.ontologyClass__relations = Slot(uri=NMDC['basic_classes/relations'], name="ontologyClass__relations", curie=NMDC.curie('basic_classes/relations'),
model_uri=NMDC.ontologyClass__relations, domain=None, range=Optional[Union[Union[dict, OntologyRelation], List[Union[dict, OntologyRelation]]]])

slots.ontologyRelation__subject = Slot(uri=NMDC['basic_classes/subject'], name="ontologyRelation__subject", curie=NMDC.curie('basic_classes/subject'),
model_uri=NMDC.ontologyRelation__subject, domain=None, range=Union[str, OntologyClassId])

slots.ontologyRelation__predicate = Slot(uri=NMDC['basic_classes/predicate'], name="ontologyRelation__predicate", curie=NMDC.curie('basic_classes/predicate'),
model_uri=NMDC.ontologyRelation__predicate, domain=None, range=Union[str, OntologyClassId])

slots.ontologyRelation__object = Slot(uri=NMDC['basic_classes/object'], name="ontologyRelation__object", curie=NMDC.curie('basic_classes/object'),
model_uri=NMDC.ontologyRelation__object, domain=None, range=Union[str, OntologyClassId])

slots.NucleotideSequencing_id = Slot(uri=NMDC.id, name="NucleotideSequencing_id", curie=NMDC.curie('id'),
model_uri=NMDC.NucleotideSequencing_id, domain=NucleotideSequencing, range=Union[str, NucleotideSequencingId],
pattern=re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_\.]+:[a-zA-Z0-9_][a-zA-Z0-9_\-\/\.,]*$'))
Expand Down Expand Up @@ -12779,7 +12856,7 @@ class slots:

slots.Biosample_alternative_identifiers = Slot(uri=NMDC.alternative_identifiers, name="Biosample_alternative_identifiers", curie=NMDC.curie('alternative_identifiers'),
model_uri=NMDC.Biosample_alternative_identifiers, domain=Biosample, range=Optional[Union[Union[str, URIorCURIE], List[Union[str, URIorCURIE]]]],
pattern=re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_\.]+:[a-zA-Z0-9_][a-zA-Z0-9_\-\/\.,]*$'))
pattern=re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_\.]+:[a-zA-Z0-9_][a-zA-Z0-9_\-\/\.,\(\)\=\#]*$'))

slots.Biosample_lat_lon = Slot(uri=MIXS['0000009'], name="Biosample_lat_lon", curie=MIXS.curie('0000009'),
model_uri=NMDC.Biosample_lat_lon, domain=Biosample, range=Optional[Union[dict, GeolocationValue]])
Expand Down Expand Up @@ -12952,7 +13029,7 @@ class slots:

slots.Study_alternative_identifiers = Slot(uri=NMDC.alternative_identifiers, name="Study_alternative_identifiers", curie=NMDC.curie('alternative_identifiers'),
model_uri=NMDC.Study_alternative_identifiers, domain=Study, range=Optional[Union[Union[str, URIorCURIE], List[Union[str, URIorCURIE]]]],
pattern=re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_\.]+:[a-zA-Z0-9_][a-zA-Z0-9_\-\/\.,]*$'))
pattern=re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9_\.]+:[a-zA-Z0-9_][a-zA-Z0-9_\-\/\.,\(\)\=\#]*$'))

slots.Study_alternative_names = Slot(uri=NMDC.alternative_names, name="Study_alternative_names", curie=NMDC.curie('alternative_names'),
model_uri=NMDC.Study_alternative_names, domain=Study, range=Optional[Union[str, List[str]]])
Expand Down
Loading
Loading