Skip to content

Commit

Permalink
Major fix to bug where order of sequence context would alter the stat…
Browse files Browse the repository at this point in the history
…e of the pseudo random number generator
  • Loading branch information
ctokheim committed Nov 7, 2016
1 parent 1d410da commit 6d1760e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions prob2020/python/sequence_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class SequenceContext(object):
def __init__(self, gene_seq, seed=None):
self._init_context(gene_seq)
self.seed = seed # seed for random number generator
self.prng = np.random.RandomState(seed=self.seed)
context_names = prob2020.python.mutation_context.get_all_context_names(gene_seq.nuc_context)
self.prng_dict = {
c: np.random.RandomState(seed=self.seed)
for c in context_names
}

def _init_context(self, gene_seq):
"""Initializes attributes defining mutation contexts and their position.
Expand Down Expand Up @@ -197,7 +201,7 @@ def random_context_pos(self, num, num_permutations, context):

# randomly select from available positions that fit the specified context
available_pos = self.context2pos[context]
random_pos = self.prng.choice(available_pos, (num_permutations, num))
random_pos = self.prng_dict[context].choice(available_pos, (num_permutations, num))
return random_pos

def random_pos(self, context_iterable, num_permutations):
Expand Down

0 comments on commit 6d1760e

Please sign in to comment.