Skip to content

Instantly share code, notes, and snippets.

@nhoffman
nhoffman / script.R
Created April 24, 2014 19:11
An R script template
#!/usr/bin/env Rscript
suppressPackageStartupMessages(library(lattice, quietly = TRUE))
suppressPackageStartupMessages(library(latticeExtra, quietly = TRUE))
suppressPackageStartupMessages(library(argparse, quietly = TRUE))
main <- function(arguments){
parser <- ArgumentParser()
parser$add_argument('infile')
@nhoffman
nhoffman / build_wheels.py
Last active August 29, 2015 13:59
Create python wheels
#!/bin/bash
set -e
REQFILE="${1-requirements.txt}"
WHEELSTREET="${2-wheelstreet}" # base dir for wheel dirs
if [[ ! -f "$REQFILE" ]]; then
echo "Cannot find requirements file named $REQFILE"
echo "Usage: $(basename $0) [requirements.txt] [wheelstreet]"
@nhoffman
nhoffman / test_cast.py
Last active August 29, 2015 13:57
Relative speed of various methods of coercion from int to real in sqlite3
#!/usr/bin/env python
import sqlite3
from random import choice
from timeit import timeit
from itertools import chain
con = sqlite3.connect('test_cast.db', isolation_level=None) # autocommit
cur = con.cursor()
@nhoffman
nhoffman / bedfilter.py
Last active December 31, 2015 21:09
Filter a file of genomic positions given positions specified in a bed file
#!/bin/env/python
"""Filter a file of genomic positions given ranges of start positions
specified in a bed file - totally untested.
"""
from collections import defaultdict
from operator import itemgetter
import csv
@nhoffman
nhoffman / ssh-refresh.bash
Created November 27, 2013 00:36
ssh-refresh
function get_ssh_sock(){
sock=$(find /tmp/ssh-* -user $USER -name "agent.*" 2> /dev/null | head -1)
if [[ -z $sock ]]; then
eval $(ssh-agent -s)
fi
find /tmp/ssh-* -user $USER -name "agent.*" 2> /dev/null | head -1
}
function ssh-refresh() {
echo shell: SSH_AUTH_SOCK=$SSH_AUTH_SOCK
@nhoffman
nhoffman / gref.py
Created October 31, 2013 16:46
Retrieve and format pubmed citations
#!/usr/bin/env python
# see http://eutils.ncbi.nlm.nih.gov/entrez/query/static/efetchlit_help.html
import sys
import urllib
import os
import xml.dom.minidom
import re
import urllib2
@nhoffman
nhoffman / script.R
Last active January 21, 2016 23:18
R language script template
#!/usr/bin/env Rscript
if(Sys.getenv("VIRTUAL_ENV") == ""){ stop("An active virtualenv is required") }
source(file.path(Sys.getenv('VIRTUAL_ENV'), 'bin', 'rvenv'))
suppressPackageStartupMessages(library(argparse, quietly = TRUE))
suppressPackageStartupMessages(library(lattice, quietly = TRUE))
suppressPackageStartupMessages(library(latticeExtra, quietly = TRUE))
main <- function(arguments){
@nhoffman
nhoffman / tab.csv
Last active December 21, 2015 14:59
Data for a question to the R mailing list
label method assignment reads freq
38894_39171 a category-01 8944 0.0951337552518215
38894_39171 a category-17 44990 0.478540658405574
38894_39171 a category-28 19142 0.203605807583896
38894_39171 a category-41 11527 0.122608094453013
38894_39171 a category-45 3501 0.0372387384991757
38894_39171 a category-49 5911 0.0628729458065202
40454_40882 a category-01 88304 0.414288797350173
40454_40882 a category-04 17235 0.0808600677469903
40454_40882 a category-28 12581 0.0590252690643972
@nhoffman
nhoffman / unclassified.py
Created November 16, 2012 20:54
More patterns for matching unclassified sequences
#!/usr/bin/env python
import re
import sys
rexp = re.compile(r'|'.join([
r'\bactinomycete\b',
r'\bcrenarchaeote\b',
r'\bculture\b',
r'\bchimeric\b',
@nhoffman
nhoffman / parallel.sh
Created July 24, 2012 19:11
Demonstrate parallel processes using xargs
#!/bin/bash
# try me out:
# two processors
# $ echo {1..9} | xargs -n1 -P2 ./ps.sh
# four processors
# $ echo {1..9} | xargs -n1 -P4 ./ps.sh
# sleeptime set to a random integer between 2 and 5
sleeptime=$(shuf -i 2-5 -n 1)