Last active
April 11, 2016 13:43
-
-
Save jenzopr/02bc8205e85e51dfbfc80f4373194466 to your computer and use it in GitHub Desktop.
The calc_dm function implements the distance-to-the-median measurement from Kolodziejczyk et. al. (Cell Stem Cell, 2015).
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
library(zoo) | |
calc_dm = function(expr, func=median) { | |
if( is.null(rownames(expr)) ) { rownames(expr) = 1:nrow(expr) } | |
# Calculate log10 mean of the rows | |
m = log10(rowMeans(expr)) | |
names(m) = rownames(expr) | |
# Calculate the squared cv | |
cv2 = apply(expr, 1, function(x) { (sd(x)/mean(x))^2 }) | |
# Sort the means | |
s = names(sort(m)) | |
# Calculate median squared cv in a window of 50 genes | |
r = rollapply(data = log10(cv2[s]), width = 50, FUN=func, fill="extend") | |
names(r) = s | |
# Return distance to the median | |
log10(cv2) - r[names(cv2)] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Application on data from mouse single ES cells from Mantsoki et. al. (Comp. Biol. Chem, 2016)