コード例 #1
0
ファイル: test_distance.py プロジェクト: yurong2020/cogent3
 def test_get_raw_estimates(self):
     """correctly return raw result object"""
     d = EstimateDistances(self.al, HKY85(), est_params=["kappa"])
     d.run(show_progress=False)
     expect = {
         ("a", "b"): {
             "kappa": 1.0000226766004808e-06,
             "length": 0.18232155856115662,
         },
         ("a", "c"): {
             "kappa": 1.0010380037049357e-06,
             "length": 0.087070406623635604,
         },
         ("a", "e"): {"kappa": 2.3965871843412687, "length": 0.4389176272584539},
         ("b", "e"): {"kappa": 2.3965871854366592, "length": 0.43891762729173389},
         ("b", "c"): {
             "kappa": 1.0010380037049357e-06,
             "length": 0.087070406623635604,
         },
         ("c", "e"): {"kappa": 0.57046787478038707, "length": 0.43260232210282784},
     }
     got = d.get_all_param_values()
     for pair in expect:
         for param in expect[pair]:
             self.assertAlmostEqual(got[pair][param], expect[pair][param], places=6)
コード例 #2
0
ファイル: test_distance.py プロジェクト: tla256/cogent3
 def test_EstimateDistances_other_model_params(self):
     """test getting other model params from EstimateDistances"""
     d = EstimateDistances(self.al, HKY85(), est_params=["kappa"])
     d.run(show_progress=False)
     # this will be a Number object with Mean, Median etc ..
     kappa = d.get_param_values("kappa")
     self.assertAlmostEqual(kappa.mean, 0.8939, 4)
     # this will be a dict with pairwise instances, it's called by the above
     # method, so the correctness of it's values is already checked
     kappa = d.get_pairwise_param("kappa")
コード例 #3
0
 def test_progressive_params(self):
     """excercise progressive alignment providing model params"""
     self._test_aln(
         {
             "A": "tacagta",
             "B": "tac-gtc",
             "C": "ta---ta",
             "D": "cac-cta"
         },
         model=HKY85(),
         param_vals=[("kappa", 2.0)],
     )
コード例 #4
0
ファイル: test_distance.py プロジェクト: tla256/cogent3
    def test_EstimateDistances_modify_lf(self):
        """tests modifying the lf"""
        def constrain_fit(lf):
            lf.set_param_rule("kappa", is_constant=True)
            lf.optimise(local=True)
            return lf

        d = EstimateDistances(self.al, HKY85(), modify_lf=constrain_fit)
        d.run(show_progress=False)
        result = d.get_pairwise_distances().to_dict()
        d = EstimateDistances(self.al, F81())
        d.run(show_progress=False)
        expect = d.get_pairwise_distances().to_dict()
        self.assertDistsAlmostEqual(expect, result)
コード例 #5
0
ファイル: test_distance.py プロジェクト: tla256/cogent3
 def test_EstimateDistancesWithMotifProbs(self):
     """EstimateDistances with supplied motif probs"""
     motif_probs = {"A": 0.1, "C": 0.2, "G": 0.2, "T": 0.5}
     d = EstimateDistances(self.al, HKY85(), motif_probs=motif_probs)
     d.run(show_progress=False)
     canned_result = {
         ("a", "c"): 0.07537,
         ("b", "c"): 0.07537,
         ("a", "e"): 0.39921,
         ("a", "b"): 0.15096,
         ("b", "e"): 0.39921,
         ("c", "e"): 0.37243,
     }
     result = d.get_pairwise_distances().to_dict()
     self.assertDistsAlmostEqual(canned_result, result)
コード例 #6
0
    def test_get_object_provenance(self):
        """correctly deduce object provenance"""
        result = get_object_provenance("abncd")
        self.assertEqual(result, "str")
        from cogent3 import DNA

        got = get_object_provenance(DNA)
        self.assertEqual(got, "cogent3.core.moltype.MolType")
        from cogent3.evolve.models import HKY85

        sm = HKY85()
        got = get_object_provenance(sm)
        self.assertEqual(
            got, "cogent3.evolve.substitution_model."
            "TimeReversibleNucleotide")
コード例 #7
0
 def test_get_param_matrix_coords(self):
     """return correct coords for continuous-time models"""
     f81 = F81()
     self.assertEqual(f81.get_param_matrix_coords(), {})
     self.assertTrue(
         len(f81.get_param_matrix_coords(include_ref_cell=True)["ref_cell"]) == 12
     )
     hky85 = HKY85()
     coords = hky85.get_param_matrix_coords()
     self.assertEqual(set(coords), set(["kappa"]))
     coords = hky85.get_param_matrix_coords(include_ref_cell=True)
     self.assertEqual(set(coords), set(["kappa", "ref_cell"]))
     gn = GN()
     coords = gn.get_param_matrix_coords(include_ref_cell=True)
     self.assertTrue(len(coords) == 12)
     self.assertTrue(len(coords["ref_cell"]) == 1)
コード例 #8
0
    def test_progressive_est_tree(self):
        """excercise progressive alignment without a guide tree"""
        seqs = make_unaligned_seqs(
            data={
                "A": "TGTGGCACAAATGCTCATGCCAGCTCTTTACAGCATGAGAACA",
                "B": "TGTGGCACAGATACTCATGCCAGCTCATTACAGCATGAGAACAGCAGTTT",
                "C": "TGTGGCACAAGTACTCATGCCAGCTCAGTACAGCATGAGAACAGCAGTTT",
            })
        aln, tree = cogent3.align.progressive.TreeAlign(
            HKY85(), seqs, show_progress=False, param_vals={"kappa": 4.0})

        expect = {
            "A": "TGTGGCACAAATGCTCATGCCAGCTCTTTACAGCATGAGAACA-------",
            "C": "TGTGGCACAAGTACTCATGCCAGCTCAGTACAGCATGAGAACAGCAGTTT",
            "B": "TGTGGCACAGATACTCATGCCAGCTCATTACAGCATGAGAACAGCAGTTT",
        }
        self.assertEqual(aln.to_dict(), expect)
コード例 #9
0
def get_root_alns(aln, ref_name, aln_flank):
    """returns alns from selected files, build a tree and produce ancestor 
    sequence and then project a sequence position onto the alignment position,
    and get the ancestral state, which is the mutation start state"""
    ref_seq = aln.get_seq(ref_name)
    variant = aln.get_seq(ref_name).add_feature('variant', 'variant',
                                                [(aln_flank, aln_flank + 1)])

    tree = LoadTree(tip_names=aln.names)
    sm = HKY85()
    lf = sm.make_likelihood_function(tree, digits=3, space=2)
    lf.set_alignment(aln)
    lf.optimise(show_progress=False, local=True)
    ancestor = lf.likely_ancestral_seqs()

    seq = ancestor.take_seqs(['root'])
    alns = aln.add_seqs(seq)

    return alns
コード例 #10
0
 def test_to_rich_dict(self):
     """returns complete dict of attributes"""
     f81 = F81().to_rich_dict()
     hky85 = HKY85().to_rich_dict()
     gn = GN().to_rich_dict()
コード例 #11
0
ファイル: test_distance.py プロジェクト: tla256/cogent3
 def test_no_calc(self):
     """returns None if no calculation done"""
     al = load_aligned_seqs("data/brca1_5.paml")
     d = EstimateDistances(al, submodel=HKY85())
     self.assertEqual(d.get_pairwise_distances(), None)