Posted: Wed Oct 21
Due: Thursday 10/22 10:00am
Submission name: w15_strands
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 lengthsz. - The squares should have no stroke, and each type of nucleotide should be given a distinct color. See below for a
baseColorfunction that you can use. - The letter for the nucleotide should be displayed within the square in a color that is easy to see.
- Draws a single base in a square at
void drawStrand(String dna, int x, int y, int sz)- Draws the entire
dnastrand starting at(x, y)usingszfor the size of each square. - This method should call
drawBase.

- Draws the entire
boolean basePairMatch(char b0, char b1)- Returns
trueifb0andb1are a correct base pair match (i.eaandtorcandg). - Returns
false otherwise
- Returns
boolean strandMatch(String strand0, String strand1)- Returns
trueifstrand0andstrand1match as described above. - This does not mean the strings are equal, but that the appropriate nucleotides are matched.
- Returns
void strandCompare(String strand0, String strand1, int x, int y, int sz)- Draws
strand0directly abovestrand1. - If there is a nucleotide mismatch, draw a yellow border around the nucleotide.

- Draws
- The following global variables, and
setup()will test the above functions.baseColoris also provided to aid in the first part of this assignment.
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
color baseColor(char c) {
color col = color(0);
if (c == 'A') {
col = #fa3737;
}
else if (c == 'T') {
col = #7c0000;
}
else if (c == 'C') {
col = #85C0F9;
}
else if (c == 'G') {
col = #0F2080;
}
return col;
}//baseColor