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)
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)
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
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
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
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
def isnan(value): try: return _isnan(value) except TypeError: return False
def isnan(value): try: return _isnan(value) except Exception: return False