Skip to content

Instantly share code, notes, and snippets.

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

Christopher Bare cbare

👹
¯\_(ツ)_/¯
View GitHub Profile
@cbare
cbare / testRoundTrip.R
Created October 6, 2012 00:13
Test some corner-cases in JSON serialization of R objects
library(RJSONIO)
# locations will be an array of objects in JSON
# expected serialization: {"locations": [ {"path":"https://s3.amazonaws.com/foo/bar/", "type":"awss3"} ]}
e1 <- list(locations=list(list(path="https://s3.amazonaws.com/foo/bar/",type="awss3")))
e2 <- fromJSON(toJSON(e1))
if(!(names(e2) == 'locations'))
stop("Roundtrip R->JSON->R failed names")
@cbare
cbare / predictive_modeling_ccle.Rmd
Created October 11, 2012 12:08
Predictive modeling demo Knitr-ized
Predictive Modeling: Drug Response in Cancer Cell Lines
=======================================================
This is a demo of **Knitr**, an R package for authoring executable documents, documents that mix formatted text, source code and graphical output. I've used In Sock's demos of drug response in [CCLE][1] data, but I've probably gotten most of the analysis mixed up. Apologies to In Sock.
Analysis of cancer cell lines for drug sensitity using:
* [Cancer Cell Line Encyclopedia][1]
* [Gene Set Enrichment Analysis][2]
Workflow
@cbare
cbare / overlap.R
Created October 24, 2012 19:35
Compute the intersection of all combinations of a list of vectors
## Compute the intersection of all combinations of the
## elements in the list of vectors l. Might be useful
## for generating Venn/Euler diagrams.
## There might be better ways to do this!
overlap <- function(l) {
results <- list()
# combinations of m elements of list l
for (m in seq(along=l)) {
@cbare
cbare / test.R
Created November 14, 2012 01:10
mvnorn test
library(MASS)
CreateSigma <- function(rho, p) {
aux1 <- matrix(rep(1:p, p), p, p)
aux2 <- matrix(rep(1:p, each = p), p, p)
rho^abs(aux1 - aux2)
}
rho <- 0.5
p <- 3
@cbare
cbare / create_matrix_entity.R
Created November 19, 2012 16:09
Synapse Test
library(MASS)
library(synapseClient)
## create a matrix with defined correlation structure
cm <- matrix(c(1.0,0.5,0.25,0.125, 0.5,1,0.5,0.25, 0.25,0.5,1,0.5, 0.125,0.25,0.5,1), nrow=4, ncol=4)
m <- mvrnorm( 100, rep(0.0, 4), cm)
cor(m)
d <- Data(parentId=1493172, name='matrix100x4')
d <- storeEntity(d)
@cbare
cbare / checkpoint.py
Last active April 21, 2020 14:13
create a new directory and put a checkpoint in it
#!/usr/bin/python
# crontab -e
# */20 * * * * /home/ubuntu/checkpoint.py > /home/ubuntu/checkpoint.log 2>&1
import os
hosts = []
with open('/usr/local/Rmpi/hostfile.plain') as f:
for line in f:
@cbare
cbare / combine_logs.R
Created December 1, 2012 07:07
Combine RSSD output from multiple nodes into a data.frame
system('cp ../rssd.10x.node* .')
dfs <- lapply( list.files('.','rssd.10x.*'), function(fn) { read.delim(fn, sep="\t", header=T) } )
df <- do.call(rbind, dfs)
dim(df)
all(is.na(df$error))
@cbare
cbare / find_workers.rb
Created December 2, 2012 08:53
Find EC2 worker instances
#!/usr/bin/env ruby
require 'rubygems'
require 'fileutils'
require 'right_aws'
require 'optparse'
require 'pp'
@cbare
cbare / parallel_cluster_ssh.json
Created December 5, 2012 19:21
Bioconductor CloudFormation template
{
"AWSTemplateFormatVersion":"2010-09-09",
"Description":"Start up a parallel Bioconductor cluster with ssh access. **WARNING** This template creates Amazon EC2 instances. You will be billed for the AWS resources used if you create a stack from this template.",
"Parameters":{
"BiocVersion" : {
"Description" : "Bioconductor Version. 2.11 is recommended.",
"Type" : "String",
"Default": "2.11",
"AllowedValues": ["2.11"],
"ConstraintDescription": "Must be 2.11"
## Demonstrate following redirects with POST using urllib2.
##
## Note: This is an experiment and may not be the best way
## to go about doing this. For example, why not just
## change the endpoints and issue a new request? Do
## we really want to be redirected on every request?
############################################################
import urllib2
import json