# Run scanpy.pp.neighbors and UMAP on a different layer other than X?

**URL:** <https://discourse.scverse.org/t/run-scanpy-pp-neighbors-and-umap-on-a-different-layer-other-than-x/1791>\
**Category:** scanpy\
**Created:** [October 2, 2023, 5:13pm UTC](https://discourse.scverse.org/t/run-scanpy-pp-neighbors-and-umap-on-a-different-layer-other-than-x/1791 "2023-10-02T17:13:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![singhbhavya](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/singhbhavya/32/818_2.png) [@singhbhavya](https://discourse.scverse.org/u/singhbhavya)\
**Post date:** [October 2, 2023, 5:13pm UTC](https://discourse.scverse.org/t/run-scanpy-pp-neighbors-and-umap-on-a-different-layer-other-than-x/1791/1 "2023-10-02T17:13:50Z")

</div>

Hi there! I apologize if my question is naive. I am new to not only Python, but also to anndata and spatial analysis in general.

I had an original anndata object with 12 variables - this data pertains to spatially barcoded proteins (there is no transcriptomic data). Since the normalization in this case is a bit different, I had to export raw.X as a dataframe, remove some variables, and independently do the normalization based on the images. In the end, I had a data frame of new X values for 8 variables.

I subsetted the original anndata, such that it now had 8 variables, and now I want to add the normalized X values to the subsetted anndata. Right now, I have added them as a new layer:

`adata_pc_subsampled.layers["X_norm"] = df_merge[["var1", "var2", "var3", "var4", "var5", "var6", "var7", "var8"]]`

The problem is that I want to run `scanpy.pp.neighbors` and `snappy.tl.umap` on this X\_norm layer. How can I do this?

---

<div class="post-metadata">

**Author:** ![dub2s](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/dub2s/32/361_2.png) [@dub2s](https://discourse.scverse.org/u/dub2s)\
**Post date:** [October 11, 2023, 4:42am UTC](https://discourse.scverse.org/t/run-scanpy-pp-neighbors-and-umap-on-a-different-layer-other-than-x/1791/2 "2023-10-11T04:42:30Z")

</div>

Or maybe you could copy your existing adata.X to a layer and then do sth like this :

> adata.X = adata.layers[“X\_norm”].copy()

---

<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:** [October 11, 2023, 6:28pm UTC](https://discourse.scverse.org/t/run-scanpy-pp-neighbors-and-umap-on-a-different-layer-other-than-x/1791/3 "2023-10-11T18:28:36Z")

</div>

Hi @singhbhavya, you can save your new layer to `adata.obsm` and use the `use_rep` argument in `scanpy.pp.neighbors` to compute neighbors on that representation. You can then run `scanpy.tl.umap` on this knn graph.
