Exemplo n.º 1
0
def main():
    # getting the tree
    tree_gen = Phylo.parse(PATH_EXAMPLE, 'newick')
    tree_object = next(tree_gen)

    # the tree basic information
    print(tree_info(tree_object))

    # drawing the tree
    Phylo.draw(tree_object)

    # distance comparing
    tns = dendropy.TaxonNamespace()
    tre_one = Tree.get_from_path(PATH_EXAMPLE, 'newick', taxon_namespace=tns)
    tre_two = Tree.get_from_path(PATH_BIF, 'newick', taxon_namespace=tns)

    euclidean_distance = treecompare.euclidean_distance(tre_one, tre_two)
    robinson_distance = treecompare.robinson_foulds_distance(tre_one, tre_two)
    print("Robinson Foulds distance: ", robinson_distance)
    print("Euclidean distance: ", euclidean_distance)

    # common ancestors
    common_ancestor_tree = tree_object.common_ancestor({"name": "C"},
                                                       {"name": "D"})
    common_ancestor_tree.color = "blue"
    print("COMMON ANCESTOR: ", common_ancestor_tree)
    Phylo.draw(common_ancestor_tree)
Exemplo n.º 2
0
    def calcDistance(self):
        if self.path1 != '' and self.path2 != '':
            self.fileEx1 = (os.path.splitext(self.path1)[1])[1:]
            self.fileEx2 = (os.path.splitext(self.path2)[1])[1:]

            tns = dendropy.TaxonNamespace()
            self.tree1 = dendropy.Tree.get_from_path(self.path1, self.fileEx1, taxon_namespace=tns)
            self.tree2 = dendropy.Tree.get_from_path(self.path2, self.fileEx2, taxon_namespace=tns)

            self.tree1.encode_bipartitions()
            self.tree2.encode_bipartitions()

            print(treecompare.false_positives_and_negatives(self.tree1, self.tree2))

            # self.tree1 = dendropy.Tree.get_from_string('((A, B), (C, D))', 'newick')
            # self.tree2 = dendropy.Tree.get_from_string('((A, B), (C, D))', 'newick')

            # self.tree1.encode_bipartitions()
            # self.tree2.encode_bipartitions()

            # oblicz dystans
            # self.symDist = self.tree1.symmetric_difference(self.tree2)
            self.symDist = treecompare.symmetric_difference(self.tree1, self.tree2)
            self.fpnDist = treecompare.false_positives_and_negatives(self.tree1, self.tree2)
            self.eucDist = treecompare.euclidean_distance(self.tree1, self.tree2)
            self.rfDist = treecompare.robinson_foulds_distance(self.tree1, self.tree2)

            # pokaz wyniki
            self.res1.setText(str(self.eucDist)) #eucDist
            self.res2.setText(str(self.rfDist))  #rfDist
Exemplo n.º 3
0
def distance(file_path, file_format, file_path2):
    taxon_namespace = dendropy.TaxonNamespace()
    tree1 = dendropy.Tree.get_from_path(file_path,
                                        file_format,
                                        taxon_namespace=taxon_namespace)
    tree2 = dendropy.Tree.get_from_path(file_path2,
                                        file_format,
                                        taxon_namespace=taxon_namespace)
    sym_diff = treecompare.symmetric_difference(tree1, tree2)
    euc_dis = treecompare.euclidean_distance(tree1, tree2)
    false_pos = treecompare.false_positives_and_negatives(tree1, tree2)
    robinson_dis = treecompare.robinson_foulds_distance(tree1, tree2)
    print("Symetric difference: ", sym_diff)
    print("Robinson Foulds distance: ", robinson_dis)
    print("False positives and negatives: ", false_pos)
    print("Euclidean distance: ", euc_dis)
Exemplo n.º 4
0
    def calcDistance(self):
        if self.path1 != '' and self.path2 != '':
            self.fileEx1 = (os.path.splitext(self.path1)[1])[1:]
            self.fileEx2 = (os.path.splitext(self.path2)[1])[1:]

            tns = dendropy.TaxonNamespace()
            self.tree1 = dendropy.Tree.get_from_path(self.path1,
                                                     self.fileEx1,
                                                     taxon_namespace=tns)
            self.tree2 = dendropy.Tree.get_from_path(self.path2,
                                                     self.fileEx2,
                                                     taxon_namespace=tns)

            self.tree1.encode_bipartitions()
            self.tree2.encode_bipartitions()

            print(
                treecompare.false_positives_and_negatives(
                    self.tree1, self.tree2))

            # self.tree1 = dendropy.Tree.get_from_string('((A, B), (C, D))', 'newick')
            # self.tree2 = dendropy.Tree.get_from_string('((A, B), (C, D))', 'newick')

            # self.tree1.encode_bipartitions()
            # self.tree2.encode_bipartitions()

            # oblicz dystans
            # self.symDist = self.tree1.symmetric_difference(self.tree2)
            self.symDist = treecompare.symmetric_difference(
                self.tree1, self.tree2)
            self.fpnDist = treecompare.false_positives_and_negatives(
                self.tree1, self.tree2)
            self.eucDist = treecompare.euclidean_distance(
                self.tree1, self.tree2)
            self.rfDist = treecompare.robinson_foulds_distance(
                self.tree1, self.tree2)

            # pokaz wyniki
            self.res1.setText(str(self.eucDist))  #eucDist
            self.res2.setText(str(self.rfDist))  #rfDist
