reverse-complement Lisp SBCL #2 program
source code
;;; The Computer Language Benchmarks Game
;;; https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
;;; contributed by Antonio Saade
(declaim (optimize (speed 3) (safety 0) (debug 0))
(inline compl))
(defconstant +lut+
(let ((lut (make-array 256 :element-type 'base-char)))
(loop
for a across "ACGTMRWSYKVHDBNUacgtmrwsykvhdbnu"
for b across "TGCAKYWSRMBDHVNATGCAKYWSRMBDHVNA"
do (setf (aref lut (char-code a)) b))
lut))
(defun compl (a)
(declare (type base-char a))
(aref +lut+ (char-code a)))
(defun write-seq-by-n (s n out)
(declare (type simple-string s)
(type fixnum n))
(loop
with length = (length s)
for start from 0 by n below length
do (write-line s out :start start :end (min length (+ start n)))))
(defun process-fasta (s out)
(declare (type simple-string s))
(do ((start 0 (1+ start))
(end (- (length s) 1) (1- end))
(b #\0))
((< end start))
(setf b (schar s start))
(setf (schar s start) (compl (schar s end)))
(setf (schar s end) (compl b)))
(write-seq-by-n s 60 out))
(defun main ()
(with-open-file (in #p"/dev/stdin" :direction :input)
(with-open-file (out #p"/dev/stdout"
:direction :output
:if-exists :supersede)
(loop
with fasta = (make-string-output-stream :element-type 'base-char)
for line simple-string = (read-line in nil)
while line
do (if (char= (char line 0) #\>)
(progn
(process-fasta (get-output-stream-string fasta) out)
(write-line line out))
(write-string line fasta))
finally (process-fasta (get-output-stream-string fasta) out)))))
notes, command-line, and program output
NOTES:
64-bit Ubuntu quad core
SBCL 2.0.4
Fri, 22 May 2020 00:24:43 GMT
MAKE:
cp: 'revcomp.sbcl-2.sbcl' and './revcomp.sbcl-2.sbcl' are the same file
SBCL built with: /usr/local/bin/sbcl --userinit /dev/null --batch --eval '(load "revcomp.sbcl-2.sbcl_compile")'
### START revcomp.sbcl-2.sbcl_compile
(handler-bind ((sb-ext:defconstant-uneql (lambda (c) (abort c)))) (require :sb-concurrency) (load (compile-file "revcomp.sbcl-2.sbcl" ))) (save-lisp-and-die "sbcl.core" :purify t)
### END revcomp.sbcl-2.sbcl_compile
; compiling file "/home/dunham/8000-benchmarksgame/bench/revcomp/revcomp.sbcl-2.sbcl" (written 20 MAY 2019 10:50:35 AM):
; compiling (DECLAIM (OPTIMIZE # ...) ...)
; compiling (DEFCONSTANT +LUT+ ...)
; compiling (DEFUN COMPL ...)
; compiling (DEFUN WRITE-SEQ-BY-N ...)
; compiling (DEFUN PROCESS-FASTA ...)
; compiling (DEFUN MAIN ...)
; file: /home/dunham/8000-benchmarksgame/bench/revcomp/revcomp.sbcl-2.sbcl
; in: DEFUN MAIN
; (GET-OUTPUT-STREAM-STRING FASTA)
; ==>
; FASTA
;
; note: deleting unreachable code
;
; compilation unit finished
; printed 1 note
; wrote /home/dunham/benchmarksgame_quadcore/revcomp/tmp/revcomp.sbcl-2.fasl
; compilation finished in 0:00:00.834
### START revcomp.sbcl-2.sbcl_run
(main) (quit)
### END revcomp.sbcl-2.sbcl_run
5.44s to complete and log all make actions
COMMAND LINE:
/usr/local/bin/sbcl --dynamic-space-size 3072 --noinform --core sbcl.core --userinit /dev/null --load revcomp.sbcl-2.sbcl_run 0 < revcomp-input100000000.txt
PROGRAM FAILED