File: treecalc.py

package info (click to toggle)
python-dendropy 4.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 68,392 kB
  • ctags: 3,947
  • sloc: python: 41,840; xml: 1,400; makefile: 15
file content (134 lines) | stat: -rw-r--r-- 7,258 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! /usr/bin/env python

##############################################################################
##  DendroPy Phylogenetic Computing Library.
##
##  Copyright 2010-2015 Jeet Sukumaran and Mark T. Holder.
##  All rights reserved.
##
##  See "LICENSE.rst" for terms and conditions of usage.
##
##  If you use this work or any portion thereof in published work,
##  please cite it as:
##
##     Sukumaran, J. and M. T. Holder. 2010. DendroPy: a Python library
##     for phylogenetic computing. Bioinformatics 26: 1569-1571.
##
##############################################################################

"""
DEPRECATED IN DENDROPY 4: USE
`dendropy.calculate.treecompare`,`dendropy.calculate.treemeasure`,
or `dendropy.calculate.treescore`,
"""

import dendropy
from dendropy.calculate import treecompare
from dendropy.calculate import treemeasure
from dendropy.calculate import treescore
from dendropy.utility import deprecate

##############################################################################
## dendropy.calculate.treemeasure

class PhylogeneticDistanceMatrix(dendropy.PhylogeneticDistanceMatrix):
    def __init__(self, tree=None):
        deprecate.dendropy_deprecation_warning(
                preamble="Deprecated since DendroPy 4: The 'dendropy.treecalc.PhylogeneticDistanceMatrix' class has moved to 'dendropy.PhylogeneticDistanceMatrix'.",
                old_construct="from dendropy import treecalc\npdm = treecalc.PhylogeneticDistanceMatrix(...)",
                new_construct="import dendropy\npdm = dendropy.PhylogeneticDistanceMatrix(...)")
        dendropy.PhylogeneticDistanceMatrix.__init__(self, tree=tree)

def patristic_distance(tree, taxon1, taxon2):
    deprecate.dendropy_deprecation_warning(
            preamble="Deprecated since DendroPy 4: The 'dendropy.treecalc.patristic_distance()' function has moved to 'dendropy.calculate.treemeasure.patristic_distance()'.",
            old_construct="from dendropy import treecalc\npdm = treecalc.patristic_distance(...)",
            new_construct="from dendropy.calculate import treemeasure\npdm = treemeasure.patristic_distance(...)")
    return treemeasure.patristic_distance(
            tree=tree,
            taxon1=taxon1,
            taxon2=taxon2)

##############################################################################
## dendropy.calculate.treecompare

def robinson_foulds_distance(tree1,
        tree2,
        edge_length_attr="length"):
    deprecate.dendropy_deprecation_warning(
            preamble="Deprecated since DendroPy 4: The 'dendropy.treecalc.robinson_foulds_distance()' function has moved to 'dendropy.calculate.treecompare.weighted_robinson_foulds_distance()'.",
            old_construct="from dendropy import treecalc\nd = treecalc.robinson_foulds_distance(...)",
            new_construct="from dendropy.calculate import treecompare\nd = treecompare.weighted_robinson_foulds_distance(...)")
    return treecompare.weighted_robinson_foulds_distance(
            tree1=tree1,
            tree2=tree2,
            edge_weight_attr=edge_length_attr)

def euclidean_distance(tree1,
        tree2,
        edge_length_attr="length",
        value_type=float):
    deprecate.dendropy_deprecation_warning(
            preamble="Deprecated since DendroPy 4: The 'dendropy.treecalc.euclidean_distance()' function has moved to 'dendropy.calculate.treecompare.euclidean_distance()'.",
            old_construct="from dendropy import treecalc\nd = treecalc.euclidean_distance(...)",
            new_construct="from dendropy.calculate import treecompare\nd = treecompare.euclidean_distance(...)")
    return treecompare.euclidean_distance(
            tree1=tree1,
            tree2=tree2,
            edge_weight_attr=edge_length_attr,
            value_type=value_type)

def false_positives_and_negatives(reference_tree, test_tree):
    deprecate.dendropy_deprecation_warning(
            preamble="Deprecated since DendroPy 4: The 'dendropy.treecalc.false_positives_and_negatives()' function has moved to 'dendropy.calculate.treecompare.false_positives_and_negatives()'.",
            old_construct="from dendropy import treecalc\nd = treecalc.false_positives_and_negatives(...)",
            new_construct="from dendropy.calculate import treecompare\nd = treecompare.false_positives_and_negatives(...)")
    return treecompare.false_positives_and_negatives(
            reference_tree=reference_tree,
            comparison_tree=test_tree)

def symmetric_difference(tree1, tree2):
    deprecate.dendropy_deprecation_warning(
            preamble="Deprecated since DendroPy 4: The 'dendropy.treecalc.symmetric_difference()' function has moved to 'dendropy.calculate.treecompare.symmetric_difference()'.",
            old_construct="from dendropy import treecalc\nd = treecalc.symmetric_difference(...)",
            new_construct="from dendropy.calculate import treecompare\nd = treecompare.symmetric_difference(...)")
    return treecompare.symmetric_difference(
            tree1=tree1,
            tree2=tree2)

def find_missing_splits(reference_tree, test_tree):
    deprecate.dendropy_deprecation_warning(
            preamble="Deprecated since DendroPy 4: The 'dendropy.treecalc.find_missing_splits()' function has moved to 'dendropy.calculate.treecompare.find_missing_splits()'.",
            old_construct="from dendropy import treecalc\nd = treecalc.find_missing_splits(...)",
            new_construct="from dendropy.calculate import treecompare\nd = treecompare.find_missing_splits(...)")
    return treecompare.find_missing_splits(
            reference_tree=reference_tree,
            comparison_tree=test_tree)

##############################################################################
## dendropy.calculate.treescore

# def fitch_up_pass(preorder_node_list, attr_name="state_sets", taxa_to_state_set_map=None):
#     deprecate.dendropy_deprecation_warning(
#             preamble="Deprecated since DendroPy 4: The 'dendropy.treecalc.euclidean_distance()' function has moved to 'dendropy.calculate.treecompare.euclidean_distance()'.",
#             old_construct="from dendropy import treecalc\nd = treecalc.euclidean_distance(...)",
#             new_construct="from dendropy.calculate import treecompare\nd = treecompare.euclidean_distance(...)")
#     return treecompare.euclidean_distance(
#             tree1=tree1,
#             tree2=tree2,
#             edge_weight_attr=edge_length_attr,
#             value_type=value_type)

# def fitch_down_pass(postorder_node_list, attr_name="state_sets", weight_list=None, taxa_to_state_set_map=None):
#     deprecate.dendropy_deprecation_warning(
#             preamble="Deprecated since DendroPy 4: The 'dendropy.treecalc.euclidean_distance()' function has moved to 'dendropy.calculate.treecompare.euclidean_distance()'.",
#             old_construct="from dendropy import treecalc\nd = treecalc.euclidean_distance(...)",
#             new_construct="from dendropy.calculate import treecompare\nd = treecompare.euclidean_distance(...)")
#     return treecompare.euclidean_distance(
#             tree1=tree1,
#             tree2=tree2,
#             edge_weight_attr=edge_length_attr,
#             value_type=value_type)

# def mason_gamer_kellogg_score(tree1, tree2):