lamindb.dev.QueryManager#
- class lamindb.dev.QueryManager(*args, **kwargs)#
Bases:
Manager
Manage queries through fields.
See also
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
, seelamindb.dev.QuerySet.df()
.
- df(**kwargs)#
Convert to DataFrame.
For
**kwargs
, seelamindb.dev.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() [ULabel(id=sFMcPepC, name=ULabel1, updated_at=2023-07-19 19:45:17, created_by_id=DzTjkKse), # noqa ULabel(id=2SscQvsM, name=ULabel2, updated_at=2023-07-19 19:45:17, created_by_id=DzTjkKse), # noqa ULabel(id=lecV87vi, name=ULabel3, updated_at=2023-07-19 19:45:17, created_by_id=DzTjkKse)] # noqa >>> label.parents.list("name") ['ULabel1', 'ULabel2', 'ULabel3']
- lookup(field=None, **kwargs)#
Return an auto-complete object for a field.
- Parameters:
field (
Optional
[TypeVar
(StrField
,str
,DeferredAttribute
)], 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
Examples
>>> import lnschema_bionty as lb >>> lb.settings.organism = "human" >>> lb.Gene.from_bionty(symbol="ADGB-DT").save() >>> lookup = lb.Gene.lookup() >>> lookup.adgb_dt >>> lookup_dict = lookup.dict() >>> lookup_dict['ADGB-DT'] >>> lookup_by_ensembl_id = lb.Gene.lookup(field="ensembl_gene_id") >>> genes.ensg00000002745 >>> lookup_return_symbols = lb.Gene.lookup(field="ensembl_gene_id", return_field="symbol")
- search(string, **kwargs)#
Search.
Makes reasonable choices of which fields to search.
For instance, for
File
, searcheskey
anddescription
fields.- Parameters:
string (
str
) – The input string to match against the field ontology values.field – The field against which the input string is matching.
limit – Maximum amount of top results to return.
return_queryset – Return search result as a sorted QuerySet.
case_sensitive – Whether the match is case sensitive.
synonyms_field – Search synonyms if column is available. If
None
, is ignored.
- Returns:
A sorted
DataFrame
of search results with a score in columnscore
. Ifreturn_queryset
isTrue
, an orderedQuerySet
.
Examples
>>> ln.save(ln.ULabel.from_values(["ULabel1", "ULabel2", "ULabel3"], field="name")) >>> ln.ULabel.search("ULabel2") name ULabel2 o3FY3c5n 100.0 ULabel1 CcFPLmpq 75.0 ULabel3 Qi3c4utq 75.0