Skip to content

support gene panel selection/adaptation #1697

Description

@mojtababahrami

I come across this issue many times when I have two Anndata objects A and B and I want to change B to have the same vars as A by keeping the shared genes and inflating the new genes that are in A but not in B with a default value (e.g. zeros). I searched the API but did not find a function to do this.
Now I do something like the following to achieve this:

adata = ad.concat([adata_train, adata_test], join='outer')
adata_test = adata[len(adata_train):]
adata_test = adata_test[:, adata_train.var.index]
assert (adata_train.var_names == adata_test.var_names).all()

It would be good to support it natively as I assume this is a very common use case (for example you train a model e.g. a simple PCA on A and you want to project/transform the B using that model).

So I imagine something like this:

adata_test.adapt_vars(adata_train, fill_value=0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Enhancement.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions