public class DNA
extends java.lang.Object
Internally the class represents DNA as a string. You are responsible for implementing the longest common subsequence method and a straightforward constructor.
The DNA class does not need to provide a setter for the sequence, meaning that it can be allowed to not change after the instance is created. As a result, it should not provide an empty constructor.
Constructor | Description |
---|---|
DNA(java.lang.String setSequence) |
Create a new DNA instance from the given sequence of base pairs.
|
Modifier and Type | Method | Description |
---|---|---|
static DNA |
getLongestCommonSubsequence(DNA firstSequence,
DNA secondSequence) |
Return the longest common subsequence of the two provided DNA sequences.
|
java.lang.String |
getSequence() |
Gets the sequence of base pairs for this DNA instance.
|
public DNA(java.lang.String setSequence)
The constructor should validate and normalize its inputs. All characters in the string should be from the set A, T, C, and G (this in DNA, not RNA). You should accept lower-case inputs but convert them to upper-case for the purposes of later comparison.
setSequence
- the sequence of base pairs to initialize the instance withpublic java.lang.String getSequence()
public static DNA getLongestCommonSubsequence(DNA firstSequence, DNA secondSequence)
You should complete a recursive implementation of this algorithm. You may want to use a helper function so that you can recurse on strings, which have helpful methods, rather than the DNA sequence object.
A recursive solution to this problem can get quite slow, particularly as the length of the sequences to compare increases. The testing timeouts provided should be sufficient and will be adjusted as needed. However, feel free to investigate and consider faster approaches.
firstSequence
- the first DNA sequence to comparesecondSequence
- the second DNA sequence to compare