alphapepttools.pp.filter_by_metadata#
- alphapepttools.pp.filter_by_metadata(adata, filter_dict, axis, logic='and', action='keep')#
Filter based on metadata
Filter or drop rows/columns from an adata object based on filter conditions specified in a filter_dict. The filter_dict contains keys, which are column names, and values, which can be either strings, lists or tuples. The ‘logic’ parameter determines whether multiple filters operate on an ‘and’ or ‘or’ basis.
- Parameters:
adata (ad.AnnData) – Anndata object to filter.
filter_dict (dict) – Dictionary with column names as keys and filter values as values. Values can be either string, list or tuple. For strings, exact matches are performed. For lists, matches are performed on any element in the list. Tuples specify value ranges and must consist of numeric values, where ‘None’ is interpreted as an open end. Ranges are inclusive on the lower end and exclusive on the upper end to prevent double counting with adjacent filters.
axis (int) – Axis to filter on. 0 for obs and 1 for var.
logic (str, optional) – Filtering logic to apply in case of multiple filters. Default to ‘and’. Can be ‘and’ or ‘or’.
action (str, optional) – If “keep”, extract rows/columns that match the filter conditions. If “drop”, extract rows/columns outside the filter conditions. Default to “keep”.
- Return type:
- Returns:
-adata (
AnnData) Filtered anndata object.