src/problems/tran.lisp @ 0c68769a8788
KMP
author |
Steve Losh <steve@stevelosh.com> |
date |
Thu, 04 Aug 2022 21:48:26 -0400 |
parents |
2735aa6aab79 |
children |
(none) |
(defpackage :rosalind/tran (:use :cl :rosalind :losh :iterate))
(in-package :rosalind/tran)
(defparameter *input* ">Rosalind_0209
GCAACGCACAACGAAAACCCTTAGGGACTGGATTATTTCGTGATCGTTGTAGTTATTGGA
AGTACGGGCATCAACCCAGTT
>Rosalind_2200
TTATCTGACAAAGAAAGCCGTCAACGGCTGGATAATTTCGCGATCGTGCTGGTTACTGGC
GGTACGAGTGTTCCTTTGGGT")
(defparameter *output* "1.21428571429")
(defun rings (base)
"Return the number of rings in the structure of `base`.
Pyrimidines (cytosine, thymine, and uracil) have a single-ring structure.
Purines (adenine and guanine) have a double-ring structure.
"
(ecase base
((#\A #\G) 2)
((#\C #\T #\U) 1)))
(defun transitionp (x y)
(and (char/= x y)
(= (rings x) (rings y))))
(defun transversionp (x y)
(and (char/= x y)
(/= (rings x) (rings y))))
(define-problem tran (data stream) *input* *output*
(destructuring-bind (x y)
(mapcar #'cdr (u:read-fasta-into-alist data))
(format nil "~,11F" (coerce (/ (u:mapcount #'transitionp x y)
(u:mapcount #'transversionp x y))
'double-float))))