Skip to content

Instantly share code, notes, and snippets.

@dela3499
dela3499 / cmap_ks_test.py
Last active January 12, 2016 01:02
CMAP KS-test Implementation
# type PrerankedProfile = Series(Index = Integer, Probe_ID = String, Rank = Integer)
# DataFrame -> List PrerankedProfile
def cmap2sortedseries(df):
return [series.order(ascending = True).reset_index() for series in df2series(df)]
# PrerankedProfile -> List a -> Float
def gsea_preranked(sorted_series, tag_list):
""" Apply KS test.
ex: scores = map(lambda profile: gsea_preranked(profile, up_probes), profiles)
module Penrose where
import List exposing (foldr, map)
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import Color exposing (..)
goldenRatio = (1 + sqrt 5) / 2
type alias Point = (Float, Float)
type Triangle
= Kite (Point, Point, Point)
@dela3499
dela3499 / geo2r.R
Created January 29, 2016 21:56
GEO2R test
# Version info: R 2.14.1, Biobase 2.15.3, GEOquery 2.23.2, limma 3.10.1
# R scripts generated Fri Jan 29 16:56:51 EST 2016
################################################################
# Differential expression analysis with limma
library(Biobase)
library(GEOquery)
library(limma)
# load series and platform data from GEO
@dela3499
dela3499 / convnet.py
Created January 31, 2016 23:58
Rewriting keras example
from keras.models import Sequential
from keras.layers import Convolution2D, ZeroPadding2D, MaxPooling2D
img_width, img_height = 128, 128
# this will contain our generated images
input_img = K.placeholder((1, 3, img_width, img_height))
# build the VGG16 network with our input_img as input
first_layer = ZeroPadding2D((1, 1), input_shape=(3, img_width, img_height))
@dela3499
dela3499 / checker.py
Last active February 2, 2016 21:18
Generate a checkered matrix in Python.
from itertools as it
# Generator a -> Int -> List a
def take(generator, n):
""" Return first n elements of generator as list. """
return list(it.islice(generator, n))
# List a -> Int -> List a
def takecycle(elements, n):
""" Return first n elements of infinite cycle given by elements. """
@dela3499
dela3499 / acronym2word.py
Created February 8, 2016 22:32
Produce candidate pronunciation for an acronym. Take set of letters, perhaps a potential acronym, and try to expand it. Maybe just to have a new word to pronounce. Turn crps to carapace.
import numpy as np
import toolz as tz
np.random.seed(1000)
# String -> String
def generate_word(word):
""" Given a word, return a new word with vowels interspersed between the letters. """
vowels = list('aeiouy_')
letters = list(word)
@dela3499
dela3499 / chunkapply.py
Created February 11, 2016 02:36
Apply function to file in chunks.
import fileinput
import numpy as np
import cPickle as pickle
# (String -> a) -> Filename -> Int -> SideEffect[FileSystem] # List a
def chunkapply(f, filename, chunksize, savefile):
""" For each chunk, apply f to each line, and save the list of results to
file starting with savefilename, and followed by chunk number. """
data = []
def thread_last(val, *forms):
""" Thread value through a sequence of functions/forms
>>> def double(x): return 2*x
>>> def inc(x): return x + 1
>>> thread_last(1, inc, double)
4
If the function expects more than one input you can specify those inputs
in a tuple. The value is used as the last input.
@dela3499
dela3499 / combinations.js
Last active March 1, 2016 12:34
Given a format string, replace appropriate fields with all combinations of input lists.
function hasValue(x) {
return x.toString().length > 0;
}
function hasValues(values) {
for (var i = 0; i < values.length; i += 1) {
if (values[i].toString().length > 0) {
return true;
}
}
@dela3499
dela3499 / forking_paths.py
Last active March 4, 2016 23:57
Generate a tree of paths, and repeatedly travel random paths from root to leaf to generate strings.
import random
def lprint(xs):
for x in xs:
print(x)
def repeat_and_deduplicate(f, args, n):
return list(set([f(*args) for _ in range(n)]))