Skip to content

Instantly share code, notes, and snippets.

Avatar

Erik Clarke eclarke

  • Janssen Research & Development
  • Philadelphia, PA
View GitHub Profile
@eclarke
eclarke / filter_obs.py
Created May 2, 2012
filter obsolete go terms
View filter_obs.py
#!/usr/bin/env python
import re
import json
import clint
def import_go(gofile='go.json'):
try:
return json.loads(json.load(open(gofile)))
except IOError:
@eclarke
eclarke / procspawn.py
Created Jun 15, 2012
Spawning processes in Python
View procspawn.py
import sqlite3
import multiprocessing
store_results_sql = """ some sql code here """
select_results_sql = """ some other sql code here """
def find_enriched(**kwargs):
# do some heavy computation task here
results = enrichment_analysis(**kwargs)
# sqlite is not ideal for parallel processing, but with a timeout it should be fine
@eclarke
eclarke / indvals.R
Last active Dec 4, 2015
Indicator species (indicator value) functions
View indvals.R
# Indicator value functions -----------------------------------------------
#' Returns the indicator value (Dufrene, 1997) for a given row of species counts
#' along with a vector of class assignments.
#' @param row: vector of counts (usually a row in a counts matrix)
#' @param class: which level in the grouping variable to test
#' @param classes: factor describing the grouping of the counts vector
.indval <- function(row, class, classes) {
idxs <- classes == class
A.ij <- sum(row[idxs]) / sum(row)
View taxonomy_fixer.py
#!/usr/bin/env python
"""Usage: python taxonomy_fixer.py [FILE]
Converts an ITS taxonomy file to eliminate taxa marked as unidentified,
swaps [kpcofg]__unidentified;s__Fungi to k__Fungi, and eliminates species
taxa that are simply s__[genus]_sp.
Writes to stdout.
"""
# Erik Clarke <ecl@mail.med.upenn.edu>
@eclarke
eclarke / Makefile
Created Apr 20, 2016
Builds docs, html site, and pushes to github
View Makefile
docs:
Rscript -e "devtools::document(roclets=c('rd', 'collate', 'namespace', 'vignette'))"
gh-pages:
git checkout gh-pages
git merge master -X theirs -m "merge master"
site:docs gh-pages
Rscript -e "staticdocs::build_site(site_path='.', launch=FALSE)"
git commit -am 'updated docs'
@eclarke
eclarke / indicspecies_tutorial.R
Last active Jul 26, 2016
Using indicspecies with a melted data frame
View indicspecies_tutorial.R
# Using indicspecies with a melted data frame
# Their input is actually not hard to work with. First we need to re-create the count matrix.
# This creates a data frame with the sample ID and study group as the first two columns, then each column after that is an OTU name
# (Replace column names as appropriate)
mat <- melted.df %>% reshape2::dcast(SampleID + StudyGroup ~ otu)
# Next, we actually convert things into inputs
# Hadley's stuff hates rownames, so we have to remake them
rownames(mat) = mat$SampleID
View glmm.R
# This is the testing function that builds the models
testMixedEffects <- function(test.col) {
# We return this default in case of error/no fit
default <- list(null.model=NA, model=NA)
counts <- .mat[, colnames(.mat)==test.col]
if (sum(counts > 0)/length(counts) < sparsity) {
message(sprintf("%s: too sparse, skipping", test.col))
return(default)
}
@eclarke
eclarke / ggheatmaps.R
Created Apr 8, 2014
Some r code relating to heatmaps and OTU counts
View ggheatmaps.R
prop_presence_absence <- function(otu.pa, groups) {
# Creates a proportional presence-absence melted dataframe suitable for use in
# ggplot heatmaps to show varying within-group proportions of species.
#
# Args:
# otu.pa: Matrix of presence-absence data. Columns are samples, rows are
# species.
# groups: Grouping data frame. A column named "SampleID" should be unique
# list of sample identifiers that match the column names of otu.pa.
# The other column, named "group", should correspond to the group
View keybase.md

Keybase proof

I hereby claim:

  • I am eclarke on github.
  • I am erikclarke (https://keybase.io/erikclarke) on keybase.
  • I have a public key ASDtTlFKxCJoOWfwfhHy-MJtbmGKnvzo-zxrJETJmi1kNQo

To claim this, I am signing this object:

@eclarke
eclarke / lab-notebook.el
Created Oct 21, 2014
Minor mode and functions for a lab notebook in emacs
View lab-notebook.el
(defun ensure-in-vc-or-checkin ()
(interactive)
(if (file-exists-p (format "%s" (buffer-file-name)))
(progn (vc-next-action nil) (message "Committed"))
(ding) (message "File not checked in.")))
(defun export-bibtex ()
"Exports Papers library using a custom applescript."
(interactive)
(message "Exporting papers library...")