Due: Wednesday 4/9 10:00am

Submission name: w14_drawDNA

Background Genetics Information

DNA is made up of strands of nucleotides, of which there are 4 types: adenine, thymine, cytosine and guanine. Because of this, DNA sequences can be represented as strings like this:

tcgcagctcgaaccactatg

When two strands of DNA match, then adenine is paired with thymine, and cytosine is paired with guanine. So the following two DNA strands match:

 tcgcagctcgaaccactatg
 agcgtcgagcttggtgatac

Task at Hand

Using the information above, write the following processing functions:

  • void drawBase(char base, int x, int y, int sz)
    • Draws a single base in a square at (x, y) with side length sz.
    • The squares should have no stroke, and each type of nucleotide should be given a distinct color.
    • The letter for the nucleotide should be displayed within the square in a color that is easy to see.
    • You may reuse code form yesterday’s assignment it you’d like.
  • void drawStrand(String dna, int x, int y, int sz)
    • Draws the entire dna strand starting at (x, y) using sz for the size of each square.
    • This method should call drawBase().

    a06_drawStrand

  • boolean basePairMatch(char b0, char b1)
    • Returns true if b0 and b1 are a correct base pair match (i.e a and t or c and g).
    • Returns false otherwise
  • boolean strandMatch(String strand0, String strand1)
    • Returns true if strand0 and strand1 match as described above.
    • This does not mean the strings are equal, but that the appropriate nucleotides are matched.
  • void strandCompare(String strand0, String strand1, int x, int y, int sz)
    • Draws strand0 directly above strand1.
    • If there is a nucleotide mismatch, draw a yellow border around the nucleotide.

    a06_strandCompare

  • The following global variables and setup() will test the above functions:
String s0 = "tcgcagctcgaaccactatg";
String s1 = "agcgtcgagcttggtgatac";
String s2 = "atcgtccagctatgtgatac";
String s3 = "caatcacctgagtatcgcga";

int NUC_SIZE = 30;

void setup() {
  size(800, 200);
  background(0);
  textAlign(CENTER, CENTER);

  strandCompare(s0, s1, 0, 0, NUC_SIZE);

  strandCompare(s0, s2, 0, NUC_SIZE*3, NUC_SIZE);

  //strandMatch tests
  println(strandMatch(s0, s1)); //correct match
  println(strandMatch(s0, s0)); //strand should not match itself
  println(strandMatch(s0, s2)); //mismatch
}//setup