Avatar of 4d47
0
0
Genius
0
0

4d47's solution

to RNA Transcription in the Perl 6 Track

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

Resources

Remember to check out the Perl 6 documentation and resources pages for information, tips, and examples if you get stuck.

Running the tests

There is a test suite and module included with the exercise. The test suite (a file with the extension .t) will attempt to run routines from the module (a file with the extension .pm6). Add/modify routines in the module so that the tests will pass! You can view the test data by executing the command perl6 --doc *.t (* being the name of the test suite), and run the test suite for the exercise by executing the command prove . --exec=perl6 in the exercise directory. You can also add the -v flag e.g. prove . --exec=perl6 -v to display all tests, including any optional tests marked as 'TODO'.

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

#!/usr/bin/env perl6
use v6;
use Test;
use JSON::Fast;
use lib $?FILE.IO.dirname;
use RNA;
plan 5;

my Version:D $version = v3;

if RNA.^ver !~~ $version {
  warn "\nExercise version mismatch. Further tests may fail!"
    ~ "\nRNA is {RNA.^ver.gist}. "
    ~ "Test is {$version.gist}.\n";
}

my $c-data = from-json $=pod.pop.contents;
is .<input><dna>.&to-rna, |.<expected description> for $c-data<cases>.values;

=head2 Canonical Data
=begin code
{
  "exercise": "rna-transcription",
  "version": "1.2.0",
  "cases": [
    {
      "description": "RNA complement of cytosine is guanine",
      "property": "toRna",
      "input": {
        "dna": "C"
      },
      "expected": "G"
    },
    {
      "description": "RNA complement of guanine is cytosine",
      "property": "toRna",
      "input": {
        "dna": "G"
      },
      "expected": "C"
    },
    {
      "description": "RNA complement of thymine is adenine",
      "property": "toRna",
      "input": {
        "dna": "T"
      },
      "expected": "A"
    },
    {
      "description": "RNA complement of adenine is uracil",
      "property": "toRna",
      "input": {
        "dna": "A"
      },
      "expected": "U"
    },
    {
      "description": "RNA complement",
      "property": "toRna",
      "input": {
        "dna": "ACGTGGTCTTAA"
      },
      "expected": "UGCACCAGAAUU"
    }
  ]
}
=end code
unit class RNA_Transcription;

subset DNA of Str where / <[ G C T A ]> + /;
subset RNA of Str where / <[ C G A U ]> + /;

method to_rna(DNA $dna --> RNA) {
    $dna.trans: 'GCTA' => 'CGAU'
}

What can you learn from this solution?

A huge amount can be learnt 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 I could read more about to develop my understanding?