1 class Seq: 2 """General sequence class""" 3 4 def __init__(self, seq, pattern): 5 """Constructor for Seq. 6 Takes arguments: seq and pattern""" 7 8 if pattern.search(seq): 9 print "Warning: sequence contains illegal characters" 10 self.data = seq.upper() 11 12 def __getitem__(self, index): 13 """Returns an item given a specific index""" 14 return self.data[index] 15 16 def __len__(self): 17 """Returns the size of the data""" 18 return len(self.data) 19 20 def __repr__(self): 21 """Returns representation of the sequence.""" 22 return self.data 23 24 25 class Dna(Seq): 26 """DNA sequence class""" 27 import re 28 # Valid chars: ACGT 29 pattern = re.compile("[^ACGTacgt]") 30 31 def __init__(self, seq): 32 self.parent = Seq.__init__(self, seq, self.pattern) 33 34 def __repr__(self): 35 return "DNA sequence: ", repr(self.parent) 36