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

pilpod's solution

to RNA Transcription in the PHP Track

Published at Mar 20 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'));

namespace App;

class RnaTranscription {

    private $rna;
    private $newrna = '';

    public function toRna(string $char) : string
        $this->rna = [
            'G' => 'C',
            'C' => 'G',
            'T' => 'A',
            'A' => 'U',

        for( $i = 0; $i < strlen($char); $i++) {
            $character = $char[$i];
            $this->newrna .= $this->rna[$character];

        return $this->newrna;

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?