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

isaac1024's solution

to RNA Transcription in the PHP Track

Published at Feb 27 2021 · 0 comments
Test suite

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 the tests

  1. Go to the root of your PHP exercise directory, which is <EXERCISM_WORKSPACE>/php. To find the Exercism workspace run

     % exercism debug | grep Workspace
  2. Get PHPUnit if you don't have it already.

     % wget --no-check-certificate https://phar.phpunit.de/phpunit.phar
     % chmod +x phpunit.phar
  3. Execute the tests:

     % ./phpunit.phar rna-transcription/rna-transcription_test.php


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.



class ComplementTest extends PHPUnit\Framework\TestCase
    public static function setUpBeforeClass() : void
        require_once 'rna-transcription.php';

    public function testTranscribesGuanineToCytosine() : void
        $this->assertSame('G', toRna('C'));

    public function testTranscribesCytosineToGuanine() : void
        $this->assertSame('C', toRna('G'));

    public function testTranscribesThymineToAdenine() : void
        $this->assertSame('A', toRna('T'));

    public function testTranscribesAdenineToUracil() : void
        $this->assertSame('U', toRna('A'));

    public function testTranscribesAllOccurencesOne() : void
        $this->assertSame('UGCACCAGAAUU', toRna('ACGTGGTCTTAA'));

function toRna(string $rna): string
    return strtoupper(preg_replace(['/C/', '/G/', '/T/', '/A/'], ['g', 'c', 'a', 'u'], $rna));

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?