Using a model with categorical_covariate_key instead of batch_key

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

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.

Quick update: I found that the same issue exists in both scvi and scanvi in the load_query_data functions.