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

AttributeError: 'numpy.ndarray' object has no attribute 'todense' with H5AD file as input for 'scaden simulate' #126

Open
WanderingHedgie opened this issue May 3, 2024 · 0 comments

Comments

@WanderingHedgie
Copy link

WanderingHedgie commented May 3, 2024

Hi !
I want to use H5AD as input format to use scaden simulate as it is indicated in the help comand, but here is the error I get :

(/CONDAS/users/username/scaden) [username@gknwwd2 example]$ scaden simulate -n 100 -d ./example_data/ -f h5ad --pattern "*.h5ad"

     ____                _            
    / ___|  ___ __ _  __| | ___ _ __  
    \___ \ / __/ _` |/ _` |/ _ \ '_ \ 
     ___) | (_| (_| | (_| |  __/ | | |
    |____/ \___\__,_|\__,_|\___|_| |_|

    
INFO     Datasets: ['reference']                                                             bulk_simulator.py:84
INFO     Simulating data from reference                                                      bulk_simulator.py:89
INFO     Loading reference dataset ...                                                      bulk_simulator.py:141
Traceback (most recent call last):
  File "/CONDAS/users/username/scaden/bin/scaden", line 10, in <module>
    sys.exit(main())
  File "/CONDAS/users/username/scaden/lib/python3.8/site-packages/scaden/__main__.py", line 48, in main
    cli()
  File "/CONDAS/users/username/scaden/lib/python3.8/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/CONDAS/users/username/scaden/lib/python3.8/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/CONDAS/users/username/scaden/lib/python3.8/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/CONDAS/users/username/scaden/lib/python3.8/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/CONDAS/users/username/scaden/lib/python3.8/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/CONDAS/users/username/scaden/lib/python3.8/site-packages/scaden/__main__.py", line 207, in simulate
    simulation(
  File "/CONDAS/users/username/scaden/lib/python3.8/site-packages/scaden/simulate.py", line 22, in simulation
    bulk_simulator.simulate()
  File "/CONDAS/users/username/scaden/lib/python3.8/site-packages/scaden/simulation/bulk_simulator.py", line 90, in simulate
    self.simulate_dataset(dataset)
  File "/CONDAS/users/username/scaden/lib/python3.8/site-packages/scaden/simulation/bulk_simulator.py", line 104, in simulate_dataset
    data_x, data_y = self.load_dataset(dataset)
  File "/CONDAS/users/username/scaden/lib/python3.8/site-packages/scaden/simulation/bulk_simulator.py", line 201, in load_dataset
    x = pd.DataFrame(data_h5ad.X.todense()) 
AttributeError: 'numpy.ndarray' object has no attribute 'todense'

The reason of this is that I write my H5AD file at the end of preprocessing provided in Jupyter Notebooks available in paper_data.tar.gz on figshare (version 1).

The thing is, after the preprocessing, the data is stored in the anndata.X as numpy array with dense data (obtained throug preprocessing with regress_out() function) and cannot be handled by the simulate function. I suppose that the simulate function aimed to process sparse data, even in H5AD format, with a sparse matrix (see Scipy sparse formats).

Maybe it would be a good idea to add a warning in the documentation and/or add a verification in the code to handle this case.

Hope it will be useful for someone !

WanderingHedgie

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