# How to implement MonkeyBread pipeline for Visium spatial data

**URL:** <https://discourse.scverse.org/t/how-to-implement-monkeybread-pipeline-for-visium-spatial-data/1693>\
**Category:** spatialdata\
**Created:** [August 18, 2023, 12:10am UTC](https://discourse.scverse.org/t/how-to-implement-monkeybread-pipeline-for-visium-spatial-data/1693 "2023-08-18T00:10:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Piotto](https://avatars.discourse-cdn.com/v4/letter/p/c4cdca/32.png) [@Piotto](https://discourse.scverse.org/u/Piotto)\
**Post date:** [August 18, 2023, 12:10am UTC](https://discourse.scverse.org/t/how-to-implement-monkeybread-pipeline-for-visium-spatial-data/1693/1 "2023-08-18T00:10:54Z")

</div>

Hi there!  
I am trying to implement MonkeyBread package on my spatial transcriptomics data but I get some error while I have put all the data files needed in the directory:

I followed the tutorial so far exactly as explained. But get this error.

## folder\_path = ‘/Users/pedram/Desktop/MonkeyBread’ adata = mb.util.load\_merscope(folder\_path) … reading from cache file cache/Users-pedram-Desktop-MonkeyBread-cell\_by\_gene.h5ad

KeyError Traceback (most recent call last)  
Input In [25], in \<cell line: 2\>()  
1 folder\_path = '/Users/pedram/Desktop/MonkeyBread  
----\> 2 adata = mb.util.load\_merscope(folder\_path)

File ~/opt/anaconda3/lib/python3.9/site-packages/monkeybread/util/\_load\_merscope.py:74, in load\_merscope(folder, use\_cache, cell\_bounds, transcript\_locations, paths)  
72 coordinates = pd.read\_csv(f"{folder}/{paths[‘coordinates’]}")  
73 coordinates = coordinates.rename({“Unnamed: 0”: “cell\_id”}, axis=1)  
—\> 74 data = counts[coordinates.cell\_id] # Slice data by coordinate index  
75 data.obsm[“X\_spatial”] = coordinates[[“center\_x”, “center\_y”]].to\_numpy()  
76 data.obs[“width”] = coordinates[“max\_x”].to\_numpy() - coordinates[“min\_x”].to\_numpy()

File ~/opt/anaconda3/lib/python3.9/site-packages/anndata/\_core/anndata.py:1113, in AnnData. **getitem** (self, index)  
1111 def **getitem** (self, index: Index) → “AnnData”:  
1112 “”“Returns a sliced view of the object.”“”  
 → 1113 oidx, vidx = self.\_normalize\_indices(index)  
1114 return AnnData(self, oidx=oidx, vidx=vidx, asview=True)

File ~/opt/anaconda3/lib/python3.9/site-packages/anndata/\_core/anndata.py:1094, in AnnData.\_normalize\_indices(self, index)  
1093 def \_normalize\_indices(self, index: Optional[Index]) → Tuple[slice, slice]:  
 → 1094 return \_normalize\_indices(index, self.obs\_names, self.var\_names)

File ~/opt/anaconda3/lib/python3.9/site-packages/anndata/\_core/index.py:35, in \_normalize\_indices(index, names0, names1)  
33 index = index[0].values, index[1]  
34 ax0, ax1 = unpack\_index(index)  
—\> 35 ax0 = \_normalize\_index(ax0, names0)  
36 ax1 = \_normalize\_index(ax1, names1)  
37 return ax0, ax1

File ~/opt/anaconda3/lib/python3.9/site-packages/anndata/\_core/index.py:101, in \_normalize\_index(indexer, index)  
99 if np.any(positions \< 0):  
100 not\_found = indexer[positions \< 0]  
 → 101 raise KeyError(  
102 f"Values {list(not\_found)}, from {list(indexer)}, "  
103 “are not valid obs/ var names or indices.”  
104 )  
105 return positions # np.ndarray[int]  
106 else:

KeyError: “Values [‘AAACAAGTATCTCCCA.1’, ‘AAACAATCTACTAGCA.1’, ‘AAACACCAATAACTGC.1’, ‘AAACAGAGCGACTCCT.1’, ‘AAACAGGGTCTATATT.1’, ‘AAACAGTGTTCCTGGG.1’, ‘AAACATTTCCCGGATT.1’, ‘AAACCGGGTAGGTACC.1’, ‘AAACCGTTCGTCCAGG.1’, ‘AAACCTAAGCAGCCGG.1’, ‘AAACCTCATGAAGTTG.1’, ‘AAACGAAGAACATACC.1’, ‘AAACGAGACGGTTGAT.1’, ‘AAACGGGCGTACGGGT.1’, ‘AAACGGTTGCGAACTG.1’, ‘AAACGTGTTCGCCCTA.1’, ‘AAACTAACGTGGCGAC.1’, ‘AAACTCGGTTCGCAAT.1’, ‘AAACTCGTGATATAAG.1’, ‘AAACTGCTGGCTCCAA.1’, ‘AAACTTAATTGCACGC.1’, ‘AAACTTGCAAACGTAT.1’, ‘AAAGACCCAAGTCGCG.1’, ‘AAAGACTGGGCGCTTT.1’, ‘AAAGCTTGCCTACATA.1’, ‘AAAGGCCCTATAATAC.1’, ‘AAAGGCTACGGACCAT.1’, ‘AAAGGCTCTCGCGCCG.1’, ‘AAAGGGATGTAGCAAG.1’, ‘AAAGGGCAGCTTGAAT.1’, ‘AAAGGTAAGCTGTACC.1’, 'AAAGTAGCATTGC”

---

<div class="post-metadata">

**Author:** ![LucaMarconato](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/lucamarconato/32/661_2.png) [@LucaMarconato](https://discourse.scverse.org/u/LucaMarconato)\
**Post date:** [August 18, 2023, 11:53am UTC](https://discourse.scverse.org/t/how-to-implement-monkeybread-pipeline-for-visium-spatial-data/1693/2 "2023-08-18T11:53:41Z")

</div>

Hi, thanks for reaching out.

It seems that the error is related to the `AnnData` package and not the `SpatialData` package. Could you please provide additional details? Which tutorial did you run? Also, can you post a reproducible minimal working example of the code that fails (or as a start the code that fails itself, even if not reproducible, sometimes it is enough).

---

<div class="post-metadata">

**Author:** ![Piotto](https://avatars.discourse-cdn.com/v4/letter/p/c4cdca/32.png) [@Piotto](https://discourse.scverse.org/u/Piotto)\
**Post date:** [August 18, 2023, 2:37pm UTC](https://discourse.scverse.org/t/how-to-implement-monkeybread-pipeline-for-visium-spatial-data/1693/3 "2023-08-18T14:37:15Z")

</div>

Thanks @LucaMarconato for your response.  
I follow this tutorial:  
“[Tutorial — monkeybread](https://monkeybread.readthedocs.io/en/latest/notebooks/tutorial.html)”

Everything from the first codes are working great.But when it comes to this, I get error:  
“# No need to specify custom file paths, this function will read in all relevant files in the directory provided.  
adata = mb.util.load\_merscope(”./data")"[quote=“LucaMarconato, post:2, topic:1693, full:true”]  
Hi, thanks for reaching out.

It seems that the error is related to the `AnnData` package and not the `SpatialData` package. Could you please provide additional details? Which tutorial did you run? Also, can you post a reproducible minimal working example of the code that fails (or as a start the code that fails itself, even if not reproducible, sometimes it is enough).  
[/quote]

[quote=“LucaMarconato, post:2, topic:1693, full:true”]  
Hi, thanks for reaching out.

It seems that the error is related to the `AnnData` package and not the `SpatialData` package. Could you please provide additional details? Which tutorial did you run? Also, can you post a reproducible minimal working example of the code that fails (or as a start the code that fails itself, even if not reproducible, sometimes it is enough).

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/forum11/original/1X/67f114554e728b13252ec7c03ce3d26071bafab9.png)

---

<div class="post-metadata">

**Author:** ![LucaMarconato](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/lucamarconato/32/661_2.png) [@LucaMarconato](https://discourse.scverse.org/u/LucaMarconato)\
**Post date:** [August 22, 2023, 3:03pm UTC](https://discourse.scverse.org/t/how-to-implement-monkeybread-pipeline-for-visium-spatial-data/1693/4 "2023-08-22T15:03:24Z")

</div>

Thanks for the additional info. It seems indeed a bug in the monkeybread package, not developed by us.

I see that you opened a issue also there, so I am going to link it here for future reference ([Cannot merge the dataset · Issue #25 · immunitastx/monkeybread · GitHub](https://github.com/immunitastx/monkeybread/issues/25)) and close this thread.

---

<div class="post-metadata">

**Author:** ![LucaMarconato](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.scverse.org/lucamarconato/32/661_2.png) [@LucaMarconato](https://discourse.scverse.org/u/LucaMarconato)\
**Post date:** [August 22, 2023, 3:03pm UTC](https://discourse.scverse.org/t/how-to-implement-monkeybread-pipeline-for-visium-spatial-data/1693/5 "2023-08-22T15:03:29Z")

</div>


