Get_normalized_expression function arguments

Hi,

I had a few questions about the get_normalized_expression function that I hoped to get some clarification for. From the totalVI tutorial (CITE-seq analysis with totalVI — scvi-tools), n_samples is set to 25 and transform_batch is given the list of both datasets.

First, does n_samples refer to the number of cells (surely it can’t be number of biological samples, as the example dataset only has 2 individuals?), and if yes, why is the default 1 / why is the suggested number in the tutorial 25 / what might be a recommended number to set this as?

Second, how exactly should the transform_batch argument be used? I understand from the documentation and github (how to get corrected expression matrix after batch removal · Issue #786 · YosefLab/scvi-tools · GitHub) that it is about which batch to condition over. Intuitively, it seems to be that it would make the most sense to condition over all the batches as is also done in the tutorial, but would there be any situation where that might not be recommended?

Many thanks in advance.

n_samples refers to Monte Carlo sampling for each cell. The normalized expression is a random variable, and we return the average over 25 samples in this case. It’s an unbiased estimate of the expectation, but you need a LOT more samples to reduce the variance of this estimate. So empirically, 25 just seemed to work well.

Generally, you would take all the batches, but you could have the case where one cell type is only seen in one batch. In this case, you’d want to call the function separately for that cell type, and not use the transform batch param in that case.

That’s super useful to know - thank you!

Hello - just wanted to briefly follow up on this function. Is it possible to only get the denoised/normalised protein expression data matrix, and not the RNA one, or vice versa?

The method returns both, you can ignore the RNA denoised expression. It wouldn’t save any time really to reimplement in a way that only returns protein, so feel free to just ignore the RNA part for now.

I see. The problem I’m running into is actually that I keep running out of memory, and was wondering whether returning only the protein expression might reduce the memory? If not I suppose then I don’t have options other than increase memory or forgo the denoised expression values?

You can do two things:

  1. Reduce batch_size
  2. Pass an argument to gene_list (e.g., a list of two genes, so only two genes are used)

Both of these steps will save you memory.

Ah, number 2 makes a lot of sense - thank you!

I tried the strategy of passing an argument to gene_list, but get an error:

ValueError: Value passed for key 'denoised_rna' is of incorrect shape. Values of layers must match dimensions (0, 1) of parent. Value had shape (92009, 3) while it should have had (92009, 4000).

Do you have any idea how this could be fixed?

Probably a bug, would you be able to make an issue on GitHub? Thanks!