def get_median(graph): """ Returns the median :param graph <dict> - the input graph :return random_median <dict> - the median """ median_graph, n_meds, median_roots = DTLMedian.get_median_graph( graph, gene_tree, species_tree, gene_root, best_roots) med_counts = DTLMedian.get_med_counts(median_graph, median_roots) random_median = DTLMedian.choose_random_median_wrapper( median_graph, median_roots, med_counts) return random_median
def event_support_hist(species_tree, gene_tree, gene_root, graph): """ Compute the event support histogram (x-axis is event support, y-axis is fraction of events with that support) :param species_tree <tree> :param gene_tree <tree> :param gene_root <node> :param graph <recon_graph> :return hist <array float> - fraction of events for each bin :return bins <array float> - RHS of each bin (see numpy.histogram) """ preorder_mapping_nodes = DTLMedian.mapping_node_sort(gene_tree, species_tree, list(graph.keys())) event_support, count = \ DTLMedian.generate_scores(list(reversed(preorder_mapping_nodes)), graph, gene_root) supports = list(event_support.values()) hist, bins = np.histogram(supports, bins=20, range=(0,1)) total = np.sum(hist) return hist / float(total), bins
def avg_event_support(species_tree, gene_tree, g, gene_root): """ Compute the average event support for a graph. :param species_tree <tree> :param gene_tree <tree> :param g <recon_graph> :param gene_root <node> :return <float> - the average event support in g """ # Compute the event support for each event preorder_mapping_nodes = DTLMedian.mapping_node_sort(gene_tree, species_tree, list(g.keys())) event_support, count = \ DTLMedian.generate_scores(list(reversed(preorder_mapping_nodes)), g, gene_root) # Take the average over each event total_support = 0 for support in event_support.values(): total_support += support return total_support / len(event_support)