Pastebin
Paste #965: her
< previous paste - next paste>
Pasted by Morten
1 #! /usr/bin/python
2
3 # Linux And Python Programming
4 # Hand-in 5
5 # 5. October 2007
6
7 class Seq:
8 """
9 Class defining generel methods for a biological sequence
10 """
11
12 def __init__(self, seq, pattern):
13 """
14 Constructor method. Checks whether an input-sequence is a legal biological
15 sequence
16
17 seq -- the input sequence
18 pattern -- the pattern that determines if the sequence is invalid
19 """
20
21 if pattern.search(seq):
22 print " Warning: sequence contains illegal characters"
23 self.data = seq.upper()
24
25 def __getitem__(self, index):
26 """
27 Return element
28
29 index -- the position of the element wished to be returned
30 """
31 return self.data[index]
32
33 def __len__(self):
34 """
35 Returns the length of the sequence
36 """
37 return len(self.data)
38
39
40 class Dna(Seq):
41 """
42 Class defining methods for a DNA sequence
43 """
44
45 def __init__(self, seq):
46 """
47 Constructor method.
48
49 seq -- the input sequence
50 """
51 import re
52
53 patternString = '[AGCTagct]+'
54
55 pattern = re.compile(patternString)
56
57 Seq.__init__(self,seq,pattern)
58
59 def __repr__ ( self ):
60 """
61 Return data attribute
62 """
63
64 return self .data
65
66
67
68 if __name__ == "__main__":
69 d = Dna('ACCCGT')
New Paste
Go to most recent paste.