def calc_histogram(tree_data, d, t, l, time_it, normalize=False, zero_loss=False): """ Compute the PDV from a .newick file :param tree_data <_ReconInput> - Output of newickFormatReader.getInput() :param d <float> - the cost of a duplication :param t <float> - ^^ transfer :param l <float> - ^^ loss :param time_it <bool> - collect timing info :param normalize <bool> - normalize the histogram by the size of the gene tree :param zero_loss <bool> - ignore loss events :return diameter_alg_hist <Histogram> - the PDV for the given .newick :return elapsed <float> - the time it took to compute the PDV None if time_it is False """ # From the newick tree create the reconciliation graph edge_species_tree, edge_gene_tree, dtl_recon_graph, mpr_count, best_roots \ = recongraph_tools.reconcile(tree_data, d, t, l) # If we want to know the number of MPRs #print(mpr_count) # Reformat the host and parasite tree to use it with the histogram algorithm gene_tree, gene_tree_root, gene_node_count = diameter.reformat_tree( edge_gene_tree, "pTop") species_tree, species_tree_root, species_node_count \ = diameter.reformat_tree(edge_species_tree, "hTop") if time_it: start = time.time() # Calculate the histogram via histogram algorithm diameter_alg_hist = histogram_alg.diameter_algorithm( species_tree, gene_tree, gene_tree_root, dtl_recon_graph, dtl_recon_graph, False, zero_loss) if time_it: end = time.time() elapsed = end - start else: elapsed = None if normalize: # Number of internal gene tree nodes gene_tree_nodes = int(math.ceil(len(gene_tree) / 2.0)) diameter_alg_hist = diameter_alg_hist.xscale(1.0 / (2 * gene_tree_nodes)) return diameter_alg_hist, elapsed
def draw_on(self, axes: plt.Axes): """ Draw Pairwise Distance Histogram on axes """ # Reformat the host and parasite tree to use it with the histogram algorithm parasite_tree, parasite_tree_root, parasite_node_count = diameter.reformat_tree( self.recon_input.parasite_dict, "pTop") host_tree, host_tree_root, host_node_count \ = diameter.reformat_tree(self.recon_input.host_dict, "hTop") hist = histogram_alg.diameter_algorithm(host_tree, parasite_tree, parasite_tree_root, self.recongraph, self.recongraph, False, False) histogram_display.plot_histogram_to_ax(axes, hist.histogram_dict)
def get_hist(g): h = histogram_alg.diameter_algorithm(species_tree, gene_tree, gene_root, g, g, False, False) return h.histogram_dict
def score(g): hist = histogram_alg.diameter_algorithm(species_tree, gene_tree, gene_root, g, g, False, False) return hist.mean()