Skip to content

Instantly share code, notes, and snippets.

@LouisFaure
Last active November 6, 2024 15:21
Show Gist options
  • Save LouisFaure/ec2a9202a984b3632dfa1c9990615ff0 to your computer and use it in GitHub Desktop.
Save LouisFaure/ec2a9202a984b3632dfa1c9990615ff0 to your computer and use it in GitHub Desktop.
rescale log-norm scRNAseq counts back to raw
import scipy.sparse as sp
import numpy as np
def get_raw(adata):
X = adata.X
if not sp.isspmatrix_csr(X):
raise Exception("matrix needs to be in csr format")
if is_integer_vector(adata.X[0,:].data):
raise Exception("matrix is already in integer format")
row_mins = np.minimum.reduceat(X.data, X.indptr[:-1])
X.data /= np.repeat(row_mins, np.diff(X.indptr))
adata.X.data=np.round(X.data).astype(int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment