TreeSAK 1.48.2__tar.gz → 1.49.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {TreeSAK-1.48.2/TreeSAK.egg-info → TreeSAK-1.49.1}/PKG-INFO +2 -2
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/VERSION +5 -2
- TreeSAK-1.49.1/TreeSAK/VisHPD95.py +200 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/iTOL.py +41 -2
- TreeSAK-1.49.1/TreeSAK/mcmctree_vs_reltime.R +44 -0
- TreeSAK-1.49.1/TreeSAK/mcmctree_vs_reltime.py +252 -0
- TreeSAK-1.48.2/TreeSAK/VisHPD95.py → TreeSAK-1.49.1/TreeSAK/parse_mcmctree.py +12 -14
- TreeSAK-1.49.1/TreeSAK/tmp_3.py +120 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1/TreeSAK.egg-info}/PKG-INFO +2 -2
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK.egg-info/SOURCES.txt +4 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/bin/TreeSAK +11 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/LICENSE +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/MANIFEST.in +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/README.md +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ALE.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ALE1.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ALE2.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ALE2RTC.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ALE3.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ALE4.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ALE5.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ALE6.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ALE7.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ALE_backup.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/AssessCVG.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/AssessMarker.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/AssessMarkerDeltaLL.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/AssessMarkerPA.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/AssessPB.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/BMGE.jar +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/BMGE.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/CompareMCMC.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ConcateMSA.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ConvertMSA.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/Dir.rb +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ExtractMarkerSeq.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/FastRoot.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/FastRoot_backup.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/FigTree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/GTDB_tree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/GeneTree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/KEGG_Luo17.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/LcaToLeaves.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/MarkerRef2Tree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/MarkerRef2Tree_backup.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/MarkerSeq2Tree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/MarkerSeq2Tree_backup.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ModifyTopo.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/Newick_tree_plotter.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/OMA.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/OMA2.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/OneLineAln.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/PB.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/PMSF.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/PhyloBiAssoc.R +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/PhyloBiAssoc.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/PlotMCMC.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/PlotMcmcNode.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/PlotMcmcNode_old.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/RootTree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/RootTreeGTDB214.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/RootTreeGTDB220.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/SequentialDating.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/SingleAleHGT.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/SingleLinePhy.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/SliceMSA.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/SplitScore.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/SplitScore1.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/SplitScore1OMA.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/SplitScore2.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/TaxaCountStats.R +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/TaxonTree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/TreeSAK_config.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/VisHPD95.R +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/__init__.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ale_parser.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/ale_splitter.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/alignment_pruner.pl +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/assessOG.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/catfasta2phy.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/cogTree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/compare_trees.R +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/compare_trees.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/dating.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/dating_ss.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/deltall.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/do_rrtc.rb +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/fa2phy.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/format_leaf_name.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/gap_stats.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/get_SCG_tree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/get_arCOG_seq.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/global_functions.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/gnm_leaves.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/iTOL_gene_tree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/keep_highest_rrtc.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/koTree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/label_tree.R +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/label_tree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/mad.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/mcmc2tree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/mcmcTC copy.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/mcmcTC.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/merge_pdf.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/pRTC.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/parse_reltime.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/phy2fa.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/plot_distruibution_th.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/prep_mcmctree_ctl.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/print_leaves.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/pruneMSA.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/recode.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/remove_bias.R +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/rename_leaves.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/replace_clade.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/root_with_out_group.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/run_TaxaCountStats_R_s1.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/subsample_drep_gnms.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/subset.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/subset_tree_stupid_old_way.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/supertree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/tmp_1.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/tmp_2.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK/weighted_rand.rb +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK.egg-info/dependency_links.txt +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK.egg-info/requires.txt +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/TreeSAK.egg-info/top_level.txt +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/setup.cfg +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.1}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: TreeSAK
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.49.1
|
|
4
4
|
Summary: BioSAK
|
|
5
5
|
Home-page: https://github.com/songweizhi/TreeSAK
|
|
6
6
|
Author: Weizhi Song
|
|
@@ -24,4 +24,4 @@ Requires-Dist: kaleido
|
|
|
24
24
|
Requires-Dist: PyPDF3
|
|
25
25
|
Requires-Dist: dendropy
|
|
26
26
|
|
|
27
|
-
TreeSAK v1.
|
|
27
|
+
TreeSAK v1.49.1
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import glob
|
|
3
|
+
import argparse
|
|
4
|
+
from ete3 import Tree
|
|
5
|
+
from TreeSAK.TreeSAK_config import config_dict
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def mcmctree_out_to_tree_str(mamctree_out):
|
|
9
|
+
|
|
10
|
+
# get tree string from mamctree_out
|
|
11
|
+
tree_str = ''
|
|
12
|
+
tree_line = 0
|
|
13
|
+
current_line = 1
|
|
14
|
+
for each_line in open(mamctree_out):
|
|
15
|
+
if 'Species tree for FigTree. Branch lengths = posterior mean times; 95% CIs = labels' in each_line:
|
|
16
|
+
tree_line = current_line + 1
|
|
17
|
+
if tree_line == current_line:
|
|
18
|
+
tree_str = each_line.strip()
|
|
19
|
+
current_line += 1
|
|
20
|
+
|
|
21
|
+
tree_str_no_space = tree_str.replace(' ', '')
|
|
22
|
+
|
|
23
|
+
# rename tree nodes
|
|
24
|
+
t = Tree(tree_str_no_space, format=1)
|
|
25
|
+
for each_node in t.traverse():
|
|
26
|
+
if each_node.is_leaf():
|
|
27
|
+
node_name_new = '_'.join(each_node.name.split('_')[1:])
|
|
28
|
+
else:
|
|
29
|
+
node_name_new = 't_n%s' % each_node.name
|
|
30
|
+
each_node.name = node_name_new
|
|
31
|
+
|
|
32
|
+
tree_str_renamed = t.write(format=8)
|
|
33
|
+
|
|
34
|
+
return tree_str_renamed
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def get_internal_node_to_plot(node_txt, mo_file):
|
|
38
|
+
|
|
39
|
+
tree_str = ''
|
|
40
|
+
if os.path.isfile(mo_file):
|
|
41
|
+
tree_str = mcmctree_out_to_tree_str(mo_file)
|
|
42
|
+
|
|
43
|
+
# get nodes to plot
|
|
44
|
+
node_set = set()
|
|
45
|
+
node_rename_dict = dict()
|
|
46
|
+
if os.path.isfile(node_txt) is True:
|
|
47
|
+
for each in open(node_txt):
|
|
48
|
+
each_split = each.strip().split('\t')
|
|
49
|
+
node_str = each_split[0]
|
|
50
|
+
|
|
51
|
+
# get internal_node_to_plot
|
|
52
|
+
internal_node_to_plot = ''
|
|
53
|
+
if ',' not in node_str:
|
|
54
|
+
internal_node_to_plot = each_split[0]
|
|
55
|
+
else:
|
|
56
|
+
leaf_list = node_str.split(',')
|
|
57
|
+
if tree_str == '':
|
|
58
|
+
print('MCMCTree out file not found, program exited!')
|
|
59
|
+
exit()
|
|
60
|
+
current_lca = Tree(tree_str, format=1).get_common_ancestor(leaf_list)
|
|
61
|
+
internal_node_to_plot = current_lca.name
|
|
62
|
+
|
|
63
|
+
# add internal_node_to_plot to node_set
|
|
64
|
+
if internal_node_to_plot != '':
|
|
65
|
+
node_set.add(internal_node_to_plot)
|
|
66
|
+
|
|
67
|
+
# read in name to show in plot
|
|
68
|
+
if len(each_split) == 2:
|
|
69
|
+
if each_split[1] != '':
|
|
70
|
+
node_rename_dict[internal_node_to_plot] = each_split[1]
|
|
71
|
+
else:
|
|
72
|
+
node_set = node_txt.split(',')
|
|
73
|
+
|
|
74
|
+
return node_set, node_rename_dict, tree_str
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def read_in_posterior_mean(mcmctree_out):
|
|
78
|
+
|
|
79
|
+
# read in Posterior mean
|
|
80
|
+
node_to_mean_hpd95_dict = dict()
|
|
81
|
+
current_line = 1
|
|
82
|
+
posterior_mean_header_line = 0
|
|
83
|
+
for each_line in open(mcmctree_out):
|
|
84
|
+
if 'Posterior mean (95% Equal-tail CI) (95% HPD CI) HPD-CI-width' in each_line:
|
|
85
|
+
posterior_mean_header_line = current_line
|
|
86
|
+
|
|
87
|
+
if (posterior_mean_header_line != 0) and (current_line > posterior_mean_header_line):
|
|
88
|
+
each_line_split = each_line.strip().split(' ')
|
|
89
|
+
|
|
90
|
+
each_line_split_no_empty = []
|
|
91
|
+
for each_element in each_line_split:
|
|
92
|
+
if each_element not in ['', '(']:
|
|
93
|
+
each_element_value = each_element.replace('(', '').replace(')', '').replace(',', '')
|
|
94
|
+
each_line_split_no_empty.append(each_element_value)
|
|
95
|
+
if len(each_line_split_no_empty) == 9:
|
|
96
|
+
node_id = each_line_split_no_empty[0]
|
|
97
|
+
value_mean = each_line_split_no_empty[1]
|
|
98
|
+
value_hpd95_small = each_line_split_no_empty[4]
|
|
99
|
+
value_hpd95_big = each_line_split_no_empty[5]
|
|
100
|
+
node_to_mean_hpd95_dict[node_id] = [value_mean, value_hpd95_small, value_hpd95_big]
|
|
101
|
+
current_line += 1
|
|
102
|
+
|
|
103
|
+
return node_to_mean_hpd95_dict
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
VisHPD95_usage = '''
|
|
107
|
+
============================ VisHPD95 example command ============================
|
|
108
|
+
|
|
109
|
+
TreeSAK VisHPD95 -i mcmc_out -o HPD95.pdf -n nodes.txt -label label.txt
|
|
110
|
+
TreeSAK VisHPD95 -i mcmc_out -o HPD95.pdf -n nodes.txt -label label.txt -x 9 -y 6
|
|
111
|
+
|
|
112
|
+
# Example data
|
|
113
|
+
https://github.com/songweizhi/TreeSAK/tree/master/DemoData/VisHPD95
|
|
114
|
+
|
|
115
|
+
==================================================================================
|
|
116
|
+
'''
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def VisHPD95(args):
|
|
120
|
+
|
|
121
|
+
mcmc_in = args['i']
|
|
122
|
+
node_txt = args['n']
|
|
123
|
+
label_txt = args['label']
|
|
124
|
+
plot_out = args['o']
|
|
125
|
+
plot_width = args['x']
|
|
126
|
+
plot_height = args['y']
|
|
127
|
+
|
|
128
|
+
pwd_current_file = os.path.realpath(__file__)
|
|
129
|
+
current_file_path = '/'.join(pwd_current_file.split('/')[:-1])
|
|
130
|
+
VisHPD95_R = '%s/VisHPD95.R' % current_file_path
|
|
131
|
+
|
|
132
|
+
dm_out = '%s.txt' % plot_out
|
|
133
|
+
|
|
134
|
+
# check MCMCTree output file/dir
|
|
135
|
+
if os.path.isfile(mcmc_in) is True:
|
|
136
|
+
mcmc_out_file_list = [mcmc_in]
|
|
137
|
+
else:
|
|
138
|
+
mcmc_out_file_re = '%s/*_out.txt' % (mcmc_in)
|
|
139
|
+
mcmc_out_file_list = glob.glob(mcmc_out_file_re)
|
|
140
|
+
|
|
141
|
+
if len(mcmc_out_file_list) == 0:
|
|
142
|
+
print('MCMCTree out file not found, program exited!')
|
|
143
|
+
exit()
|
|
144
|
+
|
|
145
|
+
# read in y-axis label file
|
|
146
|
+
label_dict = dict()
|
|
147
|
+
color_dict = dict()
|
|
148
|
+
shape_dict = dict()
|
|
149
|
+
if label_txt is not None:
|
|
150
|
+
for each_sample in open(label_txt):
|
|
151
|
+
each_sample_split = each_sample.strip().split('\t')
|
|
152
|
+
if len(each_sample_split) == 3:
|
|
153
|
+
label_dict[each_sample_split[0]] = each_sample_split[1]
|
|
154
|
+
color_dict[each_sample_split[0]] = each_sample_split[1]
|
|
155
|
+
shape_dict[each_sample_split[0]] = each_sample_split[2]
|
|
156
|
+
else:
|
|
157
|
+
print('Format error: %s' % label_txt)
|
|
158
|
+
exit()
|
|
159
|
+
|
|
160
|
+
dm_out_handle = open(dm_out, 'w')
|
|
161
|
+
dm_out_handle.write('Test\tShape\tVar\tMean\tLow\tHigh\n')
|
|
162
|
+
for mcmc_out_file in mcmc_out_file_list:
|
|
163
|
+
mcmc_out_file_no_path = mcmc_out_file
|
|
164
|
+
if '/' in mcmc_out_file_no_path:
|
|
165
|
+
mcmc_out_file_no_path = mcmc_out_file_no_path.split('/')[-1]
|
|
166
|
+
|
|
167
|
+
color_col_to_write = color_dict.get(mcmc_out_file_no_path, mcmc_out_file_no_path)
|
|
168
|
+
shape_col_to_write = shape_dict.get(mcmc_out_file_no_path, mcmc_out_file_no_path)
|
|
169
|
+
node_set, node_rename_dict, tree_str = get_internal_node_to_plot(node_txt, mcmc_out_file)
|
|
170
|
+
node_to_mean_95_hpd_dict = read_in_posterior_mean(mcmc_out_file)
|
|
171
|
+
|
|
172
|
+
for each_node in node_set:
|
|
173
|
+
node_name_to_write = node_rename_dict.get(each_node, each_node)
|
|
174
|
+
mean_95_hpd_list = node_to_mean_95_hpd_dict.get(each_node)
|
|
175
|
+
dm_out_handle.write('%s\t%s\t%s\t%s\n' % (color_col_to_write, shape_col_to_write, node_name_to_write, '\t'.join(mean_95_hpd_list)))
|
|
176
|
+
dm_out_handle.close()
|
|
177
|
+
|
|
178
|
+
plot_cmd = 'Rscript %s -i %s -x %s -y %s -o %s' % (VisHPD95_R, dm_out, plot_width, plot_height, plot_out)
|
|
179
|
+
os.system(plot_cmd)
|
|
180
|
+
print('Plot exported to: %s' % plot_out)
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
if __name__ == '__main__':
|
|
184
|
+
|
|
185
|
+
VisHPD95_parser = argparse.ArgumentParser()
|
|
186
|
+
VisHPD95_parser.add_argument('-i', required=True, help='mcmc.txt file or folder')
|
|
187
|
+
VisHPD95_parser.add_argument('-n', required=True, help='Nodes to plot')
|
|
188
|
+
VisHPD95_parser.add_argument('-label', required=False, default=None, help='labels on y axis')
|
|
189
|
+
VisHPD95_parser.add_argument('-x', required=False, default=8,type=int, help='plot width, default: 8')
|
|
190
|
+
VisHPD95_parser.add_argument('-y', required=False, default=5,type=int, help='plot height, default: 5')
|
|
191
|
+
VisHPD95_parser.add_argument('-o', required=True, help='Output plot')
|
|
192
|
+
args = vars(VisHPD95_parser.parse_args())
|
|
193
|
+
VisHPD95(args)
|
|
194
|
+
|
|
195
|
+
'''
|
|
196
|
+
|
|
197
|
+
cd /Users/songweizhi/Desktop/777
|
|
198
|
+
python3 ~/PycharmProjects/TreeSAK/TreeSAK/VisHPD95.py -i M1_mcmc_txt -o M1_HPD95.pdf -n nodes_five.txt -label y_label_out.txt
|
|
199
|
+
|
|
200
|
+
'''
|
|
@@ -5,11 +5,17 @@ import argparse
|
|
|
5
5
|
import seaborn as sns
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
'''
|
|
9
|
+
TreeSAK iTOL -ColorLabel -lg Mag_genus.txt -gc genus_color.txt-o ColorLabel_genus.txt
|
|
10
|
+
'''
|
|
11
|
+
|
|
8
12
|
iTOL_usage = '''
|
|
9
13
|
==================================== iTOL example commands ====================================
|
|
10
14
|
|
|
11
15
|
# Example commands
|
|
12
16
|
TreeSAK iTOL -Labels -ll new_Mag_name.txt -o Mag_name_iTOL_Labels.txt
|
|
17
|
+
TreeSAK iTOL -ColoredLabel -lg leaf_group.txt -gc group_color.txt -o iTOL_ColoredLabel.txt
|
|
18
|
+
TreeSAK iTOL -ColoredLabel -lg leaf_group.txt -gc group_color.txt -o iTOL_ColoredLabel.txt -ll new_Mag_name.txt
|
|
13
19
|
TreeSAK iTOL -Binary -lm Binary_matrix.txt -lt Enzyme -o Presence_Absence_iTOL.txt -cc "#F1BB83"
|
|
14
20
|
TreeSAK iTOL -Binary -lm Binary_matrix.txt -lt Enzyme -o Presence_Absence_iTOL.txt -cc col_color.txt
|
|
15
21
|
TreeSAK iTOL -BinaryID -id MagID.txt -lt dRep95 -o dRep95_representatives_iTOL.txt
|
|
@@ -19,7 +25,6 @@ TreeSAK iTOL -ColorStrip -lg MagTaxon.txt -lt Phylum -gc phylum_color.txt -o Col
|
|
|
19
25
|
TreeSAK iTOL -ColorRange -lg MagTaxon.txt -lt Phylum -gc phylum_color.txt -o ColorRange_taxon.txt
|
|
20
26
|
TreeSAK iTOL -ColorRange -taxon Taxonomy.txt -rank f -lt Family -o ColorRange_taxon.txt
|
|
21
27
|
TreeSAK iTOL -ColorClade -lg Mag_genus.txt -gc genus_color.txt-o ColorClade_genus.txt
|
|
22
|
-
TreeSAK iTOL -ColorLabel -lg Mag_genus.txt -gc genus_color.txt-o ColorLabel_genus.txt
|
|
23
28
|
TreeSAK iTOL -ExternalShape -lm identity_matrix.txt -lt Identity -scale 25-50-75-100 -o ExternalShape_identity.txt
|
|
24
29
|
TreeSAK iTOL -PieChart -lv MagCompleteness.txt -lt Completeness -o PieChart_completeness.txt
|
|
25
30
|
TreeSAK iTOL -Collapse -lg MagTaxon.txt -o Collapse_by_taxon.txt
|
|
@@ -116,6 +121,7 @@ def iTOL(args):
|
|
|
116
121
|
|
|
117
122
|
# read in arguments
|
|
118
123
|
Labels = args['Labels']
|
|
124
|
+
ColoredLabel = args['ColoredLabel']
|
|
119
125
|
ColorStrip = args['ColorStrip']
|
|
120
126
|
ColorRange = args['ColorRange']
|
|
121
127
|
ColorClade = args['ColorClade']
|
|
@@ -165,7 +171,7 @@ def iTOL(args):
|
|
|
165
171
|
|
|
166
172
|
# check the number of specified file type
|
|
167
173
|
True_num = 0
|
|
168
|
-
for file_type in [Labels, ColorStrip, ColorRange, SimpleBar, Heatmap, ExternalShape, Binary, BinaryID, PieChart, Collapse, ColorClade, ColorLabel]:
|
|
174
|
+
for file_type in [Labels, ColorStrip, ColorRange, SimpleBar, Heatmap, ExternalShape, Binary, BinaryID, PieChart, Collapse, ColorClade, ColorLabel, ColoredLabel]:
|
|
169
175
|
if file_type is True:
|
|
170
176
|
True_num += 1
|
|
171
177
|
|
|
@@ -178,6 +184,38 @@ def iTOL(args):
|
|
|
178
184
|
|
|
179
185
|
####################################################################################################################
|
|
180
186
|
|
|
187
|
+
if ColoredLabel is True:
|
|
188
|
+
|
|
189
|
+
leaf_label_dict = dict()
|
|
190
|
+
if LeafLabel is not None:
|
|
191
|
+
for each in open(LeafLabel):
|
|
192
|
+
each_split = each.strip().split('\t')
|
|
193
|
+
leaf_label_dict[each_split[0]] = each_split[1]
|
|
194
|
+
|
|
195
|
+
leaf_group_dict = dict()
|
|
196
|
+
for each in open(LeafGroup):
|
|
197
|
+
each_split = each.strip().split('\t')
|
|
198
|
+
leaf_group_dict[each_split[0]] = each_split[1]
|
|
199
|
+
|
|
200
|
+
group_color_dict = dict()
|
|
201
|
+
for each in open(GroupColor):
|
|
202
|
+
each_split = each.strip().split('\t')
|
|
203
|
+
group_color_dict[each_split[0]] = each_split[1]
|
|
204
|
+
|
|
205
|
+
FileOut_handle = open(FileOut, 'w')
|
|
206
|
+
FileOut_handle.write('DATASET_TEXT\n')
|
|
207
|
+
FileOut_handle.write('SEPARATOR TAB\n')
|
|
208
|
+
FileOut_handle.write('DATASET_LABEL\t%s\n' % 'ColoredLabel')
|
|
209
|
+
FileOut_handle.write('\nDATA\n')
|
|
210
|
+
for leaf in leaf_group_dict:
|
|
211
|
+
leaf_label = leaf_label_dict.get(leaf, leaf)
|
|
212
|
+
leaf_group = leaf_group_dict[leaf]
|
|
213
|
+
leaf_color = group_color_dict.get(leaf_group, '#000000')
|
|
214
|
+
FileOut_handle.write('%s\t%s\t-1\t%s\tnormal\t1\t0\n' % (leaf, leaf_label, leaf_color))
|
|
215
|
+
FileOut_handle.close()
|
|
216
|
+
|
|
217
|
+
####################################################################################################################
|
|
218
|
+
|
|
181
219
|
# Prepare ColorStrip and ColorRange file
|
|
182
220
|
if (ColorStrip is True) or (ColorRange is True):
|
|
183
221
|
|
|
@@ -716,6 +754,7 @@ if __name__ == '__main__':
|
|
|
716
754
|
|
|
717
755
|
iTOL_parser = argparse.ArgumentParser(usage=iTOL_usage)
|
|
718
756
|
iTOL_parser.add_argument('-Labels', required=False, action='store_true', help='Labels')
|
|
757
|
+
iTOL_parser.add_argument('-ColoredLabel', required=False, action='store_true', help='ColoredLabel')
|
|
719
758
|
iTOL_parser.add_argument('-MultiStyleLabel', required=False, action='store_true', help='MultiStyleLabel')
|
|
720
759
|
iTOL_parser.add_argument('-ColorStrip', required=False, action='store_true', help='ColorStrip')
|
|
721
760
|
iTOL_parser.add_argument('-ColorRange', required=False, action='store_true', help='ColorRange')
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
library(ggplot2)
|
|
2
|
+
library(optparse)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
plot_grouped_HPD95 <- function(data_file, plot_width, plot_height, plot_file){
|
|
6
|
+
|
|
7
|
+
dat <- read.table(data_file, header = T)
|
|
8
|
+
|
|
9
|
+
ggplot(dat, aes(x = Node, y = Mean, ymin = Low, ymax = High)) +
|
|
10
|
+
geom_pointrange(aes(col = factor(ColorBy)),
|
|
11
|
+
position=position_dodge(width=0.6), # controls distance between groups
|
|
12
|
+
linewidth = 0.9, # line width
|
|
13
|
+
size=0.75) + # size of shape
|
|
14
|
+
theme_bw() + # remove background
|
|
15
|
+
theme(panel.grid.major=element_blank(), # remove grid
|
|
16
|
+
panel.grid.minor=element_blank()) + # remove grid
|
|
17
|
+
xlab("") + # x-axis label text
|
|
18
|
+
ylab("95% HPD CI") + # y-axis label text
|
|
19
|
+
theme(axis.text.x=element_text(size=12, color='black', angle=30, hjust=1), # x-axis label, rotate at an angle of 45
|
|
20
|
+
axis.text.y=element_text(size=12, color='black'), # y-axis label
|
|
21
|
+
legend.text=element_text(size=10)) + # legend label
|
|
22
|
+
scale_color_discrete(name="Color") + # customize color legend, title
|
|
23
|
+
guides(color=guide_legend(override.aes=list(linetype=0))) + # customize color legend
|
|
24
|
+
coord_flip() # # plot vertically
|
|
25
|
+
|
|
26
|
+
# write to file
|
|
27
|
+
ggsave(plot_file, width=plot_width, height=plot_height, dpi=300)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
option_list = list(
|
|
32
|
+
make_option(c("-i", "--datain"), type="character", default=NULL, help="input data matrix"),
|
|
33
|
+
make_option(c("-x", "--width"), type="double", default=8, help="plot width"),
|
|
34
|
+
make_option(c("-y", "--height"), type="double", default=5, help="plot height"),
|
|
35
|
+
make_option(c("-o", "--plotout"), type="character", default=NULL, help="output plot"));
|
|
36
|
+
|
|
37
|
+
opt_parser = OptionParser(option_list=option_list);
|
|
38
|
+
opt = parse_args(opt_parser);
|
|
39
|
+
data_matrix_txt = opt$datain
|
|
40
|
+
plot_width = opt$width
|
|
41
|
+
plot_height = opt$height
|
|
42
|
+
output_plot = opt$plotout
|
|
43
|
+
|
|
44
|
+
plot_grouped_HPD95(data_matrix_txt, plot_width, plot_height, output_plot)
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import argparse
|
|
3
|
+
from ete3 import Tree
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
mcmctree_vs_reltime_usage = '''
|
|
7
|
+
====================== mcmctree_vs_reltime example command ======================
|
|
8
|
+
|
|
9
|
+
TreeSAK mcmctree_vs_reltime -m mcmc.out -r reltime.txt -n nodes.txt -o ages.pdf
|
|
10
|
+
|
|
11
|
+
# Example data
|
|
12
|
+
https://github.com/songweizhi/TreeSAK/tree/master/DemoData/mcmctree_vs_reltime
|
|
13
|
+
|
|
14
|
+
=================================================================================
|
|
15
|
+
'''
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def sep_path_basename_ext(file_in):
|
|
19
|
+
|
|
20
|
+
f_path, f_name = os.path.split(file_in)
|
|
21
|
+
if f_path == '':
|
|
22
|
+
f_path = '.'
|
|
23
|
+
f_base, f_ext = os.path.splitext(f_name)
|
|
24
|
+
|
|
25
|
+
return f_name, f_path, f_base, f_ext[1:]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_lca(reltime_txt, leaf_1_name, leaf_2_name):
|
|
29
|
+
|
|
30
|
+
leaf_set = set()
|
|
31
|
+
child_to_parent_dict = dict()
|
|
32
|
+
id_to_name_dict = dict()
|
|
33
|
+
name_to_id_dict = dict()
|
|
34
|
+
for each_line in open(reltime_txt):
|
|
35
|
+
if not each_line.startswith('NodeLabel'):
|
|
36
|
+
each_line_split = each_line.strip().split('\t')
|
|
37
|
+
each_line_split = [i.strip() for i in each_line_split]
|
|
38
|
+
if len(each_line_split) > 1:
|
|
39
|
+
node_name = each_line_split[0].replace(' ', '_')
|
|
40
|
+
node_id = each_line_split[1]
|
|
41
|
+
des1 = each_line_split[2]
|
|
42
|
+
des2 = each_line_split[3]
|
|
43
|
+
id_to_name_dict[node_id] = node_name
|
|
44
|
+
name_to_id_dict[node_name] = node_id
|
|
45
|
+
child_to_parent_dict[des1] = node_id
|
|
46
|
+
child_to_parent_dict[des2] = node_id
|
|
47
|
+
if (des1 == '-') and (des2 == '-'):
|
|
48
|
+
leaf_set.add(node_id)
|
|
49
|
+
|
|
50
|
+
leaf_to_lineage_dict = dict()
|
|
51
|
+
for leaf in sorted([i for i in leaf_set]):
|
|
52
|
+
original_leaf = leaf
|
|
53
|
+
lineage_list = [leaf]
|
|
54
|
+
while leaf in child_to_parent_dict:
|
|
55
|
+
leaf_p = child_to_parent_dict[leaf]
|
|
56
|
+
lineage_list.append(leaf_p)
|
|
57
|
+
leaf = leaf_p
|
|
58
|
+
leaf_to_lineage_dict[original_leaf] = lineage_list
|
|
59
|
+
|
|
60
|
+
leaf_1_id = name_to_id_dict[leaf_1_name]
|
|
61
|
+
leaf_2_id = name_to_id_dict[leaf_2_name]
|
|
62
|
+
leaf_1_linage = leaf_to_lineage_dict[leaf_1_id]
|
|
63
|
+
leaf_2_linage = leaf_to_lineage_dict[leaf_2_id]
|
|
64
|
+
|
|
65
|
+
lca = ''
|
|
66
|
+
for each_p in leaf_1_linage[::-1]:
|
|
67
|
+
if each_p in leaf_2_linage:
|
|
68
|
+
lca = each_p
|
|
69
|
+
|
|
70
|
+
return lca
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def parse_reltime(reltime_txt, interested_nodes_txt, op_txt):
|
|
74
|
+
|
|
75
|
+
lca_to_leaves_dict = dict()
|
|
76
|
+
interested_node_desc_dict = dict()
|
|
77
|
+
for interested_node in open(interested_nodes_txt):
|
|
78
|
+
interested_node_split = interested_node.strip().split('\t')
|
|
79
|
+
paired_leaves = interested_node_split[0]
|
|
80
|
+
interested_node_desc = paired_leaves
|
|
81
|
+
if len(interested_node_split) > 1:
|
|
82
|
+
interested_node_desc = interested_node_split[1]
|
|
83
|
+
interested_node_desc_dict[paired_leaves] = interested_node_desc
|
|
84
|
+
leaf_1 = paired_leaves.split(',')[0]
|
|
85
|
+
leaf_2 = paired_leaves.split(',')[1]
|
|
86
|
+
lca_id = get_lca(reltime_txt, leaf_1, leaf_2)
|
|
87
|
+
lca_to_leaves_dict[lca_id] = paired_leaves.strip()
|
|
88
|
+
|
|
89
|
+
op_txt_handle = open(op_txt, 'w')
|
|
90
|
+
line_num_index = 0
|
|
91
|
+
for each_line in open(reltime_txt):
|
|
92
|
+
each_line_split = each_line.strip().split('\t')
|
|
93
|
+
each_line_split = [i.strip() for i in each_line_split]
|
|
94
|
+
if line_num_index == 0:
|
|
95
|
+
op_txt_handle.write('ColorBy\tNode\tMean\tLow\tHigh\n')
|
|
96
|
+
else:
|
|
97
|
+
if len(each_line_split) > 1:
|
|
98
|
+
node_id = each_line_split[1]
|
|
99
|
+
if node_id in lca_to_leaves_dict:
|
|
100
|
+
node_id = each_line_split[1]
|
|
101
|
+
div_time = each_line_split[7]
|
|
102
|
+
ci_lower = each_line_split[8]
|
|
103
|
+
ci_upper = each_line_split[9]
|
|
104
|
+
corresponding_leaves = lca_to_leaves_dict[node_id]
|
|
105
|
+
interested_node_desc = interested_node_desc_dict[corresponding_leaves]
|
|
106
|
+
op_txt_handle.write('RelTime\t%s\t%s\t%s\t%s\n' % (interested_node_desc, div_time, ci_lower, ci_upper))
|
|
107
|
+
line_num_index += 1
|
|
108
|
+
op_txt_handle.close()
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def mcmctree_out_to_tree_str(mamctree_out):
|
|
112
|
+
|
|
113
|
+
# get tree string from mamctree_out
|
|
114
|
+
tree_str = ''
|
|
115
|
+
tree_line = 0
|
|
116
|
+
current_line = 1
|
|
117
|
+
for each_line in open(mamctree_out):
|
|
118
|
+
if 'Species tree for FigTree. Branch lengths = posterior mean times; 95% CIs = labels' in each_line:
|
|
119
|
+
tree_line = current_line + 1
|
|
120
|
+
if tree_line == current_line:
|
|
121
|
+
tree_str = each_line.strip()
|
|
122
|
+
current_line += 1
|
|
123
|
+
|
|
124
|
+
tree_str_no_space = tree_str.replace(' ', '')
|
|
125
|
+
|
|
126
|
+
# rename tree nodes
|
|
127
|
+
t = Tree(tree_str_no_space, format=1)
|
|
128
|
+
for each_node in t.traverse():
|
|
129
|
+
if each_node.is_leaf():
|
|
130
|
+
node_name_new = '_'.join(each_node.name.split('_')[1:])
|
|
131
|
+
else:
|
|
132
|
+
node_name_new = 't_n%s' % each_node.name
|
|
133
|
+
each_node.name = node_name_new
|
|
134
|
+
|
|
135
|
+
tree_str_renamed = t.write(format=8)
|
|
136
|
+
|
|
137
|
+
return tree_str_renamed
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def get_internal_node_to_plot(node_txt, mo_file):
|
|
141
|
+
|
|
142
|
+
tree_str = ''
|
|
143
|
+
if os.path.isfile(mo_file):
|
|
144
|
+
tree_str = mcmctree_out_to_tree_str(mo_file)
|
|
145
|
+
|
|
146
|
+
# get nodes to plot
|
|
147
|
+
node_set = set()
|
|
148
|
+
node_rename_dict = dict()
|
|
149
|
+
if os.path.isfile(node_txt) is True:
|
|
150
|
+
for each in open(node_txt):
|
|
151
|
+
each_split = each.strip().split('\t')
|
|
152
|
+
node_str = each_split[0]
|
|
153
|
+
|
|
154
|
+
# get internal_node_to_plot
|
|
155
|
+
internal_node_to_plot = ''
|
|
156
|
+
if ',' not in node_str:
|
|
157
|
+
internal_node_to_plot = each_split[0]
|
|
158
|
+
else:
|
|
159
|
+
leaf_list = node_str.split(',')
|
|
160
|
+
if tree_str == '':
|
|
161
|
+
print('MCMCTree out file not found, program exited!')
|
|
162
|
+
exit()
|
|
163
|
+
current_lca = Tree(tree_str, format=1).get_common_ancestor(leaf_list)
|
|
164
|
+
internal_node_to_plot = current_lca.name
|
|
165
|
+
|
|
166
|
+
# add internal_node_to_plot to node_set
|
|
167
|
+
if internal_node_to_plot != '':
|
|
168
|
+
node_set.add(internal_node_to_plot)
|
|
169
|
+
|
|
170
|
+
# read in name to show in plot
|
|
171
|
+
if len(each_split) == 2:
|
|
172
|
+
if each_split[1] != '':
|
|
173
|
+
node_rename_dict[internal_node_to_plot] = each_split[1]
|
|
174
|
+
else:
|
|
175
|
+
node_set = node_txt.split(',')
|
|
176
|
+
|
|
177
|
+
return node_set, node_rename_dict, tree_str
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def read_in_posterior_mean(mcmctree_out):
|
|
181
|
+
|
|
182
|
+
# read in Posterior mean
|
|
183
|
+
node_to_mean_hpd95_dict = dict()
|
|
184
|
+
current_line = 1
|
|
185
|
+
posterior_mean_header_line = 0
|
|
186
|
+
for each_line in open(mcmctree_out):
|
|
187
|
+
if 'Posterior mean (95% Equal-tail CI) (95% HPD CI) HPD-CI-width' in each_line:
|
|
188
|
+
posterior_mean_header_line = current_line
|
|
189
|
+
|
|
190
|
+
if (posterior_mean_header_line != 0) and (current_line > posterior_mean_header_line):
|
|
191
|
+
each_line_split = each_line.strip().split(' ')
|
|
192
|
+
|
|
193
|
+
each_line_split_no_empty = []
|
|
194
|
+
for each_element in each_line_split:
|
|
195
|
+
if each_element not in ['', '(']:
|
|
196
|
+
each_element_value = each_element.replace('(', '').replace(')', '').replace(',', '')
|
|
197
|
+
each_line_split_no_empty.append(each_element_value)
|
|
198
|
+
if len(each_line_split_no_empty) == 9:
|
|
199
|
+
node_id = each_line_split_no_empty[0]
|
|
200
|
+
value_mean = each_line_split_no_empty[1]
|
|
201
|
+
value_hpd95_small = each_line_split_no_empty[4]
|
|
202
|
+
value_hpd95_big = each_line_split_no_empty[5]
|
|
203
|
+
node_to_mean_hpd95_dict[node_id] = [value_mean, value_hpd95_small, value_hpd95_big]
|
|
204
|
+
current_line += 1
|
|
205
|
+
|
|
206
|
+
return node_to_mean_hpd95_dict
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def parse_mcmc_out(mcmc_out_file, node_txt, dm_out):
|
|
210
|
+
|
|
211
|
+
dm_out_handle = open(dm_out, 'a')
|
|
212
|
+
#dm_out_handle.write('Test\tShape\tVar\tMean\tLow\tHigh\n')
|
|
213
|
+
node_set, node_rename_dict, tree_str = get_internal_node_to_plot(node_txt, mcmc_out_file)
|
|
214
|
+
node_to_mean_95_hpd_dict = read_in_posterior_mean(mcmc_out_file)
|
|
215
|
+
for each_node in node_set:
|
|
216
|
+
node_name_to_write = node_rename_dict.get(each_node, each_node)
|
|
217
|
+
mean_95_hpd_list = node_to_mean_95_hpd_dict.get(each_node)
|
|
218
|
+
dm_out_handle.write('MCMCTree\t%s\t%s\n' % (node_name_to_write, '\t'.join(mean_95_hpd_list)))
|
|
219
|
+
dm_out_handle.close()
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def mcmctree_vs_reltime(args):
|
|
223
|
+
|
|
224
|
+
mcmc_out_file = args['m']
|
|
225
|
+
reltime_txt = args['r']
|
|
226
|
+
interested_nodes_txt = args['n']
|
|
227
|
+
pdf_out = args['o']
|
|
228
|
+
|
|
229
|
+
dm_out_combined = '.'.join(pdf_out.split('.')[:-1]) + '.txt'
|
|
230
|
+
|
|
231
|
+
# define mcmctree_vs_reltime_R
|
|
232
|
+
pwd_current_file = os.path.realpath(__file__)
|
|
233
|
+
current_file_path = '/'.join(pwd_current_file.split('/')[:-1])
|
|
234
|
+
mcmctree_vs_reltime_R = '%s/mcmctree_vs_reltime.R' % current_file_path
|
|
235
|
+
|
|
236
|
+
parse_reltime(reltime_txt, interested_nodes_txt, dm_out_combined)
|
|
237
|
+
parse_mcmc_out(mcmc_out_file, interested_nodes_txt, dm_out_combined)
|
|
238
|
+
|
|
239
|
+
plot_cmd = 'Rscript %s -i %s -x %s -y %s -o %s' % (mcmctree_vs_reltime_R, dm_out_combined, 8, 5, pdf_out)
|
|
240
|
+
os.system(plot_cmd)
|
|
241
|
+
print('Plot exported to: %s' % pdf_out)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
if __name__ == '__main__':
|
|
245
|
+
|
|
246
|
+
mcmctree_vs_reltime_parser = argparse.ArgumentParser()
|
|
247
|
+
mcmctree_vs_reltime_parser.add_argument('-m', required=True, help='.out file from MCMCTree')
|
|
248
|
+
mcmctree_vs_reltime_parser.add_argument('-r', required=True, help='output from elTime')
|
|
249
|
+
mcmctree_vs_reltime_parser.add_argument('-n', required=True, help='interested nodes txt file')
|
|
250
|
+
mcmctree_vs_reltime_parser.add_argument('-o', required=True, help='output pdf')
|
|
251
|
+
args = vars(mcmctree_vs_reltime_parser.parse_args())
|
|
252
|
+
mcmctree_vs_reltime(args)
|
|
@@ -2,9 +2,20 @@ import os
|
|
|
2
2
|
import glob
|
|
3
3
|
import argparse
|
|
4
4
|
from ete3 import Tree
|
|
5
|
-
from TreeSAK.TreeSAK_config import config_dict
|
|
6
5
|
|
|
7
6
|
|
|
7
|
+
VisHPD95_usage = '''
|
|
8
|
+
============================ VisHPD95 example command ============================
|
|
9
|
+
|
|
10
|
+
TreeSAK VisHPD95 -i mcmc_out -o HPD95.pdf -n nodes.txt -label label.txt
|
|
11
|
+
TreeSAK VisHPD95 -i mcmc_out -o HPD95.pdf -n nodes.txt -label label.txt -x 9 -y 6
|
|
12
|
+
|
|
13
|
+
# Example data
|
|
14
|
+
https://github.com/songweizhi/TreeSAK/tree/master/example_data/VisHPD95
|
|
15
|
+
|
|
16
|
+
==================================================================================
|
|
17
|
+
'''
|
|
18
|
+
|
|
8
19
|
def mcmctree_out_to_tree_str(mamctree_out):
|
|
9
20
|
|
|
10
21
|
# get tree string from mamctree_out
|
|
@@ -103,19 +114,6 @@ def read_in_posterior_mean(mcmctree_out):
|
|
|
103
114
|
return node_to_mean_hpd95_dict
|
|
104
115
|
|
|
105
116
|
|
|
106
|
-
VisHPD95_usage = '''
|
|
107
|
-
============================ VisHPD95 example command ============================
|
|
108
|
-
|
|
109
|
-
TreeSAK VisHPD95 -i mcmc_out -o HPD95.pdf -n nodes.txt -label label.txt
|
|
110
|
-
TreeSAK VisHPD95 -i mcmc_out -o HPD95.pdf -n nodes.txt -label label.txt -x 9 -y 6
|
|
111
|
-
|
|
112
|
-
# Example data
|
|
113
|
-
https://github.com/songweizhi/TreeSAK/tree/master/example_data/VisHPD95
|
|
114
|
-
|
|
115
|
-
==================================================================================
|
|
116
|
-
'''
|
|
117
|
-
|
|
118
|
-
|
|
119
117
|
def VisHPD95(args):
|
|
120
118
|
|
|
121
119
|
mcmc_in = args['i']
|