Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View johnstantongeddes's full-sized avatar

John Stanton-Geddes johnstantongeddes

  • Dealer.com
  • Burlington, Vermont
View GitHub Profile
@johnstantongeddes
johnstantongeddes / df_fit_lm.R
Created June 13, 2014 16:22
Challenge to fit a lm to every "gene" in df
df <- data.frame(gene = rep(c(paste("gene", 1:10, sep="")), 5),
treatment = rep(paste("trt", 1:5, sep=""), each=10),
temp = rep(1:5, each=10),
exp = rnorm(50))
head(df)
# lm for a single gene
lmout <- lm(exp ~ temp, data = df[df$gene == "gene1", ])
@johnstantongeddes
johnstantongeddes / ROpenBUGS_example.R
Created August 19, 2014 13:38
Example of running BUGS for Bayesian inference from R
####################################
# TITLE: ONEWAY.R
# PURPOSE: ILLUSTRATE ONE WAY ANALYSIS OF VARIANCE
# DATA: AGES AT WHICH INFANTS FIRST WALKED ALONE, FROM FISHER AND VAN BELLE (2nd edition),
# PAGE 359. FOUR GROUPS: ACTIVE GROUP,
@johnstantongeddes
johnstantongeddes / 2014-09-18_verbatim-r-chunks-in rmd.rmd
Last active August 29, 2015 14:25 — forked from jennybc/2014-09-18_verbatim-r-chunks-in rmd.rmd
How to get verbatim R chunks in R markdown. Again. Writing it down now.
---
title: "Get verbatim R chunks in R Markdown"
author: "Jenny Bryan"
date: "18 September, 2014"
output:
html_document:
keep_md: TRUE
---
My periodic revisitation of "how can I include a verbatim R chunk in `.rmd`"? This time I am writing it down! Various proposed solutions:
@johnstantongeddes
johnstantongeddes / ggplot_examples.Rmd
Last active September 25, 2015 20:39
ggplot2 examples
---
title: "GrammaR of graphics using `ggplot2` in R"
author: "John Stanton-Geddes"
date: "December 8, 2014"
output: html_document
---
The `ggplot2` package, deveoped by Hadley Wickham, is the most downloaded R package of [all time](http://www.rdocumentation.org/) and one of the standards for publication-ready figures. Fron the [ggplot website](http://ggplot2.org/)
> ggplot2 is a plotting system for R, based on the grammar of graphics, which tries to take the good parts of base and lattice graphics and none of the bad parts. It takes care of many of the fiddly details that make plotting a hassle (like drawing legends) as well as providing a powerful model of graphics that makes it easy to produce complex multi-layered graphics.)
@johnstantongeddes
johnstantongeddes / interleave-illumina-backward.py
Created July 30, 2013 13:55
Python script to add Illumina 1.3 format fastq paired read tags '\1' and '\2' for forward and reverse reads, respectively, to an interleaved Illumina 1.8 format fastq file. Modified from [/khmer/sandbox/interleave.py](https://github.com/ged-lab/khmer/blob/master/sandbox/interleave.py)
#! /usr/bin/env python
import screed, sys, itertools
s1_file = sys.argv[1]
s2_file = sys.argv[2]
for r1, r2 in itertools.izip(screed.open(s1_file), screed.open(s2_file)):
name1 = r1.name
if not name1.endswith('/1'):
name1 += '/1'
@johnstantongeddes
johnstantongeddes / RPKM-TPM.r
Created October 10, 2013 20:48
Script to compare calculation of Reads per Kilobase per Million mapped reads (RPKM) to Transcripts per Million (TPM) using example data from http://blog.nextgenetics.net/?e=51. Wagner et al. 2012 "Measurement of mRNA abundance using RNA-seq data: RPKM measure is inconsistent among samples" Theory Biosci. 131:281-285
# Script to compare Reads per Kilobase per Million mapped reads (RPKM) to Transcripts per Million (TPM) for gene expression count data
# Wagner et al. 2012 "Measurement of mRNA abundance using RNA-seq data: RPKM measure
# is inconsistent among samples" Theory Biosci. 131:281-285
library(plyr)
## Worked example from http://blog.nextgenetics.net/?e=51
X <- data.frame(gene=c("A","B","C","D","E"), count=c(80, 10, 6, 3, 1),