TRIE
author |
Steve Losh <steve@stevelosh.com> |
date |
Sat, 18 Jan 2020 14:03:44 -0500 |
parents |
23151d9021cf |
children |
2735aa6aab79 |
(in-package :rosalind)
(defparameter *input-orf*
">Rosalind_99
AGCCATGTAGCTAACTCAGGTTACATGGGGATGACCCCGCGACTTGGATTAGAGTCTCTTTTGGAATAAGCCTGAATGATCCGAGTAGCATCTCAG")
(defparameter *output-orf*
"M
MTPRLGLESLLE
MGMTPRLGLESLLE
MLLGSFRLIPKETLIQVAGSSPCNLS")
(defun translate-all (rna)
"Return all possible proteins that can be translated from `rna`."
(iterate
(for start :first 0 :then (1+ protein-start))
(for (values protein protein-start) = (translate rna :start start))
(while protein)
(collect protein)))
(define-problem orf (data stream)
*input-orf*
*output-orf*
(let* ((dna (cdr (first (read-fasta-into-alist data))))
(rna1 (transcribe dna))
(rna2 (transcribe (reverse-complement dna))))
(-<> (append (translate-all rna1)
(translate-all rna2))
(remove-duplicates <> :test #'string=)
(sort <> #'< :key #'length)
(format nil "~{~A~^~%~}" <>))))