Skip to content

Instantly share code, notes, and snippets.

View eclarke's full-sized avatar

Erik Clarke eclarke

View GitHub Profile
@eclarke
eclarke / procspawn.py
Created June 15, 2012 19:03
Spawning processes in Python
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 / filter_obs.py
Created May 2, 2012 21:33
filter obsolete go terms
#!/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 / postparams.java
Created May 1, 2012 21:30
apache http client inanity
postParams.add(new BasicNameValuePair("longestOnly","false"));
postParams.add(new BasicNameValuePair("wholeWordOnly","true"));
postParams.add(new BasicNameValuePair("filterNumber", "true"));
postParams.add(new BasicNameValuePair("stopWords","protein,gene,disease,disorder,cell,syndrome,CAN"));
postParams.add(new BasicNameValuePair("withDefaultStopWords","true"));
postParams.add(new BasicNameValuePair("isTopWordsCaseSensitive","false"));
postParams.add(new BasicNameValuePair("mintermSize","3"));
postParams.add(new BasicNameValuePair("scored", "true"));
postParams.add(new BasicNameValuePair("withSynonyms","true"));
postParams.add(new BasicNameValuePair("ontologiesToExpand", ""));
@eclarke
eclarke / wikilinks.java
Created April 30, 2012 22:01
modifying plain wikilinks in wikitext
@eclarke
eclarke / diversity.R
Created August 18, 2015 19:35
Common diversity metrics
alpha_diversity <- function(df, group.col, freq.col) {
# Returns a variety of diversity indices, including the Gini-Simpson index,
# the inverse Simpson index, and the Shannon-Weaver index. The SW index is
# calculated using the natural logarithm.
#
# Arguments:
# df: a data frame where the rows are species, with a column containing the
# grouping variable and another column containing the proportional
# abundances of each species
# group: the name of the column defining the grouping variable
@eclarke
eclarke / common_otus.fasta
Created April 23, 2015 14:45
common_otus.fasta
>denovo1793
GGAGTCTGGGCCGTGTCTCAGTCCCAGTGTGGCCGATCACCCTCTCAGGTCGGCTATGTATCGTCGCCTTGGTGAGCCGTTACCCCACCAACTAGCTAATACAACGCAGGTCCATCTGGTAGTGATGCAATTGCACCTTTTAATTGACTATCATGCAATAGTCAATATTATGCGGTATTAGCTATCGTTTCCAATAGTTATCCCCCGCTACCAGGCAGGTTACCTACGCGTTACTCACCCGTTCGCAACTCATCCAGAGAAGCAAGCTCCTCCTTCAGCGTTCTACTTGCATGTATTAGGCACGCCGCCAGCGTTCGTC
>denovo2518
GGAGTTTGGGCCGTGTCTCAGTCCCAATGTGGCCGATCACCCTCTCAGGTCGGCTATGCATCACGGCCTTGGTGAGCCGTTACCTCACCAACTAGCTAATGCACCGCGGGTCCATCCATCAGCAGAAGCTTGCGCCTCTTTTCCTCTTCAAACCATGCGGTTCGAAGACCTATGCGGTTTTAGCATCCGTTTCCGAATGTTATCCCCCTCTGATGGGCAGGTTACCCACGTGTTACTCACCCGTTCGCCACTAGATTGACCAGTGCAAGCACCGGTCGCTCTCGTTCGACTTGCATGTATTAGGCACGCCGCCAGCGTTCGTC
>denovo271
GGAGTCTGGGCCGTGTCTCAGTCCCAGTGTGGCCGATCACCCTCTCAGGTCGGCTATGTATCGTCGCCTTGGTGAGCCGTTACCCCACCAACTAGCTAATACAACGCAGGTCCATCTGGTAGTGATGCAATTGCACCTTTTAAGCAAATGTCATGCAACATTTACTGTTATGCGGTATTAGCTATCGTTTCCAATAGTTATCCCCCGNTACCAGGCAGGTTACCTACGCGTTACTCACCCGTTCGCAACTCGTCCAGAAGAGCAAGCTCTCCCTTCAGCGTTCTACTTGCATGTATTAGGCACGCCGCCAGCGTTCGTC
>denovo3052
GGAGTCTGGTCCG
@eclarke
eclarke / named.py
Created February 12, 2015 19:28
Easy dot notation with a dictionary using a context manager
# -*- coding: utf-8 -*-
"""
Uses a context manager to provide a dictionary as a 'namespace' of sorts,
allowing you to use dot notation to work with the dictionary. Example:
d = {'a': 5, 'b': 10}
with named(d) as n:
# prints 5
print n.a
# reassignment changes both n and d
@eclarke
eclarke / rendered-notebook.md
Created October 22, 2014 00:32
Rendered example notebook.org

<2014-09-25 Thu>

Reading this (Wang et al. 2010), in particular Supp. report 4. Has to do with bootstrapping population estimates using the different enzymes used to find integration sites.

<2014-09-26 Fri>

Notes on (Wang et al. 2010) :popest:petersen:intsites:

@eclarke
eclarke / notebook.org
Created October 22, 2014 00:24
Example notebook.org file

Erik’s Lab Notebook

<2014-09-25 Thu>

Reading this [@Wang:2010fh], in particular Supp. report 4. Has to do with bootstrapping population estimates using the different enzymes used to find

@eclarke
eclarke / papers2bibtex.scpt
Last active August 29, 2015 14:07
Applescript to export Papers library as bibtex file
tell application "Papers"
set outFile to "path_to_notebook_folder/library.bib"
export ((every publication item) as list) to outFile
end tell