Sha256: eac0ef4b653cf63373702d107606101083687c1dea9ff3decbcdbd3bcba3c075

Contents?: true

Size: 819 Bytes

Versions: 193

Compression:

Stored size: 819 Bytes

Contents

module rna_transcription;

import std.regex;
import std.string;

immutable dchar[dchar] rnaTransTable;

static this() {
 rnaTransTable = [
     'C': 'G',
     'G': 'C',
     'T': 'A',
     'A': 'U'];
}

enum dnaRegex = regex(r"^[CGTA]*$");

string dnaComplement(string dna) {
    import std.exception : enforce;

    enforce(dna.matchFirst(dnaRegex), "Invalid DNA string");
    return dna.translate(rnaTransTable);
}

unittest {
    import std.exception : assertThrown;

    assert(dnaComplement("C") == "G");
    assert(dnaComplement("G") == "C");
    assert(dnaComplement("T") == "A");
    assert(dnaComplement("A") == "U");

    assert(dnaComplement("ACGTGGTCTTAA") == "UGCACCAGAAUU");

    assertThrown(dnaComplement("U"));
    assertThrown(dnaComplement("XXX"));
    assertThrown(dnaComplement("ACGTXXXCTTAA"));
}

Version data entries

193 entries across 193 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.179 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.178 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.177 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.176 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.175 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.174 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.173 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.172 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.171 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.170 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.169 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.167 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.166 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.165 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.164 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.163 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.162 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.161 tracks/d/exercises/rna-transcription/example/rna_transcription.d
trackler-2.2.1.160 tracks/d/exercises/rna-transcription/example/rna_transcription.d