Lab 2 - DNA Strands
Due: Thursday, July 12th at 11:59pm



DNA strands are made up of 4 molecules called nucleotides. They are Adenine, Cytosine, Guanine, Thymine (abbrieviated A, C, G, T). A forms pairs with T and C forms pairs with G. Two strands are considered complementary if each nucleotide in one strand can form a pair with the corresponding nucleotide in the other strand. For example, AACG is complementary with TTGC.

Task 1

Complete the function areComplementary(strand1, strand2) which returns True, if and only if, two strands are complementary and False otherwise. To be clear, it should return False upon receiving malformed input. Both inputs are guaranteed to be strings, but other types of incorrect input are possible, for example, characters that are not meaningful as nucleotide abbreviations.

Task 2

Write a function which searches through a large strand of nucleotides to find the index of a smaller target strand. In order to do this, please implement each of the following functions:

Provided Code

A file called is provided to you. It contains skeletons of the required and test functions. Any code provided within these functions is provided only to ensure that they are delivered in a syntactically correct form. It is not necessarily part of the final solution.

Assertions and Correctness

The test functions include assertions. We will learn about these in more detail later. The short version is this. The expression within each assertion is designed to be True in all viable cases. Should it ever be False, the program terminates immediately. This is done to help you notice the problem early, and to help you begin debugging near the location of the problem in time and code space.

Just because your code passes all the assertions that we give you, does not mean that it is correct. The provided assertions provide only a minimum level of sanity checking and safeguarding. Please add additional assertions to force the checking of preconditions and other constraints, and otherwise ensure your code's correctness, for example through rigorous testing across many inputs.


Please consider the example below:


name  = "Greg"
length = len(name)

print "Name: " + name
print "Length: " + str(length)
print "Name[0]: " + name[0]
print "Name[1]: " + name[1]
print "Name[2]: " + name[2]
print "Name[3]: " + name[3]

while (index < length):
  print "Name[" + str(index) + "3]: " + name[index]
  index += 1