# Clustering on the scVI latent space generates only gray-colored cells

**URL:** <https://discourse.scverse.org/t/clustering-on-the-scvi-latent-space-generates-only-gray-colored-cells/1933>\
**Category:** scvi-tools\
**Tags:** scvi\
**Created:** [December 4, 2023, 1:25am UTC](https://discourse.scverse.org/t/clustering-on-the-scvi-latent-space-generates-only-gray-colored-cells/1933 "2023-12-04T01:25:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![malonzm1](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@malonzm1](https://discourse.scverse.org/u/malonzm1)\
**Post date:** [December 4, 2023, 1:25am UTC](https://discourse.scverse.org/t/clustering-on-the-scvi-latent-space-generates-only-gray-colored-cells/1933/1 "2023-12-04T01:25:03Z")

</div>

Hi,

I’d like to cluster my data on the scVI latent space using the following code:

```auto
adata = sc.read_h5ad(filename='%s/%s.h5ad'%(infolder,gse))

sc.pp.highly_variable_genes(
    adata,
    n_top_genes=1200,
    subset=True,
    layer="counts",
    flavor="seurat_v3",
    batch_key="gse",
) 
scvi.model.SCVI.setup_anndata(
    adata,
    layer="counts",
    categorical_covariate_keys=["gse"],
    continuous_covariate_keys=['pct_counts_mt', 'total_counts']
)
os.chdir(infolder)
model = scvi.model.SCVI(adata)
model.train()
latent = model.get_latent_representation()
adata.obsm["X_scVI"] = latent
adata.layers["scvi_normalized"] = model.get_normalized_expression(library_size=10e4)
sc.pp.neighbors(adata, use_rep="X_scVI")
sc.tl.umap(adata, min_dist=0.3)
SCVI_CLUSTERS_KEY = "leiden_scVI"
sc.tl.leiden(adata, key_added=SCVI_CLUSTERS_KEY, resolution=0.5)
sc.pl.umap(
    adata,
    color=[SCVI_CLUSTERS_KEY],
    frameon=False,
    save='_10x_gse_leiden_bc.png'
)

```

However, the resulting plot only has gray color for all cells for all clusters (see attached figure).

 ![umap_10x_gse_leiden_bc](https://canada1.discourse-cdn.com/flex035/uploads/forum11/original/1X/624c90e8ddb7ddb2a18ec02a2df10d4135862c31.jpeg)

Please advise how the different clusters can have different colors. Thanks.

---

<div class="post-metadata">

**Author:** ![martinkim0](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/martinkim0/32/881_2.png) [@martinkim0](https://discourse.scverse.org/u/martinkim0)\
**Post date:** [December 4, 2023, 5:36pm UTC](https://discourse.scverse.org/t/clustering-on-the-scvi-latent-space-generates-only-gray-colored-cells/1933/2 "2023-12-04T17:36:34Z")

</div>

Hi, I believe this is occurring because there are too many clusters in data such that there’s no way to color them clearly. One way around this would be to Leiden cluster with less granularity so that you have fewer clusters in the end.

---

<div class="post-metadata">

**Author:** ![cane11](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/cane11/32/241_2.png) [@cane11](https://discourse.scverse.org/u/cane11)\
**Post date:** [December 5, 2023, 5:57am UTC](https://discourse.scverse.org/t/clustering-on-the-scvi-latent-space-generates-only-gray-colored-cells/1933/3 "2023-12-05T05:57:56Z")

</div>

I would assume you have very low quality cells with only a few counts after highly variable gene filtering. This creates those dispersed points in UMAP and leads to those many clusters. Please adjust the number of highly variable genes (more genes) and check your filtering for low count cells (something like 500 or 1000 should be fine for 10X v3 - different numbers for other technologies). If you want to keep your current settings, increasing n\_neighbors in sc.pp.neighbors might help.

---

<div class="post-metadata">

**Author:** ![malonzm1](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@malonzm1](https://discourse.scverse.org/u/malonzm1)\
**Post date:** [December 24, 2023, 11:27pm UTC](https://discourse.scverse.org/t/clustering-on-the-scvi-latent-space-generates-only-gray-colored-cells/1933/4 "2023-12-24T23:27:18Z")

</div>

Thank you. I tried this.

---

<div class="post-metadata">

**Author:** ![malonzm1](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@malonzm1](https://discourse.scverse.org/u/malonzm1)\
**Post date:** [December 24, 2023, 11:27pm UTC](https://discourse.scverse.org/t/clustering-on-the-scvi-latent-space-generates-only-gray-colored-cells/1933/5 "2023-12-24T23:27:56Z")

</div>

Thank you. I also tried this. The dispersed points in UMAP turned out to be duplicates.
