mcbrowse.common.filters

Allow selecting a subset of the data. This is used for two purposes:

Filtering

For example, suppose we have metacell;type 1D 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.ndarray of 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.ndarray boolean mask specifying which elements are kept by filter in the vector.

mcbrowse.common.filters.TidyFilter(*args, **kwargs)

Describe how to filter some tidy data data.

The key is either |name or &name identifying the data frame column to filter by, and whether to bitwise-OR or bitwise-AND it into the overall result (see tidy_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.ndarray mask specifying which rows of the tidy frame survive the filter.

Given a pandas.DataFrame in tidy data format (that is, each column is some variable and each row is an observation)`,

If the filter is 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 filter is 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_mask but return just the rows of the frame that were kept by the filter.

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_filter to the frame index and the columns_filter to its columns, and return a new frame containing just the rows and columns that were kept by the filter(s).