Translate a DNA sequence into its complement.
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.
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.
Your task is to complete the implementation of sequence
, according to these specifications:
'A'
or 'a'
in sequence
must be replaced by 'T'
in the returned value.'T'
or 't'
in sequence
must be replaced by 'A'
in the returned value.'C'
or 'c'
in sequence
must be replaced by 'G'
in the returned value.'G'
or 'g'
in sequence
must be replaced by 'C'
in the returned value.You may assume that sequence
will never contain characters other than those listed above.
You may find it useful to create one or more additional static
methods as “helpers”; the problem can be solved without doing so, however.
Do not hesitate to declare any constants (static final
fields) that you feel might simplify or clarify your code.
The method to be completed includes a TODO
comments to that effect.
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" |