factor/extra/benchmark/knucleotide/knucleotide.factor

42 lines
1.1 KiB
Factor
Raw Normal View History

2010-04-14 05:32:54 -04:00
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
: discard-lines ( -- )
readln
2007-11-25 00:50:12 -05:00
[ ">THREE" head? [ discard-lines ] unless ] when* ;
: read-input ( -- input )
discard-lines
">" read-until drop
2007-11-25 00:50:12 -05:00
CHAR: \n swap remove >upper ;
: handle-table ( inputs n -- )
<clumps>
2010-04-14 05:32:54 -04:00
[ histogram >alist sort-values reverse ] [ length ] bi
'[
[ first write bl ]
[ second 100 * _ /f "%.3f" printf nl ] bi
] each ;
2010-04-14 05:32:54 -04:00
: handle-n ( input x -- )
[ nip ] [ length <clumps> histogram ] 2bi at 0 or "%d\t" printf ;
: process-input ( input -- )
2010-04-14 05:32:54 -04:00
[ 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"
ascii [ read-input ] with-file-reader
2007-11-25 00:50:12 -05:00
process-input ;
MAIN: knucleotide