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

damiankorz's solution

to RNA Transcription in the CFML Track

Published at Dec 14 2018 · 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

To run the code in this exercise, you will only need to have CommandBox CLI installed. This binary runs CFML code from the command line.

To run the tests, cd into the exercise folder and run the following:

box task run TestRunner
# Or start up a test watcher that will rerun when files change
box task run TestRunner --:watcher

The tests leverage a library called TestBox which supports xUnit and BDD style of testing. All test suites will be written in the BDD style which uses closures to define test specs. You won't need to worry about installing TestBox. The CLI test runner will take care of that for you. You just need to be connected to the internet the first time you run it. You can read more about it here:

https://testbox.ortusbooks.com/content/

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.

RnaTranscriptionTest.cfc

component extends="testbox.system.BaseSpec" {

	function beforeAll(){
	  SUT = createObject( 'RnaTranscription' );
	}

	function run(){
	
		describe( "My RnaTranscription class", function(){			

			it( 'RNA complement of cytosine is guanine', function(){
				expect( SUT.toRna( dna='C' ) ).toBe( 'G' );
			});

			it( 'RNA complement of guanine is cytosine', function(){
				expect( SUT.toRna( dna='G' ) ).toBe( 'C' );
			});

			it( 'RNA complement of thymine is adenine', function(){
				expect( SUT.toRna( dna='T' ) ).toBe( 'A' );
			});

			it( 'RNA complement of adenine is uracil', function(){
				expect( SUT.toRna( dna='A' ) ).toBe( 'U' );
			});

			it( 'RNA complement', function(){
				expect( SUT.toRna( dna='ACGTGGTCTTAA' ) ).toBe( 'UGCACCAGAAUU' );
			});

		});
		
	}
 
}

SolutionTest.cfc

component extends="RnaTranscriptionTest" {

	function beforeAll(){
	  SUT = createObject( 'Solution' );
	}

}
component {
	/**
	* @returns
	*/
	public string function toRNA( required string DNA ) {
		var converterTable = {
			"G" = "C",
			"C" = "G",
			"T" = "A",
			"A" = "U"
		};
		var splitStrand = DNA.split("");
		var RNA = "";
		for(var strand in splitStrand){
			if(structKeyExists(converterTable, strand)){
				strand = converterTable[strand];
				RNA = RNA & strand;
			}
		}
		return RNA;
	}
}

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?