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

Error in inline usage #33

Closed
jenzopr opened this issue Jun 3, 2020 · 7 comments · Fixed by #35
Closed

Error in inline usage #33

jenzopr opened this issue Jun 3, 2020 · 7 comments · Fixed by #35

Comments

@jenzopr
Copy link

jenzopr commented Jun 3, 2020

Hi!

I'm trying to use Solo inline on an Anndata object with 4 hashtag features. My code looks roughly like this:

# Load adata, filter cells and genes on min_counts = 1
...

# Subset on hashtag features
hdata = adata[:, hashtag_features].copy()

from solo import hashsolo

hashsolo.hashsolo(hdata)

Initially, the error from solo was NotImplementedError: adding a nonzero scalar to a sparse matrix is not supported - I assume because hdata.X is a sparse matrix. Then I tried to do

hdata.X = hdata.X.todense()

prior to the hashsolo call, but now I'm getting a IndexError: boolean index did not match indexed array along dimension 1; dimension is 4 but corresponding boolean dimension is 1. Any ideas how to proceed?

Thanks,
Jens

@jenzopr
Copy link
Author

jenzopr commented Jun 3, 2020

Funnily, saving the hdata object with force_dense = True (as_dense = True in scanpy >=1.5.1) and reloading the object seems to do the trick.

Nevertheless, can hashsolo be easily written to take sparse matrices as well?

@njbernstein
Copy link
Contributor

Hi Jens,

Let me take a look. It will probably just convert the sparse matrix under the hood into a dense matrix because I don't think cell hashing matrices should cause memory issues. Its interesting the

hdata.X = hdata.X.todense()

didnt work.

@jenzopr
Copy link
Author

jenzopr commented Jun 6, 2020

Any update? Maybe a workaround? :-)

@njbernstein njbernstein linked a pull request Jun 6, 2020 that will close this issue
@njbernstein
Copy link
Contributor

@jenzopr I merged a fix just now let me know if it works.

Some of the indexing I do in hashsolo doesn't work with a dense matrix so the code needs to be:

if issparse(cell_hashing_adata.X):
    cell_hashing_adata.X = np.array(cell_hashing_adata.X.todense())

@njbernstein
Copy link
Contributor

If you need this fix released to pypi let me know otherwise you can install the fix from cloning the master branch and pip installing from there

@jenzopr
Copy link
Author

jenzopr commented Jun 6, 2020

Thats great! Thanks a lot for your support 🎉

@apredeus
Copy link

Same error still appears to happen in the newest version. Saving the .h5ad file using as_dense='X' option, followed by reading it back in again seems to solve the issue, while

adata.X = adata.X.todense()

does not work.

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

Successfully merging a pull request may close this issue.

3 participants