Sha256: 8582239144849eb56cbc62b55b734e42099b460eda771ac904de6d153ea54abe

Contents?: true

Size: 762 Bytes

Versions: 20

Compression:

Stored size: 762 Bytes

Contents

module rna_transcription;

import std.exception;
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) {
    enforce(dna.matchFirst(dnaRegex), "Invalid DNA string");
    return dna.translate(rnaTransTable);
}

unittest {
    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

20 entries across 20 versions & 1 rubygems

Version Path
trackler-2.1.0.48 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.47 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.46 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.45 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.44 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.43 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.42 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.41 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.40 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.39 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.38 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.37 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.36 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.34 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.33 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.32 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.31 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.30 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.29 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d
trackler-2.1.0.28 tracks/dlang/exercises/rna-transcription/example/rna_transcription.d