Exemplo n.º 1
0
def extract_coalescent_frames(*args, **kwargs):
    deprecate.dendropy_deprecation_warning(
            preamble="Deprecated since DendroPy 4: The 'dendropy.coalescent' module has moved to 'dendropy.model.coalescent'.",
            old_construct="from dendropy import coalescent\ncoalescent.extract_coalescent_frames(...)",
            new_construct="from dendropy.model import coalescent\ncoalescent.extract_coalescent_frames(...)")
    return coalescent.extract_coalescent_frames(*args, **kwargs)
Exemplo n.º 2
0
 def compile(
     self,
     tree,
     tree_phylogenetic_distance_matrix=None,
     tree_node_distance_matrix=None,
 ):
     if self.is_measure_edge_lengths:
         if self.is_normalize:
             tree_length_nf = tree.length()
             if tree_length_nf == 0:
                 tree_length_nf = 1.0
         else:
             tree_length_nf = 1.0
         self.measurement_profiles["Edge.Lengths"] = MeasurementProfile(
             profile_data=[
                 float(e.length) / tree_length_nf
                 for e in tree.postorder_edge_iter() if e.length is not None
             ])
     if self.is_measure_patristic_distances or self.is_measure_patristic_steps:
         if tree_phylogenetic_distance_matrix is None:
             tree_phylogenetic_distance_matrix = tree.phylogenetic_distance_matrix(
             )
         if self.is_measure_patristic_distances:
             self.measurement_profiles[
                 "Patristic.Distances"] = MeasurementProfile(
                     profile_data=tree_phylogenetic_distance_matrix.
                     distances(
                         is_weighted_edge_distances=True,
                         is_normalize_by_tree_size=self.is_normalize,
                     ))
         if self.is_measure_patristic_steps:
             self.measurement_profiles[
                 "Patristic.Steps"] = MeasurementProfile(
                     profile_data=tree_phylogenetic_distance_matrix.
                     distances(
                         is_weighted_edge_distances=False,
                         is_normalize_by_tree_size=self.is_normalize,
                     ))
     if self.is_measure_node_distances or self.is_measure_node_steps:
         if tree_node_distance_matrix is None:
             tree_node_distance_matrix = tree.node_distance_matrix()
         if self.is_measure_node_distances:
             self.measurement_profiles[
                 "Node.Distances"] = MeasurementProfile(
                     profile_data=tree_node_distance_matrix.distances(
                         is_weighted_edge_distances=True,
                         is_normalize_by_tree_size=self.is_normalize,
                     ))
         if self.is_measure_node_steps:
             self.measurement_profiles["Node.Steps"] = MeasurementProfile(
                 profile_data=tree_node_distance_matrix.distances(
                     is_weighted_edge_distances=False,
                     is_normalize_by_tree_size=self.is_normalize,
                 ))
     if self.is_measure_node_ages:
         node_ages = tree.calc_node_ages(
             ultrametricity_precision=self.ultrametricity_precision)
         if self.is_normalize:
             s = sum(node_ages)
             try:
                 normalized_node_ages = [a / s for a in node_ages]
                 node_ages = normalized_node_ages
             except ZeroDivisionError as e:
                 if self.is_skip_normalization_on_zero_division_error:
                     pass
                 else:
                     raise
         self.measurement_profiles["Node.Ages"] = MeasurementProfile(
             profile_data=node_ages, )
     if self.is_measure_coalescence_intervals:
         cf = coalescent.extract_coalescent_frames(
             tree=tree,
             ultrametricity_precision=self.ultrametricity_precision,
         )
         waiting_times = cf.values()
         if self.is_normalize:
             s = sum(waiting_times)
             try:
                 normalized_waiting_times = [w / s for w in waiting_times]
                 waiting_times = normalized_waiting_times
             except ZeroDivisionError as e:
                 if self.is_skip_normalization_on_zero_division_error:
                     pass
                 else:
                     raise
         self.measurement_profiles[
             "Coalescence.Intervals"] = MeasurementProfile(
                 profile_data=waiting_times, )
Exemplo n.º 3
0
 def compile(self, tree,
         tree_phylogenetic_distance_matrix=None,
         tree_node_distance_matrix=None,
         ):
     if self.is_measure_edge_lengths:
         if self.is_normalize:
             tree_length_nf = tree.length()
             if tree_length_nf == 0:
                 tree_length_nf = 1.0
         else:
             tree_length_nf = 1.0
         self.measurement_profiles["Edge.Lengths"] = MeasurementProfile(
                 profile_data=[float(e.length)/tree_length_nf for e in tree.postorder_edge_iter() if e.length is not None])
     if self.is_measure_patristic_distances or self.is_measure_patristic_steps:
         if tree_phylogenetic_distance_matrix is None:
             tree_phylogenetic_distance_matrix = tree.phylogenetic_distance_matrix()
         if self.is_measure_patristic_distances:
             self.measurement_profiles["Patristic.Distances"] = MeasurementProfile(
                     profile_data=tree_phylogenetic_distance_matrix.distances(
                         is_weighted_edge_distances=True,
                         is_normalize_by_tree_size=self.is_normalize,))
         if self.is_measure_patristic_steps:
             self.measurement_profiles["Patristic.Steps"] = MeasurementProfile(
                     profile_data=tree_phylogenetic_distance_matrix.distances(
                     is_weighted_edge_distances=False,
                     is_normalize_by_tree_size=self.is_normalize,))
     if self.is_measure_node_distances or self.is_measure_node_steps:
         if tree_node_distance_matrix is None:
             tree_node_distance_matrix = tree.node_distance_matrix()
         if self.is_measure_node_distances:
             self.measurement_profiles["Node.Distances"] = MeasurementProfile(
                     profile_data=tree_node_distance_matrix.distances(
                         is_weighted_edge_distances=True,
                         is_normalize_by_tree_size=self.is_normalize,))
         if self.is_measure_node_steps:
             self.measurement_profiles["Node.Steps"] = MeasurementProfile(
                     profile_data=tree_node_distance_matrix.distances(
                     is_weighted_edge_distances=False,
                     is_normalize_by_tree_size=self.is_normalize,))
     if self.is_measure_node_ages:
         node_ages = tree.calc_node_ages(ultrametricity_precision=self.ultrametricity_precision)
         if self.is_normalize:
             s = sum(node_ages)
             try:
                 normalized_node_ages = [a/s for a in node_ages]
                 node_ages = normalized_node_ages
             except ZeroDivisionError as e:
                 if self.is_skip_normalization_on_zero_division_error:
                     pass
                 else:
                     raise
         self.measurement_profiles["Node.Ages"] = MeasurementProfile(profile_data=node_ages,)
     if self.is_measure_coalescence_intervals:
         cf = coalescent.extract_coalescent_frames(
                 tree=tree,
                 ultrametricity_precision=self.ultrametricity_precision,)
         waiting_times = cf.values()
         if self.is_normalize:
             s = sum(waiting_times)
             try:
                 normalized_waiting_times = [w/s for w in waiting_times]
                 waiting_times = normalized_waiting_times
             except ZeroDivisionError as e:
                 if self.is_skip_normalization_on_zero_division_error:
                     pass
                 else:
                     raise
         self.measurement_profiles["Coalescence.Intervals"] = MeasurementProfile(profile_data=waiting_times,)