Skip to content

Instantly share code, notes, and snippets.

View aaronsaunders's full-sized avatar

Aaron Marc Saunders aaronsaunders

View GitHub Profile
def grouperchunker(seq, size):
return (seq[pos:pos + size] for pos in xrange(0, len(seq), size))
for group in grouper(animals, 3):
print group
from itertools import
def grouper(n, iterable, fillvalue=None):
# https://github.com/matplotlib/matplotlib/issues/881
# Several of the ColorBrewer maps are "qualitative", meaning
# they are just a group of colors that can be used together
# for categories of data. So I remapped Accent to segments
# instead of continuous:
# Actually, these should be used with ListedColormap, and
# the number of colors should depend on the number of
# categories in the data, with colors removed from the
# list in a certain order?
@aaronsaunders
aaronsaunders / usearch_derep.bash
Created July 23, 2013 07:13
usear dereplication command line
# Dereplication
usearch --sort reads.fa --output reads.sorted.fa
usearch --derep_fullseq --cluster reads.sorted.fa --seedsout unique.fa [--uc results.uc] [--sizeoout] [--minsize n] [--slots n] [--w wordlength]
usearch --derep_fullseq --cluster reads.sorted.fa --seedsout unique.fa --uc results.uc
@aaronsaunders
aaronsaunders / bar_charts_alt.R
Created July 23, 2013 07:15
side by side barcharts
# http://timotheepoisot.fr/2013/02/17/stacked-barcharts/
library(RColorBrewer)
Abund = round(matrix(runif(200,0,1),nc=10),2)
Abund = Abund/max(Abund)
rownames(Abund) = LETTERS[c(1:nrow(Abund))]
colnames(Abund) = letters[c(1:ncol(Abund))]
@aaronsaunders
aaronsaunders / ipy_batch_rename.py
Created July 23, 2013 07:17
Batch renaming files in iPython
# infile is 'rename_mapping.txt' tab-sep: oldname newname
# ext of file to be replace can be specified
with open('rename_mapping.txt', 'r') as fh:
map = { line.strip().split()[0]:line.strip().split()[1] for line in fh.readlines() }
oldnames = !ls *.fastq.gz
for oldname in oldnames:
if oldname in map:
newname = map[oldname]
!mv $oldname $newname
source('prep_data.R')
library(vegan)
library(RColorBrewer)
# select env/process data
meta <- data[ , 1:( which( names(data) == "amplib_id" )) ]
env <- data[ , ( which( names(data) == "primary_sed" )):( which( names(data) == "otu_0" ) - 1) ]
otu <- as.matrix(data[, (which(names(data) == "otu_0" )):ncol(data) ])
summary(env)
### MATPLOTLIBRC FORMAT
# This is a sample matplotlib configuration file - you can find a copy
# of it on your system in
# site-packages/matplotlib/mpl-data/matplotlibrc. If you edit it
# there, please note that it will be overridden in your next install.
# If you want to keep a permanent local copy that will not be
# over-written, place it in HOME/.matplotlib/matplotlibrc (unix/linux
# like systems) and C:\Documents and Settings\yourname\.matplotlib
# (win32 systems).
@aaronsaunders
aaronsaunders / ggplot_help.R
Created August 5, 2013 18:41
ggplot tricks
# ggplot2 implements the idea of a "grammar of graphics". The grammar implemented
# by ggplot2 could be summarized as follows:
#
# plot: coord, scale, facet(?) + layers
# layer: data mapping stat geom position?
#
# A plot is defined by a coordinate system (coord), one or more scales (scale), an
# optional faceting specification (facet), and one or more layers (layer). A layer
# is defined as an R data frame (data), a specification mapping columns of that
# frame into aesthetic properties (mapping), a statistical approach to summarize
1:10
c(1, 2, 3, 4)
seq(1, 10, 1)
seq(from=1, to=10, by=1)
sequence(c(10, 5))
seq(along.with=myData) # makes seq of 1:length(myData))
seq(10, along.with=myData) # makes seq of 10:length(myData))
seq(from=2, length.out=10)
rep(x, times = 1, length.out = NA, each = 1)
$ git init
# Print & Set Some Basic Config Variables (Global)
$ git config --global user.email
$ git config --global user.name
$ git config --global user.email "[email protected]"
$ git config --global user.name "My Name"