Created
June 9, 2018 10:37
-
-
Save yjzhang/2cdf1e1ec8489124d05b8a4e86a9a317 to your computer and use it in GitHub Desktop.
This file contains 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
# simple implementation of quantile normalization? | |
import numpy as np | |
def quantile_norm(data): | |
""" | |
Source: https://en.wikipedia.org/wiki/Quantile_normalization | |
Note: this doesn't deal with ties very well. | |
Args: | |
data (array): dense array of shape (genes, cells_or_samples) | |
Returns: | |
new array with same shape as data, but after quantile normalization | |
""" | |
rows, cols = data.shape | |
normed_data = np.zeros(data.shape) | |
orders = data.argsort(0).argsort(0) | |
data_sorted = np.sort(data, 0) | |
ranks = data_sorted.mean(1) | |
for c in range(cols): | |
normed_data[:,c] = ranks[orders[:,c]] | |
return normed_data | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment