treetime/clock_tree.py
def _assign_dates(self):
        """assign dates to nodes

        Returns
        -------
        str
            success/error code
        """
        if self.tree is None:
            self.logger("ClockTree._assign_dates: tree is not set, can't assign dates", 0)
            return ttconf.ERROR

        bad_branch_counter = 0
        for node in self.tree.find_clades(order='postorder'):
            if node.name in self.date_dict:
                tmp_date = self.date_dict[node.name]
                if np.isscalar(tmp_date) and np.isnan(tmp_date):
                    self.logger("WARNING: ClockTree.init: node %s has a bad date: %s"%(node.name, str(tmp_date)), 2, warn=True)
                    node.raw_date_constraint = None
                    node.bad_branch = True
                else:
                    try:
                        tmp = np.mean(tmp_date)
                        node.raw_date_constraint = tmp_date
                        node.bad_branch = False
                    except:
                        self.logger("WARNING: ClockTree.init: node %s has a bad date: %s"%(node.name, str(tmp_date)), 2, warn=True)
                        node.raw_date_constraint = None
                        node.bad_branch = True
            else: # nodes without date contraints

                node.raw_date_constraint = None

                if node.is_terminal():
                    # Terminal branches without date constraints marked as 'bad'
                    node.bad_branch = True
                else:
                    # If all branches dowstream are 'bad', and there is no date constraint for
                    # this node, the branch is marked as 'bad'
                    node.bad_branch = np.all([x.bad_branch for x in node])

            if node.is_terminal() and node.bad_branch:
                bad_branch_counter += 1

        if bad_branch_counter>self.tree.count_terminals()-3:
            self.logger("ERROR: ALMOST NO VALID DATE CONSTRAINTS, EXITING", 1, warn=True)
            return ttconf.ERROR

        return ttconf.SUCCESS
def _assign_dates(self):
        """assign dates to nodes

        Returns
        -------
        str
            success/error code
        """
        if self.tree is None:
            self.logger("ClockTree._assign_dates: tree is not set, can't assign dates", 0)
            return ttconf.ERROR

        bad_branch_counter = 0
        for node in self.tree.find_clades(order='postorder'):
            if node.name in self.date_dict:
                tmp_date = self.date_dict[node.name]
                if np.isscalar(tmp_date) and np.isnan(tmp_date):
                    self.logger("WARNING: ClockTree.init: node %s has a bad date: %s"%(node.name, str(tmp_date)), 2, warn=True)
                    node.raw_date_constraint = None
                    node.bad_branch = True
                else:
                    try:
                        tmp = np.mean(tmp_date)
                        node.raw_date_constraint = tmp_date
                        node.bad_branch = False
                    except:
                        self.logger("WARNING: ClockTree.init: node %s has a bad date: %s"%(node.name, str(tmp_date)), 2, warn=True)
                        node.raw_date_constraint = None
                        node.bad_branch = True
            else: # nodes without date contraints

                node.raw_date_constraint = None

                if node.is_terminal():
                    # Terminal branches without date constraints marked as 'bad'
                    node.bad_branch = True
                else:
                    # If all branches dowstream are 'bad', and there is no date constraint for
                    # this node, the branch is marked as 'bad'
                    node.bad_branch = np.all([x.bad_branch for x in node])

            if node.is_terminal() and node.bad_branch:
                bad_branch_counter += 1

        if bad_branch_counter>self.tree.count_terminals()-3:
            self.logger("ERROR: ALMOST NO VALID DATE CONSTRAINTS, EXITING", 1, warn=True)
            return ttconf.ERROR

        return ttconf.SUCCESS
def _assign_dates ( self ) : if self . tree is None : self . logger ( "ClockTree._assign_dates: tree is not set, can't assign dates" , 0 ) return ttconf . ERROR bad_branch_counter = 0 for node in self . tree . find_clades ( order = 'postorder' ) : if node . name in self . date_dict : tmp_date = self . date_dict [ node . name ] if np . isscalar ( tmp_date ) and np . isnan ( tmp_date ) : self . logger ( "WARNING: ClockTree.init: node %s has a bad date: %s" % ( node . name , str ( tmp_date ) ) , 2 , warn = True ) node . raw_date_constraint = None node . bad_branch = True else : try : tmp = np . mean ( tmp_date ) node . raw_date_constraint = tmp_date node . bad_branch = False except : self . logger ( "WARNING: ClockTree.init: node %s has a bad date: %s" % ( node . name , str ( tmp_date ) ) , 2 , warn = True ) node . raw_date_constraint = None node . bad_branch = True else : # nodes without date contraints node . raw_date_constraint = None if node . is_terminal ( ) : # Terminal branches without date constraints marked as 'bad' node . bad_branch = True else : # If all branches dowstream are 'bad', and there is no date constraint for # this node, the branch is marked as 'bad' node . bad_branch = np . all ( [ x . bad_branch for x in node ] ) if node . is_terminal ( ) and node . bad_branch : bad_branch_counter += 1 if bad_branch_counter > self . tree . count_terminals ( ) - 3 : self . logger ( "ERROR: ALMOST NO VALID DATE CONSTRAINTS, EXITING" , 1 , warn = True ) return ttconf . ERROR return ttconf . SUCCESS
assign dates to nodes

        Returns
        -------
        str
            success/error code
assign dates to nodes