Add elisp/rna-transcription

This commit is contained in:
dwrz
2019-02-07 03:13:50 +00:00
parent 4566ec687f
commit 782b624edd
3 changed files with 80 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
# Rna Transcription
Given a DNA strand, return its RNA complement (per RNA transcription).
Both DNA and RNA strands are a sequence of nucleotides.
The four nucleotides found in DNA are adenine (**A**), cytosine (**C**),
guanine (**G**) and thymine (**T**).
The four nucleotides found in RNA are adenine (**A**), cytosine (**C**),
guanine (**G**) and uracil (**U**).
Given a DNA strand, its transcribed RNA strand is formed by replacing
each nucleotide with its complement:
* `G` -> `C`
* `C` -> `G`
* `T` -> `A`
* `A` -> `U`
## Source
Rosalind [http://rosalind.info/problems/rna](http://rosalind.info/problems/rna)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
@@ -0,0 +1,32 @@
;;; rna-transcription-test.el --- Tests for RNA Transcription (exercism)
;;; Commentary:
;;; Code:
(require 'cl)
(load-file "rna-transcription.el")
(ert-deftest transcribes-cytosine-to-guanine ()
(should (string= "G" (to-rna "C"))))
(ert-deftest transcribes-guanine-to-cytosine ()
(should (string= "C" (to-rna "G"))))
(ert-deftest transcribes-adenine-to-uracil ()
(should (string= "U" (to-rna "A"))))
(ert-deftest transcribes-thymine-to-adenine ()
(should (string= "A" (to-rna "T"))))
(ert-deftest it-transcribes-all-nucleotides ()
(should (string= "UGCACCAGAAUU"
(to-rna "ACGTGGTCTTAA"))))
(ert-deftest it-validates-dna-strands ()
(should-error (to-rna "XCGFGGTDTTAA")))
(provide 'rna-transcription-test)
;;; rna-transcription-test.el ends here
@@ -0,0 +1,23 @@
;;; rna-transcription.el -- RNA Transcription (exercism)
;;; Commentary:
;;; Code:
(provide 'rna-transcription)
(defun transcribe (nucleotide)
"Return the matching RNA pair for DNA NUCLEOTIDE."
(cond ((char-equal nucleotide ?C) "G")
((char-equal nucleotide ?G) "C")
((char-equal nucleotide ?A) "U")
((char-equal nucleotide ?T) "A")
((error "Unrecognized nucleotide"))))
(defun to-rna (dna)
"Transcribe a string representing DNA nucleotides.
Return a string representing RNA nucleotides."
(cl-loop for nucleotide being the elements of dna
concat (transcribe nucleotide)))
;;; rna-transcription.el ends here