If I am understanding the problem correctly, this is a super expensive method for doing something pretty simple. Even if it is a bit more code, this won't require memory allocation which in this case wouldn't be cheap (given how big DNA tends to be).

string s = "ACGTACGT";

uint[4] counts;

foreach(char c; s) {
        switch(c) {
                case 'A':
                case 'a':
                        counts[0]++;
                        break;
                case 'C':
                case 'c':
                        counts[1]++;
                        break;
                case 'G':
                case 'g':
                        counts[2]++;
                        break;
                case 'T':
                case 't':
                        counts[3]++;
                        break;
                default:
                        assert(0, "Unknown compound");
        }
}

writeln(counts);

Reply via email to