]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/benchmark/reverse-complement/reverse-complement.factor
New extra/tr/ vocab for fast translation of ASCII strings; improves reverse-complemen...
[factor.git] / extra / benchmark / reverse-complement / reverse-complement.factor
index b7c1db043cc89e82035a3b38469ec984de3fc75d..665cbba30d60d9b5f234f7cb25f18aab0fc5ffd5 100755 (executable)
@@ -1,30 +1,20 @@
 USING: io io.files io.streams.duplex kernel sequences
 sequences.private strings vectors words memoize splitting
-grouping hints unicode.case continuations io.encodings.ascii ;
+grouping hints tr continuations io.encodings.ascii
+unicode.case ;
 IN: benchmark.reverse-complement
 
-MEMO: trans-map ( -- str )
-    256 >string
-    "TGCAAKYRMBDHV" "ACGTUMRYKVHDB"
-    [ pick set-nth ] 2each ;
-
-: do-trans-map ( str -- )
-    [ ch>upper trans-map nth ] change-each ;
-
-HINTS: do-trans-map string ;
+TR: trans-map ch>upper "ACGTUMRYKVHDB" "TGCAAKYRMBDHV" ;
 
 : translate-seq ( seq -- str )
-    concat dup reverse-here dup do-trans-map ;
+    concat dup reverse-here dup trans-map-fast ;
 
 : show-seq ( seq -- )
     translate-seq 60 <groups> [ print ] each ;
 
 : do-line ( seq line -- seq )
-    dup first ">;" memq? [
-        over show-seq print dup delete-all
-    ] [
-        over push
-    ] if ;
+    dup first ">;" memq?
+    [ over show-seq print dup delete-all ] [ over push ] if ;
 
 HINTS: do-line vector string ;