Avatar of filaretov

filaretov's solution

to RNA Transcription in the Scheme Track

Published at Aug 07 2019 · 0 comments
Test suite


This exercise has changed since this solution 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


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.


;; 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"
          (to-rna "C"))

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

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

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

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

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

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

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

(define (transcribe c)
  (case c
    ((#\G) #\C)
    ((#\C) #\G)
    ((#\T) #\A)
    ((#\A) #\U)))

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?