Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Private Member Functions
Bio.Motif.Thresholds.ScoreDistribution Class Reference

List of all members.

Public Member Functions

def __init__
def modify
def threshold_fpr
def threshold_fnr
def threshold_balanced
def threshold_patser

Public Attributes

 min_score
 interval
 n_points
 step
 mo_density
 bg_density
 ic

Private Member Functions

def _index_diff
def _add

Detailed Description

Class representing approximate score distribution for a given motif.

Utilizes a dynamic programming approch to calculate the distribution of
scores with a predefined precision. Provides a number of methods for calculating
thresholds for motif occurences.

Definition at line 10 of file Thresholds.py.


Constructor & Destructor Documentation

def Bio.Motif.Thresholds.ScoreDistribution.__init__ (   self,
  motif,
  precision = 10**3 
)

Definition at line 17 of file Thresholds.py.

00017 
00018     def __init__(self,motif,precision=10**3):
00019         self.min_score=min(0.0,motif.min_score())
00020         self.interval=max(0.0,motif.max_score())-self.min_score
00021         self.n_points=precision*motif.length
00022         self.step=self.interval/(self.n_points-1)
00023         self.mo_density=[0.0]*self.n_points
00024         self.mo_density[-self._index_diff(self.min_score)]=1.0
00025         self.bg_density=[0.0]*self.n_points
00026         self.bg_density[-self._index_diff(self.min_score)]=1.0
00027         self.ic=motif.ic()
00028         for lo,mo in zip(motif.log_odds(),motif.pwm()):
00029             self.modify(lo,mo,motif.background)
        

Here is the caller graph for this function:


Member Function Documentation

def Bio.Motif.Thresholds.ScoreDistribution._add (   self,
  i,
  j 
) [private]

Definition at line 33 of file Thresholds.py.

00033 
00034     def _add(self,i,j):
00035         return max(0,min(self.n_points-1,i+j))
        

Here is the caller graph for this function:

def Bio.Motif.Thresholds.ScoreDistribution._index_diff (   self,
  x,
  y = 0.0 
) [private]

Definition at line 30 of file Thresholds.py.

00030 
00031     def _index_diff(self,x,y=0.0):
00032         return int((x-y+0.5*self.step)//self.step)
        

Here is the caller graph for this function:

def Bio.Motif.Thresholds.ScoreDistribution.modify (   self,
  scores,
  mo_probs,
  bg_probs 
)

Definition at line 36 of file Thresholds.py.

00036 
00037     def modify(self,scores,mo_probs,bg_probs):
00038         mo_new=[0.0]*self.n_points
00039         bg_new=[0.0]*self.n_points
00040         for k, v in scores.iteritems():
00041             d=self._index_diff(v)
00042             for i in range(self.n_points):
00043                 mo_new[self._add(i,d)]+=self.mo_density[i]*mo_probs[k]
00044                 bg_new[self._add(i,d)]+=self.bg_density[i]*bg_probs[k]
00045         self.mo_density=mo_new
00046         self.bg_density=bg_new
        

Here is the call graph for this function:

def Bio.Motif.Thresholds.ScoreDistribution.threshold_balanced (   self,
  rate_proportion = 1.0,
  return_rate = False 
)
Approximate the log-odds threshold which makes FNR equal to FPR times rate_proportion

Definition at line 69 of file Thresholds.py.

00069 
00070     def threshold_balanced(self,rate_proportion=1.0,return_rate=False):
00071         """
00072         Approximate the log-odds threshold which makes FNR equal to FPR times rate_proportion
00073         """
00074         i=self.n_points
00075         fpr=0.0
00076         fnr=1.0
00077         while fpr*rate_proportion<fnr:
00078             i-=1
00079             fpr+=self.bg_density[i]
00080             fnr-=self.mo_density[i]
00081         if return_rate:
00082             return self.min_score+i*self.step,fpr
00083         else:
00084             return self.min_score+i*self.step

Approximate the log-odds threshold which makes the type II error (false negative rate).

Definition at line 58 of file Thresholds.py.

00058 
00059     def threshold_fnr(self,fnr):
00060         """
00061         Approximate the log-odds threshold which makes the type II error (false negative rate).
00062         """
00063         i=-1
00064         prob=0.0
00065         while prob<fnr:
00066             i+=1
00067             prob+=self.mo_density[i]
00068         return self.min_score+i*self.step
            
Approximate the log-odds threshold which makes the type I error (false positive rate).

Definition at line 47 of file Thresholds.py.

00047 
00048     def threshold_fpr(self,fpr):
00049         """
00050         Approximate the log-odds threshold which makes the type I error (false positive rate).
00051         """
00052         i=self.n_points
00053         prob=0.0
00054         while prob<fpr:
00055             i-=1
00056             prob+=self.bg_density[i]
00057         return self.min_score+i*self.step
            

Here is the caller graph for this function:

Threshold selection mimicking the behaviour of patser (Hertz, Stormo 1999) software.

It selects such a threshold that the log(fpr)=-ic(M)
note: the actual patser software uses natural logarithms instead of log_2, so the numbers
are not directly comparable.

Definition at line 85 of file Thresholds.py.

00085 
00086     def threshold_patser(self):
00087         """Threshold selection mimicking the behaviour of patser (Hertz, Stormo 1999) software.
00088         
00089         It selects such a threshold that the log(fpr)=-ic(M)
00090         note: the actual patser software uses natural logarithms instead of log_2, so the numbers
00091         are not directly comparable.
00092         """
00093         return self.threshold_fpr(fpr=2**-self.ic)

Here is the call graph for this function:


Member Data Documentation

Definition at line 24 of file Thresholds.py.

Definition at line 26 of file Thresholds.py.

Definition at line 19 of file Thresholds.py.

Definition at line 18 of file Thresholds.py.

Definition at line 22 of file Thresholds.py.

Definition at line 20 of file Thresholds.py.

Definition at line 21 of file Thresholds.py.


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