コード例 #1
0
ファイル: matrix.py プロジェクト: Honglongwu/biopython
 def std(self, background=None):
     """Standard deviation of the score of a motif."""
     if background is None:
         background = dict.fromkeys(self._letters, 1.0)
     else:
         background = dict(background)
     total = sum(background.values())
     for letter in self._letters:
         background[letter] /= total
     variance = 0.0
     for i in range(self.length):
         sx = 0.0
         sxx = 0.0
         for letter in self._letters:
             logodds = self[letter, i]
             if _isnan(logodds):
                 continue
             if _isinf(logodds) and logodds < 0:
                 continue
             b = background[letter]
             p = b * math.pow(2, logodds)
             sx += p*logodds
             sxx += p*logodds*logodds
         sxx -= sx*sx
         variance += sxx
     variance = max(variance, 0) # to avoid roundoff problems
     return math.sqrt(variance)
コード例 #2
0
ファイル: matrix.py プロジェクト: cbirdlab/sap
 def std(self, background=None):
     """Standard deviation of the score of a motif."""
     if background is None:
         background = dict.fromkeys(self._letters, 1.0)
     else:
         background = dict(background)
     total = sum(background.values())
     for letter in self._letters:
         background[letter] /= total
     variance = 0.0
     for i in range(self.length):
         sx = 0.0
         sxx = 0.0
         for letter in self._letters:
             logodds = self[letter, i]
             if _isnan(logodds):
                 continue
             if _isinf(logodds) and logodds < 0:
                 continue
             b = background[letter]
             p = b * math.pow(2, logodds)
             sx += p * logodds
             sxx += p * logodds * logodds
         sxx -= sx * sx
         variance += sxx
     variance = max(variance, 0)  # to avoid roundoff problems
     return math.sqrt(variance)
コード例 #3
0
 def mean(self, background=None):
     """Expected value of the score of a motif."""
     if background is None:
         background = dict.fromkeys(self._letters, 1.0)
     else:
         background = dict(background)
     total = sum(background.values())
     for letter in self._letters:
         background[letter] /= total
     sx = 0.0
     for i in range(self.length):
         for letter in self._letters:
             logodds = self[letter, i]
             if _isnan(logodds):
                 continue
             b = background[letter]
             p = b * math.pow(2, logodds)
             sx += p * logodds
     return sx
コード例 #4
0
ファイル: matrix.py プロジェクト: adeshpande/biopython
 def mean(self, background=None):
     """Expected value of the score of a motif."""
     if background is None:
         background = dict.fromkeys(self._letters, 1.0)
     else:
         background = dict(background)
     total = sum(background.values())
     for letter in self._letters:
         background[letter] /= total
     sx = 0.0
     for i in range(self.length):
         for letter in self._letters:
             logodds = self[letter,i]
             if _isnan(logodds):
                 continue
             b = background[letter]
             p = b * math.pow(2,logodds)
             sx += p * logodds
     return sx
コード例 #5
0
ファイル: fdsnws_events.py プロジェクト: gempa/caravan
def _parse(value, except_value=float("NaN"), nan_is_numeric=True):
    """Returns value parsed to float (via the function float(value)) 
    with more freedom to control the returned value. 
    Parameters:
    - except_value (NaN by default) is the value returned on errors, e.g., when trying to parse dicts (float({})). 
    - nan_is_numeric tells whether nan values should be treated as numeric (this is the default) 
    or should be treated as errors (in this case nan values will return except_value)
    
    Note that this function is handy in that it can be used also to get if value is either 
    a number or a numeric string via, e.g.:
    
        if _parse(value, None, False) is not None
    """
    try:
        val = float(value)
        if not nan_is_numeric and _isnan(val):
            return except_value
        else:
            return val
    except:
        return except_value
コード例 #6
0
ファイル: fdsnws_events.py プロジェクト: matebarny/caravan
def _parse(value, except_value=float('NaN'), nan_is_numeric=True):
    """Returns value parsed to float (via the function float(value)) 
    with more freedom to control the returned value. 
    Parameters:
    - except_value (NaN by default) is the value returned on errors, e.g., when trying to parse dicts (float({})). 
    - nan_is_numeric tells whether nan values should be treated as numeric (this is the default) 
    or should be treated as errors (in this case nan values will return except_value)
    
    Note that this function is handy in that it can be used also to get if value is either 
    a number or a numeric string via, e.g.:
    
        if _parse(value, None, False) is not None
    """
    try:
        val = float(value)
        if not nan_is_numeric and _isnan(val):
            return except_value
        else:
            return val
    except:
        return except_value
コード例 #7
0
ファイル: __init__.py プロジェクト: sumsung007/DaPy
def isnan(value):
    try:
        return _isnan(value)
    except TypeError:
        return False
コード例 #8
0
def isnan(value):
    try:
        return _isnan(value)
    except Exception:
        return False