I have created a cophenetic distance matrix in dendropy using:
from dendropy.simulate import treesim
tree = treesim.birth_death_tree(birth_rate=1.0, death_rate=0.5, ntax=10)
pdm = tree.phylogenetic_distance_matrix()
However, having read the documentation and trying many things I cannot extract the actual matrix in a usable manner from the object "pdm"
NB there is a method as_data_table
with this class that I am also unable to fathom
as_data_table()
returns an object of type dendropy.utility.container.DataTable
. This DataTable
is a custom container class, which implements lots of useful methods you can use to get at your data. You can read the source here to understand it:
https://dendropy.org/_modules/dendropy/utility/container.html
You can very quickly see the data in a format you can understand by looking at its _data
variable:
from dendropy.simulate import treesim
import pprint
tree = treesim.birth_death_tree(birth_rate=1.0, death_rate=0.5, ntax=10)
pdm = tree.phylogenetic_distance_matrix()
pp = pprint.PrettyPrinter(depth=2)
pp.pprint(pdm.as_data_table()._data)
Outputs:
{'T1': {'T1': 0.0,
'T10': 1.832709865628535,
'T2': 2.2418431376329204,
'T3': 1.8146189808922477,
'T4': 1.832709865628535,
'T5': 1.832709865628535,
'T6': 0.5848837844916799,
'T7': 0,
'T8': 1.6307174196094565,
'T9': 1.8146189808922477},
'T10': {'T1': 1.832709865628535,
'T10': 0.0,
'T2': 2.2418431376329204,
'T3': 1.832709865628535,
'T4': 0.8434862029618123,
'T5': 1.215095937098336,
'T6': 1.832709865628535,
'T7': 1.832709865628535,
'T8': 1.832709865628535,
'T9': 1.832709865628535},
'T2': {'T1': 2.2418431376329204,
'T10': 2.2418431376329204,
'T2': 0.0,
'T3': 2.2418431376329204,
'T4': 2.2418431376329204,
'T5': 2.2418431376329204,
'T6': 2.2418431376329204,
'T7': 2.2418431376329204,
'T8': 2.2418431376329204,
'T9': 2.2418431376329204},
'T3': {'T1': 1.8146189808922477,
'T10': 1.832709865628535,
'T2': 2.2418431376329204,
'T3': 0.0,
'T4': 1.832709865628535,
'T5': 1.832709865628535,
'T6': 1.8146189808922477,
'T7': 1.8146189808922477,
'T8': 1.8146189808922477,
'T9': 1.4811625503429378},
'T4': {'T1': 1.832709865628535,
'T10': 0.8434862029618123,
'T2': 2.2418431376329204,
'T3': 1.832709865628535,
'T4': 0.0,
'T5': 1.215095937098336,
'T6': 1.832709865628535,
'T7': 1.832709865628535,
'T8': 1.832709865628535,
'T9': 1.832709865628535},
'T5': {'T1': 1.832709865628535,
'T10': 1.215095937098336,
'T2': 2.2418431376329204,
'T3': 1.832709865628535,
'T4': 1.215095937098336,
'T5': 0.0,
'T6': 1.832709865628535,
'T7': 1.832709865628535,
'T8': 1.832709865628535,
'T9': 1.832709865628535},
'T6': {'T1': 0.5848837844916799,
'T10': 1.832709865628535,
'T2': 2.2418431376329204,
'T3': 1.8146189808922477,
'T4': 1.832709865628535,
'T5': 1.832709865628535,
'T6': 0.0,
'T7': 0.5848837844916799,
'T8': 1.6307174196094565,
'T9': 1.8146189808922477},
'T7': {'T1': 0,
'T10': 1.832709865628535,
'T2': 2.2418431376329204,
'T3': 1.8146189808922477,
'T4': 1.832709865628535,
'T5': 1.832709865628535,
'T6': 0.5848837844916799,
'T7': 0.0,
'T8': 1.6307174196094565,
'T9': 1.8146189808922477},
'T8': {'T1': 1.6307174196094565,
'T10': 1.832709865628535,
'T2': 2.2418431376329204,
'T3': 1.8146189808922477,
'T4': 1.832709865628535,
'T5': 1.832709865628535,
'T6': 1.6307174196094565,
'T7': 1.6307174196094565,
'T8': 0.0,
'T9': 1.8146189808922477},
'T9': {'T1': 1.8146189808922477,
'T10': 1.832709865628535,
'T2': 2.2418431376329204,
'T3': 1.4811625503429378,
'T4': 1.832709865628535,
'T5': 1.832709865628535,
'T6': 1.8146189808922477,
'T7': 1.8146189808922477,
'T8': 1.8146189808922477,
'T9': 0.0}}