This file contains 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
(defn parse-flags | |
"Parse a list of flags. Each flag name must be a keyword, and the | |
value must not be a keyword. If the value is omitted, true is | |
assumed. Returns a map. | |
e.g. (parse-flags [:i :j 1 :k \"two\"]) | |
=> {:i true, :j 1, :k \"two\"}" | |
[flags] | |
(loop [flags (seq flags) accum {}] | |
(if flags |
This file contains 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
(ns clj-playground.enzyme-selection | |
(:require [clojure.data.csv :as csv] | |
[clojure.java.io :as io])) | |
(defn read-enzyme-data | |
"Read clone/analysis/enzyme data from CSV file filename. Group | |
enzymes for each clone/analysis pair into a set and return a list of | |
sets of enzymes" | |
[filename] | |
(with-open [in-file (io/reader filename)] |
This file contains 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
(defn factorial [n] (reduce * (range 1 (inc n)))) | |
(defn multinomial [n & ms] | |
(/ (factorial n) (reduce * (map factorial ms)))) | |
(def N (reduce + (for [m1 (range 1 6) | |
m2 (range 1 (- 7 m1)) | |
m3 (range 1 (- 8 m1 m2)) | |
m4 (range 1 (- 9 m1 m2 m3)) | |
m5 (range 1 (- 10 m1 m2 m3 m4)) |
This file contains 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
#!/usr/bin/env perl | |
use strict; | |
use warnings FATAL => 'all'; | |
my %seen; | |
my @uniq; | |
while ( <> ) { | |
chomp; |
This file contains 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
#!/usr/bin/env perl | |
use strict; | |
use warnings FATAL => 'all'; | |
use List::Util qw(max min); | |
my @COLS = qw( label _ chr strand start end ); | |
my @KEY_COLS = qw( label chr strand ); |
This file contains 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
(fn solve-maze | |
[maze] | |
(let [num-rows (count maze) | |
num-cols (count (first maze)) | |
char-at-pos (fn [[row col]] (get (get maze row) col)) | |
free? (fn [p] (when-let [c (char-at-pos p)] (not= c \#))) | |
neighbours (fn [[row col]] (filter free? (map (fn [[delta-row delta-col]] | |
[(+ row delta-row) | |
(+ col delta-col)]) | |
[[0 0] [0 1] [0 -1] [1 0] [-1 0]]))) |
This file contains 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
(ns parsatron-play.core | |
(:refer-clojure :exclude [char]) | |
(:require [the.parsatron :refer :all])) | |
;; Goal is to parse something like: | |
;; ##INFO=<ID=foo,Type=Integer,Number=1,Description="Some description, which may contain commas"> | |
(defparser not-char [& cs] | |
(token (complement (set cs)))) |
This file contains 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
(defn filter-file [filename] | |
(with-open [rdr (io/reader filename)] | |
(reduce (fn [words line] | |
(into words (filter #(<= 4 (count %) 9) (str/split line #"\s+")))) | |
#{} | |
(line-seq rdr)))) |
This file contains 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
(defn expand-partition | |
"Given a partition of size n and an element, generate n new | |
partitions by adding `element` to each subset in turn." | |
[partition element] | |
(let [partition (vec partition)] | |
(for [i (range (count partition))] | |
(set (update-in partition [i] #(conj % element)))))) | |
(defn partitions | |
"Return all partitions of the set `X` into `n` non-empty subsets. |
This file contains 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
(require '[clojure.java.io :as io]) | |
(require '[oauth.twitter :refer [oauth-client]]) | |
(defn read-properties | |
"Parse a properties file, convert the property keys to Clojure | |
keywords and return as a Clojure map." | |
[resource-name] | |
(when-let [resource (io/resource resource-name)] | |
(let [properties (java.util.Properties.)] | |
(with-open [stream (io/input-stream resource)] |