cellxgene_ontology_guide.entities
1from collections import Counter 2from enum import Enum 3from typing import Any, Dict, List 4 5 6class Ontology(Enum): 7 """ 8 Enum for the set of ontologies supported by CZ CellXGene. 9 """ 10 11 CL = "cl" 12 EFO = "efo" 13 MONDO = "mondo" 14 UBERON = "uberon" 15 HANCESTRO = "hancestro" 16 HsapDv = "hsapdv" 17 MmusDv = "mmusdv" 18 PATO = "pato" 19 NCBITaxon = "ncbitaxon" 20 FBbt = "fbbt" 21 FBdv = "fbdv" 22 ZFA = "zfa" 23 WBbt = "wbbt" 24 WBls = "wbls" 25 CVCL = "cvcl" 26 CHEBI = "chebi" 27 # NOTE: UniProt is a special case. Unlike OBO/OWL ontologies, UniProt does not expose a 28 # parseable is-a hierarchy through this pipeline. The ``ancestors`` field is empty for 29 # all UniProt terms. Hierarchy support (e.g. via Gene Ontology molecular-function 30 # annotations) is not yet implemented in cellxgene-ontology-guide. 31 UniProt = "uniprot" 32 33 34class CuratedOntologyTermList(Enum): 35 """ 36 Enum for the set of curated ontology term lists supported by CZ CellXGene 37 """ 38 39 CELL_CLASS = "cell_class" 40 CELL_SUBCLASS = "cell_subclass" 41 ORGAN = "organ" 42 SYSTEM = "system" 43 TISSUE_GENERAL = "tissue_general" 44 UBERON_DEVELOPMENT_STAGE = "uberon_development_stage" 45 46 47class OntologyNode: 48 """ 49 Class to represent an ontology term and its subclasses 50 """ 51 52 def __init__(self, term_id: str, name: str): 53 self._term_id = term_id 54 self._name = name 55 self._children: List["OntologyNode"] = [] 56 self._term_counter: Counter[str] = Counter({self.term_id: 1}) 57 58 @property 59 def term_id(self) -> str: 60 """ 61 Ontology term ID represented by this OntologyNode. 62 """ 63 return self._term_id 64 65 @property 66 def name(self) -> str: 67 """ 68 Human-readable label for ontology term represented by this OntologyNode. 69 """ 70 return self._name 71 72 @property 73 def children(self) -> List["OntologyNode"]: 74 """ 75 List of children OntologyNode of this OntologyNode. 76 """ 77 return self._children 78 79 @property 80 def term_counter(self) -> Counter[str]: 81 """ 82 Mapping of unique ontology term ID descendants of this OntologyNode to the number of times each term 83 appears in the graph rooted at this node. 84 :return: 85 """ 86 return self._term_counter 87 88 def add_child(self, child: "OntologyNode") -> None: 89 self._children.append(child) 90 self._term_counter.update(child.term_counter) 91 92 def to_dict(self) -> Dict[str, Any]: 93 return { 94 "term_id": self.term_id, 95 "name": self.name, 96 "children": [child.to_dict() for child in self.children], 97 }
class
Ontology(enum.Enum):
7class Ontology(Enum): 8 """ 9 Enum for the set of ontologies supported by CZ CellXGene. 10 """ 11 12 CL = "cl" 13 EFO = "efo" 14 MONDO = "mondo" 15 UBERON = "uberon" 16 HANCESTRO = "hancestro" 17 HsapDv = "hsapdv" 18 MmusDv = "mmusdv" 19 PATO = "pato" 20 NCBITaxon = "ncbitaxon" 21 FBbt = "fbbt" 22 FBdv = "fbdv" 23 ZFA = "zfa" 24 WBbt = "wbbt" 25 WBls = "wbls" 26 CVCL = "cvcl" 27 CHEBI = "chebi" 28 # NOTE: UniProt is a special case. Unlike OBO/OWL ontologies, UniProt does not expose a 29 # parseable is-a hierarchy through this pipeline. The ``ancestors`` field is empty for 30 # all UniProt terms. Hierarchy support (e.g. via Gene Ontology molecular-function 31 # annotations) is not yet implemented in cellxgene-ontology-guide. 32 UniProt = "uniprot"
Enum for the set of ontologies supported by CZ CellXGene.
CL =
<Ontology.CL: 'cl'>
EFO =
<Ontology.EFO: 'efo'>
MONDO =
<Ontology.MONDO: 'mondo'>
UBERON =
<Ontology.UBERON: 'uberon'>
HANCESTRO =
<Ontology.HANCESTRO: 'hancestro'>
HsapDv =
<Ontology.HsapDv: 'hsapdv'>
MmusDv =
<Ontology.MmusDv: 'mmusdv'>
PATO =
<Ontology.PATO: 'pato'>
NCBITaxon =
<Ontology.NCBITaxon: 'ncbitaxon'>
FBbt =
<Ontology.FBbt: 'fbbt'>
FBdv =
<Ontology.FBdv: 'fbdv'>
ZFA =
<Ontology.ZFA: 'zfa'>
WBbt =
<Ontology.WBbt: 'wbbt'>
WBls =
<Ontology.WBls: 'wbls'>
CVCL =
<Ontology.CVCL: 'cvcl'>
CHEBI =
<Ontology.CHEBI: 'chebi'>
UniProt =
<Ontology.UniProt: 'uniprot'>
class
CuratedOntologyTermList(enum.Enum):
35class CuratedOntologyTermList(Enum): 36 """ 37 Enum for the set of curated ontology term lists supported by CZ CellXGene 38 """ 39 40 CELL_CLASS = "cell_class" 41 CELL_SUBCLASS = "cell_subclass" 42 ORGAN = "organ" 43 SYSTEM = "system" 44 TISSUE_GENERAL = "tissue_general" 45 UBERON_DEVELOPMENT_STAGE = "uberon_development_stage"
Enum for the set of curated ontology term lists supported by CZ CellXGene
CELL_CLASS =
<CuratedOntologyTermList.CELL_CLASS: 'cell_class'>
CELL_SUBCLASS =
<CuratedOntologyTermList.CELL_SUBCLASS: 'cell_subclass'>
ORGAN =
<CuratedOntologyTermList.ORGAN: 'organ'>
SYSTEM =
<CuratedOntologyTermList.SYSTEM: 'system'>
TISSUE_GENERAL =
<CuratedOntologyTermList.TISSUE_GENERAL: 'tissue_general'>
UBERON_DEVELOPMENT_STAGE =
<CuratedOntologyTermList.UBERON_DEVELOPMENT_STAGE: 'uberon_development_stage'>
class
OntologyNode:
48class OntologyNode: 49 """ 50 Class to represent an ontology term and its subclasses 51 """ 52 53 def __init__(self, term_id: str, name: str): 54 self._term_id = term_id 55 self._name = name 56 self._children: List["OntologyNode"] = [] 57 self._term_counter: Counter[str] = Counter({self.term_id: 1}) 58 59 @property 60 def term_id(self) -> str: 61 """ 62 Ontology term ID represented by this OntologyNode. 63 """ 64 return self._term_id 65 66 @property 67 def name(self) -> str: 68 """ 69 Human-readable label for ontology term represented by this OntologyNode. 70 """ 71 return self._name 72 73 @property 74 def children(self) -> List["OntologyNode"]: 75 """ 76 List of children OntologyNode of this OntologyNode. 77 """ 78 return self._children 79 80 @property 81 def term_counter(self) -> Counter[str]: 82 """ 83 Mapping of unique ontology term ID descendants of this OntologyNode to the number of times each term 84 appears in the graph rooted at this node. 85 :return: 86 """ 87 return self._term_counter 88 89 def add_child(self, child: "OntologyNode") -> None: 90 self._children.append(child) 91 self._term_counter.update(child.term_counter) 92 93 def to_dict(self) -> Dict[str, Any]: 94 return { 95 "term_id": self.term_id, 96 "name": self.name, 97 "children": [child.to_dict() for child in self.children], 98 }
Class to represent an ontology term and its subclasses
term_id: str
59 @property 60 def term_id(self) -> str: 61 """ 62 Ontology term ID represented by this OntologyNode. 63 """ 64 return self._term_id
Ontology term ID represented by this OntologyNode.
name: str
66 @property 67 def name(self) -> str: 68 """ 69 Human-readable label for ontology term represented by this OntologyNode. 70 """ 71 return self._name
Human-readable label for ontology term represented by this OntologyNode.
children: List[OntologyNode]
73 @property 74 def children(self) -> List["OntologyNode"]: 75 """ 76 List of children OntologyNode of this OntologyNode. 77 """ 78 return self._children
List of children OntologyNode of this OntologyNode.
term_counter: collections.Counter[str]
80 @property 81 def term_counter(self) -> Counter[str]: 82 """ 83 Mapping of unique ontology term ID descendants of this OntologyNode to the number of times each term 84 appears in the graph rooted at this node. 85 :return: 86 """ 87 return self._term_counter
Mapping of unique ontology term ID descendants of this OntologyNode to the number of times each term appears in the graph rooted at this node.