This file contains hidden or 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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains hidden or 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
# Could be generalised to handle the full arguments of merge.data.table but I've kept it simple. | |
# mergeDT based on http://r.789695.n4.nabble.com/merge-multiple-data-frames-td4331089.html | |
# Takes a (named) list of data.tables (lodt) where all columns are common to all data.tables | |
# The key of each table is the same but is only a subset of the columns, e.g. (chr, pos1, pos2) | |
# The remaining columns of each data.table are the "counts", e.g. (MM, MU, UM, UU) | |
# We append the names of each sample (the names of lodt) to the "counts" so that we can keep | |
# track of from which sample the counts came. | |
mergeAll <- function(lodt) { | |
dotNames <- lapply(lodt, names) | |
repNames <- Reduce(intersect, dotNames) |
This file contains hidden or 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(RColorBrewer) | |
mypar <- function(a = 1, b = 1, brewer.n = 8, brewer.name = "Dark2",...){ | |
par(mar=c(2.5,2.5,1.6,1.1),mgp=c(1.5,.5,0)) | |
par(mfrow=c(a,b),...) | |
palette(brewer.pal(brewer.n,brewer.name)) | |
} |
This file contains hidden or 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
## Create some test data (a matrix) | |
# The matrix, x, has at least 3 columns, all of which contain integers. | |
# The first column is an integer-encoding of a chromosome and so there are approximately 20-30 unique values. | |
# The second column is an integer-encoding of a genomic strand and so there are at most 3 unique values (representing positive, negative or unknown/irrelevant). | |
# The remaining columns are genomic positions, which are integers in the range of approximately 1-250,000,000. | |
# sim_data adds 'd' duplicates as the last 'd' rows | |
# n is the number of rows | |
# m + 2 is the number of columns. m = 1 is the minimum. | |
# d is the number of duplicates added to the end of the matrix | |
# sim_strand is whether the strand is simulated (column 2 of the matrix) |
This file contains hidden or 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
#### Modified version of Dirk's impoved ls() function and shortcut (http://stackoverflow.com/questions/1358003/tricks-to-manage-the-available-memory-in-an-r-session) #### | |
# improved list of objects | |
.ls.objects <- function (pos = 1, pattern, order.by, | |
decreasing=FALSE, head=FALSE, n=5) { | |
napply <- function(names, fn) sapply(names, function(x) | |
fn(get(x, pos = pos))) | |
names <- ls(pos = pos, pattern = pattern) | |
obj.class <- napply(names, function(x) as.character(class(x))[1]) | |
obj.mode <- napply(names, mode) | |
obj.type <- ifelse(is.na(obj.class), obj.mode, obj.class) |
This file contains hidden or 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
#### Function to do a recursive intersection of a list of GRanges (x) #### | |
recursiveIntersect <- function(x){ | |
if (length(x) > 2){ | |
print(paste0('Recursing (length = ', length(x), ')')) | |
z <- intersect(x[[1]], x[[2]]) | |
x <- x[seq.int(3, length(x))] | |
x <- c(x, z) | |
recursiveIntersect(x) | |
} else if (length(x) == 2){ | |
print(paste0('Base case (length = ', length(x), ')')) |
NewerOlder