Exemplo n.º 5
0
    def calculateDistance(self):
        if self.path1 != '' and self.path2 != '':
            #get files extensions

            self.fileExtension1 = (os.path.splitext(self.path1)[1])[1:]
            self.fileExtension2 = (os.path.splitext(self.path2)[1])[1:]

            #open tree files
            tns = dendropy.TaxonNamespace()
            self.tree1 = dendropy.Tree.get_from_path(self.path1, self.fileExtension1, taxon_namespace=tns)
            self.tree2 = dendropy.Tree.get_from_path(self.path2, self.fileExtension2, taxon_namespace=tns)

            self.tree1.encode_bipartitions()
            self.tree2.encode_bipartitions()

            print(treecompare.false_positives_and_negatives(self.tree1, self.tree2))

            # self.tree1 = dendropy.Tree.get_from_string('((A, B), (C, D))', 'newick')
            # self.tree2 = dendropy.Tree.get_from_string('((A, B), (C, D))', 'newick')

            # self.tree1.encode_bipartitions()
            #self.tree2.encode_bipartitions()


            #calculate distances
            #self.symDist = self.tree1.symmetric_difference(self.tree2)
            self.symDist = treecompare.symmetric_difference(self.tree1, self.tree2)
            self.fpnDist = treecompare.false_positives_and_negatives(self.tree1, self.tree2)
            self.eucDist = treecompare.euclidean_distance(self.tree1, self.tree2)
            self.rfDist  = treecompare.robinson_foulds_distance(self.tree1, self.tree2)
            
            #show distances
            self.dist1Value.setText(str(self.eucDist))
            self.dist2Value.setText(str(self.rfDist))
            self.dist3Value.setText(str(self.symDist))
            self.dist4Value.setText(str(self.fpnDist))
import sys
import dendropy
from dendropy.calculate import treecompare

t1_filename = sys.argv[1]
t2_filename = sys.argv[2]

# Create taxon namespace
tns = dendropy.TaxonNamespace()

# Read in the trees
t1 = dendropy.Tree.get(path=t1_filename, schema="newick", taxon_namespace=tns)
t2 = dendropy.Tree.get(path=t2_filename, schema="newick", taxon_namespace=tns)

# Calculate rf distance
rf_dist = treecompare.robinson_foulds_distance(t1, t2)

# Calculate weighted rf distance
weighted_rf_dist = treecompare.weighted_robinson_foulds_distance(t1, t2)

print("Your rf dist: " + str(rf_dist) + ".")
print("Your weighted rf dist: " + str(weighted_rf_dist) + ".")
Exemplo n.º 7
0
import dendropy
from dendropy.calculate import treecompare

trees = dendropy.TreeList.get(path="pythonidae.random.bd0301.tre",
                              schema="nexus")

for tree in trees:
    print(tree.as_string("newick"))

print(len(trees))

print(trees[4].as_string("nexus"))
print(treecompare.robinson_foulds_distance(trees[0], trees[1]))
print(treecompare.weighted_robinson_foulds_distance(trees[0], trees[1]))

first_10_trees = trees[:10]
last_10_trees = trees[-10:]

# Note that the TaxonNamespace is propogated to slices
assert first_10_trees.taxon_namespace is trees.taxon_namespace
assert first_10_trees.taxon_namespace is trees.taxon_namespace

print(id(trees[4]))
print(id(trees[5]))
trees[4] = trees[5]
print(id(trees[4]))
print(id(trees[5]))
print(trees[4] in trees)

trees.remove(trees[-1])
tx = trees.pop()
Exemplo n.º 8
0
import dendropy
from dendropy.calculate import treecompare

trees = dendropy.TreeList.get(
        path="pythonidae.random.bd0301.tre",
        schema="nexus")

for tree in trees:
    print(tree.as_string("newick"))

print(len(trees))

print(trees[4].as_string("nexus"))
print(treecompare.robinson_foulds_distance(trees[0], trees[1]))
print(treecompare.weighted_robinson_foulds_distance(trees[0], trees[1]))

first_10_trees = trees[:10]
last_10_trees = trees[-10:]

# Note that the TaxonNamespace is propogated to slices
assert first_10_trees.taxon_namespace is trees.taxon_namespace
assert first_10_trees.taxon_namespace is trees.taxon_namespace


print(id(trees[4]))
print(id(trees[5]))
trees[4] = trees[5]
print(id(trees[4]))
print(id(trees[5]))
print(trees[4] in trees)