Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added the capability to set the number of pseudocounts equal to the s…

…quare root of the number of instances
  • Loading branch information...
commit ff691543c5c9495e5156c5f1dabbcc0e21fc4418 1 parent 9c16c09
mdehoon authored
Showing with 17 additions and 0 deletions.
  1. +17 −0 Bio/motifs/__init__.py
View
17 Bio/motifs/__init__.py
@@ -13,6 +13,8 @@
Bio.motifs is replacing the older and now obsolete Bio.Motif module.
"""
+import math
+
def create(instances, alphabet=None):
instances = Instances(instances, alphabet)
@@ -267,6 +269,21 @@ def __set_pseudocounts(self, value):
self._pseudocounts = {}
if isinstance(value, dict):
self._pseudocounts = dict((letter, value[letter]) for letter in self.alphabet.letters)
+ elif value == 'sqrt':
+ nb_instances = sum([column[0] for column in self.counts.values()])
+ sq_nb_instances = math.sqrt(nb_instances)
+
+ alphabet = self.alphabet
+ background = self.background
+ if background:
+ background = dict(background)
+ else:
+ background = dict.fromkeys(sorted(alphabet.letters), 1.0)
+ total = sum(background.values())
+ self._pseudocounts = {}
+ for letter in alphabet.letters:
+ background[letter] /= total
+ self._pseudocounts[letter] = sq_nb_instances * background[letter]
else:
if value is None:
value = 0.0
Please sign in to comment.
Something went wrong with that request. Please try again.