Skip to content

Commit

Permalink
Made pseudo random number generator an attribute so it can be re-used…
Browse files Browse the repository at this point in the history
… multiple times (a seed would give the same result each time).
  • Loading branch information
ctokheim committed Jun 13, 2016
1 parent b5afa2f commit 188e7a2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions prob2020/python/sequence_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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)

def _init_context(self, gene_seq):
"""Initializes attributes defining mutation contexts and their position.
Expand Down Expand Up @@ -196,8 +197,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]
prng = np.random.RandomState(seed=self.seed)
random_pos = prng.choice(available_pos, (num_permutations, num))
random_pos = self.prng.choice(available_pos, (num_permutations, num))
return random_pos

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

0 comments on commit 188e7a2

Please sign in to comment.