import Bio Phylo BaseTree and _DistanceMatrix inside - #2229
Conversation
dd48e63 to
3b84b0f
Compare
karolamik13
left a comment
There was a problem hiding this comment.
The test is below. Looks good.
Outcome:
--- UPGMA tree ---
Tree type: Tree
Leaves: ['C', 'B', 'D', 'A']
Top-level clades: 2
--- Neighbor-joining tree ---
Tree type: Tree
Leaves: ['A', 'C', 'B', 'D']
Top-level clades: 3
--- Writing and reading Newick file ---
File created: True
Parsed tree type: Tree
Parsed leaves: ['C', 'B', 'D', 'A']
Used code:
from prody import *
import numpy as np
import os
names = ['A', 'B', 'C', 'D']
distance_matrix = np.array([
[0.0, 1.0, 2.0, 1.0],
[1.0, 0.0, 1.5, 2.0],
[2.0, 1.5, 0.0, 2.0],
[1.0, 2.0, 2.0, 0.0]])
print('--- UPGMA tree ---')
upgma_tree = calcTree(names, distance_matrix, method='upgma')
print('Tree type:', type(upgma_tree).name)
print('Leaves:', [leaf.name for leaf in upgma_tree.get_terminals()])
print('Top-level clades:', len(upgma_tree.root.clades))
print('\n--- Neighbor-joining tree ---')
nj_tree = calcTree(names, distance_matrix, method='nj')
print('Tree type:', type(nj_tree).name)
print('Leaves:', [leaf.name for leaf in nj_tree.get_terminals()])
print('Top-level clades:', len(nj_tree.root.clades))
print('\n--- Writing and reading Newick file ---')
filename = 'test_tree.nwk'
writeTree(filename, upgma_tree)
parsed_tree = parseTree(filename)
print('File created:', os.path.isfile(filename))
print('Parsed tree type:', type(parsed_tree).name)
print('Parsed leaves:', [leaf.name for leaf in parsed_tree.get_terminals()])
Otherwise, this breaks scipion importing prody