From 782b624edd671b2c913418b17bd365573d04017a Mon Sep 17 00:00:00 2001 From: dwrz Date: Thu, 7 Feb 2019 03:13:50 +0000 Subject: [PATCH] Add elisp/rna-transcription --- elisp/rna-transcription/README.md | 25 +++++++++++++++ .../rna-transcription-test.el | 32 +++++++++++++++++++ elisp/rna-transcription/rna-transcription.el | 23 +++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 elisp/rna-transcription/README.md create mode 100644 elisp/rna-transcription/rna-transcription-test.el create mode 100644 elisp/rna-transcription/rna-transcription.el diff --git a/elisp/rna-transcription/README.md b/elisp/rna-transcription/README.md new file mode 100644 index 0000000..3f2c612 --- /dev/null +++ b/elisp/rna-transcription/README.md @@ -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. diff --git a/elisp/rna-transcription/rna-transcription-test.el b/elisp/rna-transcription/rna-transcription-test.el new file mode 100644 index 0000000..0bea56e --- /dev/null +++ b/elisp/rna-transcription/rna-transcription-test.el @@ -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 diff --git a/elisp/rna-transcription/rna-transcription.el b/elisp/rna-transcription/rna-transcription.el new file mode 100644 index 0000000..42781da --- /dev/null +++ b/elisp/rna-transcription/rna-transcription.el @@ -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