benchmark.knucleotide: some cleanups

release
Slava Pestov 2010-04-14 02:32:54 -07:00
parent 216a05e68a
commit 5615671560
1 changed files with 19 additions and 38 deletions

View File

@ -1,16 +1,9 @@
USING: kernel locals io io.files splitting strings io.encodings.ascii
hashtables sequences assocs math namespaces prettyprint
math.parser combinators arrays sorting unicode.case ;
USING: ascii kernel io io.files splitting strings
io.encodings.ascii hashtables sequences assocs math
math.statistics namespaces prettyprint math.parser combinators
arrays sorting formatting grouping fry ;
IN: benchmark.knucleotide
: float>string ( float places -- string )
swap >float number>string
"." split1 rot
over length over <
[ CHAR: 0 pad-tail ]
[ head ] if "." glue ;
: discard-lines ( -- )
readln
[ ">THREE" head? [ discard-lines ] unless ] when* ;
@ -20,37 +13,25 @@ IN: benchmark.knucleotide
">" read-until drop
CHAR: \n swap remove >upper ;
: tally ( x exemplar -- b )
clone [ [ inc-at ] curry each ] keep ;
: small-groups ( x n -- b )
swap
[ length swap - 1 + iota ] 2keep
[ [ over + ] dip subseq ] 2curry map ;
: handle-table ( inputs n -- )
small-groups
[ length ] keep
H{ } tally >alist
sort-values reverse
[
dup first write bl
second 100 * over / 3 float>string print
] each
drop ;
clump
[ histogram >alist sort-values reverse ] [ length ] bi
'[
[ first write bl ]
[ second 100 * _ /f "%.3f" printf nl ] bi
] each ;
:: handle-n ( inputs x -- )
inputs x length small-groups :> groups
groups H{ } tally :> b
x b at [ 0 ] unless*
number>string 8 CHAR: \s pad-tail write ;
: handle-n ( input x -- )
[ nip ] [ length clump histogram ] 2bi at 0 or "%d\t" printf ;
: process-input ( input -- )
dup 1 handle-table nl
dup 2 handle-table nl
{ "GGT" "GGTA" "GGTATT" "GGTATTTTAATT" "GGTATTTTAATTTATAGT" }
[ [ dupd handle-n ] keep print ] each
drop ;
[ 1 handle-table nl ]
[ 2 handle-table nl ]
[
{ "GGT" "GGTA" "GGTATT" "GGTATTTTAATT" "GGTATTTTAATTTATAGT" }
[ [ handle-n ] keep print ] with each
]
tri ;
: knucleotide ( -- )
"resource:extra/benchmark/knucleotide/knucleotide-input.txt"