Complementary DNA

Translate a DNA sequence into its complement.

Overview

DNA sequences are generally represented by a string consisting of the characters 'A', 'T', 'G', and 'C', representing the nucleobases adenine, thymine, guanine, and cytosine. Complementarity describes a relationship between two sequences (or one portion of a sequence with another portion of the same sequence), based on an interaction relationship between the nucleobases in each. In very general terms, A and T are complements of each other, as G and C are complements of each other.

Your task is to implement a method that processes a string, replacing each of the 4 nucleobase characters with its complement.

Implementation

Declaration

The edu.cnm.deepdive.DNA class defines the method

public static String complement(String sequence)

For more method declaration declaration details, see the Javadoc documentation.

Specifications

Your task is to complete the implementation of sequence, according to these specifications:

You may assume that sequence will never contain characters other than those listed above.

Tips

Unit tests

The following test cases will be used to verify your implementation.

sequence Expected value returned by DNA.complement(sequence)
"ATATGCGC" "TATACGCG"
"AtaTGcgC" "TATACGCG"
"GCCTTTAAAATTTCCG" "CGGAAATTTTAAAGGC"
"GCctTtaAAaTTtcCG" "CGGAAATTTTAAAGGC"
"ATCGATCG" "TAGCTAGC"
"ATcgAtcG" "TAGCTAGC"
"CCCCGGGTTA" "GGGGCCCAAT"
"CccCGggTta" "GGGGCCCAAT"