Exemplo n.º 1
0
 def getsubmod(self, choice="F81"):
     if choice == "F81":
         return substitution_model.TimeReversibleNucleotide(model_gaps=True)
     else:
         return substitution_model.TimeReversibleNucleotide(
             model_gaps=True, predicates={"kappa": "transition"}
         )
Exemplo n.º 2
0
    def test_get_param_list(self):
        """testing getting the parameter list"""
        model = substitution_model.TimeReversibleNucleotide()
        self.assertEqual(model.get_param_list(), [])

        model = substitution_model.TimeReversibleNucleotide(
            predicates=["beta:transition"])
        self.assertEqual(model.get_param_list(), ["beta"])
Exemplo n.º 3
0
def _est_simulations():
    # specify the 4 taxon tree, and a 'dummy' alignment
    t = make_tree(treestring="(a:0.4,b:0.3,(c:0.15,d:0.2)edge.0:0.1)root;")

    # how long the simulated alignments should be
    # at 1000000 the estimates get nice and close
    length_of_align = 10000

    #########################
    #
    # For a Jukes Cantor model
    #
    #########################

    sm = substitution_model.TimeReversibleNucleotide()
    lf = sm.make_likelihood_function(t)
    lf.set_constant_lengths()
    lf.set_name("True JC model")
    print(lf)
    simulated = lf.simulate_alignment(sequence_length=length_of_align)
    print(simulated)

    new_lf = sm.make_likelihood_function(t)
    new_lf = new_lf.set_alignment(simulated)
    new_lf.optimise(tolerance=1.0)
    new_lf.optimise(local=True)
    new_lf.set_name("True JC model")
    print(new_lf)

    #########################
    #
    # a Kimura model
    #
    #########################

    # has a ts/tv term, different values for every edge
    sm = substitution_model.TimeReversibleNucleotide(
        predicates={"kappa": "transition"})
    lf = sm.make_likelihood_function(t)
    lf.set_constant_lengths()
    lf.set_param_rule("kappa", is_constant=True, value=4.0, edge_name="a")
    lf.set_param_rule("kappa", is_constant=True, value=0.5, edge_name="b")
    lf.set_param_rule("kappa", is_constant=True, value=0.2, edge_name="c")
    lf.set_param_rule("kappa", is_constant=True, value=3.0, edge_name="d")
    lf.set_param_rule("kappa", is_constant=True, value=2.0, edge_name="edge.0")
    lf.set_name("True Kappa model")
    print(lf)
    simulated = lf.simulate_alignment(sequence_length=length_of_align)
    print(simulated)
    new_lf = sm.make_likelihood_function(t)
    new_lf.set_param_rule("kappa", is_independent=True)
    new_lf.set_alignment(simulated)
    new_lf.optimise(tolerance=1.0)
    new_lf.optimise(local=True)
    new_lf.set_name("Estimated Kappa model")
    print(new_lf)
Exemplo n.º 4
0
 def test_isIndel(self):
     """testing indel comparison nucleotide model"""
     model = substitution_model.TimeReversibleNucleotide(model_gaps=True)
     isIndel = model.get_predefined_predicate("indel")
     assert isIndel("A", "-")
     assert isIndel("-", "G")
     # assert not self.submodel.isIndel('-', '-')
     assert not isIndel("a", "t")
Exemplo n.º 5
0
 def _makeModel(self, predicates, scale_rules=None):
     scale_rules = scale_rules or []
     return substitution_model.TimeReversibleNucleotide(
         equal_motif_probs=True,
         model_gaps=False,
         predicates=predicates,
         scales=scale_rules,
     )
Exemplo n.º 6
0
 def test_nonrev_exception(self):
     """constructing a Nucleotide model with non-reversible preds raises exception"""
     preds = predicate.MotifChange("A", "G", forward_only=True)
     with self.assertRaises(ValueError):
         sm = substitution_model.TimeReversibleNucleotide(
             predicates=[preds])
Exemplo n.º 7
0
 def test_getMotifs(self):
     """testing return of motifs"""
     model_motifs = substitution_model.TimeReversibleNucleotide(
     ).get_motifs()
Exemplo n.º 8
0
 def test_includinggaps(self):
     """testing excluding gaps from model"""
     model = substitution_model.TimeReversibleNucleotide(model_gaps=True)
     assert len(model.get_alphabet()) == 5
Exemplo n.º 9
0
 def setUp(self):
     self.submodel = substitution_model.TimeReversibleNucleotide(
         motif_length=3, mprob_model="tuple")
Exemplo n.º 10
0
 def setUp(self):
     self.submodel = substitution_model.TimeReversibleNucleotide(
         model_gaps=False)