Back to index

python-biopython  1.60
Public Member Functions | Public Attributes
Bio.SubsMat.LogOddsMatrix Class Reference
Inheritance diagram for Bio.SubsMat.LogOddsMatrix:
Inheritance graph
[legend]
Collaboration diagram for Bio.SubsMat.LogOddsMatrix:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def calculate_relative_entropy
def make_entropy
def sum
def print_full_mat
def print_mat
def __str__
def __sub__
def __mul__
def __add__

Public Attributes

 alphabet
 ab_list
 mat_name
 sum_letters
 relative_entropy
 entropy

Detailed Description

Log odds matrix

Definition at line 383 of file __init__.py.


Member Function Documentation

def Bio.SubsMat.SeqMat.__add__ (   self,
  other 
) [inherited]

Definition at line 353 of file __init__.py.

00353 
00354    def __add__(self, other):
00355       new_mat = copy.copy(self)
00356       for i in self:
00357          new_mat[i] += other[i]
00358       return new_mat

def Bio.SubsMat.SeqMat.__mul__ (   self,
  other 
) [inherited]
returns a matrix for which each entry is the multiplication product of the
two matrices passed

Definition at line 345 of file __init__.py.

00345 
00346    def __mul__(self,other):
00347       """ returns a matrix for which each entry is the multiplication product of the
00348       two matrices passed"""
00349       new_mat = copy.copy(self)
00350       for i in self:
00351          new_mat[i] *= other[i]
00352       return new_mat

def Bio.SubsMat.SeqMat.__str__ (   self) [inherited]
Print a nice half-matrix.

Definition at line 316 of file __init__.py.

00316 
00317    def __str__(self):
00318       """Print a nice half-matrix."""
00319       output = ""
00320       alphabet = self.ab_list
00321       n = len(alphabet)
00322       for i in range(n):
00323          c1 = alphabet[i]
00324          output += c1
00325          for j in range(i+1):
00326             c2 = alphabet[j]
00327             try:
00328                val = self[c2,c1]
00329             except KeyError:
00330                val = self[c1,c2]
00331             if val == -999:
00332                output += '  ND' 
00333             else:
00334                output += "%4d" % val
00335          output += '\n'
00336       output += '%4s' * n % tuple(alphabet) + "\n"
00337       return output

def Bio.SubsMat.SeqMat.__sub__ (   self,
  other 
) [inherited]
returns a number which is the subtraction product of the two matrices

Definition at line 338 of file __init__.py.

00338 
00339    def __sub__(self,other):
00340       """ returns a number which is the subtraction product of the two matrices"""
00341       mat_diff = 0
00342       for i in self:
00343          mat_diff += (self[i] - other[i])
00344       return mat_diff

def Bio.SubsMat.LogOddsMatrix.calculate_relative_entropy (   self,
  obs_freq_mat 
)
Calculate and return the relative entropy with respect to an
observed frequency matrix

Definition at line 386 of file __init__.py.

00386 
00387     def calculate_relative_entropy(self,obs_freq_mat):
00388         """Calculate and return the relative entropy with respect to an
00389         observed frequency matrix"""
00390         relative_entropy = 0.
00391         for key, value in self.iteritems():
00392             relative_entropy += obs_freq_mat[key]*value/log(2)
00393         return relative_entropy
00394 

Here is the call graph for this function:

def Bio.SubsMat.SeqMat.make_entropy (   self) [inherited]

Definition at line 229 of file __init__.py.

00229 
00230    def make_entropy(self):
00231       self.entropy = 0
00232       for i in self:
00233          if self[i] > EPSILON:
00234             self.entropy += self[i]*log(self[i])/log(2)
00235       self.entropy = -self.entropy

def Bio.SubsMat.SeqMat.print_full_mat (   self,
  f = None,
  format = "%4d",
  topformat = "%4s",
  alphabet = None,
  factor = 1,
  non_sym = None 
) [inherited]

Definition at line 250 of file __init__.py.

00250 
00251               alphabet=None,factor=1,non_sym=None):
00252       f = f or sys.stdout 
00253       # create a temporary dictionary, which holds the full matrix for
00254       # printing
00255       assert non_sym == None or type(non_sym) == type(1.) or \
00256       type(non_sym) == type(1)
00257       full_mat = copy.copy(self)
00258       for i in self:
00259          if i[0] != i[1]:
00260             full_mat[(i[1],i[0])] = full_mat[i]
00261       if not alphabet:
00262          alphabet = self.ab_list
00263       topline = ''
00264       for i in alphabet:
00265          topline = topline + topformat % i
00266       topline = topline + '\n'
00267       f.write(topline)
00268       for i in alphabet:
00269          outline = i
00270          for j in alphabet:
00271             if alphabet.index(j) > alphabet.index(i) and non_sym is not None:
00272                val = non_sym
00273             else:
00274                val = full_mat[i,j]
00275                val *= factor
00276             if val <= -999:
00277                cur_str = '  ND' 
00278             else:
00279                cur_str = format % val
00280             
00281             outline = outline+cur_str
00282          outline = outline+'\n'
00283          f.write(outline)

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.SubsMat.SeqMat.print_mat (   self,
  f = None,
  format = "%4d",
  bottomformat = "%4s",
  alphabet = None,
  factor = 1 
) [inherited]
Print a nice half-matrix. f=sys.stdout to see on the screen
User may pass own alphabet, which should contain all letters in the
alphabet of the matrix, but may be in a different order. This
order will be the order of the letters on the axes

Definition at line 285 of file __init__.py.

00285 
00286               alphabet=None,factor=1):
00287       """Print a nice half-matrix. f=sys.stdout to see on the screen
00288       User may pass own alphabet, which should contain all letters in the
00289       alphabet of the matrix, but may be in a different order. This
00290       order will be the order of the letters on the axes"""
00291       
00292       f = f or sys.stdout
00293       if not alphabet:
00294          alphabet = self.ab_list
00295       bottomline = ''
00296       for i in alphabet:
00297          bottomline = bottomline + bottomformat % i
00298       bottomline = bottomline + '\n'
00299       for i in alphabet:
00300          outline = i
00301          for j in alphabet[:alphabet.index(i)+1]:
00302             try:
00303                val = self[j,i]
00304             except KeyError:
00305                val = self[i,j]
00306             val *= factor
00307             if val == -999:
00308                cur_str = '  ND' 
00309             else:
00310                cur_str = format % val
00311             
00312             outline = outline+cur_str
00313          outline = outline+'\n'
00314          f.write(outline)
00315       f.write(bottomline)

Here is the caller graph for this function:

def Bio.SubsMat.SeqMat.sum (   self) [inherited]

Definition at line 236 of file __init__.py.

00236 
00237    def sum(self):
00238       result = {}
00239       for letter in self.alphabet.letters:
00240           result[letter] = 0.0
00241       for pair, value in self.iteritems():
00242           i1, i2 = pair
00243           if i1==i2:
00244               result[i1] += value
00245           else:
00246               result[i1] += value / 2
00247               result[i2] += value / 2
00248       return result

Here is the call graph for this function:


Member Data Documentation

Definition at line 186 of file __init__.py.

Definition at line 177 of file __init__.py.

Definition at line 230 of file __init__.py.

Definition at line 189 of file __init__.py.

Definition at line 197 of file __init__.py.

Definition at line 196 of file __init__.py.


The documentation for this class was generated from the following file: