Last active
August 29, 2015 13:57
-
-
Save vals/9749477 to your computer and use it in GitHub Desktop.
NumPy implementation of estimateSizeFactorsForMatrix from DESeq
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
def estimate_size_factor(counts): | |
#COUNTS = GENES (rows) x CELLS (columns) | |
genes = counts[:, 0] | |
#ONLY COUNTS WITHOUT HEADER NOR GENES | |
counts = numpy.array(counts[1:, 1:], dtype = int) | |
#DONT REMOVE INFITE VALUES AS IT CAUSES PROBLEMS | |
log_counts = numpy.log(counts) | |
def column_normalization(column): | |
distance_to_mean = numpy.log(column) - logmeans | |
distance_to_mean = distance_to_mean[numpy.isfinite(distance_to_mean)] | |
return numpy.exp(numpy.median(distance_to_mean)) | |
size_factors = numpy.apply_along_axis(column_normalization, 0, counts) | |
return size_factors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment