Skip to content

Instantly share code, notes, and snippets.

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 / 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)
@dela3499
dela3499 / ks.py
Last active January 7, 2016 03:13
Refactoring the Kolmogorov-Smirnov Test implementation in Scipy
# Wikipedia: https://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Smirnov_test#Two-sample_Kolmogorov.E2.80.93Smirnov_test
# Scipy source: https://github.com/scipy/scipy/blob/v0.15.1/scipy/stats/stats.py#L3966
def ks_2samp(data1, data2):
data1, data2 = map(asarray, (data1, data2))
n1 = data1.shape[0] # n1 and n2 reassigned below, and can be removed here.
n2 = data2.shape[0] # maybe this is used for error message, in case inputs aren't lists. But len provides a good error message.
n1 = len(data1) # Avoid repetition with list comprehension or map
n2 = len(data2)
data1 = np.sort(data1) # Avoid repetition with list comprehension or map
@dela3499
dela3499 / abstract-similarity.py
Last active November 19, 2015 01:46
PubMed abstract similarity
from sklearn.feature_extraction.text import TfidfVectorizer
import pandas as pd
# String -> [String]
def parse_abstracts(filename):
""" Given a text file containing PubMed abstracts,
return these abstracts as a list of strings. """
f = open(filename).read()
lines = f.split("\n")
docs = [[]]
@dela3499
dela3499 / normalize.R
Last active November 12, 2015 23:22
Using Frozen RMA to normalize microarray CEL files for GPL570
# source("http://bioconductor.org/biocLite.R")
library("affy")
library("frma")
library("hgu133plus2frmavecs")
library("parallel")
# String -> String
change.file.extension <- function(filename, extension){
# Strip file extensions from filename,
# and replace with given extension
@dela3499
dela3499 / cosine_distance_background.py
Created November 6, 2015 00:31
Cosine distance between two random vectors is normally distributed around 0.75
import numpy as np
mag = np.linalg.norm
r = np.random.random
def cosdist(x,y):
return sum(x * y) / (mag(x) * mag(y))
def repeat(f,n):
return [f() for _ in range(n)]
@dela3499
dela3499 / heatmap.py
Last active October 7, 2015 20:56
Dendrograms and heatmaps
import pandas as pd
from pandas import DataFrame as DF
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from IPython.display import display
import IPython.html.widgets as widgets
from scipy.cluster.hierarchy import \
linkage,\
leaves_list,\
@dela3499
dela3499 / example.py
Last active September 22, 2015 22:24
Tools for gene expression analysis
# Download or retrieve dataset in SOFT format
soft_filepath = "./GSE11882.soft.gz"
gse = GEOparse.get_GEO(filepath = soft_filepath)
# Parse metadata for individual samples
# [String] -> Dict (individual_id, brain_region, gender, age)
def parse_characteristics(c):
@dela3499
dela3499 / RadialDisplay2.elm
Created September 7, 2015 04:53
Radial Display 2
import Graphics.Element exposing (..)
import Graphics.Collage exposing (..)
import Window
import Signal
import Color exposing (..)
main =
Signal.map (view x) Window.dimensions
@dela3499
dela3499 / RadialDisplay.elm
Created September 7, 2015 04:02
Radial Display
import Graphics.Element exposing (..)
import Graphics.Collage exposing (..)
import Window
import Signal
import Color exposing (..)
main =
Signal.map (view x) Window.dimensions