ingest confidence thresholding
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.6k
- Forks
- 779
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 27
Description
What kind of feature would you like to request?
Additional function parameters / changed functionality / changed defaults?
Please describe your wishes
First thank you for the amazing tool you guys developed
I am currently trying to use the ingest function to map cluster identities from a single cell dataset to a spatial data set.
the single cell is composed from a subset of cell types while the spatial has all of the cells. The single cell has many genes while the spatial has a few.
I parse out the common genes from from both datasets and use those to run the ingest function which works quiet well!
common_genes = sc_data.var_names.intersection(spatial_data.var_names)
sc_data = sc_data[:, common_genes]
spatial_data = spatial_data[:, common_genes]
sc.tl.pca(sc_data, svd_solver='arpack')
sc.pp.neighbors(sc_data, use_rep='X_pca')
sc.tl.umap(sc_data)
sc.tl.pca(spatial_data, svd_solver='arpack')
sc.tl.ingest(spatial_data, sc_data, obs='unified_clusters')
The issue I am running into is that the ingest function forces an identity onto cells even though the confidence of that identity is probably very low.
I am getting around that, in part, by subsetting the spatial dataset, but it would be terrific if I could use a confidence parameter to specify which cells would get an identity at all.
I was playing around with the ingest scripts and was thinking of something like this
def map_labels(self, labels: str, method: str, confidence_threshold: float = 0.5):
if method == 'knn':
self.neighbors()
cat_array: pd.Series = self._adata_ref.obs[labels].astype("category")
confident_labels = []
for inds in self._indices:
mode_label = cat_array.iloc[inds].mode()[0]
mode_count = (cat_array.iloc[inds] == mode_label).sum()
confidence = mode_count / len(inds)
if confidence >= confidence_threshold:
confident_labels.append(mode_label)
else:
confident_labels.append('unassigned')
self._adata_new.obs[labels] = pd.Categorical(values=confident_labels, categories=cat_array.cat.categories)
else:
raise NotImplementedError("Ingest supports knn labeling for now.")
perhaps I am misunderstanding the tool, or unaware of another tool which exists for my purpose, and would love input and help
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the ingest function's label-mapping path and the proposed map_labels implementation in the issue. Clarify how confidence should be calculated and represented for unassigned cells, then verify that the threshold behavior is covered for the supported knn method.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- bioinformatics
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100