Ejemplo n.º 1
0
 def adaptPredicate(self, pred, label=None):
     if isinstance(pred, str):
         pred = predicate.parse(pred)
     elif callable(pred):
         pred = predicate.UserPredicate(pred)
     pred_func = pred.makeModelPredicate(self)
     label = label or repr(pred)
     mask = predicate2matrix(
         self.getAlphabet(), pred_func, mask=self._instantaneous_mask)
     return (label, mask)
Ejemplo n.º 2
0
 def adaptPredicate(self, pred, label=None):
     if isinstance(pred, str):
         pred = predicate.parse(pred)
     elif callable(pred):
         pred = predicate.UserPredicate(pred)
     pred_func = pred.makeModelPredicate(self)
     label = label or repr(pred)
     mask = predicate2matrix(
         self.getAlphabet(), pred_func, mask=self._instantaneous_mask)
     return (label, mask)
Ejemplo n.º 3
0
 def getPredefinedPredicates(self):
     gc = self.getAlphabet().getGeneticCode()
     def silent(x, y):
         return x != '---' and y != '---' and gc[x] == gc[y]
     def replacement(x, y):
         return x != '---' and y != '---' and gc[x] != gc[y]
     
     preds = _Nucleotide.getPredefinedPredicates(self)
     preds.update({
         'indel' : predicate.parse('???/---'),
         'silent' : predicate.UserPredicate(silent),
         'replacement' : predicate.UserPredicate(replacement),
         })
     return preds
Ejemplo n.º 4
0
 def getPredefinedPredicates(self):
     gc = self.getAlphabet().getGeneticCode()
     def silent(x, y):
         return x != '---' and y != '---' and gc[x] == gc[y]
     def replacement(x, y):
         return x != '---' and y != '---' and gc[x] != gc[y]
     
     preds = _Nucleotide.getPredefinedPredicates(self)
     preds.update({
         'indel' : predicate.parse('???/---'),
         'silent' : predicate.UserPredicate(silent),
         'replacement' : predicate.UserPredicate(replacement),
         })
     return preds
Ejemplo n.º 5
0
 def getPredefinedPredicates(self):
     return {
         'transition' : predicate.parse('R/R') | predicate.parse('Y/Y'),
         'transversion' : predicate.parse('R/Y'),
         'indel': predicate.parse('-/?'),
         }
Ejemplo n.º 6
0
 def getPredefinedPredicates(self):
     # overridden in subclasses
     return {'indel': predicate.parse('-/?')}
Ejemplo n.º 7
0
 def getPredefinedPredicates(self):
     return {
         'transition': predicate.parse('R/R') | predicate.parse('Y/Y'),
         'transversion': predicate.parse('R/Y'),
         'indel': predicate.parse('-/?'),
     }
Ejemplo n.º 8
0
 def getPredefinedPredicates(self):
     # overridden in subclasses
     return {'indel': predicate.parse('-/?')}
Ejemplo n.º 9
0
        if self.alphabet[-1] == '---':
            Q[:-1, :-1] *= mprobs_matrix[:-1, :-1]
            pi = numpy.array(word_probs)
            pi /= pi.sum()
            Q[-1, :-1] *= pi[:-1]
            Q[:-1, -1] *= pi[-1]
        else:
            Q *= mprobs_matrix
        row_totals = Q.sum(axis=1)
        Q -= numpy.diag(row_totals)
        if self._do_scaling:
            Q *= 1.0 / (word_probs * row_totals).sum()
        return Q


_gap_preds = [parse('--->???'), parse('???>---')]
_indel = ModelSays('indel')


class MonkeyPatchModel(object):
    def makeLikelihoodFunction(self,
                               tree,
                               motif_probs_from_align=None,
                               optimise_motif_probs=None,
                               aligned=True,
                               expm=None,
                               digits=None,
                               space=None,
                               **kw):
        if motif_probs_from_align is None:
            motif_probs_from_align = self.motif_probs_from_align