Skip to content

Instantly share code, notes, and snippets.

@vals
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vals/9749477 to your computer and use it in GitHub Desktop.
Save vals/9749477 to your computer and use it in GitHub Desktop.
NumPy implementation of estimateSizeFactorsForMatrix from DESeq
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