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
27
28class CuratedOntologyTermList(Enum):
29    """
30    Enum for the set of curated ontology term lists supported by CZ CellXGene
31    """
32
33    CELL_CLASS = "cell_class"
34    CELL_SUBCLASS = "cell_subclass"
35    ORGAN = "organ"
36    SYSTEM = "system"
37    TISSUE_GENERAL = "tissue_general"
38    UBERON_DEVELOPMENT_STAGE = "uberon_development_stage"
39
40
41class OntologyNode:
42    """
43    Class to represent an ontology term and its subclasses
44    """
45
46    def __init__(self, term_id: str, name: str):
47        self._term_id = term_id
48        self._name = name
49        self._children: List["OntologyNode"] = []
50        self._term_counter: Counter[str] = Counter({self.term_id: 1})
51
52    @property
53    def term_id(self) -> str:
54        """
55        Ontology term ID represented by this OntologyNode.
56        """
57        return self._term_id
58
59    @property
60    def name(self) -> str:
61        """
62        Human-readable label for ontology term represented by this OntologyNode.
63        """
64        return self._name
65
66    @property
67    def children(self) -> List["OntologyNode"]:
68        """
69        List of children OntologyNode of this OntologyNode.
70        """
71        return self._children
72
73    @property
74    def term_counter(self) -> Counter[str]:
75        """
76        Mapping of unique ontology term ID descendants of this OntologyNode to the number of times each term
77        appears in the graph rooted at this node.
78        :return:
79        """
80        return self._term_counter
81
82    def add_child(self, child: "OntologyNode") -> None:
83        self._children.append(child)
84        self._term_counter.update(child.term_counter)
85
86    def to_dict(self) -> Dict[str, Any]:
87        return {
88            "term_id": self.term_id,
89            "name": self.name,
90            "children": [child.to_dict() for child in self.children],
91        }
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"

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'>
class CuratedOntologyTermList(enum.Enum):
29class CuratedOntologyTermList(Enum):
30    """
31    Enum for the set of curated ontology term lists supported by CZ CellXGene
32    """
33
34    CELL_CLASS = "cell_class"
35    CELL_SUBCLASS = "cell_subclass"
36    ORGAN = "organ"
37    SYSTEM = "system"
38    TISSUE_GENERAL = "tissue_general"
39    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:
42class OntologyNode:
43    """
44    Class to represent an ontology term and its subclasses
45    """
46
47    def __init__(self, term_id: str, name: str):
48        self._term_id = term_id
49        self._name = name
50        self._children: List["OntologyNode"] = []
51        self._term_counter: Counter[str] = Counter({self.term_id: 1})
52
53    @property
54    def term_id(self) -> str:
55        """
56        Ontology term ID represented by this OntologyNode.
57        """
58        return self._term_id
59
60    @property
61    def name(self) -> str:
62        """
63        Human-readable label for ontology term represented by this OntologyNode.
64        """
65        return self._name
66
67    @property
68    def children(self) -> List["OntologyNode"]:
69        """
70        List of children OntologyNode of this OntologyNode.
71        """
72        return self._children
73
74    @property
75    def term_counter(self) -> Counter[str]:
76        """
77        Mapping of unique ontology term ID descendants of this OntologyNode to the number of times each term
78        appears in the graph rooted at this node.
79        :return:
80        """
81        return self._term_counter
82
83    def add_child(self, child: "OntologyNode") -> None:
84        self._children.append(child)
85        self._term_counter.update(child.term_counter)
86
87    def to_dict(self) -> Dict[str, Any]:
88        return {
89            "term_id": self.term_id,
90            "name": self.name,
91            "children": [child.to_dict() for child in self.children],
92        }

Class to represent an ontology term and its subclasses

OntologyNode(term_id: str, name: str)
47    def __init__(self, term_id: str, name: str):
48        self._term_id = term_id
49        self._name = name
50        self._children: List["OntologyNode"] = []
51        self._term_counter: Counter[str] = Counter({self.term_id: 1})
term_id: str
53    @property
54    def term_id(self) -> str:
55        """
56        Ontology term ID represented by this OntologyNode.
57        """
58        return self._term_id

Ontology term ID represented by this OntologyNode.

name: str
60    @property
61    def name(self) -> str:
62        """
63        Human-readable label for ontology term represented by this OntologyNode.
64        """
65        return self._name

Human-readable label for ontology term represented by this OntologyNode.

children: List[OntologyNode]
67    @property
68    def children(self) -> List["OntologyNode"]:
69        """
70        List of children OntologyNode of this OntologyNode.
71        """
72        return self._children

List of children OntologyNode of this OntologyNode.

term_counter: collections.Counter[str]
74    @property
75    def term_counter(self) -> Counter[str]:
76        """
77        Mapping of unique ontology term ID descendants of this OntologyNode to the number of times each term
78        appears in the graph rooted at this node.
79        :return:
80        """
81        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.

Returns
def add_child(self, child: OntologyNode) -> None:
83    def add_child(self, child: "OntologyNode") -> None:
84        self._children.append(child)
85        self._term_counter.update(child.term_counter)
def to_dict(self) -> Dict[str, Any]:
87    def to_dict(self) -> Dict[str, Any]:
88        return {
89            "term_id": self.term_id,
90            "name": self.name,
91            "children": [child.to_dict() for child in self.children],
92        }