Ejemplo n.º 1
0
 def check_value_is_valid(self, value, is_constant):
     if value.shape != (self.size, self.size):
         raise ValueError(
             "Wrong array shape %s for %s, expected (%s,%s)"
             % (value.shape, self.name, self.size, self.size)
         )
     for part in value:
         PartitionDefn.check_value_is_valid(self, part, is_constant)
Ejemplo n.º 2
0
    def __init__(
        self, default=None, name=None, dimensions=None, dimension=None, size=None, **kw
    ):
        PartitionDefn.__init__(self, default, name, dimensions, dimension, size, **kw)

        (dim_name, dim_cats) = self.internal_dimension
        self.internal_dimensions = (dim_name, dim_name + "2")
        self.array_template = DictArrayTemplate(dim_cats, dim_cats)
Ejemplo n.º 3
0
def make_forward_tree_defn(
    subst_model, tree, bin_names, with_indel_params=True, kn=True
):
    """Pairwise Fwd"""
    indel = make_indel_model_defn(with_indel_params, kn)
    subst = subst_model.make_fundamental_param_controller_defns(bin_names)
    leaf = NonParamDefn("leaf", dimensions=("edge",))

    if len(bin_names) > 1:
        switch = ProbabilityParamDefn("bin_switch", dimensions=["locus"])
        bprobs = PartitionDefn(
            [1.0 / len(bin_names) for bin in bin_names],
            name="bprobs",
            dimensions=["locus"],
            dimension=("bin", bin_names),
        )
        edge_args = [switch, bprobs]
        edge_defn_constructor = EdgeSumAndAlignDefnWithBins
    else:
        edge_args = []
        edge_defn_constructor = EdgeSumAndAlignDefn

    mprobs = subst["word_probs"]
    bin_data = CalcDefn(BinData)(mprobs, indel, subst["Qd"])
    bin_data = bin_data.across_dimension("bin", bin_names)
    edge_args.extend(bin_data)

    (top, scores) = _recursive_defns(
        tree, subst, leaf, edge_defn_constructor, edge_args
    )
    defn = FwdDefn(top)
    # defn = SumDefn(*scores)
    return AnnotateFloatDefn(defn, top)
Ejemplo n.º 4
0
 def make_motif_word_prob_defns(self):
     monomer_probs = PartitionDefn(
         name="psmprobs",
         default=None,
         dimensions=("locus", "position", "edge"),
         dimension=("motif", tuple(self.get_input_alphabet())),
     )
     monomer_probs3 = monomer_probs.across_dimension(
         "position", [str(i) for i in range(self.word_length)])
     monomer_probs3 = CalcDefn(lambda *x: numpy.array(x),
                               name="mprobs")(*monomer_probs3)
     word_probs = CalcDefn(self.calc_word_probs,
                           name="wprobs")(monomer_probs3)
     mprobs_matrix = CalcDefn(self.calc_word_weight_matrix,
                              name="mprobs_matrix")(monomer_probs3)
     return (monomer_probs, word_probs, mprobs_matrix)
Ejemplo n.º 5
0
 def make_motif_probs_defn(self):
     """Makes the first part of a parameter controller definition for this
     model, the calculation of motif probabilities"""
     return PartitionDefn(
         name="mprobs",
         default=None,
         dimensions=("locus", "edge"),
         dimension=("motif", tuple(self.get_input_alphabet())),
     )