# Using a model with categorical\_covariate\_key instead of batch\_key

**URL:** <https://discourse.scverse.org/t/using-a-model-with-categorical-covariate-key-instead-of-batch-key/1993>\
**Category:** scvi-tools\
**Created:** [January 9, 2024, 7:42pm UTC](https://discourse.scverse.org/t/using-a-model-with-categorical-covariate-key-instead-of-batch-key/1993 "2024-01-09T19:42:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jflusche](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@jflusche](https://discourse.scverse.org/u/jflusche)\
**Post date:** [January 9, 2024, 7:42pm UTC](https://discourse.scverse.org/t/using-a-model-with-categorical-covariate-key-instead-of-batch-key/1993/1 "2024-01-09T19:42:23Z")

</div>

Hi Martin,

I am currently using scvi-tools reference mapping with scArches to integrate a query data set with a reference data set that has an existing scVI model. I am at the step where I create a new query model instance, but I have encountered the following error:

NotImplementedError: scArches currently does not support models with extra categorical covariates.

This error arises because I used one ‘categorical\_covariate\_key’ in my original model instead of a ‘batch\_key’. This package seems to only recognize ‘batch\_key’. The reason I chose to use ‘categorical\_covariate\_key’ is because the scvi-tools quick start tutorial first suggests to use ‘categorical\_covariate\_key’ (and only after suggests that ‘batch\_key’ may _also_ be used if there is only one key).

I am trying to avoid running a new model with a ‘batch\_key’ instead of a ‘categorical\_covariate\_key’ because I would like to preserve the UMAP, latent space, and other work.

Is there any way for scArches to recognize a single batch covariate that is stored in ‘categorical\_covariate\_key’ instead of in ‘batch\_key’? I have attached a view of my model if it helps.

Thank you,  
Julianne Flusche

 ![Screenshot 2024-01-09 at 2.21.20 PM](https://canada1.discourse-cdn.com/flex035/uploads/forum11/original/1X/c23b2cfa20240a6bb1e3ee8167b24736a650fdef.png)

---

<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:** [January 9, 2024, 9:18pm UTC](https://discourse.scverse.org/t/using-a-model-with-categorical-covariate-key-instead-of-batch-key/1993/2 "2024-01-09T21:18:50Z")

</div>

Hi @jflusche, it should be possible to transfer a categorical covariate to a batch key when loading in a model for scArches, but it would require delving a bit into the codebase. Let me get back to you with a code snippet to make this work.

---

<div class="post-metadata">

**Author:** ![jflusche](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@jflusche](https://discourse.scverse.org/u/jflusche)\
**Post date:** [February 1, 2024, 3:30pm UTC](https://discourse.scverse.org/t/using-a-model-with-categorical-covariate-key-instead-of-batch-key/1993/3 "2024-02-01T15:30:46Z")

</div>

Quick update: I found that the same issue exists in both scvi and scanvi in the load\_query\_data functions.
