Jupyter Notebook

Manage biological registries

This guide shows how to manage metadata for basic biological entities based on plugin bionty.

# !pip install 'lamindb[bionty]'
!lamin init --storage ./test-registries --modules bionty
Hide code cell output
 initialized lamindb: testuser1/test-registries
import lamindb as ln
import bionty as bt
 connected lamindb: testuser1/test-registries

Seed registries with public ontologies

Let’s first populate our CellType registry with the configured public ontology (Cell Ontology):

# check configured public ontology
bt.Source.filter(entity="bionty.CellType", currently_used=True).one()
Source(uid='3Uw2', entity='bionty.CellType', organism='all', name='cl', version='2024-08-16', in_db=False, currently_used=True, description='Cell Ontology', url='http://purl.obolibrary.org/obo/cl/releases/2024-08-16/cl.owl', md5='', source_website='https://obophenotype.github.io/cell-ontology', created_by_id=1, space_id=1, created_at=2025-01-12 14:03:47 UTC)
# populate the database with the public ontology
bt.CellType.import_source()

This is now your in-house CellType registry:

# all public cell types are now available in LaminDB
bt.CellType.df()
Hide code cell output
uid name ontology_id abbr synonyms description space_id source_id run_id created_at created_by_id aux _branch_code
id
2959 77KNSTIT cycling neuroblast (sensu Vertebrata) CL:4047005 None proliferating neuroblast (sensu Vertebrata) A(N) Neuroblast (Sensu Vertebrata) That Is Cyc... 1 32 None 2025-01-12 14:03:57.347239+00:00 1 None 1
2958 tEH7Cu81 cycling type EC enteroendocrine cell CL:4047004 None proliferating type EC enteroendocrine cell A(N) Type Ec Enteroendocrine Cell That Is Cycl... 1 32 None 2025-01-12 14:03:57.347169+00:00 1 None 1
2957 5CQynGea cycling plasma cell CL:4047003 None proliferating plasma cell A(N) Plasma Cell That Is Cycling. 1 32 None 2025-01-12 14:03:57.347100+00:00 1 None 1
2956 d8qkyh5t cycling glial cell CL:4047002 None proliferating glial cell A(N) Glial Cell That Is Cycling. 1 32 None 2025-01-12 14:03:57.347030+00:00 1 None 1
2955 4C2F94cV cycling stromal cell CL:4047001 None proliferating stromal cell A(N) Stromal Cell That Is Cycling. 1 32 None 2025-01-12 14:03:57.346961+00:00 1 None 1
... ... ... ... ... ... ... ... ... ... ... ... ... ...
2864 4efKc9o9 retinal astrocyte CL:4033015 None None A Star-Shaped Glial Cell That Is Part Of Some ... 1 32 None 2025-01-12 14:03:57.336935+00:00 1 None 1
2863 6zbMPCM6 peg cell CL:4033014 None FTE stem-like cell|fallopian tube epithelial s... A Small, Narrow, Peg-Shaped Epithelial Cell Wi... 1 32 None 2025-01-12 14:03:57.336865+00:00 1 None 1
2862 3VV9jqFH suprabasal keratinocyte CL:4033013 None None A Keratinocyte Of The Epidermis Suprabasal Lay... 1 32 None 2025-01-12 14:03:57.336795+00:00 1 None 1
2861 3olktS6h smooth muscle cell of large intestine smooth m... CL:4033012 None None A(N) Smooth Muscle Cell That Is Part Of A(N) L... 1 32 None 2025-01-12 14:03:57.336721+00:00 1 None 1
2860 1poo3P4b smooth muscle cell of large intestine smooth m... CL:4033011 None None A(N) Smooth Muscle Cell That Is Part Of A(N) L... 1 32 None 2025-01-12 14:03:57.336651+00:00 1 None 1

100 rows × 13 columns

# similarly, let's populate the Gene registry with human and mouse genes
bt.Gene.import_source(organism="human")
bt.Gene.import_source(organism="mouse")

Access records in in-house registries

Search key words:

bt.CellType.search("gamma-delta T").df().head(2)
uid name ontology_id abbr synonyms description space_id source_id run_id created_at created_by_id aux _branch_code
id
780 1HuNn2EP gamma-delta T cell CL:0000798 None gamma-delta T-cell|gamma-delta T lymphocyte|ga... A T Cell That Expresses A Gamma-Delta T Cell R... 1 32 None 2025-01-12 14:03:57.090716+00:00 1 None 1
781 70lHcCNw immature gamma-delta T cell CL:0000799 None immature gamma-delta T lymphocyte|immature gam... A Gamma-Delta T Cell That Has An Immature Phen... 1 32 None 2025-01-12 14:03:57.090785+00:00 1 None 1

Or look up with auto-complete:

