def part21_king(num_taxa_king, Ns_king): ##### Part 2: NJ vs SNJ vs RG vs CLRG print("Starting Part 21 for kingman tree") snj = spectraltree.SpectralNeighborJoining(spectraltree.JC_similarity_matrix) nj = spectraltree.NeighborJoining(spectraltree.JC_similarity_matrix) rg = spectraltree.RG(spectraltree.JC_distance_matrix) #clrg = spectraltree.CLRG() methods = [snj, nj,rg] alphabet = "DNA" ## Part 2.1: different N king_tree = spectraltree.unrooted_pure_kingman_tree(num_taxa_king) res_king21 = compare_methods.experiment(tree_list = [king_tree], sequence_model = sequence_model, Ns = Ns_king, methods = methods, mutation_rates=mutation_rates, reps_per_tree=5, alphabet=alphabet, verbose=True) return res_king21
def part21_bin(num_taxa_bin, Ns_bin): ##### Part 2: NJ vs SNJ vs RG vs CLRG print("Starting Part 21 for binary tree") snj = spectraltree.SpectralNeighborJoining(spectraltree.JC_similarity_matrix) nj = spectraltree.NeighborJoining(spectraltree.JC_similarity_matrix) rg = spectraltree.RG(spectraltree.JC_distance_matrix) #clrg = spectraltree.CLRG() methods = [snj, nj,rg] alphabet = "DNA" ## Part 2.1: different N bin_tree = spectraltree.balanced_binary(num_taxa_bin) res_bin21 = compare_methods.experiment(tree_list = [bin_tree], sequence_model = sequence_model, Ns = Ns_bin, methods = methods, mutation_rates=mutation_rates, reps_per_tree=5, alphabet=alphabet, verbose=True) return res_bin21
def part22_cat(num_taxa_s_cat, Ns_cat): ## Part 2.2: different Taxa print("Starting Part 22 for caterpillar trees") snj = spectraltree.SpectralNeighborJoining(spectraltree.JC_similarity_matrix) nj = spectraltree.NeighborJoining(spectraltree.JC_similarity_matrix) rg = spectraltree.RG(spectraltree.JC_distance_matrix) clrg = spectraltree.CLRG() methods = [snj, nj,rg] alphabet = "Binary" cat_trees = [spectraltree.lopsided_tree(num_taxa) for num_taxa in num_taxa_s_cat] res_cat22 = compare_methods.experiment(tree_list = cat_trees, sequence_model = sequence_model, Ns = Ns_cat, methods = methods, mutation_rates=mutation_rates, reps_per_tree=5, alphabet=alphabet , verbose=True) return res_cat22
def part21_cat(num_taxa_cat, Ns_cat): ##### Part 2: NJ vs SNJ vs RG vs CLRG print("Starting Part 21 for caterpillar tree") snj = spectraltree.SpectralNeighborJoining(spectraltree.JC_similarity_matrix) nj = spectraltree.NeighborJoining(spectraltree.JC_similarity_matrix) rg = spectraltree.RG(spectraltree.JC_distance_matrix) #clrg = spectraltree.CLRG() methods = [snj, nj,rg] alphabet = "DNA" ## Part 2.1: different N cat_tree = spectraltree.lopsided_tree(num_taxa_cat) res_cat21 = compare_methods.experiment(tree_list = [cat_tree], sequence_model = sequence_model, Ns = Ns_cat, methods = methods, mutation_rates=mutation_rates, reps_per_tree=5, alphabet=alphabet, verbose=True) return res_cat21
def part22_king(num_taxa_s_king, Ns_king): ## Part 2.2: different Taxa print("Starting Part 22 for kingman trees") snj = spectraltree.SpectralNeighborJoining(spectraltree.JC_similarity_matrix) nj = spectraltree.NeighborJoining(spectraltree.JC_similarity_matrix) rg = spectraltree.RG(spectraltree.JC_distance_matrix) clrg = spectraltree.CLRG() methods = [snj, nj,rg] alphabet = "DNA" king_trees = [spectraltree.unrooted_pure_kingman_tree(num_taxa) for num_taxa in num_taxa_s_king] res_king22 = compare_methods.experiment(tree_list = king_trees, sequence_model = sequence_model, Ns = Ns_king, methods = methods, mutation_rates=mutation_rates, reps_per_tree=5, alphabet=alphabet , verbose=True) return res_king22
def part22_bin(num_taxa_s_bin, Ns_bin): ## Part 2.2: different Taxa print("Starting Part 22 for binary trees") snj = spectraltree.SpectralNeighborJoining(spectraltree.JC_similarity_matrix) nj = spectraltree.NeighborJoining(spectraltree.JC_similarity_matrix) rg = spectraltree.RG(spectraltree.JC_distance_matrix) clrg = spectraltree.CLRG() methods = [snj, nj,rg] alphabet = "DNA" bin_trees = [spectraltree.balanced_binary(num_taxa) for num_taxa in num_taxa_s_bin] res_bin22 = compare_methods.experiment(tree_list = bin_trees, sequence_model = sequence_model, Ns = Ns_bin, methods = methods, mutation_rates=mutation_rates, reps_per_tree=5, alphabet=alphabet , verbose=True) return res_bin22
def test_jukes_cantor(self): # reference_tree = spectraltree.unrooted_birth_death_tree(num_taxa, birth_rate=1, rng=) # reference_tree = spectraltree.lopsided_tree(num_taxa) reference_tree = spectraltree.balanced_binary(8) jc = spectraltree.Jukes_Cantor(num_classes=2) observations, meta = spectraltree.simulate_sequences( seq_len=10_000, tree_model=reference_tree, seq_model=jc, mutation_rate=jc.p2t(0.98), rng=default_rng(678), alphabet="Binary") rg = spectraltree.RG(spectraltree.JC_distance_matrix) recoverd_tree = rg(observations, meta) print("(RF distance,F1 score):", spectraltree.compare_trees(reference_tree, recoverd_tree)) self.assertTrue(spectraltree.topos_equal( reference_tree, recoverd_tree)) # this doesn't work very well
import spectraltree import spectraltree.compare_methods as compare_methods tree_list = [spectraltree.balanced_binary(32)] jc = spectraltree.Jukes_Cantor(num_classes=2) Ns = [100,200,300] mutation_rates = [jc.p2t(0.9)] snj = spectraltree.SpectralNeighborJoining(spectraltree.JC_similarity_matrix) nj = spectraltree.NeighborJoining(spectraltree.JC_similarity_matrix) RG = spectraltree.RG(spectraltree.JC_distance_matrix) CLRG = spectraltree.CLRG() methods = [nj,snj,RG,CLRG] num_reps = 1 results = compare_methods.experiment(tree_list = tree_list, sequence_model = jc, Ns = Ns, methods=methods, mutation_rates = mutation_rates, reps_per_tree=num_reps,savepath='balanced_binary_m_512.pkl',folder = './data/',overwrite=True) df = compare_methods.results2frame(results) print(df) a =1