Avatar of craigmaloney

craigmaloney's solution

to RNA Transcription in the Scheme Track

Published at Jul 13 2018 · 0 comments
Instructions
Test suite
Solution

Note:

This solution was written on an old version of Exercism. The tests below might not correspond to the solution code, and the exercise may have changed since this code was written.

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

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

rna-transcription-test.scm

;; Load SRFI-64 lightweight testing specification
(use-modules (srfi srfi-64))

;; Suppress log file output. To write logs, comment out the following line:
(module-define! (resolve-module '(srfi srfi-64)) 'test-log-to-file #f)

(add-to-load-path (dirname (current-filename)))
(use-modules (dna))

(test-begin "rna-transcription")

(test-equal "transcribes-cytosine-to-guanine"
          "G"
          (to-rna "C"))

(test-equal "transcribes-guanine-to-cytosine"
          "C"
          (to-rna "G"))

(test-equal "transcribes-adenine-to-uracil"
          "U"
          (to-rna "A"))

(test-equal "transcribes-thymine-to-adenine"
          "A"
          (to-rna "T"))

(test-equal "transcribes-all-nucleotides"
          "UGCACCAGAAUU"
          (to-rna "ACGTGGTCTTAA"))


(test-error "it-validates-dna-strands"
            #t
            (to-rna "XCGFGGTDTTAA"))

(test-end "rna-transcription")
(define-module (dna)
  #:export (to-rna))

(define (dna-to-rna dna)
  (cond
    ((char=? dna #\G) #\C)
    ((char=? dna #\C) #\G)
    ((char=? dna #\T) #\A)
    ((char=? dna #\A) #\U)))

(define (to-rna strand)
  (list->string 
    (map dna-to-rna 
      (string->list strand))))

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?