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
require(RColorBrewer) | |
# since gene expression data always contains a lot of samples. | |
# If one want to see distributions of samples, using boxplot would be not so clear. | |
# The function use continuous colors to represent density distributions of expression | |
# values in samples and can make a better illustration of the data. | |
heatplot = function(x, col=rev(brewer.pal(10, "Spectral")), draw.quantiles = TRUE, align = TRUE, each = FALSE, ...) { | |
if(is.vector(x) && class(x) != "list") { | |
x = as.matrix(x) |
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
color.pal = function(x, col = c("green", "black", "red"), breaks = c(-5, 0, 5)) { | |
if(length(col) != length(breaks)) { | |
stop("Length of col should be equal to the length of breaks.\n") | |
} | |
# change col represented as strings to RGB space | |
col_section = sapply(col, function(x) as.vector(col2rgb(x))) | |
col_section = t(col_section) | |
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
# == title | |
# Simple template for text interpolation | |
# | |
# == description | |
# I like text interpolation in Perl. But in R, if you want to connect plain text and variables, | |
# you need to use `paste` or functions in `stringr`. However, if there are so many variables or | |
# or many quotes in the string you want to construct, it would be a little terrible. | |
# So, this function allows you to construct strings as Perl style. | |
# | |
# == param |
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
assignment = function(x, k = 4) { | |
names(x) = seq_along(x) | |
y = vector("list", k) | |
ysum = sapply(y, function(x) 0) | |
flag = 0 | |
while(length(x)) { | |
if(flag) { |
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
build.position.index = function(x, by = 5) { | |
segment = round((x/(10^by)))*10^by | |
se = unique(segment) | |
mat = matrix(nrow = length(se), ncol = 2) | |
for(i in seq_along(se)) { | |
mat[i, ] = range(which(segment == se[i])) | |
} | |
list(mat = mat, segment = se, by = 10^by) | |
} |
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
bedtools = function(cmd, envir = parent.frame()) { | |
gr = gsub("^.*@\\{(.*?)\\}.*$", "\\1", cmd) | |
gr = get(gr, envir = envir) | |
file = tempfile(fileext = ".bed") | |
write.table(gr, file = file, sep = "\t", quote = FALSE, row.names = FALSE, col.names = FALSE) | |
cmd = gsub("@\\{.*?\\}", file, cmd) | |
try(tb <- read.table(pipe(cmd), stringsAsFactors = FALSE)) | |
file.remove(file) | |
return(tb) | |
} |
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
set_module = function(module) { | |
assign("__module__", module, envir = parent.frame()) | |
} | |
load_module = function(file) { | |
e = new.env() | |
source(file, local = e, verbose = FALSE) | |
module = get("__module__", envir = e) | |
rm(e) |
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
is_abs_unit <- function(x) UseMethod("is_abs_unit") | |
is_abs_unit.unit = function(x) { | |
unit = attr(x, "valid.unit") | |
if(unit %in% c(1:4, 7:24)) { | |
return(TRUE) | |
} else { | |
return(FALSE) | |
} |
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
var unread = new Array(); | |
var checked = new Array(); | |
var from = new Array(); | |
var subject = new Array(); | |
var rows = new Array(); | |
load_all = function() { | |
rows = document.getElementsByClassName("lvm")[0].lastChild.childNodes; |
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
Path of SRA files: | |
http://sra-download.ncbi.nlm.nih.gov/srapub/SRR\\d+ |
OlderNewer