Skip to content

Instantly share code, notes, and snippets.

@mtmorgan
mtmorgan / gist:bd147505b89e42a151f9
Created June 24, 2015 18:54
dplyr / SummarizedExperiment compatibility layer -- half baked
## dplyr compatibility
as.data.frame.RangedSummarizedExperiment <-
function(x, row.names=NULL, optional=FALSE, ...)
{
colData <- colData(x)
rownames(colData) <- NULL
cbind(as.data.frame(rowRanges(x)[as.vector(row(x))]),
as.data.frame(colData[as.vector(col(x)),, drop=FALSE]),
sapply(assays(x), as.vector))
@mtmorgan
mtmorgan / readKallisto.R
Last active December 4, 2017 11:51
read kallisto RNA-seq quantification into R / Bioconductor data structures
.require <-
function(pkg)
{
withCallingHandlers({
suppressPackageStartupMessages({
require(pkg, character.only=TRUE, quietly=TRUE)
})
}, warning=function(w) {
invokeRestart("muffleWarning")
}) || {
## Imports: GEOquery, Biobase
acc <- "GSE62944"
if (!file.exists(acc))
GEOquery::getGEOSuppFiles(acc)
setwd(acc)
clinvar <- local({
message("clinvar")
fl <- "GSE62944_TCGA_20_420_Clinical_Variables_7706_Samples.txt.gz"
@mtmorgan
mtmorgan / methods.R
Last active August 29, 2015 14:16
wrap methods() to report S3 and S4 methods for generic or class
## compatibility
if (!exists("lengths"))
lengths <- function(x) vapply(x, length, integer(1))
##
## methods
##
.S4methodsForClass <-
@mtmorgan
mtmorgan / ucscAnnotateGenome.R
Created September 29, 2014 02:02
Retrieve UCSC genomes() and their latin bionomial by scraping UCSC web pages, and translate these to NCBI taxonomyId through entrez eutils calls
loadNamespace("rtracklayer")
loadNamespace("XML")
.organismToTaxid <- function(organism=character())
{
## query NCBI for taxonomy ID
.eutils <- "http://eutils.ncbi.nlm.nih.gov/entrez/eutils"
## 1. ids
uorganism <- unique(organism[!is.na(organism)])
@mtmorgan
mtmorgan / global.R
Created December 5, 2012 23:21
shiny AnnotationTable
library(shiny)
library(org.Hs.eg.db)
library(org.Mm.eg.db)
library(org.Dm.eg.db)
db <- c(Human="org.Hs.eg.db", Mouse="org.Mm.eg.db",
Drosophila="org.Dm.eg.db")
map <- lapply(db, function(elt) tryCatch({
library(elt, quietly=TRUE, character.only=TRUE)
@mtmorgan
mtmorgan / cigarAlign.R
Created November 13, 2012 17:32
Represent aligned DNA sequences as a DNAStringSet based on position and CIGAR
library(Rsamtools)
.cigarAlignInput <-
function(file, param, what)
{
result <- readBamGappedAlignments(file, param=param)
names(mcols(result))[names(mcols(result)) == what] <- "what"
result
}