Closed chenlingantelope closed 4 years ago
Hi @chenlingantelope!
I think my open PR #817 fixes this.
Can you pip install that branch and let me know?
pip install git+https://github.com/yoseflab/scvi-tools.git@transformbatch_fix
Thanks!
Hi, I have experienced the same issue above when I tried to extract batch corrected scvi normalized expression using transform_batch option. Here is the command I ran.
adata_scvi.layers["scvi_normalized"] = model_scvi.get_normalized_expression(adata_scvi,library_size = 10e3, batch_key="library", transform_batch=['my_batch'])
I have installed scvi-tools using following commands
git clone https://github.com/scverse/scvi-tools
pip install -e .
Installed scvi-tools is version 1.1.3 any ideas how to solve this issue? below is error message
ValueError Traceback (most recent call last) Cell In[62], line 1 ----> 1 adata_scvi.layers["scvi_normalized"] = model_scvi.get_normalized_expression(adata_scvi,library_size = 10e3, batch_key="library", transform_batch=['CHR0211'])
File ~/anaconda3/envs/scvi/lib/python3.9/site-packages/torch/utils/_contextlib.py:115, in context_decorator.
File /data/_90.User_Data/dlekrud456/4.Programs/scvi-tools/src/scvi/model/base/_rnamixin.py:223, in RNASeqMixin.get_normalized_expression(self, adata, indices, transform_batch, gene_list, library_size, n_samples, n_samples_overall, weights, batch_size, return_mean, return_numpy, **importance_weighting_kwargs) 220 n_samples = n_samples_overall // len(indices) + 1 221 scdl = self._make_data_loader(adata=adata, indices=indices, batch_size=batch_size) --> 223 transform_batch = _get_batch_code_from_category( 224 self.get_anndata_manager(adata, required=True), transform_batch 225 ) 227 gene_mask = slice(None) if gene_list is None else adata.var_names.isin(gene_list) 229 if n_samples > 1 and return_mean is False:
File /data/_90.User_Data/dlekrud456/4.Programs/scvi-tools/src/scvi/model/_utils.py:311, in _get_batch_code_from_category(adata_manager, category) 309 batch_code.append(None) 310 elif cat not in batch_mappings: --> 311 raise ValueError(f'"{cat}" not a valid batch category.') 312 else: 313 batch_loc = np.where(batch_mappings == cat)[0][0]
ValueError: "CHR0211" not a valid batch category.
Hi, the issue points to that transform_batch=['CHR0211']
is not an existing batch category. The function has changed in the meantime from the error message above. Please provide adata.obs[batch_key].value_counts if you think the category should exist.
Hi,
Thanks for the reply.
I used library as batch_key and here is the result for adata.obs[batch_key].value_counts
.
Can you check the version of scvi-tools installed?
When running DE on a subset of a dataset with lots of batches, seems like I need to re-index the batches of subsets so that it is consecutive from 0 ~ n_batches. Perhaps this can be done automatically within the DE function.