Skip to content

Cell hashing - #797

Closed
njbernstein wants to merge 5 commits into
scverse:masterfrom
njbernstein:cell_hashing
Closed

njbernstein wants to merge 5 commits into
scverse:masterfrom
njbernstein:cell_hashing

Conversation

@njbernstein

Copy link
Copy Markdown
Contributor

Here is a stab at adding cell hashing demultiplexing to scanpy. This will address #351.

@njbernstein

Copy link
Copy Markdown
Contributor Author

@flying-sheep Let me know next steps

@njbernstein

Copy link
Copy Markdown
Contributor Author

The test is failing because scipy.stats is not a wanted import. Let me know how you'd like to deal with that

Comment thread scanpy/preprocessing/_cell_hashing.py Outdated
adata
The annotated data matrix of shape ``n_obs`` × ``n_vars``. Rows correspond
to cells and columns to genes.
percentile_candidates

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add if the adata object needs any particular formatting or pre-processing steps? Maybe here or in the description. For example for 10x, just processing the sample with cell ranger is enough or other steps are required?

which cell hashing barcodes a cell has
"""
barcodes_hits = []
number_of_barcodes = adata.X.shape[1]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about the logic here. Normally, the columns contain genes, I assume that in cell-hashing there will be barcodes, but could the data be mixed ? Maybe if you clarify what is needed/expected in the description of the function would make the code easy to read.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are the columns here represent hashing barcodes, not genes. @njbernstein I think both RNA UMIs and hashing barcode counts should be stored in the same AnnData object. Hashing barcodes can be stored in adata.obs or adata.obsm but definitely not in adata.X.

I think it makes more sense to first discuss 1) how to store hashing barcodes and 2) how to demultiplex them either in the PR or in the #351 issue.

Comment thread scanpy/preprocessing/_cell_hashing.py Outdated
The annotated data matrix of shape ``n_obs`` × ``n_vars``. Rows correspond
to cells and columns to genes.
percentile_candidates
Choose exact percentiles to evaluate thresholding at

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This percentiles refer to what exactly? Can you elaborate a bit?

@njbernstein

Copy link
Copy Markdown
Contributor Author

@fidelram lemme know if the new comments make things more clear

@fidelram

Copy link
Copy Markdown
Collaborator

@ivirshup @flying-sheep I would like to merge this code but I have some questions:

  • Do you know why the test is failing?
  • Currently, this is located in preprocessing, but I think that the right place is external.pp would you agree on that?

@ivirshup

ivirshup commented Oct 1, 2019

Copy link
Copy Markdown
Member

Do you know why the test is failing?

@flying-sheep and I have put some effort into reducing import times for scanpy (they were getting up to a few seconds). This can most effectively be done by deferring the import of slow-to-import packages until they're actually needed. Phil added a test which blacklists top level import of some of particularly egregious packages (scipy and seaboarn for example).

Here, the imports for argrelextrema and gaussian_kde are pretty slow (about half a second). These should be moved inside _demultiplex_per_barcode function instead of being top level.

Currently, this is located in preprocessing, but I think that the right place is external.pp would you agree on that?

I think I would be fine with this going in preprocessing, since it isn't tied to another tool/ code base. I'm also not too familiar with the current state of demultiplexing techniques so I'd be fine to defer to you on this. Could you elaborate on why you think it should go in external?

@fidelram

fidelram commented Oct 1, 2019 •

Copy link
Copy Markdown
Collaborator

@ivirshup : Thanks for the background explanation.

@njbernstein Can you move the import statements inside the _demultiplex_per_barcode to remove the test errors?

I think the tool should go to external to point out that this is based on a method that we have not tested and thus the responsibility of its accuracy and implementation lies on the external contributor.

@flying-sheep

Copy link
Copy Markdown
Member

Hmm, I’m pretty happy with my self-documented test code:

    def test_deferred_imports(imported_modules):
        slow_to_import = {
            'umap',             # neighbors, tl.umap
            'seaborn',          # plotting
            'sklearn.metrics',  # neighbors
            'scipy.stats',      # tools._embedding_density
            'networkx',         # diffmap, paga, plotting._utils
            # TODO: 'matplotlib.pyplot',
            # TODO (maybe): 'numba',
        }
        falsely_imported = slow_to_import & imported_modules
>       assert not falsely_imported
E       AssertionError: assert not {'scipy.stats'}

Do you think this could be clearer?

@fidelram

fidelram commented Oct 2, 2019

Copy link
Copy Markdown
Collaborator

@flying-sheep I think the output is clear once you know what is about. Since this error may happen to future contributions that are not aware of the efforts to reduce import times, I think is better to be explicit. Something like: "Slow import detected (scipy.stats). Please check that slow-to-import packages are not in top level calls but inside the functions that require them".

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 this pull request may close these issues.

5 participants