In [ ]:
import numpy as np
In [ ]:
import treedist
from skbio import TreeNode, DistanceMatrix, TabularMSA, DNA
from scipy.spatial.distance import hamming
import ete3
In [ ]:
In [ ]:
#aln = TabularMSA.read('../runs/run_2016-03-17/all_genomes-0.1.fasta', constructor=DNA)
aln = TabularMSA.read('../runs/run_2016-03-17/ali', constructor=DNA)
In [ ]:
ad = DistanceMatrix.from_iterable([seq.values for seq in aln], metric=hamming, keys=aln.index)
In [ ]:
t = ete3.Tree('../runs/run_2016-03-17/data/125467289/population.nwk')
In [ ]:
In [ ]:
import string
string.ascii_uppercase
In [ ]:
_, maxdist = t.get_farthest_leaf()
maxdist
In [ ]:
list(sorted(t.get_leaf_names()))
In [ ]:
from math import ceil, log
In [ ]:
ceil(log(101)/log(10))
In [ ]:
import itertools as itl
itl.product(string.ascii_uppercase, )
In [ ]:
?itl.product
In [ ]:
t = ete3.Tree('../runs/run_2016-03-17/data/125467289/population.nwk')a
In [ ]:
dists = []
for a, b in itl.combinations(t.get_leaf_names(), 2):
a = t&a
dists.append(a.get_distance(b))
In [ ]:
from statistics import median, mean
In [ ]:
mean(dists)
In [ ]:
t.get_farthest_leaf()
In [ ]:
In [ ]:
def pwdist()
In [ ]:
t = ete3.Tree('../runs/run_2016-03-17/data/125467289/population.nwk')
_, maxdist = t.get_farthest_leaf()
for ch in t.iter_descendants():
ch.dist /= maxdist
In [ ]:
t.write(format=5)
In [ ]:
t.write?
In [ ]:
#t.convert_to_ultrametric()
print(t.get_ascii())
x = t.describe()
In [ ]:
x
In [ ]:
l = list(t.iter_descendants())
a = l[0]
a.dist /= t.describe(
In [ ]:
t = TreeNode.read('../runs/run_2016-03-17/data/125467289/population.nwk')
In [ ]:
t.tip_tip_distances()
In [ ]:
print(t.ascii_art())
In [ ]:
d = DistanceMatrix.read('../runs/run_2016-03-17/data/125467289/kwip/100x-0.01-wip.dist')
d.filter(sorted(d.ids))
In [ ]:
treedist.partition_weighted_distance('../runs/run_2016-03-17/data/125467289/population.nwk')
In [ ]:
from glob import glob
In [ ]:
In [ ]:
distfiles = glob("../runs/2016-03-15_genomics-nci/125467289/kwip/*.dist")
In [ ]:
truth = treedist.get_truth(treef, 3)
In [ ]:
truth
In [ ]:
treef = '../runs/2016-03-15_genomics-nci/125467289/population.nwk'
In [ ]:
treedist.get_table(treef, distfiles)k
In [ ]: