1 USING: kernel locals io io.files splitting strings io.encodings.ascii
2 hashtables sequences assocs math namespaces prettyprint
3 math.parser combinators arrays sorting unicode.case ;
5 IN: benchmark.knucleotide
7 : float>string ( float places -- string )
8 swap >float number>string
12 [ head ] if "." glue ;
14 : discard-lines ( -- )
16 [ ">THREE" head? [ discard-lines ] unless ] when* ;
18 : read-input ( -- input )
21 CHAR: \n swap remove >upper ;
23 : tally ( x exemplar -- b )
24 clone [ [ inc-at ] curry each ] keep ;
26 : small-groups ( x n -- b )
28 [ length swap - 1 + ] 2keep
29 [ [ over + ] dip subseq ] 2curry map ;
31 : handle-table ( inputs n -- )
38 second 100 * over / 3 float>string print
42 :: handle-n ( inputs x -- )
43 inputs x length small-groups :> groups
44 groups H{ } tally :> b
46 number>string 8 CHAR: \s pad-tail write ;
48 : process-input ( input -- )
51 { "GGT" "GGTA" "GGTATT" "GGTATTTTAATT" "GGTATTTTAATTTATAGT" }
52 [ [ dupd handle-n ] keep print ] each
56 "resource:extra/benchmark/knucleotide/knucleotide-input.txt"
57 ascii [ read-input ] with-file-reader