Skip to content

Instantly share code, notes, and snippets.

View audy's full-sized avatar
🔬

Austin Richardson audy

🔬
View GitHub Profile
@jnpaulson
jnpaulson / read_hdf5_biom.R
Last active March 25, 2020 17:24
Hacks to load an hdf5 biom file and be able to add it to metagenomeSeq or phyloseq
source("http://bioconductor.org/biocLite.R")
biocLite(c("rhdf5","biom"))
library(rhdf5)
library(biom)
# This generates the matrix columns-wise
generate_matrix <- function(x){
indptr = x$sample$matrix$indptr+1
indices = x$sample$matrix$indices+1
data = x$sample$matrix$data
# R lexer
# based on http://www.jayconrod.com/posts/37/a-simple-interpreter-from-scratch-in-python-part-1
#' Returns list of patterns and token names.
#' This saves typing.
#'
#' @param pattern a regex pattern
#' @param tag the resulting token tag
tk <- function(pattern, token) {
return(list(pattern=paste0("^", pattern), tag=token))
@davfre
davfre / bamfilter_oneliners.md
Last active February 24, 2024 01:23
SAM and BAM filtering oneliners
anonymous
anonymous / streaming_fasta_stats.py
Created September 18, 2013 17:32
efficiently calculate mean and variance of sequence lengths in an infinitely large fasta file
#!/usr/bin/env python
# calculate mean and variance of the sequence lengths in a large fasta file
# method taken from:
# http://math.stackexchange.com/questions/20593/calculate-variance-from-a-stream-of-sample-values
# m_k = m_(k-1) + x_k + m_(k-1)
# v_k = v_(k-1) + (x_k -m_(k-1))(x_k - m_k)
@spikegrobstein
spikegrobstein / mcwrapper.conf
Created August 27, 2013 12:10
Getting mcwrapper working with Docker (docker.io)
# Example configuration for mcwrapper: mcwrapper.conf
# this file can live in any of the following places (in order of priority):
# - the value of MCWRAPPER_CONFIG_PATH env variable
# - the current working directory as "mcwrapper.conf"
# - ~/.mcwrapper.conf
# - /etc/mcwrapper.conf
#
# Configuration is actual Bash. You can use conditionals... not that you would.
. "/root/minecraft/minecraft-docker"
@minrk
minrk / nbstripout
Last active June 6, 2023 06:23
git pre-commit hook for stripping output from IPython notebooks
#!/usr/bin/env python
"""strip outputs from an IPython Notebook
Opens a notebook, strips its output, and writes the outputless version to the original file.
Useful mainly as a git filter or pre-commit hook for users who don't want to track output in VCS.
This does mostly the same thing as the `Clear All Output` command in the notebook UI.
LICENSE: Public Domain
@komasaru
komasaru / rndnum_box_muller.rb
Created February 21, 2013 08:45
Ruby script to calc normal random numbers by box-muller method.
#*********************************************
# ボックス=ミューラー法法による正規乱数生成
#*********************************************
class RndnumBoxMuller
# 各種定数
M = 10 # 平均
S = 2.5 # 標準偏差
N = 10000 # 発生させる乱数の個数
PI = 3.1415926535 # 円周率
SCALE = N / 100.0 # ヒストグラム用スケール
@wasade
wasade / cluster_jobs.py
Created February 19, 2013 20:56
Updated cluster_jobs.py for use on some Torque based clusters
#!/bin/env python
#cluster_jobs.py
"""
Simple helper script to make pbs jobs and submit to the cluster
Will only work if run on bmf or hemisphere
Can run from command line or import into python code.
Author: Micah Hamady
@obeleh
obeleh / gist:4451005
Last active March 10, 2021 09:47
Python autovivicating tree with parent reference (variation of the one-line tree)

I was reading the gist @https://gist.github.com/2012250

I found the autovivification functionality of it pretty cool. If only I could have a parent reference...

Obviously this was not going to be a one-line tree. But that wasn't the goal

A simple variant:

from collections import defaultdict
@amueller
amueller / digits_video.py
Created October 5, 2012 19:13
Visualization of iris and digits datasets via random projections
# (c) 2012 Andreas Mueller amueller@ais.uni-bonn.de
# License: BSD 2-Clause
#
# See my blog for details: http://peekaboo-vision.blogspot.com
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation