CellType¶
lamindb provides access to the following public CellType ontologies through bionty:
Here we show how to access and search CellType ontologies to standardize new data.
import bionty as bt
import pandas as pd
PublicOntology objects¶
Let us create a public ontology accessor with .public
method, which chooses a default public ontology source from Source
.
It’s a PublicOntology object, which you can think about as a public registry:
celltypes = bt.CellType.public(organism="all")
celltypes
→ connected lamindb: testuser1/test-public-ontologies
PublicOntology
Entity: CellType
Organism: all
Source: cl, 2024-08-16
#terms: 2959
As for registries, you can export the ontology as a DataFrame
:
df = celltypes.df()
df.head()
name | definition | synonyms | parents | |
---|---|---|---|---|
ontology_id | ||||
CL:0000000 | cell | A Material Entity Of Anatomical Origin (Part O... | None | [] |
CL:0000001 | primary cultured cell | A Cultured Cell That Is Freshly Isolated From ... | primary cell culture cell|unpassaged cultured ... | [CL:0000010] |
CL:0000002 | obsolete immortal cell line cell | Obsolete: A Cell Line Cell That Is Expected To... | continuous cell line cell|permanent cell line ... | [] |
CL:0000003 | obsolete native cell | Obsolete. A Cell That Is Found In A Natural Se... | None | [] |
CL:0000004 | obsolete cell by organism | Obsolete: A Classification Of Cells By The Org... | None | [] |
Unlike registries, you can also export it as a Pronto object via public.ontology
.
Look up terms¶
As for registries, terms can be looked up with auto-complete:
lookup = celltypes.lookup()
The .
accessor provides normalized terms (lower case, only contains alphanumeric characters and underscores):
lookup.cd8_positive_alpha_beta_t_cell
CellType(ontology_id='CL:0000625', name='CD8-positive, alpha-beta T cell', definition='A T Cell Expressing An Alpha-Beta T Cell Receptor And The Cd8 Coreceptor.', synonyms='CD8-positive, alpha-beta T-cell|CD8-positive, alpha-beta T lymphocyte|CD8-positive, alpha-beta T-lymphocyte', parents=array(['CL:0000791'], dtype=object))
To look up the exact original strings, convert the lookup object to dict and use the []
accessor:
lookup_dict = lookup.dict()
lookup_dict["CD8-positive, alpha-beta T cell"]
CellType(ontology_id='CL:0000625', name='CD8-positive, alpha-beta T cell', definition='A T Cell Expressing An Alpha-Beta T Cell Receptor And The Cd8 Coreceptor.', synonyms='CD8-positive, alpha-beta T-cell|CD8-positive, alpha-beta T lymphocyte|CD8-positive, alpha-beta T-lymphocyte', parents=array(['CL:0000791'], dtype=object))
By default, the name
field is used to generate lookup keys. You can specify another field to look up:
lookup = celltypes.lookup(celltypes.ontology_id)
lookup.cl_0000625
CellType(ontology_id='CL:0000625', name='CD8-positive, alpha-beta T cell', definition='A T Cell Expressing An Alpha-Beta T Cell Receptor And The Cd8 Coreceptor.', synonyms='CD8-positive, alpha-beta T-cell|CD8-positive, alpha-beta T lymphocyte|CD8-positive, alpha-beta T-lymphocyte', parents=array(['CL:0000791'], dtype=object))
Search terms¶
Search behaves in the same way as it does for registries:
celltypes.search("Tc1 cell").head(3)
name | definition | synonyms | parents | |
---|---|---|---|---|
ontology_id | ||||
CL:0000917 | Tc1 cell | A Cd8-Positive, Alpha-Beta Positive T Cell Tha... | Th1 non-TFH CD8-positive T cell|Tc1 T lymphocy... | [CL:0000908] |
By default, search also covers synonyms and all other fileds containing strings:
celltypes.search("Tc1 T lymphocyte").head(3)
name | definition | synonyms | parents | |
---|---|---|---|---|
ontology_id | ||||
CL:0000917 | Tc1 cell | A Cd8-Positive, Alpha-Beta Positive T Cell Tha... | Th1 non-TFH CD8-positive T cell|Tc1 T lymphocy... | [CL:0000908] |
Search specific field (by default, search is done on all fields containing strings):
celltypes.search(
"cd8-positive, alpha-beta positive t cell",
field=celltypes.definition,
).head()
name | definition | synonyms | parents | |
---|---|---|---|---|
ontology_id | ||||
CL:0000917 | Tc1 cell | A Cd8-Positive, Alpha-Beta Positive T Cell Tha... | Th1 non-TFH CD8-positive T cell|Tc1 T lymphocy... | [CL:0000908] |
CL:0000918 | Tc2 cell | A Cd8-Positive, Alpha-Beta Positive T Cell Exp... | Tc2 T-cell|T-cytotoxic T cell type 2|Th2 non-T... | [CL:0000908, CL:0001052] |
Standardize CellType identifiers¶
Let us generate a DataFrame
that stores a number of CellType identifiers, some of which corrupted:
df_orig = pd.DataFrame(
index=[
"Boettcher cell",
"bone marrow cell",
"interstitial cell of ovary",
"pancreatic ductal cell",
"This celltype does not exist",
]
)
df_orig
Boettcher cell |
---|
bone marrow cell |
interstitial cell of ovary |
pancreatic ductal cell |
This celltype does not exist |
We can check whether any of our values are validated against the ontology reference:
validated = celltypes.validate(df_orig.index, celltypes.name)
df_orig.index[~validated]
! 1 unique term (20.00%) is not validated: 'This celltype does not exist'
Index(['This celltype does not exist'], dtype='object')
Ontology source versions¶
For any given entity, we can choose from a number of versions:
bt.Source.filter(entity="bionty.CellType").df()
# only lists the sources that are currently used
bt.Source.filter(entity="bionty.CellType", currently_used=True).df()
uid | entity | organism | name | in_db | currently_used | description | url | md5 | source_website | space_id | dataframe_artifact_id | version | run_id | created_at | created_by_id | _aux | branch_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||||||
16 | 3Uw2Va7a | bionty.CellType | all | cl | False | True | Cell Ontology | http://purl.obolibrary.org/obo/cl/releases/202... | None | https://obophenotype.github.io/cell-ontology | 1 | None | 2024-08-16 | None | 2025-07-14 06:41:44.843000+00:00 | 1 | None | 1 |
When instantiating a Bionty object, we can choose a source or version:
source = bt.Source.filter(
name="cl", organism="all"
).first()
celltypes= bt.CellType.public(source=source)
celltypes
PublicOntology
Entity: CellType
Organism: all
Source: cl, 2024-08-16
#terms: 2959
The currently used ontologies can be displayed using:
bt.Source.filter(currently_used=True).df()