anndict.utils.get_adata_columns

anndict.utils.get_adata_columns#

anndict.utils.get_adata_columns(adata, starts_with=None, ends_with=None, contains=None, not_starts_with=None, not_ends_with=None, not_contains=None)[source]#

A simple string matching and filtering function to get column names from adata.obs. The not_ parameters are used to exclude columns from the results after the inclusion filters have already been applied.

Parameters:
adata AnnData

An AnnData object.

starts_with str | list[str] | None (default: None)

Include columns that start with this.

ends_with str | list[str] | None (default: None)

Include columns that end with this.

contains str | list[str] | None (default: None)

Include columns that contain this.

not_starts_with str | list[str] | None (default: None)

Exclude columns that start with this.

not_ends_with str | list[str] | None (default: None)

Exclude columns that end with this.

not_contains str | list[str] | None (default: None)

Exclude columns that contain this.

Return type:

list[str]

Returns:

A list of column names from adata.obs that match the specified criteria.

Examples

import anndict as adt

adata.obs.columns
> Index(['cell_type', 'total_counts', 'total_counts_mt', 'total_counts_protein_coding',
     'pct_counts_mt', 'pct_counts_protein_coding'], dtype='object')

#get all total counts columns
get_adata_columns(adata, starts_with='total_counts')
> ['total_counts', 'total_counts_mt', 'total_counts_protein_coding']

#get all mitochondrial columns
get_adata_columns(adata, contains='mt')
> ['total_counts_mt', 'pct_counts_mt']

#get all columns that are not total counts
get_adata_columns(adata, contains = '', not_starts_with='total_counts') #contains = '' will match all columns, then from this list, we exclude columns that start with ``'total_counts'``
> ['cell_type', 'pct_counts_mt', 'pct_counts_protein_coding']