Skip to content

Instantly share code, notes, and snippets.

@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
## package biocViews dumbbell
library(BiocPkgTools)
library(dplyr)
library(tidyr)
library(graph)
library(biocViews)
data(biocViewsVocab)
@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">
@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, ...)
dna <- getFastaSeq()
## function for finding orfs. Returned as IRanges.
ORFdef <- find_in_frame_ORFs(dna, longestORF = FALSE, minimumLength = 8)
ORFdef <- ORFdef[lengths(ORFdef) > 0]
## Map (mapply) on each five prime leader
uORFs <- Map(
function(granges, tx_name, ORFdef) {
map_granges(ORFdef, granges, tx_name)
},
@mtmorgan
mtmorgan / g_range.R
Last active December 10, 2016 15:47
endomorphic overlaps, etc
suppressPackageStartupMessages({
library(tibble)
library(GenomicRanges)
})
.g_range <- setClass("g_range", contains="GRanges")
.g_columns <- c("chr", "start", "end", "strand")
setAs("GRanges", "g_range", function(from) {

These functions are in response to StackOverflow questions like [this][], wanting to fill in missing NA values with preceeding values, optionally by group

fill_down <- function(v) {
    if (length(v) > 1) {
        keep <- c(TRUE, !is.na(v[-1]))
        v[keep][cumsum(keep)]
    } else v
@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 / DisGeNET.R
Created April 7, 2016 09:04
Query DisGeNET disease / gene database from R
#' Query DisGeNET disease / gene database
#'
#' Based on a script by jpinero@imim.es, retrieved from
#' http://www.disgenet.org/ds/DisGeNET/scripts/disgenet.R on 7 April,
#' 2016. This version is meant for interactive use within an R
#' session, and makes a single query to DisGeNET rather than one query
#' for each input symbol.
#'
#' @param input: character vector of gene or disease identifiers
#'
@mtmorgan
mtmorgan / phred2ASCIIOffset.R
Created March 15, 2016 14:44
Translate integer or ASCII character fastq phred score encodings to integer offsets useful in Rsamtools
.ascii_offset <- function()
setNames(33:126 - 33L, strsplit(rawToChar(as.raw(33:126)), "")[[1]])
.phred2ascii_int <-
function(x, scheme)
{
## See https://en.wikipedia.org/wiki/FASTQ_format#Encoding
ascii <- .ascii_offset()
switch(scheme, "Illumina 1.8+" = {
## L - Illumina 1.8+ Phred+33, raw reads typically (0, 41)