lamindb.ULabel

class lamindb.ULabel(name: str, description: str | None = None, reference: str | None = None, reference_type: str | None = None)

Bases: Record, HasParents, CanValidate, TracksRun, TracksUpdates

Universal labels.

Parameters:
  • namestr A name.

  • descriptionstr A description.

  • referencestr | None = None For instance. n external ID or a URL.

  • reference_typestr | None = None For instance, "url".

A ULabel record provides the easiest way to annotate a dataset with a label: "My project", "curated", or "Batch X":

>>> my_project = ULabel(name="My project")
>>> my_project.save()
>>> artifact.ulabels.add(my_project)

Often, a ulabel is measured within a dataset. For instance, an artifact might characterize 2 species of the Iris flower ("setosa" & "versicolor") measured by a "species" feature. Use the Curate flow to automatically parse, validate, and annotate with labels that are contained in DataFrame or AnnData artifacts.

See Tutorial: Features & labels to learn more.

Note

If you work with complex entities like cell lines, cell types, tissues, etc., consider using the pre-defined biological registries in bionty to label artifacts & collections.

If you work with biological samples, likely, the only sustainable way of tracking metadata, is to create a custom schema module.

See also

Feature()

Dimensions of measurement for artifacts & collections.

labels

Label manager of an artifact or collection.

Examples

Create a new label:

>>> my_project = ln.ULabel(name="My project")
>>> my_project.save()

Label a artifact without associating it to a feature:

>>> ulabel = ln.ULabel.filter(name="My project").one()
>>> artifact = ln.Artifact("./myfile.csv")
>>> artifact.save()
>>> artifact.ulabels.add(ulabel)

Organize labels in a hierarchy:

>>> ulabels = ln.ULabel.lookup()  # create a lookup
>>> is_project = ln.ULabel(name="is_project")  # create a super-category `is_project`
>>> is_project.save()
>>> ulabels.my_project.parents.add(is_project)

Query by ULabel:

>>> ln.Artifact.filter(ulabels=project).first()

Fields

run: Run

Last run that created or updated the record.

id: int

Internal id, valid only in one DB instance.

uid: str

A universal random id, valid across DB instances.

name: str

Name or title of ulabel (required).

description: str

A description (optional).

reference: str

A reference like URL or external ID.

reference_type: str

Type of reference, e.g., donor_id from Vendor X.

previous_runs: Run

Sequence of runs that created or updated the record.

parents: ULabel

Parent labels, useful to hierarchically group labels (optional).

created_at: datetime

Time of creation of record.

created_by: User

Creator of record.

updated_at: datetime

Time of last update to record.

Methods