Skip to content

Instantly share code, notes, and snippets.

View cbare's full-sized avatar
👹
¯\_(ツ)_/¯

Christopher Bare cbare

👹
¯\_(ツ)_/¯
View GitHub Profile
@cbare
cbare / counts.py
Created October 6, 2011 23:27
A customized script (aka hack) to parse apache server logs and count stuff
## Parse gaggle apache server logs to compile usage stats
## ...with thanks to: https://github.com/lethain/apache-log-parser
## Track number of accesses by IP address, accesses to Java Web Starts (.jnlp files)
## and subversion access.
import sys
import re
import subprocess
import argparse
@cbare
cbare / extract_features.py
Created April 13, 2012 22:11
Extract features from GFF
############################################################
## A hacky script to extract features from a GFF3 file ##
## and output them in a format compatible with the ##
## Gaggle genome browser. ##
## ##
## J. Christopher Bare, March 2012 ##
## ##
############################################################
# I got the gene annotations in GFF format from here:
@cbare
cbare / extract_expression_data.R
Created April 20, 2012 17:14
Extract gene expression data from a cmonkey output file
# Extract expression data
# =======================
#
# Gene expression data comes from the cmonkey output RData file:
# ~/Documents/work/projects/network_portal/cm_session.RData
#
# ...in a variable: env$ratios$ratios, a 3491 by 739 matrix
conditions <- c('X130.1', 'X127.1', 'X435.8', 'X435.7', 'X435.6', 'X435.1', 'X435.2', 'X435.3', 'X435.4', 'X435.10', 'X435.9', 'X435.5', 'X435.11', 'X449.1', 'X450.1', 'X450.2', 'X450.3', 'X450.4', 'X450.5', 'X1271.1', 'X1271.2', 'X1271.3', 'X1271.4', 'X1271.5', 'X1271.7', 'X1271.9', 'X1271.10', 'X1709.2', 'X1709.3', 'X1709.4', 'X1709.5', 'X1709.6', 'X1709.7', 'X1709.8', 'X1709.9', 'X1709.10', 'X1709.12', 'X1709.13', 'X1709.14', 'X1709.15', 'X1713.1', 'X1713.2', 'X1713.3', 'X1713.4', 'X1713.5', 'X1736.5', 'X1736.10', 'X1736.17', 'X1736.19', 'X1736.21')
@cbare
cbare / create.gene.table.R
Created June 26, 2012 22:22
Extract halo GO annotations from network_portal database, along with synonym translation table
# read in files extracted from the database
hg <- read.table(file='halo.go.txt', header=F, sep="\t", stringsAsFactors=F)
hs <- read.table(file='halo.id.synonyms.txt', header=F, sep="\t", stringsAsFactor=F)
colnames(hs) <- c('name', 'synonym')
colnames(hg) <- c('name', 'go')
# join the two tables and translate gene names to their synonyms
hg2 <- merge(hg,hs,by="name",all.x=TRUE)
# na.omit(hg2)[1:20,]
hg2$name[!is.na(hg2$synonym)] <- hg2$synonym[!is.na(hg2$synonym)]
@cbare
cbare / linear_regression_by_gradient_descent.R
Created July 27, 2012 21:52
Linear regression by gradient descent
##
## Linear regression by gradient descent
##
## A learning exercise to help build intuition about gradient descent.
## J. Christopher Bare, 2012
##
# generate random data in which y is a noisy function of x
x <- runif(1000, -5, 5)
y <- x + rnorm(1000) + 3
@cbare
cbare / core.clj
Created August 20, 2012 21:41
Poker kata
(ns poker-kata.core)
;; Functions to evaluate (5 card) poker hands, based on the code kata
;; at http://codingdojo.org/cgi-bin/wiki.pl?KataPokerHands
;; A card is represented by a vector with a numeric rank and a suit.
;; example cards:
;; 5 of diamonds [5 :diamonds]
;; ace of spades [14 :spades]
@cbare
cbare / talented_people.R
Created September 7, 2012 23:08
Example of R's S4 classes
## S4 classes for talented people
##
## Code to go along with a blog post about
## object oriented programming in R:
##
## http://digitheadslabnotebook.blogspot.com/2012/09/oo-in-r.html
##
################################################################
# define an S4 class for people
@cbare
cbare / poker.R
Created September 9, 2012 06:38
Evaluate poker hands in R
## Poker.R
## Evaluate poker hands
##
## by: Christopher Bare
############################################################
## define suits and ranks
suits <- c('c','d','h','s')
ranks <- c(2:10,"J","K","Q","A")
suit_names <- c(c="clubs", d="diamonds", h="hearts", s="spades")
@cbare
cbare / args.R
Created September 14, 2012 17:49
Handling of missing arguments in R
# How the "missingness" status of arguments can be passed down
# the call stack. (Thanks Martin Morgan!)
bar <- function(q,...) {
cat(q)
foo(...)
}
foo <- function(a=123) {
if (missing(a))
@cbare
cbare / munge-ufo-data.R
Created September 24, 2012 13:09
An exercise in data manipulation from chapter 1 of Machine Learning for Hackers
## Cbare's code from Machine Learning for Hackers
## Chapter 1 - cleaning up data on UFO sightings
##
## for data files and lot's more R code, see:
## https://github.com/johnmyleswhite/ML_for_Hackers
##
############################################################
library(ggplot2)
library(scales)