🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of Jame

Jame's solution

to RNA Transcription in the Vim script Track

Published at Aug 25 2020 · 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

How to run the tests

If you don't know how to run Vader tests, see: Tests.

For general information about the Vim script track, see: Help.

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.vader

"
" Version: 1.0.1
"

Before:
  unlet! input expected

Execute (RNA complement of cytosine is guanine):
  let input = "C"
  let expected = "G"
  AssertEqual expected, ToRna(input)

Execute (RNA complement of guanine is cytosine):
  let input = "G"
  let expected = "C"
  AssertEqual expected, ToRna(input)

Execute (RNA complement of thymine is adenine):
  let input = "T"
  let expected = "A"
  AssertEqual expected, ToRna(input)

Execute (RNA complement of adenine is uracil):
  let input = "A"
  let expected = "U"
  AssertEqual expected, ToRna(input)

Execute (RNA complement):
  let input = "ACGTGGTCTTAA"
  let expected = "UGCACCAGAAUU"
  AssertEqual expected, ToRna(input)

Execute (correctly handles invalid input (RNA instead of DNA)):
  let input = "U"
  let expected = ''
  AssertEqual expected, ToRna(input)

Execute (correctly handles completely invalid DNA input):
  let input = "XXX"
  let expected = ''
  AssertEqual expected, ToRna(input)

Execute (correctly handles partially invalid DNA input):
  let input = "ACGTXXXCTTAA"
  let expected = ''
  AssertEqual expected, ToRna(input)
function! RNAComplementBase(base) abort
  let l:pairsDict = {
      \"G" : "C",
      \"C" : "G",
      \"T" : "A",
      \"A" : "U"
    \}

  return l:pairsDict[a:base]
endfunction
"
function! ToRna(strand) abort
  try
    return join(
              \map(
                \split(a:strand,'\zs'),
                \{ _, base -> RNAComplementBase(base) }),
           \'')
  catch
    return ''
  endtry
endfunction

Community comments

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

Jame's Reflection

accidentally uploaded the vader file as my 'first iteration' of this problem OOPS