Skip to content

Instantly share code, notes, and snippets.

import Graphics.Element exposing (..)
import Window
import Text
import Signal
main = Signal.map view Window.dimensions
view (w, h) =
(w, h)
|> toString
@dela3499
dela3499 / MobilePubmedExplorer.elm
Created September 1, 2015 04:15
Mobile version of Pubmed Explorer
import Signal
import Graphics.Element exposing (..)
import Color exposing (..)
import Mouse
import Window
import Text
type alias Model =
{ titles: List String
, accepted: List Int
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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