Skip to content

Commit 90789fc

Browse files
Mai To UyenMai To Uyen
Mai To Uyen
authored and
Mai To Uyen
committed
mv compute_Poisson_likelihood.py to Scripts
1 parent 4136152 commit 90789fc

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Scripts/compute_Poisson_likelihood.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#! /usr/bin/env
2+
3+
4+
from dendropy import Tree, TaxonNamespace
5+
from sys import argv
6+
import argparse
7+
from scipy.stats import poisson
8+
from math import log
9+
10+
parser = argparse.ArgumentParser()
11+
12+
parser.add_argument("-b","--bTree", required=True,help="Input tree with branch length in substitution unit")
13+
parser.add_argument("-c","--cTree", required=True,help="Calibrated tree. Must have the same rooted topology as bTree")
14+
parser.add_argument("-r","--rate", required=False,help="Global mutation rate. Default: 1.0")
15+
parser.add_argument("-l","--length", required=False,help="Sequence length. Default: 1000")
16+
parser.add_argument("-o","--output", required=True,help="Output file")
17+
18+
args = vars(parser.parse_args())
19+
20+
taxa = TaxonNamespace()
21+
22+
b_tree = Tree.get_from_path(args["bTree"],schema="newick",taxon_namespace=taxa)
23+
c_tree = Tree.get_from_path(args["cTree"],schema="newick",taxon_namespace=taxa)
24+
r = float(args["rate"]) if args["rate"] else 1.0
25+
l = float(args["length"]) if args["length"] else 1000
26+
27+
b_tree.is_rooted = True
28+
c_tree.is_rooted = True
29+
30+
b_tree.encode_bipartitions()
31+
c_tree.encode_bipartitions()
32+
33+
mapping = {}
34+
llh = 0
35+
36+
for node in b_tree.postorder_node_iter():
37+
if node is not b_tree.seed_node:
38+
mapping[node.bipartition] = node.edge_length
39+
40+
41+
for node in c_tree.postorder_node_iter():
42+
if node is not c_tree.seed_node:
43+
b = int(mapping[node.bipartition]*l)
44+
ld = int(node.edge_length*r*l)
45+
llh += log(poisson.pmf(b,ld))
46+
47+
with open(args["output"],'w') as fout:
48+
fout.write(str(llh) + "\n")

0 commit comments

Comments
 (0)