Skip to content

RESOLVI: using num_samples > 1 in get_normalized_expression fails #3283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
abs51295 opened this issue Apr 3, 2025 · 1 comment
Open

RESOLVI: using num_samples > 1 in get_normalized_expression fails #3283

abs51295 opened this issue Apr 3, 2025 · 1 comment
Labels

Comments

@abs51295
Copy link

abs51295 commented Apr 3, 2025

I am trying to get normalized expression from resolVI model. If I pass num_samples > 1 it fails.

resolvae = RESOLVI.load(args.scvi_output_dir, adata=adata)

adata.layers['generated_counts'] = scp.csr_matrix(resolvae.get_normalized_expression(batch_size=5000, n_samples=30, library_size=10000))

Traceback (most recent call last):
  File "/common/knottsilab/MET_analysis/MET_analysis_2025/neoadjuvant_cagra_outputs/run_resolVI_downstream.py", line 91, in <module>
    adata.layers['generated_counts'] = scp.csr_matrix(resolvae.get_normalized_expression(batch_size=5000, n_samples=3, library_size=10000))
                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/shaha4/miniforge3/envs/rapids-24.12-stable/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/shaha4/miniforge3/envs/rapids-24.12-stable/lib/python3.11/site-packages/scvi/external/resolvi/_utils.py", line 341, in get_normalized_expression
    return pd.DataFrame(
           ^^^^^^^^^^^^^
  File "/home/shaha4/miniforge3/envs/rapids-24.12-stable/lib/python3.11/site-packages/pandas/core/frame.py", line 827, in __init__
    mgr = ndarray_to_mgr(
          ^^^^^^^^^^^^^^^
  File "/home/shaha4/miniforge3/envs/rapids-24.12-stable/lib/python3.11/site-packages/pandas/core/internals/construction.py", line 336, in ndarray_to_mgr
    _check_values_indices_shape_match(values, index, columns)
  File "/home/shaha4/miniforge3/envs/rapids-24.12-stable/lib/python3.11/site-packages/pandas/core/internals/construction.py", line 420, in _check_values_indices_shape_match
    raise ValueError(f"Shape of passed values is {passed}, indices imply {implied}")
ValueError: Shape of passed values is (34338927, 380), indices imply (11446309, 380)

Versions:

1.3.0

@abs51295 abs51295 added the bug label Apr 3, 2025
@abs51295
Copy link
Author

abs51295 commented Apr 3, 2025

also, this might sound like a stupid question but is using this method equivalent to getting generated counts from sample_posterior?

 sample_quantile = 'post_sample_q25'

 samples_corr = resolvae.sample_posterior(
                   model=resolvae.module.model_corrected,
                   return_sites=['px_rate', 'obs'],
                   num_samples=30, return_samples=False, batch_size=6000)

samples_corr = pd.DataFrame(samples_corr).T

 adata.layers["generated_expression"] = scp.csr_matrix(samples_corr.loc[sample_quantile, 'obs'])```
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant