Custom transformation API (variant of scanpy.pp.normalize_total such as scanpy.pp.normalize)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.6k
- Forks
- 779
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 27
Description
- Additional function parameters / changed functionality / changed defaults?
- New analysis tool: A simple analysis tool you have been using and are missing in
sc.tools? - New plotting function: A kind of plot you would like to seein
sc.pl? - External tools: Do you know an existing package that should go into
sc.external.*? - Other?
...
I'm in the process of redesigning my most used workflows from https://github.com/jolespin/soothsayer to wrap around ScanPy. I come from microbial ecology but do a good amount of machine learning. In microbial ecology, the community is shifting towards a compositional data analysis (CoDA) approach which has fundamentals firmly rooted in mathematics.
Here is some literature about broad-scale applications across all NGS datasets:
- A field guide for the compositional analysis of any-omics data
- Understanding sequencing data as compositions: an outlook and review
it is even catching attention in scRNA-seq too:
Anyways, off my soap box. As mentioned, I'm in the process of adapting my workflows to take advantage of ScanPy's power but I'm having a few difficulties. The first incorporating custom transformations.
In future versions, would it be possible to create an API that is similar to [scanpy.pp.normalize_total)(https://scanpy.readthedocs.io/en/stable/generated/scanpy.pp.normalize_total.html) but allows for a custom metric?
For example:
import numpy as np
import pandas as pd
from typing import Union
def clr(x:Union[np.ndarray, pd.Series], multiplicative_replacement:Union[None,str,float,int]="auto") -> Union[np.ndarray, pd.Series]:
"""
http://scikit-bio.org/docs/latest/generated/skbio.stats.composition.clr.html#skbio.stats.composition.clr
"""
assert np.all(x >= 0)
if multiplicative_replacement == "auto":
if np.any(x == 0):
multiplicative_replacement = 1/(len(x)**2)
if multiplicative_replacement is None:
multiplicative_replacement = 0
x = x.copy() + multiplicative_replacement
x = x/x.sum()
log_x = np.log(x)
geometric_mean = log_x.mean()
return log_x - geometric_mean
kwargs = {"multiplicative_replacement":"auto"}
sc.pp.normalize(adata, function=clr, **kwargs) # -> addata object with the transformation as one of the layers
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 with the scanpy.pp.normalize_total API and the issue's clr example to understand the requested custom transformation entry point. Done would be a decided and documented API that accepts a custom metric with keyword arguments and produces the transformed data in a layer, as described.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, pandas, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100