Skip to content
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

ValueError: assignment destination is read-only #229

Open
SalvatoreRa opened this issue Apr 12, 2024 · 0 comments
Open

ValueError: assignment destination is read-only #229

SalvatoreRa opened this issue Apr 12, 2024 · 0 comments

Comments

@SalvatoreRa
Copy link

Hi,

I am trying just to replicate the tutorial:

https://nbviewer.org/github/theislab/diffxpy_tutorials/blob/master/diffxpy_tutorials/test/introduction_differential_testing.ipynb

import anndata
import matplotlib.pyplot as plt
import seaborn as sns
import logging
import numpy as np
import pandas as pd
import scipy.stats
import diffxpy.api as de

from batchglm.api.models.tf1.glm_nb import Simulator

sim = Simulator(num_observations=200, num_features=100)
sim.generate_sample_description(num_batches=0, num_conditions=2)
sim.generate_params(
    rand_fn_loc=lambda shape: np.random.uniform(-0.1, 0.1, shape),
    rand_fn_scale=lambda shape: np.random.uniform(0.1, 2, shape)
)
sim.generate_data()

data = anndata.AnnData(
    X=sim.x,
    var=pd.DataFrame(index=["gene" + str(i) for i in range(sim.x.shape[1])]),
    obs=sim.sample_description
)

test = de.test.wald(
    data=data,
    formula_loc="~ 1 + condition",
    factor_loc_totest="condition"
)

and I got this error:

ValueError                                Traceback (most recent call last)
<ipython-input-6-046dde1595dc> in <module>
      2     data=data,
      3     formula_loc="~ 1 + condition",
----> 4     factor_loc_totest="condition"
      5 )

~/anaconda3/lib/python3.7/site-packages/diffxpy/testing/tests.py in wald(data, factor_loc_totest, coef_to_test, formula_loc, formula_scale, as_numeric, init_a, init_b, gene_names, sample_description, dmat_loc, dmat_scale, constraints_loc, constraints_scale, noise_model, size_factors, batch_size, backend, train_args, training_strategy, quick_scale, dtype, **kwargs)
    734         quick_scale=quick_scale,
    735         dtype=dtype,
--> 736         **kwargs,
    737     )
    738 

~/anaconda3/lib/python3.7/site-packages/diffxpy/testing/tests.py in _fit(noise_model, data, design_loc, design_scale, design_loc_names, design_scale_names, constraints_loc, constraints_scale, init_model, init_a, init_b, gene_names, size_factors, batch_size, backend, training_strategy, quick_scale, train_args, close_session, dtype)
    242     estim.train_sequence(
    243         training_strategy=training_strategy,
--> 244         **train_args
    245     )
    246 

~/anaconda3/lib/python3.7/site-packages/batchglm/models/base/estimator.py in train_sequence(self, training_strategy, **kwargs)
    122                         (x, str(d[x]), str(kwargs[x]))
    123                     )
--> 124             self.train(**d, **kwargs)
    125             logger.debug("Training sequence #%d complete", idx + 1)
    126 

~/anaconda3/lib/python3.7/site-packages/batchglm/train/numpy/base_glm/estimator.py in train(self, max_steps, method_b, update_b_freq, ftol_b, lr_b, max_iter_b, nproc, **kwargs)
    110                         lr=lr_b,
    111                         max_iter=max_iter_b,
--> 112                         nproc=nproc
    113                     )
    114                     # Perform trial update.

~/anaconda3/lib/python3.7/site-packages/batchglm/train/numpy/base_glm/estimator.py in b_step(self, idx_update, method, ftol, lr, max_iter, nproc)
    349                 ftol=ftol,
    350                 max_iter=max_iter,
--> 351                 nproc=nproc
    352             )
    353 

~/anaconda3/lib/python3.7/site-packages/batchglm/train/numpy/base_glm/estimator.py in _b_step_loop(self, idx_update, method, max_iter, ftol, nproc)
    479                 )
    480                 pool.close()
--> 481             delta_theta[0, idx_update] = np.array([x[0] for x in results])
    482             sys.stdout.write('\r')
    483             sys.stdout.flush()

ValueError: assignment destination is read-only
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant