]> gitweb.factorcode.org Git - factor.git/blob - extra/benchmark/knucleotide/knucleotide.factor
Merge branch 'master' of git://github.com/erikcharlebois/factor
[factor.git] / extra / benchmark / knucleotide / knucleotide.factor
1 USING: ascii kernel io io.files splitting strings
2 io.encodings.ascii hashtables sequences assocs math
3 math.statistics namespaces prettyprint math.parser combinators
4 arrays sorting formatting grouping fry ;
5 IN: benchmark.knucleotide
6
7 : discard-lines ( -- )
8     readln
9     [ ">THREE" head? [ discard-lines ] unless ] when* ;
10
11 : read-input ( -- input )
12     discard-lines
13     ">" read-until drop
14     CHAR: \n swap remove >upper ;
15
16 : handle-table ( inputs n -- )
17     clump
18     [ histogram >alist sort-values reverse ] [ length ] bi
19     '[
20         [ first write bl ]
21         [ second 100 * _ /f "%.3f" printf nl ] bi
22     ] each ;
23
24 : handle-n ( input x -- )
25     [ nip ] [ length clump histogram ] 2bi at 0 or "%d\t" printf ;
26
27 : process-input ( input -- )
28     [ 1 handle-table nl ]
29     [ 2 handle-table nl ]
30     [
31         { "GGT" "GGTA" "GGTATT" "GGTATTTTAATT" "GGTATTTTAATTTATAGT" }
32         [ [ handle-n ] keep print ] with each
33     ]
34     tri ;
35
36 : knucleotide ( -- )
37     "resource:extra/benchmark/knucleotide/knucleotide-input.txt"
38     ascii [ read-input ] with-file-reader
39     process-input ;
40
41 MAIN: knucleotide