Skip to content

Instantly share code, notes, and snippets.

View mikelove's full-sized avatar

Michael Love mikelove

View GitHub Profile
@mikelove
mikelove / svd_residual.R
Last active December 27, 2015 20:49
SVD residual structure measure
########
#
# http://mikelove.wordpress.com/2009/09/14/measure-of-structure-in-residual-matrix/
#
#######
k <- 15
p <- 40
n <- 100
var <- 10
@mikelove
mikelove / script2Rmd
Created January 8, 2014 00:31
this hastily written script converts an R script which starts with a comment into a Rmd file, splitting code into chunks and turning comments into text
script2Rmd <- function(filein) {
lns <- scan(filein,what="char",sep="\n")
comments <- substr(lns,1,1) == "#"
lnsout <- lns
lnsout[comments] <- substr(lns[comments],3,nchar(lns[comments]))
rlelens <- rle(comments)$lengths
f <- factor(rep(seq_along(rlelens),rlelens))
lnsoutsplit <- split(lnsout, f)
chunkdelims <- rep(c("\n\n```{r}","```\n\n"), length(lnsoutsplit)/2)
#from https://stat.ethz.ch/pipermail/r-help/2006-March/101023.html
@mikelove
mikelove / gse52202 fccounts.csv
Last active August 29, 2015 14:02
gse52202 fc$counts
We can't make this file beautiful and searchable because it's too large.
"","SRR1027591Aligned.out.sam","SRR1027592Aligned.out.sam","SRR1027593Aligned.out.sam","SRR1027594Aligned.out.sam","SRR1027595Aligned.out.sam","SRR1027596Aligned.out.sam","SRR1027597Aligned.out.sam","SRR1027598Aligned.out.sam","SRR1027599Aligned.out.sam","SRR1027600Aligned.out.sam","SRR1027601Aligned.out.sam","SRR1027602Aligned.out.sam","SRR1027603Aligned.out.sam","SRR1027604Aligned.out.sam","SRR1027605Aligned.out.sam","SRR1027606Aligned.out.sam"
"653635",19,23,12,23,2,5,3,6,0,0,1,1,8,8,4,4
"100422834",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
"645520",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
"79501",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
"729737",28,35,22,42,15,15,36,25,7,4,15,14,47,61,20,9
"100507658",1,3,2,1,0,0,0,2,0,0,1,0,0,2,1,0
"100132287",0,0,9,7,0,0,1,5,2,1,0,0,8,3,3,7
"100288646",0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0
"729759",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
@mikelove
mikelove / gse52202 pheno.csv
Last active August 29, 2015 14:02
gse52202 pheno.csv
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 10.
"","experiment","title","gsm","condition","study","submission","sample","run"
"SRR1027592","SRX375129","Control 00i","GSM1261105","Normal control","SRP032798","SRA110634","SRS500408","SRR1027592"
"SRR1027591","SRX375129","Control 00i","GSM1261105","Normal control","SRP032798","SRA110634","SRS500408","SRR1027591"
"SRR1027593","SRX375130","Control 03i","GSM1261106","Normal control","SRP032798","SRA110634","SRS500407","SRR1027593"
"SRR1027594","SRX375130","Control 03i","GSM1261106","Normal control","SRP032798","SRA110634","SRS500407","SRR1027594"
"SRR1027595","SRX375131","Control 14i","GSM1261107","Normal control","SRP032798","SRA110634","SRS500409","SRR1027595"
"SRR1027596","SRX375131","Control 14i","GSM1261107","Normal control","SRP032798","SRA110634","SRS500409","SRR1027596"
"SRR1027598","SRX375132","Control 83i","GSM1261108","Normal control","SRP032798","SRA110634","SRS500410","SRR1027598"
"SRR1027597","SRX375132","Control 83i","GSM1261108","Normal control","SRP032798","SRA110634","SRS500410","SRR1027597"
"S
@mikelove
mikelove / gse52202 script.R
Last active August 29, 2015 14:02
gse52202 script.R
fc.counts <- read.csv("fccounts.csv",row.names=1)
pheno <- read.csv("pheno.csv",row.names=1)
pheno$sam <- paste0(pheno$run,"Aligned.out.sam")
library(DESeq2)
dds <- DESeqDataSetFromMatrix(fc.counts,
DataFrame(pheno[match(colnames(fc.counts),pheno$sam),]),
~ condition)
dds$condition <- relevel(dds$condition,"Normal control")
levels(dds$condition)
@mikelove
mikelove / ph525x_pic.R
Last active August 29, 2015 14:02
ph525x video stats
d <- read.csv("ph525x_vids.csv")
d <- d[-1,] # first 1 minute video
d$week <- factor(d$week)
sum(d$min)/60 # "hours of video")
barplot(tapply(d$min, d$week, sum)/60, main="hours of video / week")
barplot(table(d$week), main="video units / week")
stripchart(min ~ week, data=d, vertical=TRUE,
pch=1, method="jitter",
xlab="week", ylab="min", main="minutes per video unit")
abline(h=10, lwd=2, col="red")
@mikelove
mikelove / polymode
Last active September 22, 2015 14:21
markdown mode and polymode for emacs Rmd support
;; obtain from http://jblevins.org/projects/markdown-mode/
(load "~/path/to/markdown-mode.el")
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
;; obtain from https://github.com/vitoshka/polymode
(setq load-path
@mikelove
mikelove / rcpp.R
Created July 30, 2014 18:42
Rcpp demo for BioC2014
# Rcpp demo
# Mike Love
# BioC2014
# 30 Jul 2014
# Go here for all the info:
# http://dirk.eddelbuettel.com/code/rcpp.html
# examples: go down to the 'Other documentation' vignettes
@mikelove
mikelove / .emacs
Last active July 8, 2023 11:35
.emacs
; mike love's .emacs
; general stuff
(menu-bar-mode -1)
(tool-bar-mode -1)
(global-set-key "\C-x\C-b" 'electric-buffer-list)
(global-unset-key (kbd "\C-x DEL") )
(global-unset-key (kbd "\C-t") )
(setq inhibit-startup-screen t)
(setq backup-directory-alist '(("" . "~/emacs-backup")))
@mikelove
mikelove / .Rprofile
Last active February 14, 2019 16:12
.Rprofile
options(repos=c("https://cran.rstudio.com/"),showWarnCalls=TRUE,showErrorCalls=TRUE,
max.print=1000,width=100,menu.graphics=FALSE)
options(defaultPackages = c(getOption("defaultPackages"),"devtools","rmarkdown"))
# Sys.setenv(TZDIR = "/usr/share/zoneinfo") # this is for a peculiar Mac OS X setup
library(utils)
rc.settings(ipck=TRUE)
if (interactive()) message(R.version$version.string)