-
Notifications
You must be signed in to change notification settings - Fork 0
SequencePhenotype.java
I wrote a very rough draft of SequencePhenotype.java.
On Monday's meeting, Erick said something about Strings and a Wrapper class. I think he meant generic class, since String is not a primitive type. At first, I tried including a type parameter, S, but it got too complex for an outline. A few String methods are used in the class, and public class SequencePhenotype<S extends String>
seems a little silly.
constants
public final String[] NUCLEOBASES = new String[]{"A", "C", "G", "T"};
- Not entirely sure if these are the letters we should be using
fields
private String sequence;
- No longer a double.
- Always this 1 field (unlike number of traits in
GeometricPhenotype.java
and GeometricPhenotype3D.java).
distance
public double distance(Phenotype p) {
- Only works for sequences of the same length. Should we use something like this to include sequences of different lengths?
- The parameter
Phenotype p
must be an instance of SequencePhenotype since hamming distance is a metric for comparing Strings. It is not enough to be an instance of Phenotype.
mutate
public Phenotype mutate() {
- Naïve implementation of mutate. Currently, all this method does is add one randomly chosen nucleobase to the current sequence. It's possible to mutate a sequence without increasing its length if that's what we want (as well). In other words, we can change the sequence at one index instead of adding.
Here's a trivial static method if you would like to try out the class:
public static void main(String[] args) { System.out.print("SequencePhenotype(): "); SequencePhenotype emptyConstructor = new SequencePhenotype(); System.out.println(emptyConstructor); System.out.println("After mutate(): " + emptyConstructor.mutate()); System.out.println(); System.out.print("SequencePhenotype(\"AGTCTTCCG\"): "); SequencePhenotype constructor = new SequencePhenotype("AGTCTTCCG"); System.out.println(constructor); SequencePhenotype seq1 = (SequencePhenotype) constructor.mutate(); SequencePhenotype seq2 = (SequencePhenotype) constructor.mutate(); System.out.println("(1) AGTCTTCCG after mutate(): " + seq1); System.out.println("(2) AGTCTTCCG after mutate(): " + seq2); System.out.println(); System.out.println("Distance: " + constructor.distance(seq1)); System.out.println("Distance: " + constructor.distance(seq2)); System.out.println("Distance: " + seq1.distance(seq2)); }
Note, your output will be different, since the nucleobases are randomly chosen in the empty constructor and mutate.
SequencePhenotype(): C After mutate(): CA SequencePhenotype("AGTCTTCCG"): AGTCTTCCG (1) AGTCTTCCG after mutate(): AGTCTTCCGA (2) AGTCTTCCG after mutate(): AGTCTTCCGC Distance: 1.0