Skip to content

Instantly share code, notes, and snippets.

@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")
}) || {
@mtmorgan
mtmorgan / uvlock_client.R
Last active May 26, 2018 17:32
Simple distributed lock using BiocParallel::ipclock() and httpuv
.host <- "localhost"
.port <- 5001
library(httr)
library(BiocParallel)
.get <-
function(fmt, ..., host = .host, port = .port)
{
query <- sprintf(fmt, host, port, ...)
@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 / prettify.html
Created February 1, 2019 22:31
prettify support site example
<!DOCTYPE html>
<html lang="en">
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.11.0/highlight.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.11.0/languages/r.min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/lib/prism/prism.css">
## package biocViews dumbbell
library(BiocPkgTools)
library(dplyr)
library(tidyr)
library(graph)
library(biocViews)
data(biocViewsVocab)
@mtmorgan
mtmorgan / grangesToSymbol
Created July 29, 2016 20:50
Extract ranges of genes, and map ranges to corresponding genes
geneRanges <-
function(db, column="ENTREZID")
{
g <- genes(db, columns=column)
col <- mcols(g)[[column]]
genes <- granges(g)[rep(seq_along(g), elementNROWS(col))]
mcols(genes)[[column]] <- as.character(unlist(col))
genes
}
@mtmorgan
mtmorgan / BiocManager_test.sh
Last active October 21, 2019 13:18
BiocManager test scripts
export BIOCVERSION_REPOS=~/b/git/BiocVersion
export BIOCMANAGER_REPOS=~/b/git/BiocManager
export BIOCMANAGER_SANDBOX=/Users/ma38727/tmp/BiocManagerSandbox
#
# R-4.0
#
echo "R-4.0"
export R_LIBS_USER=$BIOCMANAGER_SANDBOX/R-4.0-Bioc-3.10
@mtmorgan
mtmorgan / f.rda
Last active October 25, 2019 13:48
loud load debug
@mtmorgan
mtmorgan / obo_graph.R
Last active April 12, 2020 16:20
construct distance between GO nodes from OBO file
obo = readLines("go.obo")
##
## Clean data
##
## blank lines separate different 'groups' in the obo
group <- cumsum(!nzchar(obo))
## keep groups that have the [Term] label
package_dependencies <- tools::package_dependencies
trim <- function(deps, drop) {
lvls = names(deps)
df = data.frame(
pkg = factor(rep(names(deps), lengths(deps)), levels = lvls),
dep = unlist(deps, use.names = FALSE)
)
df = df[!df$dep %in% drop,, drop = FALSE]
split(df$dep, df$pkg)