src/problems/orf.lisp @ 1b97142d9722

MOTZ
author Steve Losh <steve@stevelosh.com>
date Sat, 30 Apr 2022 21:11:44 -0400
parents 86d92162dc1f
children (none)
(defpackage :rosalind/orf (:use :cl :rosalind :losh :iterate))
(in-package :rosalind/orf)

(defparameter *input*
  ">Rosalind_99
AGCCATGTAGCTAACTCAGGTTACATGGGGATGACCCCGCGACTTGGATTAGAGTCTCTTTTGGAATAAGCCTGAATGATCCGAGTAGCATCTCAG")

(defparameter *output*
  "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) = (u:translate rna :start start))
    (while protein)
    (collect protein)))

(define-problem orf (data stream) *input* *output*
  (let* ((dna (cdr (first (u:read-fasta-into-alist data))))
         (rna1 (u:transcribe dna))
         (rna2 (u:transcribe (u:reverse-complement dna))))
    (_ (append (translate-all rna1)
                 (translate-all rna2))
      (remove-duplicates _ :test #'string=)
      (sort _ #'< :key #'length)
      (format nil "~{~A~^~%~}" _))))