Skip to content

Instantly share code, notes, and snippets.

@aaronwolen
aaronwolen / gencode-granges.r
Created February 11, 2014 15:33
Download the latest GENCODE annotations file and export as a GRanges object
# Download the latest GENCODE annotations file and export as a GRanges object
library(RCurl)
library(rtracklayer)
# Variables ---------------------------------------------------------------
# 'human' or 'mouse'
organism <- "human"
@aaronwolen
aaronwolen / alspac-enrichment-figure.r
Created April 15, 2014 18:14
Figures for Alexis' 2014-04-17 seminar.
library(ggplot2)
library(plyr)
# Load data ---------------------------------------------------------------
enrich.file <- "results/alspac/enrichment/enrichment-results-alspac-encode-dnase-h3k4me3.csv"
enrich.df <- read.csv(enrich.file, stringsAsFactors = FALSE)
# address stem-cell samples missing tissue annotation
@aaronwolen
aaronwolen / insert-proxy-bookmarklet.js
Last active August 29, 2015 14:05
Bookmarklet to automatically insert proxy stems for accessing journal articles off-campus.
javascript:var%20insert_proxy%20=%20function(proxy)%20{var%20url%20=%20document.URL;if%20(url.indexOf(proxy)%20===%20-1)%20{var%20parser%20=%20document.createElement(%27a%27);parser.href%20=%20url;var%20host%20=%20parser.host;if%20(host%20==%20%27www.ncbi.nlm.nih.gov%27)%20{host%20=%20host.replace(/\./g,%20%27-%27);};host%20=%20host.concat(proxy);proxy_url%20=%20url.replace(parser.host,%20host);window.open(proxy_url,%20%27_self%27);};};insert_proxy(%27.proxy.library.vcu.edu%27);
@aaronwolen
aaronwolen / parse-paths.r
Last active August 29, 2015 14:06
Parse FastA paths file into a data.frame
# Parse pathway file containing entries from the KEGG enzyme, orthology and
# pathway databases.
#
# For cases when there are multiple matches across databases all combinations
# of the match are returned. For example, some enzyme entries map to multiple
# orthologies:
#
# K00918 ADP-dependent phosphofructokinase/glucokinase [EC:2.7.1.146 2.7.1.147]
#
# will become...
@aaronwolen
aaronwolen / unembed.r
Last active August 29, 2015 14:07
Extract and append multiple values embedded in rows
# Extract and append multiple values embedded in rows
#
# data: data.frame
# col: column name containing embedded values
# sep: regular expression to split column by
#
# df <- data.frame(key = c("a", "a;b", "a;b;c"), val = 1:3)
# unembed(df, "key", ";")
unembed <- function(data, col, sep, ...) {
@aaronwolen
aaronwolen / dendrogram-contigs.r
Created November 12, 2014 16:22
Identify clusters of contiguous factors within a dendrogram
# Identify clusters of contiguous factors within a dendrogram
# Aaron Wolen
#
# See http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0038422
# for an example situation in which this would be useful
#
# x: dendrogram
# f: a named vector containing the factor that defines the grouping of leaves,
# must be named using the same values that define x's leaf labels
@aaronwolen
aaronwolen / iplotmap-searchbox.Rmd
Last active August 29, 2015 14:09
qtlcharts::iplotMap() search box
---
title: "test"
output:
html_document:
keep_md: yes
---
```{r}
library(qtl)
library(qtlcharts)
@aaronwolen
aaronwolen / toggleFullscreen.scpt
Last active August 29, 2015 14:16
Toggle fullscreen mode for OS X applications depending on display size
(*
display-specific fullscreen behavior
enable fullscreen for specific applications on MacBook and disable fullscreen
when using a larger external display
adapted from:
* https://gist.github.com/dsummersl/4175461
* http://daringfireball.net/2006/12/display_size_applescript_the_lazy_way
*)
@aaronwolen
aaronwolen / newkindofscience.r
Created April 10, 2015 17:37
Simple R implementation of cellular automata described in A New Kind of Science.
# A few simple rules from Stephen Wolfram's A New Kind of Science
apply_rule <- function(x, rule = "254") {
stopifnot(length(x) == 3)
stopifnot(all(x %in% c(0, 1)))
rules <- list("254" = c(1, 1, 1, 1, 1, 1, 1, 0),
"250" = c(1, 1, 1, 1, 1, 0, 1, 0),
"90" = c(0, 1, 0, 1, 1, 0, 1, 0),
"30" = c(0, 0, 0, 1, 1, 1, 1, 0))
@aaronwolen
aaronwolen / matrix-benchmark.md
Created July 2, 2015 16:25
Benchmark for converting matrixes to tidy data.frames in R

library(microbenchmark)

set.seed(1024) nr <- 1e4 nc <- 100

m <- matrix(runif(nr * nc), nrow = nr, dimnames = list(paste0("g", seq_len(nr)), paste0("s", seq_len(nc))))