src/problems/orf.lisp @ b3598dc7ef5c

ORF
author Steve Losh <steve@stevelosh.com>
date Thu, 08 Nov 2018 21:17:47 -0500
parents (none)
children 23151d9021cf
(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))))
    (with-output-to-string (s)
      (-<> (append (translate-all rna1)
                   (translate-all rna2))
        (remove-duplicates <> :test #'string=)
        (sort <> #'< :key #'length)
        (format s "~{~A~^~%~}" <>)))))