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
;; This is a suggested improvement for processing SNP data, in response | |
;; to Jan Aerts' blog post <http://saaientist.blogspot.com/2010/06/encounter-with-incanter-about-clojure.html>. | |
;; Note that this example is for Clojure 1.1.0; if you're using Clojure 1.2, change the ns definition | |
;; to use clojure.contrib.io instead of duck-streams. | |
(ns ray1729.clojure.bio.snps | |
(:use [clojure.contrib.duck-streams :only (read-lines)])) | |
(defn parse-line | |
[s] |
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 ( $key, @values ) = next_record(); | |
while ( defined $key ) { | |
my ( $next_key, @next_values ) = next_record(); | |
if ( defined $next_key and $next_key eq $key ) { |
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 secret-santa | |
[names] | |
(let [s (shuffle names)] | |
(partition 2 1 (cons (last s) s)))) |
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 keep-only | |
[n bucket-fn s] | |
(letfn [(my-filter | |
[s seen] | |
(when (seq s) | |
(let [e (first s) | |
b (bucket-fn e) | |
c (inc (get seen b 0))] | |
(if (> c n) | |
(recur (rest s) seen) |
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
;; Perl: $RE{num}{-base => 2}{real}{-group => 3}{-sep => ','} | |
(re-seq (re :real {:base 2 :group 3 :sep \,} ) "1.345") |
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 ); |
OlderNewer