Pastebin

Paste #967: No description

< previous paste - next paste>

Pasted by Anonymous Coward

Download View as text

  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        Seq.__init__(self, seq, self.pattern)
 33
 34     def __repr__(self):
 35         return "DNA sequence: ", self.data
 36
 37 class Rna(Seq):
 38     """DNA sequence class"""
 39     import re
 40     # Valid chars: ACGU
 41     pattern = re.compile("[^ACGUacgu]")
 42
 43     def __init__(self, seq):
 44         Seq.__init__(self, seq, self.pattern)
 45
 46     def __repr__(self):
 47         return "RNA sequence: ", self.data
 48
 49 d = Dna("ACCCGT")
 50 print d
 51 r = Rna("UGACG")
 52 print r
 53
~

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.