Skip to content

Instantly share code, notes, and snippets.

@aaronwolen
aaronwolen / matrix-benchmark.Rmd
Last active August 29, 2015 14:24
Benchmark for converting matrixes to tidy data.frames in R
```{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))))
@aaronwolen
aaronwolen / dataframetools.r
Created July 5, 2012 21:37
dataframetools: A few simple functions for performing simple tasks with data.frames
# dataframetools
# A few simple functions for performing simple tasks with data.frames
# ---
# Includes functions for:
#
# - reordering data.frames
# - identifying invariant or blank columns
# - identifying groups of columns that are redundant with each other
# - converting all columns of class factor to class character
@aaronwolen
aaronwolen / annotate_chip.r
Created September 12, 2012 17:21
Generate data.frame of feature annotations using Bioconductor
#' Generate data.frame of feature annotations
#'
#' Use bioconductor annotation packages to create a data.frame of feature/probe
#' annotations.
#'
#' @param chip character string identifying chip model (e.g., "illuminaHumanv2")
#' @param features optional character vector of chip features (i.e., probeset ids)
#' @param vars character vector of desired annotations. These must match objects
#' provided by the annotation package (e.g., "CHR")
#' @param duplicate.values how should duplicate values be handled? The default
@aaronwolen
aaronwolen / map_ftp.r
Created October 31, 2012 14:42
FTP tree mapper: save an FTP site's directory stucture as a list
#' FTP tree mapper
#' Save an FTP site's directory stucture as a list.
#' @author Aaron Wolen
#'
#' @example
#' url <- 'ftp://ftp.genboree.org/EpigenomeAtlas/Current-Release/experiment-sample'
#' roadmap <- map_ftp(url = url, dirs = "Histone_H2BK120ac", recursive = TRUE)
map_ftp <- function(url, dirs, recursive = FALSE) {
require(RCurl, quietly = TRUE)
@aaronwolen
aaronwolen / wig-sources.csv
Created November 4, 2012 16:08
List of sources of wig/bigwig genomic data
Name URL
ENCODE ftp://encodeftp.cse.ucsc.edu/pipeline/hg19/
ENCODE (test) http://hgdownload-test.cse.ucsc.edu/goldenPath/hg19/encodeDCC/
RoadMap ftp://ftp.genboree.org/EpigenomeAtlas/Current-Release
@aaronwolen
aaronwolen / load-bigwig.r
Created November 20, 2012 17:08
Example: loading data from a bigWig file
library(IRanges)
library(GenomicRanges)
library(rtracklayer)
# Select a BigWig file
bw.dir <- "/home/chromatin/roadmap/DNase_hypersensitivity/brain_fetal"
bw.file <- dir(bw.dir, full.names = TRUE, pattern = "*.bigWig")[1]
# Specify a genomic range
selection <- GRanges(seqnames = "chr4",
@aaronwolen
aaronwolen / bioc_archive.r
Created November 21, 2012 15:39
Install bioconductor for older versions of R
install.packages(c("RCurl", "XML"))
bioc.v <- tools:::.BioC_version_associated_with_R_version
repos <- tools:::.read_repositories(file.path(R.home("etc"), "repositories"))
bioc.repo <- repos["BioCsoft",]$URL
bioc.repo <- sub("2\\.\\d+", bioc.v, bioc.repo)
packages <- c("zlibbioc", "BiocGenerics", "Biobase", "IRanges",
"AnnotationDbi", "GenomicRanges", "Biostrings", "Rsamtools",
@aaronwolen
aaronwolen / rnw2rmd.sh
Created December 1, 2015 12:53
Convert Rnw presentations to Rmarkdown files
#!/bin/bash
# Partially convert Rnw presentations to Rmd syntax
# - [x]: Code chunks
# - [x]: Section headers
# - [x]: Slide headers
# - [x]: Presenter notes
# - [x]: Lists
# - [ ]: Inlinde code (sort of, not really)
@aaronwolen
aaronwolen / clipboard.r
Created January 11, 2013 20:11
Paste directly to Mac clipboard
clipboard <- function(x, sep.lines = FALSE){
clipboard <- pipe('pbcopy', 'w')
if(sep.lines){
x <- unlist(strsplit(as.character(x), split = ","))
x <- sub(" ", "", x)
}
write.table(x, clipboard, sep = "\t",
quote = FALSE, col.names = FALSE, row.names = FALSE)
@aaronwolen
aaronwolen / README.md
Last active December 14, 2015 11:59
Copy markdown formatted links from BibDesk
  1. Open the "Template Files" pane in BibDesk's preferences
  2. Use the "+" button to add a new general template
  3. Double click the red text and choose citeServiceTemplateMD.txt
  4. Open the "Citation" pane in BibDesk's preferences
  5. Change "Default format" to "Template"
  6. Change "Template" to "citeServiceTemplateMD"