1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: ascii kernel io io.files splitting strings
4 io.encodings.ascii hashtables sequences assocs math
5 math.statistics namespaces math.parser combinators arrays
6 sorting formatting grouping fry ;
7 IN: benchmark.knucleotide
9 CONSTANT: knucleotide-in "vocab:benchmark/knucleotide/knucleotide-input.txt"
11 : discard-lines ( -- )
13 [ ">THREE" head? [ discard-lines ] unless ] when* ;
15 : read-input ( -- input )
18 CHAR: \n swap remove >upper ;
20 : handle-table ( inputs n -- )
22 [ sorted-histogram reverse ] [ length ] bi
25 [ second 100 * _ /f "%.3f" printf nl ] bi
28 : handle-n ( input x -- )
29 [ nip ] [ length clump histogram ] 2bi at 0 or "%d\t" printf ;
31 : process-input ( input -- )
35 { "GGT" "GGTA" "GGTATT" "GGTATTTTAATT" "GGTATTTTAATTTATAGT" }
36 [ [ handle-n ] keep print ] with each
40 : knucleotide-benchmark ( -- )
42 ascii [ read-input ] with-file-reader
45 MAIN: knucleotide-benchmark