예제 #1
0
 def _send_message(node, **kwargs):
     """
     Calc the desired LH distribution of the parent
     """
     if node.msg_to_parent.is_delta:
         res = Distribution.shifted_x(node.branch_length_interpolator, node.msg_to_parent.peak_pos)
     else: # convolve two distributions
         res =  NodeInterpolator.convolve(node.msg_to_parent,
                     node.branch_length_interpolator, n_integral=self.n_integral,
                     rel_tol=self.rel_tol_refine)
     self.logger("ClockTree._ml_t_leaves_root._send_message: "
                 "computed convolution with %d points at node %s"%(len(res.x),node.name),4)
     return res
예제 #2
0
    def _set_final_dates(self):
        """
        Given the location of the node in branch length units, convert it to the
        date-time information.

        Args:
         - node(Phylo.Clade): tree node. NOTE the node should have the abs_t attribute
         to have a valid value. This is automatically taken care of in the
         procedure to get the node location probability distribution.

        """
        self.logger("ClockTree: Setting dates and node distributions...", 2)
        def collapse_func(dist):
            if dist.is_delta:
                return dist.peak_pos
            else:
                return dist.peak_pos


        for node in self.tree.find_clades(order='preorder'):  # ancestors first, msg to children
            # set marginal distribution
            ## This is the root node
            if node.up is None:
                node.marginal_lh = node.msg_to_parent
            elif node.msg_to_parent is None:
                node.marginal_lh = node.msg_from_parent
            elif node.msg_to_parent.is_delta:
                node.marginal_lh = node.msg_to_parent
            else:
                node.marginal_lh = NodeInterpolator.multiply((node.msg_from_parent, node.msg_to_parent))

            if node.up is None:
                node.joint_lh = node.msg_to_parent
                node.time_before_present = collapse_func(node.joint_lh)
                node.branch_length = self.one_mutation
            else:
                # shift position of parent node (time_before_present) by the branch length
                # towards the present. To do so, add branch length to negative time_before_present
                # and rescale the resulting distribution by -1.0
                res = Distribution.shifted_x(node.branch_length_interpolator, -node.up.time_before_present)
                res.x_rescale(-1.0)
                # multiply distribution from parent with those from children and determine peak
                if node.msg_to_parent is not None:
                    node.joint_lh = NodeInterpolator.multiply((node.msg_to_parent, res))
                else:
                    node.joint_lh = res
                node.time_before_present = collapse_func(node.joint_lh)

                node.branch_length = node.up.time_before_present - node.time_before_present
            node.clock_length = node.branch_length