mcbrowse.common.filters¶
Allow selecting a subset of the data. This is used for two purposes:
- Filtering
For example, suppose we have
metacell;type1D data assigning a type to each metacell, and we want to include just the data of metacells of specific type(s) in the figure.- Highlighting
For example, suppose we have “selected” some metacells we want to focus on, and we’d want the figure to show these in a different way (larger size, different shape, etc.
Both operations require us to select a subset of the data. Convenience functions for doing so are provided here.
- mcbrowse.common.filters.VectorFilter(*args, **kwargs)¶
Describe how to filter a vector of values.
This is either a collection of values to keep, or a function that looks at a 1D
numpy.ndarrayof values and returns a boolean mask of values to keep.alias of
Union[Callable[[Vector],bool],Collection[Any]]
- mcbrowse.common.filters.vector_filter_mask(vector: Vector, filter: Union[Callable[[Vector], bool], Collection[Any]]) Vector[source]¶
Return a 1D
numpy.ndarrayboolean mask specifying which elements are kept byfilterin thevector.
- mcbrowse.common.filters.TidyFilter(*args, **kwargs)¶
Describe how to filter some tidy data data.
The key is either
|nameor&nameidentifying the data frame column to filter by, and whether to bitwise-OR or bitwise-AND it into the overall result (seetidy_filter_mask).alias of
Dict[str,Union[Callable[[Vector],bool],Collection[Any]]]
- mcbrowse.common.filters.tidy_filter_mask(frame: Union[FrameInRows, FrameInColumns], filter: Union[Dict[str, Union[Callable[[Vector], bool], Collection[Any]]], Callable[[Series], bool]]) Vector[source]¶
Return a boolean 1D
numpy.ndarraymask specifying which rows of the tidyframesurvive thefilter.Given a
pandas.DataFramein tidy data format (that is, each column is some variable and each row is an observation)`,If the
filteris a dictionary, it species filters to apply independently to each column. The key should start with either|or&; the final mask would bitwise-OR all the column masks that started with|, and then bitwise-AND the result with the column masks that started with&.If the
filteris a function, it is applied to each row of the frame and the results are collected as the mask.
- mcbrowse.common.filters.tidy_filter_data(frame: Union[FrameInRows, FrameInColumns], filter: Union[Dict[str, Union[Callable[[Vector], bool], Collection[Any]]], Callable[[Series], bool]]) Union[FrameInRows, FrameInColumns][source]¶
Similar to
tidy_filter_maskbut return just the rows of theframethat were kept by thefilter.
- mcbrowse.common.filters.matrix_filter_data(frame: Union[FrameInRows, FrameInColumns], *, rows_filter: Optional[Union[Callable[[Vector], bool], Collection[Any]]] = None, columns_filter: Optional[Union[Callable[[Vector], bool], Collection[Any]]] = None) Union[FrameInRows, FrameInColumns][source]¶
Apply the
rows_filterto theframeindex and thecolumns_filterto its columns, and return a new frame containing just the rows and columns that were kept by the filter(s).