cell_types = bt.CellType.lookup()
hsc_record = cell_types.hematopoietic_stem_cell
hsc_record
CellType(uid='2U8xapxu', name='hematopoietic stem cell', ontology_id='CL:0000037', synonyms='hemopoietic stem cell|blood forming stem cell', description='A Stem Cell From Which All Cells Of The Lymphoid And Myeloid Lineages Develop, Including Blood Cells And Cells Of The Immune System. Hematopoietic Stem Cells Lack Cell Markers Of Effector Cells (Lin-Negative). Lin-Negative Is Defined By Lacking One Or More Of The Following Cell Surface Markers: Cd2, Cd3 Epsilon, Cd4, Cd5 ,Cd8 Alpha Chain, Cd11B, Cd14, Cd19, Cd20, Cd56, Ly6G, Ter119.', created_by_id=1, space_id=1, source_id=32, created_at=2025-01-12 14:03:56 UTC)

Filter by fields and relationships:

gdt_cell = bt.CellType.get(ontology_id="CL:0000798", created_by__handle="testuser1")
gdt_cell
CellType(uid='1HuNn2EP', name='gamma-delta T cell', ontology_id='CL:0000798', synonyms='gamma-delta T-cell|gamma-delta T lymphocyte|gammadelta T cell|gamma-delta T-lymphocyte', description='A T Cell That Expresses A Gamma-Delta T Cell Receptor Complex.', created_by_id=1, space_id=1, source_id=32, created_at=2025-01-12 14:03:57 UTC)

View the ontological hierarchy:

gdt_cell.view_parents()  # pass with_children=True to also view children
_images/263a9f9f74a548ea1b204bbe59b2b306f2a462ef89dc238e1ad3eaa22404a8f0.svg

Or access the parents and children directly:

gdt_cell.parents.df()
Hide code cell output
uid name ontology_id abbr synonyms description space_id source_id run_id created_at created_by_id aux _branch_code
id
83 22LvKd01 T cell CL:0000084 None T-cell|T-lymphocyte|T lymphocyte A Type Of Lymphocyte Whose Defining Characteri... 1 32 None 2025-01-12 14:03:56.940242+00:00 1 None 1
gdt_cell.children.df()
Hide code cell output
uid name ontology_id abbr synonyms description space_id source_id run_id created_at created_by_id aux _branch_code
id
781 70lHcCNw immature gamma-delta T cell CL:0000799 None immature gamma-delta T lymphocyte|immature gam... A Gamma-Delta T Cell That Has An Immature Phen... 1 32 None 2025-01-12 14:03:57.090785+00:00 1 None 1
782 3W6NKGpW mature gamma-delta T cell CL:0000800 None mature gamma-delta T-lymphocyte|mature gamma-d... A Gamma-Delta T Cell That Has A Mature Phenoty... 1 32 None 2025-01-12 14:03:57.093882+00:00 1 None 1
1465 26icgrTr gamma-delta thymocyte CL:0002405 None gd thymocyte|gammadelta thymocyte A Post-Natal Thymocyte Expressing Components O... 1 32 None 2025-01-12 14:03:57.171465+00:00 1 None 1
2921 5XXsI4tm cycling gamma-delta T cell CL:4033072 None proliferating gamma-delta T cell A(N) Gamma-Delta T Cell That Is Cycling. 1 32 None 2025-01-12 14:03:57.344569+00:00 1 None 1

It is also possible to recursively query parents or children, getting direct parents (children), their parents, and so forth.

