src/problems/orf.lisp @ 32944636e2d3

TRAN
author Steve Losh <steve@stevelosh.com>
date Mon, 24 Dec 2018 01:25: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~^~%~}" <>))))