Пример #1
0
    def setUp(self):
        self.namespace1 = dendropy.TaxonNamespace(
            ["dog", "cat", "snake", "fish", "tree"])
        self.taxa1 = spectraltree.TaxaMetadata(self.namespace1,
                                               ["fish", "snake", "cat", "dog"],
                                               "DNA")
        self.dog = self.namespace1.get_taxon("dog")
        self.snake = self.namespace1.get_taxon("snake")

        self.array1 = np.array([
            [3, 1, 1, 0, 0],
            [3, 2, 1, 0, 0],
            [3, 2, 4, 0, 0],
            [2, 2, 0, 0, 0],
        ])

        self.tax2seq = {
            "fish": self.array1[0, :],
            "snake": self.array1[1, :],
            "cat": self.array1[2, :],
            "dog": self.array1[3, :],
        }

        d = {
            "fish": "TCCAA",
            "snake": "TGCAA",
            "cat": "TG-AA",
            "dog": "GGAAA",
        }
        self.dna_charmatrix = dendropy.DnaCharacterMatrix.from_dict(
            d, taxon_namespace=self.namespace1)

        self.tree = spectraltree.lopsided_tree(4, self.taxa1)
        self.dm = self.tree.phylogenetic_distance_matrix()
Пример #2
0
def part12_cat(num_taxa_s_cat, Ns_cat):
    ##### Part 1: NJ vs SNJ
    print("Starting Part 12")
    snj = spectraltree.SpectralNeighborJoining(spectraltree.JC_similarity_matrix)
    nj = spectraltree.NeighborJoining(spectraltree.JC_similarity_matrix)
    methods = [snj, nj]

    ## Part 1.2: different Taxa
    cat_trees = [spectraltree.lopsided_tree(num_taxa) for num_taxa in num_taxa_s_cat]
    res_cat12 = compare_methods.experiment(tree_list = cat_trees, sequence_model = sequence_model, Ns = Ns_cat, methods = methods, 
        mutation_rates=mutation_rates, reps_per_tree=5, verbose=True)
    return res_cat12
Пример #3
0
def part11_cat(num_taxa, Ns_cat):
    ##### Part 1: NJ vs SNJ
    print("Starting Part 11")
    snj = spectraltree.SpectralNeighborJoining(spectraltree.JC_similarity_matrix)
    nj = spectraltree.NeighborJoining(spectraltree.JC_similarity_matrix)
    methods = [snj, nj]

    ## Part 1.1: different N    
    #alphabet = "Binary"
    cat_tree = spectraltree.lopsided_tree(num_taxa)
    res_cat11 = compare_methods.experiment(tree_list = [cat_tree], sequence_model =sequence_model, Ns = Ns_cat, 
        methods = methods, mutation_rates=mutation_rates, reps_per_tree=5, verbose=True,
        savepath = '20200821_res12_cat_SNJPAPER',folder = './experiments/snj_paper_experiments/results/')
    return res_cat11
Пример #4
0
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
Пример #5
0
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
Пример #6
0
def part31_cat(num_taxa_cat, Ns_cat):
    ##### Part 3: NJ vs SNJ vs RG vs CLRG vs Forrest vs Tree_SVD
    print("Starting Part 31")
    snj = spectraltree.SpectralNeighborJoining(spectraltree.JC_similarity_matrix)
    nj = spectraltree.NeighborJoining(spectraltree.JC_similarity_matrix)
    #rg = spectraltree.RG(spectraltree.JC_distance_matrix)
    #clrg = spectraltree.CLRG()
    forrest = spectraltree.Forrest()
    tree_svd = spectraltree.TreeSVD()
    #methods = [snj, nj,rg,clrg, forrest,tree_svd]
    methods = [snj, nj, forrest,tree_svd]

    alphabet = "Binary"

    ## Part 3.1: different N
    
    cat_tree = spectraltree.lopsided_tree(num_taxa_cat)

    res_cat31  = compare_methods.experiment(tree_list = [cat_tree], sequence_model = sequence_model2, Ns = Ns_cat, methods = methods, mutation_rates=mutation_rates2, reps_per_tree=5, alphabet=alphabet, verbose=True)
    return res_cat31
Пример #7
0
    def test_angle_least_square(self):
        # copied from test_deep_spectral_tree_reonstruction
        N = 1000
        jc = spectraltree.Jukes_Cantor()
        mutation_rate = jc.p2t(0.95)
        num_itr = 2  #0
        #reference_tree = spectraltree.balanced_binary(num_taxa)
        lopsided_reference_tree = spectraltree.lopsided_tree(128)
        # reference_tree = spectraltree.unrooted_birth_death_tree(num_taxa, birth_rate=1)
        # for x in reference_tree.preorder_edge_iter():
        #     x.length = 1
        merging_method_list = ['least_square', 'angle']
        RF = {'least_square': [], 'angle': []}
        F1 = {'least_square': [], 'angle': []}
        for merge_method in merging_method_list:
            for i in range(num_itr):

                observations, taxa_meta = spectraltree.simulate_sequences(
                    seq_len=N,
                    tree_model=lopsided_reference_tree,
                    seq_model=jc,
                    mutation_rate=mutation_rate,
                    rng=np.random.default_rng(789))
                spectral_method = spectraltree.STDR(
                    spectraltree.NeighborJoining,
                    spectraltree.JC_similarity_matrix)
                tree_rec = spectral_method.deep_spectral_tree_reconstruction(
                    observations,
                    spectraltree.JC_similarity_matrix,
                    taxa_metadata=taxa_meta,
                    threshhold=16,
                    merge_method=merge_method)
                RF_i, F1_i = spectraltree.compare_trees(
                    tree_rec, lopsided_reference_tree)
                RF[merge_method].append(RF_i)
                F1[merge_method].append(F1_i)

        self.assertEqual(np.mean(RF['angle']), 0)
        self.assertEqual(np.mean(RF['least_square']), 0)
import metricNearness

N = 100
num_taxa = 60

#################################
## Tree generation
#################################
print("Creating tree")
jc = spectraltree.Jukes_Cantor()
hky = spectraltree.HKY(kappa=2)
mutation_rate = [jc.p2t(0.95)]
# mutation_rate = [0.1]

#reference_tree = spectraltree.unrooted_birth_death_tree(num_taxa, birth_rate=0.5)
reference_tree = spectraltree.lopsided_tree(num_taxa)
# reference_tree = spectraltree.balanced_binary(num_taxa)
# for x in reference_tree.preorder_edge_iter():
#     x.length = 0.5
print("Genration observations by JC and HKY")

observationsJC, metaJC = spectraltree.simulate_sequences(
    N,
    tree_model=reference_tree,
    seq_model=jc,
    mutation_rate=mutation_rate,
    alphabet="DNA")

#################################
## SNJ - Jukes_Cantor
#################################
Пример #9
0
 def setUp(self):
     self.reference_tree = spectraltree.lopsided_tree(32)