Last active
November 6, 2024 15:21
-
-
Save LouisFaure/ec2a9202a984b3632dfa1c9990615ff0 to your computer and use it in GitHub Desktop.
rescale log-norm scRNAseq counts back to raw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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