Package obitools :: Package distances :: Module observed
[hide private]
[frames] | no frames]

Source Code for Module obitools.distances.observed

 1  ''' 
 2  Module dedicated to compute observed divergeances from 
 3  an alignment. No distance correction is applied at all 
 4  ''' 
 5   
 6  from itertools import imap 
 7   
 8  from obitools.distances import DistanceMatrix 
 9   
10 -class PairewiseGapRemoval(DistanceMatrix):
11 ''' 12 Observed divergeance matrix from an alignment. 13 Gap are removed from the alignemt on a pairewise 14 sequence base 15 ''' 16
17 - def evaluateDist(self,x,y):
18 ''' 19 Compute the observed divergeance from two sequences 20 of an aligment. 21 22 @attention: For performance purpose this method should 23 be directly used. use instead the __getitem__ 24 method from DistanceMatrix. 25 26 @see: L{__getitem__} 27 28 @param x: number of the fisrt sequence in the aligment 29 @type x: int 30 @param y: umber of the second sequence in the aligment 31 @type y: int 32 33 34 ''' 35 36 seq1 = self.aligment[x] 37 seq2 = self.aligment[y] 38 39 diff,tot = reduce(lambda x,y: (x[0]+y,x[1]+1), 40 (z[0]!=z[1] for z in imap(None,seq1,seq2) 41 if '-' not in z),(0,0)) 42 return float(diff)/tot
43 44
45 -class Pairewise(DistanceMatrix):
46 ''' 47 Observed divergeance matrix from an alignment. 48 Gap are kept from the alignemt 49 ''' 50
51 - def evaluateDist(self,x,y):
52 ''' 53 Compute the observed divergeance from two sequences 54 of an aligment. 55 56 @attention: For performance purpose this method should 57 be directly used. use instead the __getitem__ 58 method from DistanceMatrix. 59 60 @see: L{__getitem__} 61 62 @param x: number of the fisrt sequence in the aligment 63 @type x: int 64 @param y: umber of the second sequence in the aligment 65 @type y: int 66 67 68 ''' 69 70 seq1 = self.aligment[x] 71 seq2 = self.aligment[y] 72 73 diff,tot = reduce(lambda x,y: (x[0]+y,x[1]+1), 74 (z[0]!=z[1] for z in imap(None,seq1,seq2)), 75 (0,0)) 76 return float(diff)/tot
77