gdt_cell.query_parents().df()
Hide code cell output
uid name ontology_id abbr synonyms description space_id source_id run_id created_at created_by_id aux _branch_code
id
83 22LvKd01 T cell CL:0000084 None T-cell|T-lymphocyte|T lymphocyte A Type Of Lymphocyte Whose Defining Characteri... 1 32 None 2025-01-12 14:03:56.940242+00:00 1 None 1
822 2Jgr5Xx4 mononuclear cell CL:0000842 None mononuclear leukocyte A Leukocyte With A Single Non-Segmented Nucleu... 1 32 None 2025-01-12 14:03:57.096776+00:00 1 None 1
214 2K93w3xO motile cell CL:0000219 None None A Cell That Moves By Its Own Activities. 1 32 None 2025-01-12 14:03:57.028514+00:00 1 None 1
221 2cXC7cgF single nucleate cell CL:0000226 None None A Cell With A Single Nucleus. 1 32 None 2025-01-12 14:03:57.029047+00:00 1 None 1
721 3VEAlFdi leukocyte CL:0000738 None white blood cell|leucocyte An Achromatic Cell Of The Myeloid Or Lymphoid ... 1 32 None 2025-01-12 14:03:57.086551+00:00 1 None 1
967 4Ilrnj9U hematopoietic cell CL:0000988 None haematopoietic cell|hemopoietic cell|haemopoie... A Cell Of A Hematopoietic Lineage. 1 32 None 2025-01-12 14:03:57.113585+00:00 1 None 1
250 4WnpvUTH eukaryotic cell CL:0000255 None None Any Cell That Only Exists In Eukaryota. 1 32 None 2025-01-12 14:03:57.031133+00:00 1 None 1
1 4bKGljt0 cell CL:0000000 None None A Material Entity Of Anatomical Origin (Part O... 1 32 None 2025-01-12 14:03:56.929868+00:00 1 None 1
529 X6c7osZ5 lymphocyte CL:0000542 None None A Lymphocyte Is A Leukocyte Commonly Found In ... 1 32 None 2025-01-12 14:03:57.063364+00:00 1 None 1
1303 u3sr1Gdf nucleate cell CL:0002242 None None A Cell Containing At Least One Nucleus. 1 32 None 2025-01-12 14:03:57.153504+00:00 1 None 1
gdt_cell.query_children().df()
Hide code cell output
uid name ontology_id abbr synonyms description space_id source_id run_id created_at created_by_id aux _branch_code
id
1190 1DEERh4L CD27-negative gamma-delta T cell CL:0002125 None gammadelta-17 cells A Circulating Gamma-Delta T Cell That Expresse... 1 32 None 2025-01-12 14:03:57.139025+00:00 1 None 1
1572 1jlK4jJ9 Vgamma5-positive CD8alpha alpha positive gamma... CL:0002513 None tgd.vg5+.IEL A Cd8Alpha Alpha Positive Gamma-Delta Intraepi... 1 32 None 2025-01-12 14:03:57.185761+00:00 1 None 1
785 1mNzVotO CD4-negative CD8-negative gamma-delta intraepi... CL:0000803 None CD4-positive, gamma-delta intraepithelial T-ce... A Gamma-Delta Intraepithelial T Cell That Has ... 1 32 None 2025-01-12 14:03:57.094127+00:00 1 None 1
895 1tYOPZxH dendritic epidermal T cell CL:0000916 None dendritic epidermal T lymphocyte|DETC|dendriti... A Mature Gamma-Delta T Cell Located In The Epi... 1 32 None 2025-01-12 14:03:57.105152+00:00 1 None 1
1465 26icgrTr gamma-delta thymocyte CL:0002405 None gd thymocyte|gammadelta thymocyte A Post-Natal Thymocyte Expressing Components O... 1 32 None 2025-01-12 14:03:57.171465+00:00 1 None 1
1475 2SYX59uO immature Vgamma1.1-positive, Vdelta6.3-positiv... CL:0002415 None immature Vg1.1+Vd6.3+ T cell A Vgamma1.1-Positive, Vdelta6.3-Positive Thymo... 1 32 None 2025-01-12 14:03:57.172171+00:00 1 None 1
783 2xXcHDQq gamma-delta intraepithelial T cell CL:0000801 None gamma-delta intraepithelial T-cell|gamma-delta... A Mature Gamma-Delta T Cell That Is Found In T... 1 32 None 2025-01-12 14:03:57.093979+00:00 1 None 1
1468 3ABJ1l1O immature Vgamma2-negative thymocyte CL:0002408 None None A Double Negative Post-Natal Thymocyte That Ha... 1 32 None 2025-01-12 14:03:57.171676+00:00 1 None 1
782 3W6NKGpW mature gamma-delta T cell CL:0000800 None mature gamma-delta T-lymphocyte|mature gamma-d... A Gamma-Delta T Cell That Has A Mature Phenoty... 1 32 None 2025-01-12 14:03:57.093882+00:00 1 None 1
1191 3efemme8 CD25-positive, CD27-positive immature gamma-de... CL:0002126 None None A Cd25-Positive, Cd27-Positive Immature Gamma-... 1 32 None 2025-01-12 14:03:57.139094+00:00 1 None 1
1473 4cYNDr25 mature Vgamma1.1-positive, Vdelta6.3-negative ... CL:0002413 None None A Vgamma1.1-Positive, Vdelta6.3-Negative Thymo... 1 32 None 2025-01-12 14:03:57.172030+00:00 1 None 1
1466 4hrSce5T immature Vgamma2-positive thymocyte CL:0002406 None None A Double Negative Post-Natal Thymocyte That Ha... 1 32 None 2025-01-12 14:03:57.171536+00:00 1 None 1
2921 5XXsI4tm cycling gamma-delta T cell CL:4033072 None proliferating gamma-delta T cell A(N) Gamma-Delta T Cell That Is Cycling. 1 32 None 2025-01-12 14:03:57.344569+00:00 1 None 1
1474 5pDjyjfF immature Vgamma1.1-positive, Vdelta6.3-negativ... CL:0002414 None None A Vgamma1.1-Positive, Vdelta6.3-Negative Thymo... 1 32 None 2025-01-12 14:03:57.172101+00:00 1 None 1
1471 64PCjpkJ Vgamma1.1-positive, Vdelta6.3-negative thymocyte CL:0002411 None Vg1.1-positive, Vd6.3-negative T cell A Gamma-Delta Receptor That Expresses Vgamma1.... 1 32 None 2025-01-12 14:03:57.171886+00:00 1 None 1
1476 6JxpxGgM mature Vgamma1.1-positive, Vdelta6.3-positive ... CL:0002416 None mature Vg1.1+Vd6.3+ T cell A Vgamma1.1-Positive, Vdelta6.3-Positive Thymo... 1 32 None 2025-01-12 14:03:57.172242+00:00 1 None 1
1469 6RBJq86b mature Vgamma2-negative thymocyte CL:0002409 None Vgamma2-negative A Thymocyte That Has A T Cell Receptor Consist... 1 32 None 2025-01-12 14:03:57.171746+00:00 1 None 1
784 6fdlvmJ3 CD8-alpha alpha positive, gamma-delta intraepi... CL:0000802 None CD8-positive, gamma-delta intraepithelial T-ly... A Gamma-Delta Intraepithelial T Cell That Has ... 1 32 None 2025-01-12 14:03:57.094054+00:00 1 None 1
1472 6vYlL7zk Vgamma1.1-positive, Vdelta6.3-positive thymocyte CL:0002412 None Vg1.1+Vd6.3+ T cell A Gamma-Delta Receptor That Expresses Vgamma1.... 1 32 None 2025-01-12 14:03:57.171959+00:00 1 None 1
781 70lHcCNw immature gamma-delta T cell CL:0000799 None immature gamma-delta T lymphocyte|immature gam... A Gamma-Delta T Cell That Has An Immature Phen... 1 32 None 2025-01-12 14:03:57.090785+00:00 1 None 1
1467 76CEFg3A mature Vgamma2-positive thymocyte CL:0002407 None Vgamma2-positive A Thymocyte That Has A T Cell Receptor Consist... 1 32 None 2025-01-12 14:03:57.171606+00:00 1 None 1
1189 7MDv71IV CD27-positive gamma-delta T cell CL:0002124 None gammadelta27-positive|gd27-positive A Circulating Gamma-Delta T Cell That Is Cd27-... 1 32 None 2025-01-12 14:03:57.138955+00:00 1 None 1
1573 E2koIf0l Vgamma5-negative CD8alpha alpha positive gamma... CL:0002514 None tgd.vg5-.IEL A Cd8Alpha Alpha Positive Gamma-Delta Intraepi... 1 32 None 2025-01-12 14:03:57.185831+00:00 1 None 1

You can construct custom hierarchies of records:

# register a new cell type
my_celltype = bt.CellType(name="my new T-cell subtype").save()
# specify "gamma-delta T cell" as a parent
my_celltype.parents.add(gdt_cell)

# visualize hierarchy
gdt_cell.view_parents(distance=2, with_children=True)
_images/51eb98c9316f1423c5b0161ea9f9de70d0902cf75e644f8b690c3092240f704b.svg

Create records from values

When accessing datasets, one often encounters bulk references to entities that might be corrupted or standardized using different standardization schemes.

Let’s consider an example based on an AnnData object, in the cell_type annotations of this AnnData object, we find 4 references to cell types:

adata = ln.core.datasets.anndata_with_obs()
adata.obs.cell_type.value_counts()
Hide code cell output
cell_type
T cell                     10
hematopoietic stem cell    10
hepatocyte                 10
my new cell type           10
Name: count, dtype: int64

We’d like to load the corresponding records in our in-house registry to annotate a dataset.

To this end, you’ll typically use from_values, which will both validate & retrieve records that match the values.

cell_types = bt.CellType.from_values(adata.obs.cell_type)
cell_types
Hide code cell output
! did not create CellType record for 1 non-validated name: 'my new cell type'
RecordList([CellType(uid='2U8xapxu', name='hematopoietic stem cell', ontology_id='CL:0000037', synonyms='hemopoietic stem cell|blood forming stem cell', description='A Stem Cell From Which All Cells Of The Lymphoid And Myeloid Lineages Develop, Including Blood Cells And Cells Of The Immune System. Hematopoietic Stem Cells Lack Cell Markers Of Effector Cells (Lin-Negative). Lin-Negative Is Defined By Lacking One Or More Of The Following Cell Surface Markers: Cd2, Cd3 Epsilon, Cd4, Cd5 ,Cd8 Alpha Chain, Cd11B, Cd14, Cd19, Cd20, Cd56, Ly6G, Ter119.', created_by_id=1, space_id=1, source_id=32, created_at=2025-01-12 14:03:56 UTC),
            CellType(uid='22LvKd01', name='T cell', ontology_id='CL:0000084', synonyms='T-cell|T-lymphocyte|T lymphocyte', description='A Type Of Lymphocyte Whose Defining Characteristic Is The Expression Of A T Cell Receptor Complex.', created_by_id=1, space_id=1, source_id=32, created_at=2025-01-12 14:03:56 UTC),
            CellType(uid='7hggmgo1', name='hepatocyte', ontology_id='CL:0000182', description='The Main Structural Component Of The Liver. They Are Specialized Epithelial Cells That Are Organized Into Interconnected Plates Called Lobules. Majority Of Cell Population Of Liver, Polygonal In Shape, Arranged In Plates Or Trabeculae Between Sinusoids; May Have Single Nucleus Or Binucleated.', created_by_id=1, space_id=1, source_id=32, created_at=2025-01-12 14:03:57 UTC)])

Logging informed us that 3 cell types were validated. Since we loaded these records at the same time, we could readily use them to annotate a dataset.

What happened under-the-hood?

.from_values() performs the following look ups:

  1. If registry records match the values, load these records

  2. If values match synonyms of registry records, load these records

  3. If no record in the registry matches, attempt to load records from a public ontology

  4. Same as 3. but based on synonyms

No records will be returned if all 4 look ups are unsuccessful.

Sometimes, it’s useful to treat validated records differently from non-validated records. Here is a way:

original_values = ["gut", "gut2"]
inspector = bt.Tissue.inspect(original_values)
records_from_validated_values = bt.Tissue.from_values(inspector.validated)

Alternatively, we can retrieve records based on ontology ids:

adata.obs.cell_type_id.unique().tolist()
Hide code cell output
['CL:0000084', 'CL:0000037', 'CL:0000182', '']
bt.CellType.from_values(adata.obs.cell_type_id, field=bt.CellType.ontology_id)
Hide code cell output
RecordList([CellType(uid='2U8xapxu', name='hematopoietic stem cell', ontology_id='CL:0000037', synonyms='hemopoietic stem cell|blood forming stem cell', description='A Stem Cell From Which All Cells Of The Lymphoid And Myeloid Lineages Develop, Including Blood Cells And Cells Of The Immune System. Hematopoietic Stem Cells Lack Cell Markers Of Effector Cells (Lin-Negative). Lin-Negative Is Defined By Lacking One Or More Of The Following Cell Surface Markers: Cd2, Cd3 Epsilon, Cd4, Cd5 ,Cd8 Alpha Chain, Cd11B, Cd14, Cd19, Cd20, Cd56, Ly6G, Ter119.', created_by_id=1, space_id=1, source_id=32, created_at=2025-01-12 14:03:56 UTC),
            CellType(uid='22LvKd01', name='T cell', ontology_id='CL:0000084', synonyms='T-cell|T-lymphocyte|T lymphocyte', description='A Type Of Lymphocyte Whose Defining Characteristic Is The Expression Of A T Cell Receptor Complex.', created_by_id=1, space_id=1, source_id=32, created_at=2025-01-12 14:03:56 UTC),
            CellType(uid='7hggmgo1', name='hepatocyte', ontology_id='CL:0000182', description='The Main Structural Component Of The Liver. They Are Specialized Epithelial Cells That Are Organized Into Interconnected Plates Called Lobules. Majority Of Cell Population Of Liver, Polygonal In Shape, Arranged In Plates Or Trabeculae Between Sinusoids; May Have Single Nucleus Or Binucleated.', created_by_id=1, space_id=1, source_id=32, created_at=2025-01-12 14:03:57 UTC)])

Validate & standardize

Simple validation of an iterable of values works like so:

bt.CellType.validate(["fat cell", "blood forming stem cell"])
Hide code cell output
! 2 unique terms (100.00%) are not validated for name: 'fat cell', 'blood forming stem cell'
array([False, False])

Because these values don’t comply with the registry, they’re not validated!

You can easily convert these values to validated standardized names based on synonyms like so:

bt.CellType.standardize(["fat cell", "blood forming stem cell"])
Hide code cell output
['adipocyte', 'hematopoietic stem cell']

Alternatively, you can use .from_values(), which will only ever return validated records and automatically standardize under-the-hood:

bt.CellType.from_values(["fat cell", "blood forming stem cell"])
Hide code cell output
RecordList([CellType(uid='2U8xapxu', name='hematopoietic stem cell', ontology_id='CL:0000037', synonyms='hemopoietic stem cell|blood forming stem cell', description='A Stem Cell From Which All Cells Of The Lymphoid And Myeloid Lineages Develop, Including Blood Cells And Cells Of The Immune System. Hematopoietic Stem Cells Lack Cell Markers Of Effector Cells (Lin-Negative). Lin-Negative Is Defined By Lacking One Or More Of The Following Cell Surface Markers: Cd2, Cd3 Epsilon, Cd4, Cd5 ,Cd8 Alpha Chain, Cd11B, Cd14, Cd19, Cd20, Cd56, Ly6G, Ter119.', created_by_id=1, space_id=1, source_id=32, created_at=2025-01-12 14:03:56 UTC),
            CellType(uid='wdLgwUXo', name='adipocyte', ontology_id='CL:0000136', synonyms='adipose cell|fat cell', description='A Fat-Storing Cell Found Mostly In The Abdominal Cavity And Subcutaneous Tissue Of Mammals. Fat Is Usually Stored In The Form Of Triglycerides.', created_by_id=1, space_id=1, source_id=32, created_at=2025-01-12 14:03:56 UTC)])

If you are now sure what to do, use .inspect() to get instructions:

bt.CellType.inspect(["fat cell", "blood forming stem cell"]);
Hide code cell output
! 2 unique terms (100.00%) are not validated for name: 'fat cell', 'blood forming stem cell'
   detected 2 unique terms with synonyms: fat cell, blood forming stem cell
→  standardize terms via .standardize()

We can also add new synonyms to a record like so:

hsc_record.add_synonym("HSC")

And when we encounter this synonym as a value, it will now be standardized using synonyms-lookup, and mapped on the correct registry record:

bt.CellType.standardize(["HSC"])
Hide code cell output
['hematopoietic stem cell']

A special synonym is .abbr (short for abbreviation), which has its own field and can be assigned via:

hsc_record.set_abbr("HSC")

You can create a lookup object from the .abbr field:

cell_types = bt.CellType.lookup("abbr")
hsc = cell_types.hsc
hsc
Hide code cell output
CellType(uid='2U8xapxu', name='hematopoietic stem cell', ontology_id='CL:0000037', abbr='HSC', synonyms='blood forming stem cell|hemopoietic stem cell|HSC', description='A Stem Cell From Which All Cells Of The Lymphoid And Myeloid Lineages Develop, Including Blood Cells And Cells Of The Immune System. Hematopoietic Stem Cells Lack Cell Markers Of Effector Cells (Lin-Negative). Lin-Negative Is Defined By Lacking One Or More Of The Following Cell Surface Markers: Cd2, Cd3 Epsilon, Cd4, Cd5 ,Cd8 Alpha Chain, Cd11B, Cd14, Cd19, Cd20, Cd56, Ly6G, Ter119.', created_by_id=1, space_id=1, source_id=32, created_at=2025-01-12 14:03:56 UTC)

The same workflow works for all of bionty’s registries.

Manage registries across organisms

Several registries are organism-aware (has a .organism field), for instance, Gene.

In this case, API calls that interact with multi-organism registries require an organism argument when there’s ambiguity.

For instance, when validating gene symbols:

bt.Gene.validate(["TCF7", "ABC1"], organism="human")
Hide code cell output
! 1 unique term (50.00%) is not validated for symbol: 'ABC1'
array([ True, False])

In contrary, working with Ensembl Gene IDs doesn’t require passing organism, as there’s no ambiguity:

bt.Gene.validate(
    ["ENSG00000000419", "ENSMUSG00002076988"], field=bt.Gene.ensembl_gene_id
)
array([ True,  True])

When working with the same organism throughout your analysis/workflow, you can omit the organism argument by configuring it globally:

bt.settings.organism = "mouse"
bt.Gene.from_source(symbol="Ap5b1")
Gene(uid='3b8mHb0MRal4', symbol='Ap5b1', ensembl_gene_id='ENSMUSG00000049562', ncbi_gene_ids='381201', biotype='protein_coding', synonyms='Gm962', description='adaptor-related protein complex 5, beta 1 subunit ', created_by_id=1, space_id=1, source_id=15, organism_id=2, created_at=2025-01-12 14:06:12 UTC)

Track underlying ontology source versions

Under-the-hood, source ontology versions are automatically tracked for each registry:

bt.Source.filter(currently_used=True).df()
Hide code cell output
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_code
id
1 33TU bionty.Organism vertebrates ensembl False True Ensembl https://ftp.ensembl.org/pub/release-112/specie... 0ec37e77f4bc2d0b0b47c6c62b9f122d https://www.ensembl.org 1 None release-112 None 2025-01-12 14:03:47.555530+00:00 1 None 1
6 6bbV bionty.Organism bacteria ensembl False True Ensembl https://ftp.ensemblgenomes.ebi.ac.uk/pub/bacte... ee28510ed5586ea7ab4495717c96efc8 https://www.ensembl.org 1 None release-57 None 2025-01-12 14:03:47.556061+00:00 1 None 1
7 6s9n bionty.Organism fungi ensembl False True Ensembl http://ftp.ensemblgenomes.org/pub/fungi/releas... dbcde58f4396ab8b2480f7fe9f83df8a https://www.ensembl.org 1 None release-57 None 2025-01-12 14:03:47.556148+00:00 1 None 1
8 2PmT bionty.Organism metazoa ensembl False True Ensembl http://ftp.ensemblgenomes.org/pub/metazoa/rele... 424636a574fec078a61cbdddb05f9132 https://www.ensembl.org 1 None release-57 None 2025-01-12 14:03:47.556237+00:00 1 None 1
9 7GPH bionty.Organism plants ensembl False True Ensembl https://ftp.ensemblgenomes.ebi.ac.uk/pub/plant... eadaa1f3e527e4c3940c90c7fa5c8bf4 https://www.ensembl.org 1 None release-57 None 2025-01-12 14:03:47.556325+00:00 1 None 1
10 4tsk bionty.Organism all ncbitaxon False True NCBItaxon Ontology s3://bionty-assets/df_all__ncbitaxon__2023-06-... 00d97ba65627f1cd65636d2df22ea76c https://github.com/obophenotype/ncbitaxon 1 None 2023-06-20 None 2025-01-12 14:03:47.556427+00:00 1 None 1
11 4UGN bionty.Gene human ensembl False True Ensembl s3://bionty-assets/df_human__ensembl__release-... 4ccda4d88720a326737376c534e8446b https://www.ensembl.org 1 None release-112 None 2025-01-12 14:03:47.556519+00:00 1 None 1
15 4r4f bionty.Gene mouse ensembl False True Ensembl s3://bionty-assets/df_mouse__ensembl__release-... 519cf7b8acc3c948274f66f3155a3210 https://www.ensembl.org 1 None release-112 None 2025-01-12 14:03:47.556871+00:00 1 None 1
19 4RPA bionty.Gene saccharomyces cerevisiae ensembl False True Ensembl s3://bionty-assets/df_saccharomyces cerevisiae... 11775126b101233525a0a9e2dd64edae https://www.ensembl.org 1 None release-112 None 2025-01-12 14:03:47.557220+00:00 1 None 1
22 3EYy bionty.Protein human uniprot False True Uniprot s3://bionty-assets/df_human__uniprot__2024-03_... b5b9e7645065b4b3187114f07e3f402f https://www.uniprot.org 1 None 2024-03 None 2025-01-12 14:03:47.557494+00:00 1 None 1
25 01RW bionty.Protein mouse uniprot False True Uniprot s3://bionty-assets/df_mouse__uniprot__2024-03_... b1b6a196eb853088d36198d8e3749ec4 https://www.uniprot.org 1 None 2024-03 None 2025-01-12 14:03:47.557758+00:00 1 None 1
28 3kDh bionty.CellMarker human cellmarker False True CellMarker s3://bionty-assets/human_cellmarker_2.0_CellMa... d565d4a542a5c7e7a06255975358e4f4 http://bio-bigdata.hrbmu.edu.cn/CellMarker 1 None 2.0 None 2025-01-12 14:03:47.558027+00:00 1 None 1
29 7bV5 bionty.CellMarker mouse cellmarker False True CellMarker s3://bionty-assets/mouse_cellmarker_2.0_CellMa... 189586732c63be949e40dfa6a3636105 http://bio-bigdata.hrbmu.edu.cn/CellMarker 1 None 2.0 None 2025-01-12 14:03:47.558115+00:00 1 None 1
30 6LyR bionty.CellLine all clo False True Cell Line Ontology https://data.bioontology.org/ontologies/CLO/su... ea58a1010b7e745702a8397a526b3a33 https://bioportal.bioontology.org/ontologies/CLO 1 None 2022-03-21 None 2025-01-12 14:03:47.558202+00:00 1 None 1
32 3Uw2 bionty.CellType all cl True True Cell Ontology http://purl.obolibrary.org/obo/cl/releases/202... https://obophenotype.github.io/cell-ontology 1 None 2024-08-16 None 2025-01-12 14:03:47.558378+00:00 1 None 1
41 MUtA bionty.Tissue all uberon False True Uberon multi-species anatomy ontology http://purl.obolibrary.org/obo/uberon/releases... http://obophenotype.github.io/uberon 1 None 2024-08-07 None 2025-01-12 14:03:47.559205+00:00 1 None 1
50 4a3e bionty.Disease all mondo False True Mondo Disease Ontology http://purl.obolibrary.org/obo/mondo/releases/... https://mondo.monarchinitiative.org 1 None 2024-08-06 None 2025-01-12 14:03:47.560008+00:00 1 None 1
59 4ksw bionty.Disease human doid False True Human Disease Ontology http://purl.obolibrary.org/obo/doid/releases/2... bbefd72247d638edfcd31ec699947407 https://disease-ontology.org 1 None 2024-05-29 None 2025-01-12 14:03:47.564309+00:00 1 None 1
67 2a1H bionty.ExperimentalFactor all efo False True The Experimental Factor Ontology http://www.ebi.ac.uk/efo/releases/v3.70.0/efo.owl https://bioportal.bioontology.org/ontologies/EFO 1 None 3.70.0 None 2025-01-12 14:03:47.565002+00:00 1 None 1
74 48fB bionty.Phenotype human hp False True Human Phenotype Ontology https://github.com/obophenotype/human-phenotyp... e0f2e534eb2ad44a4d45573ef27b508f https://hpo.jax.org 1 None 2024-04-26 None 2025-01-12 14:03:47.565602+00:00 1 None 1
79 4t7Q bionty.Phenotype mammalian mp False True Mammalian Phenotype Ontology https://github.com/mgijax/mammalian-phenotype-... 795d8378fe48ec13b41d01a86dd1c86c https://github.com/mgijax/mammalian-phenotype-... 1 None 2024-06-18 None 2025-01-12 14:03:47.566017+00:00 1 None 1
82 sqPX bionty.Phenotype zebrafish zp False True Zebrafish Phenotype Ontology https://github.com/obophenotype/zebrafish-phen... 2231ebaa95becf8ff34a33c95a8d4350 https://github.com/obophenotype/zebrafish-phen... 1 None 2024-04-18 None 2025-01-12 14:03:47.566265+00:00 1 None 1
86 6S4q bionty.Phenotype all pato False True Phenotype And Trait Ontology http://purl.obolibrary.org/obo/pato/releases/2... 6b1eaacd3d453b34375ce2e31c16328a https://github.com/pato-ontology/pato 1 None 2024-03-28 None 2025-01-12 14:03:47.566608+00:00 1 None 1
88 7Ent bionty.Pathway all go False True Gene Ontology https://data.bioontology.org/ontologies/GO/sub... 7fa7ade5e3e26eab3959a7e4bc89ad4f http://geneontology.org 1 None 2024-06-17 None 2025-01-12 14:03:47.566773+00:00 1 None 1
93 3rm9 BFXPipeline all lamin False True Bioinformatics Pipeline s3://bionty-assets/df_all__lamin__1.0.0__BFXpi... https://lamin.ai 1 None 1.0.0 None 2025-01-12 14:03:47.567187+00:00 1 None 1
94 ugaI Drug all dron False True Drug Ontology https://data.bioontology.org/ontologies/DRON/s... https://bioportal.bioontology.org/ontologies/DRON 1 None 2024-08-05 None 2025-01-12 14:03:47.567270+00:00 1 None 1
98 1GbF bionty.DevelopmentalStage human hsapdv False True Human Developmental Stages https://github.com/obophenotype/developmental-... https://github.com/obophenotype/developmental-... 1 None 2024-05-28 None 2025-01-12 14:03:47.567617+00:00 1 None 1
100 10va bionty.DevelopmentalStage mouse mmusdv False True Mouse Developmental Stages https://github.com/obophenotype/developmental-... https://github.com/obophenotype/developmental-... 1 None 2024-05-28 None 2025-01-12 14:03:47.567782+00:00 1 None 1
102 MJRq bionty.Ethnicity human hancestro False True Human Ancestry Ontology https://github.com/EBISPOT/hancestro/raw/3.0/h... 76dd9efda9c2abd4bc32fc57c0b755dd https://github.com/EBISPOT/hancestro 1 None 3.0 None 2025-01-12 14:03:47.567953+00:00 1 None 1
103 5JnV BioSample all ncbi False True NCBI BioSample attributes s3://bionty-assets/df_all__ncbi__2023-09__BioS... 918db9bd1734b97c596c67d9654a4126 https://www.ncbi.nlm.nih.gov/biosample/docs/at... 1 None 2023-09 None 2025-01-12 14:03:47.568038+00:00 1 None 1

Each record is linked to a versioned public source (if it was created from public):

hepatocyte = bt.CellType.get(name="hepatocyte")
hepatocyte.source
Hide code cell output
Source(uid='3Uw2', entity='bionty.CellType', organism='all', name='cl', version='2024-08-16', in_db=True, currently_used=True, description='Cell Ontology', url='http://purl.obolibrary.org/obo/cl/releases/2024-08-16/cl.owl', md5='', source_website='https://obophenotype.github.io/cell-ontology', created_by_id=1, space_id=1, created_at=2025-01-12 14:03:47 UTC)

Create records from specific source

By default, new records are imported or created from the "currently_used" public sources which are configured during the instance initialization, e.g.:

bt.Source.filter(entity="bionty.Phenotype", currently_used=True).df()
Hide code cell output
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_code
id
74 48fB bionty.Phenotype human hp False True Human Phenotype Ontology https://github.com/obophenotype/human-phenotyp... e0f2e534eb2ad44a4d45573ef27b508f https://hpo.jax.org 1 None 2024-04-26 None 2025-01-12 14:03:47.565602+00:00 1 None 1
79 4t7Q bionty.Phenotype mammalian mp False True Mammalian Phenotype Ontology https://github.com/mgijax/mammalian-phenotype-... 795d8378fe48ec13b41d01a86dd1c86c https://github.com/mgijax/mammalian-phenotype-... 1 None 2024-06-18 None 2025-01-12 14:03:47.566017+00:00 1 None 1
82 sqPX bionty.Phenotype zebrafish zp False True Zebrafish Phenotype Ontology https://github.com/obophenotype/zebrafish-phen... 2231ebaa95becf8ff34a33c95a8d4350 https://github.com/obophenotype/zebrafish-phen... 1 None 2024-04-18 None 2025-01-12 14:03:47.566265+00:00 1 None 1
86 6S4q bionty.Phenotype all pato False True Phenotype And Trait Ontology http://purl.obolibrary.org/obo/pato/releases/2... 6b1eaacd3d453b34375ce2e31c16328a https://github.com/pato-ontology/pato 1 None 2024-03-28 None 2025-01-12 14:03:47.566608+00:00 1 None 1

Sometimes, the default source doesn’t contain the ontology term you are looking for.

You can then specify to create a record from a non-default source. For instance, we can use the ncbitaxon ontology:

source = bt.Source.get(entity="bionty.Organism", name="ncbitaxon")
source
Source(uid='4tsk', entity='bionty.Organism', organism='all', name='ncbitaxon', version='2023-06-20', in_db=False, currently_used=True, description='NCBItaxon Ontology', url='s3://bionty-assets/df_all__ncbitaxon__2023-06-20__Organism.parquet', md5='00d97ba65627f1cd65636d2df22ea76c', source_website='https://github.com/obophenotype/ncbitaxon', created_by_id=1, space_id=1, created_at=2025-01-12 14:03:47 UTC)
# validate against the NCBI Taxonomy
bt.Organism.validate(
    ["iris setosa", "iris versicolor", "iris virginica"], source=source
)
Hide code cell output
! Your Organism registry is empty, consider populating it first!
   → use `.import_source()` to import records from a source, e.g. a public ontology
array([False, False, False])
records = bt.Organism.from_values(
    ["iris setosa", "iris versicolor", "iris virginica"], source=source
)

# since we didn't seed the Organism registry with the NCBITaxon public ontology
# we need to save the records to the database
ln.save(records)

# now we can query a iris organism and view its parents and children
iris = bt.Organism.get(name="iris")
iris.view_parents(with_children=True)
Hide code cell output

_images/4bdcc30e4a99d4a2bd0f5d764c908666974f47a9cac2d008ec9eef2a9aba4a79.svg
Hide code cell content
# clean up test instance
!lamin delete --force test-registries
 deleting instance testuser1/test-registries