The default passed value for use_layer is "X". However,
(use_layer == 'X' or use_layer) in adata.layers
→ (True or 'X') in adata.layers
→ True in adata.layers
→ False
results in KeyError: 'X'.
In my practice, I change the line to x_dim = adata.shape[1] if user_layer is None else adata.obsm[use_layer].shape[1].
The default passed value for
use_layer
is"X"
. However, (use_layer == 'X' or use_layer) in adata.layers → (True or 'X') in adata.layers → True in adata.layers → Falseresults in KeyError: 'X'.
In my practice, I change the line to
x_dim = adata.shape[1] if user_layer is None else adata.obsm[use_layer].shape[1]
.