1 USING: kernel 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 )
26 [ [ 1+ ] [ 1 ] if* ] change-at
29 : small-groups ( x n -- b )
31 [ length swap - 1+ ] 2keep
32 [ [ over + ] dip subseq ] 2curry map ;
34 : handle-table ( inputs n -- )
41 second 100 * over / 3 float>string print
45 : handle-n ( inputs x -- )
47 small-groups H{ } tally
49 number>string 8 CHAR: \s pad-tail write ;
51 : process-input ( input -- )
54 { "GGT" "GGTA" "GGTATT" "GGTATTTTAATT" "GGTATTTTAATTTATAGT" }
55 [ [ dupd handle-n ] keep print ] each
59 "resource:extra/benchmark/knucleotide/knucleotide-input.txt"
60 ascii [ read-input ] with-file-reader