lamindb.core.QueryManager

class lamindb.core.QueryManager(*args, **kwargs)

Bases: Manager

Manage queries through fields.

Examples

>>> ln.save(ln.ULabel.from_values(["ULabel1", "ULabel2", "ULabel3"], field="name"))  # noqa
>>> labels = ln.ULabel.filter(name__icontains = "label").all()
>>> ln.ULabel(name="ULabel1").save()
>>> label = ln.ULabel.filter(name="ULabel1").one()
>>> label.parents.set(labels)
>>> manager = label.parents
>>> manager.df()

Attributes

auto_created bool
creation_counter int
db property
use_in_migrations bool

If set to True the manager will be serialized into migrations and will thus be available in e.g. RunPython operations.

Methods

all()

Return QuerySet of all.

For **kwargs, see lamindb.core.QuerySet.df().

df(**kwargs)

Convert to DataFrame.

For **kwargs, see lamindb.core.QuerySet.df().

list(field=None)

Populate a list with the results.

Examples

>>> ln.save(ln.ULabel.from_values(["ULabel1", "ULabel2", "ULabel3"], field="name"))
>>> labels = ln.ULabel.filter(name__icontains="label").all()
>>> ln.ULabel(name="ULabel1").save()
>>> label = ln.ULabel.filter(name="ULabel1").one()
>>> label.parents.set(labels)
>>> label.parents.list()
>>> label.parents.list("name")
['ULabel1', 'ULabel2', 'ULabel3']
lookup(field=None, **kwargs)

Return an auto-complete object for a field.

Parameters:
  • field (str | DeferredAttribute | None, default: None) – The field to look up the values for. Defaults to first string field.

  • return_field – The field to return. If None, returns the whole record.

Return type:

NamedTuple

Returns:

A NamedTuple of lookup information of the field values with a dictionary converter.

See also

search()

Examples

>>> import bionty as bt
>>> bt.settings.organism = "human"
>>> bt.Gene.from_public(symbol="ADGB-DT").save()
>>> lookup = bt.Gene.lookup()
>>> lookup.adgb_dt
>>> lookup_dict = lookup.dict()
>>> lookup_dict['ADGB-DT']
>>> lookup_by_ensembl_id = bt.Gene.lookup(field="ensembl_gene_id")
>>> genes.ensg00000002745
>>> lookup_return_symbols = bt.Gene.lookup(field="ensembl_gene_id", return_field="symbol")
search(string, **kwargs)

Search.

Parameters:
  • string (str) – The input string to match against the field ontology values.

  • field – The field or fields to search. Search all string fields by default.

  • limit – Maximum amount of top results to return.

  • case_sensitive – Whether the match is case sensitive.

Returns:

A sorted DataFrame of search results with a score in column score. If return_queryset is True, a QuerySet.

See also

filter()

Examples

>>> ulabels = ln.ULabel.from_values(["ULabel1", "ULabel2", "ULabel3"], field="name")
>>> ln.save(ulabels)
>>> ln.ULabel.search("ULabel2")