This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [[]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,\ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Graphics.Element exposing (..) | |
import Graphics.Collage exposing (..) | |
import Window | |
import Signal | |
import Color exposing (..) | |
main = | |
Signal.map (view x) Window.dimensions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Graphics.Element exposing (..) | |
import Graphics.Collage exposing (..) | |
import Window | |
import Signal | |
import Color exposing (..) | |
main = | |
Signal.map (view x) Window.dimensions |