Lab 11

DNA sequence class

Write a class called dna_sequence that represents the data and operations that can be applied to a DNA sequence.

Here is the interface that your class should support:

  • The constructor should receive a string as its parameter and interpret it as a DNA sequence. It should check that the string represents a valid DNA sequence, and raise a ValueError exception if it doesn't. For our purposes let's assume a DNA sequence can have one of the five letters A,C,G,T,N.
  • __len__() this method should return the length of the sequence. This allows the len function to be called on an instance of a dna_sequence.
  • __repr__() this method should provide useful information about the sequence (e.g. its length).
  • gc_content() this method should return the fraction of nucleotides that are either G or C.
  • nucleotide_composition() this method should return a list with four elements that represent the fraction of A,C,G, and T nucleotides in the sequence (N's should be ignored as we did before).
  • reverse_complement() this method should return an instance of the class dna_sequence whose sequence is the reverse-complement.

Put the class in a file called dna_sequence.py.