Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to extract all gene embeddings from one foundational model ? #3397

Open
LPioL opened this issue Dec 4, 2024 · 1 comment
Open
Assignees

Comments

@LPioL
Copy link

LPioL commented Dec 4, 2024

Hi,

It is not clear to me how to extract all gene embeddings from one of the models. I tried this code but can only extract from one specific tissue and I am not sure my code is right and do what I want. Any help will be super appreciated. My code:

emb_names = ["scgpt"]
census_version = "2023-12-15"

with cellxgene_census.open_soma(census_version=census_version) as census:
    adata = cellxgene_census.get_anndata(
        census,
        organism="homo_sapiens",
        measurement_name="RNA",
        obs_value_filter="tissue == 'tongue'",
        obs_embeddings=emb_names,
    )

# Get gene names
gene_names = adata.var.feature_name.tolist()  # List of gene names

# Convert sparse matrix to dense format
gene_embeddings_dense = adata.X.toarray()

# Map genes to their embeddings
gene_to_embedding_dict = {
    gene: gene_embeddings_dense[:, idx].tolist()  # Extract all embeddings for the gene
    for idx, gene in enumerate(gene_names)
}
@johnkerl johnkerl self-assigned this Dec 4, 2024
@johnkerl
Copy link
Member

johnkerl commented Dec 4, 2024

cc @ivirshup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants