Skip to content

Instantly share code, notes, and snippets.

View yannabraham's full-sized avatar

Yann Abraham yannabraham

  • Janssen Pharmaceutical Companies of Johnson & Johnson
  • Beerse (BE)
View GitHub Profile
@yannabraham
yannabraham / cdlist_parser.R
Last active September 2, 2016 15:02
This script parses the (very useful but broken) list of CD markers and associated genes from Uniprot found at http://www.uniprot.org/docs/cdlist.txt
library(stringr)
screwed <- readLines(con='http://www.uniprot.org/docs/cdlist.txt')
screwed <- screwed[76:521]
parser <- c(0,8,21,29,37,55,1000000L) # use fixed length parsing
screwed <- lapply(screwed,function(scr) {
sapply(seq(length(parser)-1),function(i) str_trim(substr(scr,parser[i]+1,parser[i+1])))
}
@yannabraham
yannabraham / complex_summary_w_tapply.R
Created August 2, 2016 12:49
Using tapply to return multiple values as an array
data(warpbreaks)
my.summary <- function(vals) {
return(c(avg=mean(vals),sd=sd(vals)))
}
sum.warpbreaks <- with(warpbreaks,tapply(breaks,list(tension,wool),my.summary))
sum.warpbreaks <- array(unlist(sum.warpbreaks),
dim=c(length(sum.warpbreaks[1,1][[1]]),dim(sum.warpbreaks)),