Skip to content

RNA Transcription

Intro

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

Task

Given a DNA strand, return its RNA complement (per RNA transcription).

The Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "rna_transcription.h"
#include <string>
/*
G -> C
C -> G
T -> A
A -> U
*/

namespace rna_transcription {
std::string to_rna(std::string test) {
for (auto &c : test) {
    c = to_rna(c);
}

return test;
}

char to_rna(char c) {
switch (c) {
case 'G':
    c = 'C';
    break;
case 'C':
    c = 'G';
    break;
case 'T':
    c = 'A';
    break;
case 'A':
    c = 'U';
    break;
}
return c;
}
} // namespace rna_transcription
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#if !defined(RNA_TRANSCRIPTION_H)
#define RNA_TRANSCRIPTION_H
#include "string"

namespace rna_transcription {
std::string to_rna(std::string);
char to_rna(char);
} // namespace rna_transcription

#endif // RNA_TRANSCRIPTION_H

Last update: February 8, 2021

Comments