annsel.AnnselAccessor.filter#
- AnnselAccessor.filter(self, obs=None, var=None, x=None, obs_names=None, var_names=None, obsm=None, varm=None, layer=None, copy=False)[source]#
Filter the AnnData object by the given predicates.
- Parameters:
- obs
Expr|str|Series|Iterable[Expr|str|Series] |None(default:None) Predicates to filter the observations by.
- var
Expr|str|Series|Iterable[Expr|str|Series] |None(default:None) Predicates to filter the variables by.
- x
Expr|str|Series|Iterable[Expr|str|Series] |None(default:None) Predicates to filter the data by.
- obs_names
Expr|str|Series|Iterable[Expr|str|Series] |None(default:None) Predicates to filter the observation names by.
- var_names
Expr|str|Series|Iterable[Expr|str|Series] |None(default:None) Predicates to filter the variable names by.
- obsm
Mapping[str,Expr|str|Series|Iterable[Expr|str|Series]] |None(default:None) A mapping of obsm keys and predicates to filter the obsm matrices by.
- varm
Mapping[str,Expr|str|Series|Iterable[Expr|str|Series]] |None(default:None) A mapping of varm keys and predicates to filter the varm matrices by.
- layer
str|None(default:None) The layer to filter.
- copy
bool(default:False) Whether to return a copy of the AnnData object.
- obs
- Return type:
- Returns:
The filtered AnnData object.
Examples
>>> import annsel as an >>> adata = an.datasets.leukemic_bone_marrow_dataset() >>> adata.an.filter( ... obs=( ... an.col(["Cell_label"]).is_in(["Classical Monocytes", "CD8+CD103+ tissue resident memory T cells"]), ... an.col(["sex"]) == "male", ... ), ... var=an.col(["vst.mean"]) >= 3, ... ) AnnData object with n_obs × n_vars = 6741 × 458 obs: 'Cluster_ID', 'donor_id', 'Sample_Tag', 'Cell_label', 'is_primary_data', 'organism_ontology_term_id', 'self_reported_ethnicity_ontology_term_id', 'assay_ontology_term_id', 'tissue_ontology_term_id', 'Genotype', 'development_stage_ontology_term_id', 'sex_ontology_term_id', 'disease_ontology_term_id', 'cell_type_ontology_term_id', 'suspension_type', 'tissue_type', 'cell_type', 'assay', 'disease', 'organism', 'sex', 'tissue', 'self_reported_ethnicity', 'development_stage', 'observation_joinid' var: 'vst.mean', 'vst.variance', 'vst.variance.expected', 'vst.variance.standardized', 'vst.variable', 'feature_is_filtered', 'Unnamed: 0', 'feature_name', 'feature_reference', 'feature_biotype', 'feature_length', 'feature_type' uns: 'cell_type_ontology_term_id_colors', 'citation', 'default_embedding', 'schema_reference', 'schema_version', 'title' obsm: 'X_bothumap', 'X_pca', 'X_projected', 'X_projectedmean', 'X_tsneni', 'X_umapni'