tacco.utils.AnnData_query

AnnData_query(self, expr, **kw_args)[source]

Query the columns of .obs of an AnnData with a boolean expression and use the result to subset the AnnData. This provides a convenient shorthand notation for subsetting: E.g. adata.query(‘A>4 & B==@value’) effectively expands to adata[(adata.obs[‘A’]>4) & (adata.obs[‘B’]==value)]. This is analogous to the functionality of pandas.DataFrame.query() and implemented by pandas.DataFrame.eval(), so similar restrictions apply. This function is implemented as a monkey patch and should be called as a method of an AnnData instance.

Parameters:
  • expr – The query on .obs columns to subset an AnnData. Column names and literals are referenced directly, variables in python scope by a preceeding “@”.

  • **kw_args – Additional keyword arguments are forwarded to the call to pandas.DataFrame.eval().

Returns:

Returns a view of the subsetted AnnData instance.