Exercism v3 launches on Sept 1st 2021. Learn more! ๐Ÿš€๐Ÿš€๐Ÿš€
Avatar of erszcz

erszcz's solution

to RNA Transcription in the Erlang Track

Published at Mar 23 2021 · 0 comments
Instructions
Test suite
Solution

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

Running tests

In order to run the tests, issue the following command from the exercise directory:

For running the tests provided, rebar3 is used as it is the official build and dependency management tool for erlang now. Please refer to the tracks installation instructions on how to do that.

In order to run the tests, you can issue the following command from the exercise directory.

$ rebar3 eunit

Questions?

For detailed information about the Erlang track, please refer to the help page on the Exercism site. This covers the basic information on setting up the development environment expected by the exercises.

Source

Hyperphysics http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html

Submitting Incomplete Solutions

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

rna_transcription_tests.erl

%% Generated with 'testgen v0.2.0'
%% Revision 1 of the exercises generator was used
%% https://github.com/exercism/problem-specifications/raw/42dd0cea20498fd544b152c4e2c0a419bb7e266a/exercises/rna-transcription/canonical-data.json
%% This file is automatically generated from the exercises canonical data.

-module(rna_transcription_tests).

-include_lib("erl_exercism/include/exercism.hrl").
-include_lib("eunit/include/eunit.hrl").




'1_empty_rna_sequence_test_'() ->
    {"Empty RNA sequence",
     ?_assertMatch([], rna_transcription:to_rna([]))}.

'2_rna_complement_of_cytosine_is_guanine_test_'() ->
    {"RNA complement of cytosine is guanine",
     ?_assertMatch("G", rna_transcription:to_rna("C"))}.

'3_rna_complement_of_guanine_is_cytosine_test_'() ->
    {"RNA complement of guanine is cytosine",
     ?_assertMatch("C", rna_transcription:to_rna("G"))}.

'4_rna_complement_of_thymine_is_adenine_test_'() ->
    {"RNA complement of thymine is adenine",
     ?_assertMatch("A", rna_transcription:to_rna("T"))}.

'5_rna_complement_of_adenine_is_uracil_test_'() ->
    {"RNA complement of adenine is uracil",
     ?_assertMatch("U", rna_transcription:to_rna("A"))}.

'6_rna_complement_test_'() ->
    {"RNA complement",
     ?_assertMatch("UGCACCAGAAUU",
		   rna_transcription:to_rna("ACGTGGTCTTAA"))}.
-module(rna_transcription).

-export([to_rna/1]).

to_rna([]) -> [];
to_rna([H | T]) -> [dna_to_rna(H) | to_rna(T)].

dna_to_rna($G) -> $C;
dna_to_rna($C) -> $G;
dna_to_rna($T) -> $A;
dna_to_rna($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?