shawnlyu / quantile_normalize Goto Github PK
View Code? Open in Web Editor NEWThis function implements quantile normalization in python matrix
This function implements quantile normalization in python matrix
Dear ShawnLYU,
nice piece of code! what you think about preserving np.nan values in the dataframe?
cheers
Michele
It says in the 'Readme' file:
Input data is a Pandas dataframe (df). Each row stands for an observations and each column stands for an attribute
Not sure if I got it right with what you meant by 'observations' and 'attribute'. According to Quantile Normalization, in the case of gene expression data, your codes are actually fit for input with each row being a gene (attribute?) and each column being a sample (observation?).
I found the code useful. I rewrote the function using 2D numpy array as input in my use case. I'm posting it here if it's of any help to others or as an addition to your code.
import numpy as np
import pandas as pd
def qnorm_np(arr):
sorted_arr = arr.astype(float)
sorted_arr.sort(axis=0)
rank = sorted_arr.mean(axis=1)
for col in range(arr.shape[1]):
t = np.searchsorted(np.sort(arr[:, col]), arr[:,col])
sorted_arr[:,col] = rank[t]
return sorted_arr
#Test
df_input = pd.DataFrame({'C1': {'A': 5, 'B': 2, 'C': 3, 'D': 4},
'C2': {'A': 4, 'B': 1, 'C': 4, 'D': 2},
'C3': {'A': 3, 'B': 4, 'C': 6, 'D': 8}})
arr_norm = qnorm_np(df_input.values)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.