Skip to content

Instantly share code, notes, and snippets.

View mikelove's full-sized avatar

Michael Love mikelove

View GitHub Profile
@mikelove
mikelove / accession2url.R
Created June 16, 2016 18:33
ENA accession to URL
accession2url <- function(x) {
prefix <- "ftp://ftp.sra.ebi.ac.uk/vol1/fastq"
dir1 <- paste0("/",substr(x,1,6))
dir2 <- ifelse(nchar(x) == 9, "",
ifelse(nchar(x) == 10, paste0("/00",substr(x,10,10)),
ifelse(nchar(x) == 11, paste0("/0",substr(x,10,11)),
paste0("/",substr(x,10,12)))))
paste0(prefix,dir1,dir2,"/",x)
}
@mikelove
mikelove / simu_purrr.R
Created July 19, 2016 23:28
using purrr for simple R simulations
nrep <- 100
d <- expand.grid(n=c(3,5,10,20), sd=c(1,2,3))
d <- d[rep(seq_len(nrow(d)),each=nrep),]
simulate <- function(n, sd) {
rnorm(n=n, mean=0, sd=sd)
}
library(purrr)
library(dplyr)
@mikelove
mikelove / setup_mac.md
Last active March 3, 2021 17:36
setting up mac
  • xcode
  • iterm2
  • source code pro / fire mono
  • homebrew
  • zsh
  • git
  • emacs & ESS
  • R & Rstudio
  • mactex
  • ispell
@mikelove
mikelove / tsne_snapping.R
Last active August 25, 2016 15:30
looking to see if t-SNE replicates linear separation of groups
n <- 50
m <- 40
m_inform <- 10
set.seed(1)
niter <- 200
intradist <- numeric(niter)
interdist <- numeric(niter)
mus <- seq(from=0, to=3, length=niter)
library(Rtsne)
cols <- rep(1:2, each=n/2)
@mikelove
mikelove / convert.txt
Last active May 24, 2017 19:18
convert Rnw to Rmd
perl -pe 's|\\Robject{(.+?)}|`\1`|g' |
perl -pe 's|\\Rcode{(.+?)}|`\1`|g' |
perl -pe 's|\\Rclass{(.+?)}|*\1*|g' |
perl -pe 's|\\Rfunction{(.+?)}|*\1*|g' |
perl -pe 's|\\texttt{(.+?)}|`\1`|g' |
perl -pe 's|\\textit{(.+?)}|*\1*|g' |
perl -pe 's|\\textbf{(.+?)}|**\1**|g' |
perl -pe 's|\\emph{(.+?)}|*\1*|g' |
perl -pe 's|<<|```{r |g' |
perl -pe 's|>>=|}|g' |
@mikelove
mikelove / read_gc.R
Last active December 19, 2016 15:42
expected read GC content from human txome
library(BSgenome.Hsapiens.UCSC.hg38)
library(TxDb.Hsapiens.UCSC.hg38.knownGene)
txs <- extractTranscriptSeqs(Hsapiens, TxDb.Hsapiens.UCSC.hg38.knownGene)
z <- txs[sample(length(txs), 10000)]
z <- z[width(z) > 100]
starts <- round(runif(length(z),1,width(z)-99))
gc <- as.vector(letterFrequency(subseq(z,start=starts,width=100),"GC"))
with(hist(gc), plot(mids, density, type="b", lwd=2))
abline(h=0)
@mikelove
mikelove / get_deps.R
Last active July 15, 2019 18:46
Get the missing packages from Suggests from R package DESCRIPTION
get_deps <- function(what="Suggests") {
deps <- desc::desc_get_deps()
suggests <- deps$package[deps$type==what]
setdiff(suggests, sub(".*/","",find.package(suggests, quiet=TRUE)))
}
@mikelove
mikelove / unix_examples.txt
Created January 26, 2017 22:08
unix examples
# suspend, foreground, background
Ctrl-z, fg, jobs, bg
example in R: sapply(1:100, function(i) {Sys.sleep(1);print(i)})
# list size of directories
du -sh *
@mikelove
mikelove / ase.Rmd
Created May 12, 2017 15:19
Using RNA-seq DE methods to detect allele-specific expression
---
title: "Using RNA-seq DE methods to detect allele-specific expression"
author: "Michael Love"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: html_document
---
The question has come up a few times on the Bioconductor support site how to use
methods like DESeq2 or edgeR to detect allele-specific expression,
and how to see if the allelic ratio differs across condition. Aaron Lun has written up
@mikelove
mikelove / scrape_ensembl.R
Created May 18, 2017 19:48
scrape genome information from Ensembl
library(rvest)
org <- "Takifugu_rubripes"
getdetails <- function(org) {
readit <- function(org, prefix) {
read_html(paste0("http://",prefix,".ensembl.org/",
org, "/Info/Annotation"))
}
page <- tryCatch(readit(org, "www"),