def test_flatten(self): i1 = range(2) i2 = range(10, 12) self.assertEqual( utils.flatten([i1, i2]), [0, 1, 10, 11] )
def prob_motif(motif, alphabet, markov_order, transitions): """Computes the probability of a motif based on a transitions matrix""" transitions = utils.flatten(transitions) motifs = list(permutations(alphabet, markov_order+1)) motifs_index = dict([(motifs[i], i) for i in range(len(motifs))]) prob = 1.0 for i in range(len(motif) - markov_order): prob *= transitions[motifs_index[motif[i:i+markov_order+1]]] return prob