def BTC_networks_generator(taxa): """ Generator that yields all the BTC networks over taxa. """ if len(taxa) == 1: yield phylonetwork.PhyloNetwork(eNewick=taxa[0] + ';') return ell = taxa[-1] parent_generator = BTC_networks_generator(taxa[:-1]) for net in parent_generator: for augmented in BTC_offspring_generator(net, ell): yield augmented
def random_BTC_network(taxa): """ Returns a random BTC network over taxa. It uses a recursive implementation, where at each stage the generated network is chosen uniformly between its offspring (which does not imply that the overall procedure is uniform). """ if len(taxa) == 1: return phylonetwork.PhyloNetwork(eNewick=taxa[0] + ';') net_previous = random_BTC_network(taxa[:-1]) feasibles = feasible_pairs(net_previous) chosen = random.choice(feasibles) f = chosen[0] args = chosen[1:] return f(net_previous, taxa[-1], *args)
def read_enewick(s): return ph.PhyloNetwork(eNewick=s)
def treat_line(line): line = line.strip() net = phylonetwork.PhyloNetwork(eNewick=line) return count_feasible_pairs(net)
def treat_line(line): line = line.strip() net = phylonetwork.PhyloNetwork(eNewick=line) new_nets = BTC_offspring_generator(net, newlabel) return [net.eNewick() for net in new_nets]