Closed shendong124 closed 4 years ago
Hi, I'm not sure where you found the function normalize_geometric()
, but Scanpy's inbuilt normalization is called sc.pp.normalize_total()
. You can find the documentation here:
https://scanpy.readthedocs.io/en/stable/api/scanpy.pp.normalize_total.html
I found it in the CITEseq tutorial
https://scanpy-tutorials.readthedocs.io/en/multiomics/cite-seq/pbmc5k.html
Le mar. 12 mai 2020 à 03:59, MalteDLuecken notifications@github.com a écrit :
Closed #1208 https://github.com/theislab/scanpy/issues/1208.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/theislab/scanpy/issues/1208#event-3326937703, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG6NOAWOLOUUOMFRCYB4KMLRRETYZANCNFSM4M6NCTKQ .
@ivirshup where did you get this function from?
@shendong124 @ivirshup I assume normalize_geometric
was intended to be similar to Seurat's centered log ratio transformation, which is implemented as follows in R: log1p(x = x / (exp(x = sum(log1p(x = x[x > 0]), na.rm = TRUE) / length(x = x))))
. This is CLR with some safeguards for 0 counts.
Here's a reimplementation of the Seurat CLR transformation for scanpy. Call this with clr_normalize_each_cell(adata)
:
def clr_normalize_each_cell(adata, inplace=True):
"""Normalize count vector for each cell, i.e. for each row of .X"""
import numpy as np
import scipy
def seurat_clr(x):
# TODO: support sparseness
s = np.sum(np.log1p(x[x > 0]))
exp = np.exp(s / len(x))
return np.log1p(x / exp)
if not inplace:
adata = adata.copy()
# apply to dense or sparse matrix, along axis. returns dense matrix
adata.X = np.apply_along_axis(
seurat_clr, 1, (adata.X.A if scipy.sparse.issparse(adata.X) else adata.X)
)
return adata
Actually there's a nice ongoing thread about this at #1117
normalize_geometric()
is still mentioned in the tutorial at https://scanpy-tutorials.readthedocs.io/en/multiomics/cite-seq/pbmc5k.html
Hi Scanpy team, I am trying to analyse CTE-seq data. At the nomalization step of the protein data, the attibute normalize_geometric is not recognize. Could this be a version issue? Thank you for your help!
Versions: