TreeSAK 1.48.2__tar.gz → 1.49.0__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.0}/PKG-INFO +2 -2
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/VERSION +4 -1
- TreeSAK-1.49.0/TreeSAK/VisHPD95.py +200 -0
- TreeSAK-1.49.0/TreeSAK/mcmctree_vs_reltime.R +44 -0
- TreeSAK-1.49.0/TreeSAK/mcmctree_vs_reltime.py +252 -0
- TreeSAK-1.48.2/TreeSAK/VisHPD95.py → TreeSAK-1.49.0/TreeSAK/parse_mcmctree.py +12 -14
- TreeSAK-1.49.0/TreeSAK/tmp_3.py +120 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0/TreeSAK.egg-info}/PKG-INFO +2 -2
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK.egg-info/SOURCES.txt +4 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/bin/TreeSAK +10 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/LICENSE +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/MANIFEST.in +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/README.md +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ALE.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ALE1.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ALE2.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ALE2RTC.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ALE3.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ALE4.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ALE5.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ALE6.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ALE7.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ALE_backup.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/AssessCVG.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/AssessMarker.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/AssessMarkerDeltaLL.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/AssessMarkerPA.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/AssessPB.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/BMGE.jar +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/BMGE.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/CompareMCMC.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ConcateMSA.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ConvertMSA.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/Dir.rb +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ExtractMarkerSeq.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/FastRoot.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/FastRoot_backup.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/FigTree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/GTDB_tree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/GeneTree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/KEGG_Luo17.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/LcaToLeaves.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/MarkerRef2Tree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/MarkerRef2Tree_backup.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/MarkerSeq2Tree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/MarkerSeq2Tree_backup.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ModifyTopo.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/Newick_tree_plotter.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/OMA.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/OMA2.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/OneLineAln.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/PB.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/PMSF.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/PhyloBiAssoc.R +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/PhyloBiAssoc.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/PlotMCMC.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/PlotMcmcNode.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/PlotMcmcNode_old.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/RootTree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/RootTreeGTDB214.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/RootTreeGTDB220.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/SequentialDating.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/SingleAleHGT.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/SingleLinePhy.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/SliceMSA.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/SplitScore.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/SplitScore1.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/SplitScore1OMA.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/SplitScore2.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/TaxaCountStats.R +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/TaxonTree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/TreeSAK_config.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/VisHPD95.R +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/__init__.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ale_parser.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/ale_splitter.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/alignment_pruner.pl +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/assessOG.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/catfasta2phy.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/cogTree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/compare_trees.R +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/compare_trees.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/dating.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/dating_ss.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/deltall.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/do_rrtc.rb +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/fa2phy.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/format_leaf_name.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/gap_stats.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/get_SCG_tree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/get_arCOG_seq.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/global_functions.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/gnm_leaves.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/iTOL.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/iTOL_gene_tree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/keep_highest_rrtc.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/koTree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/label_tree.R +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/label_tree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/mad.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/mcmc2tree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/mcmcTC copy.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/mcmcTC.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/merge_pdf.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/pRTC.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/parse_reltime.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/phy2fa.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/plot_distruibution_th.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/prep_mcmctree_ctl.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/print_leaves.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/pruneMSA.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/recode.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/remove_bias.R +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/rename_leaves.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/replace_clade.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/root_with_out_group.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/run_TaxaCountStats_R_s1.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/subsample_drep_gnms.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/subset.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/subset_tree_stupid_old_way.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/supertree.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/tmp_1.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/tmp_2.py +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK/weighted_rand.rb +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK.egg-info/dependency_links.txt +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK.egg-info/requires.txt +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/TreeSAK.egg-info/top_level.txt +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/setup.cfg +0 -0
- {TreeSAK-1.48.2 → TreeSAK-1.49.0}/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.0
|
|
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.0
|
|
@@ -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
|
+
'''
|
|
@@ -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']
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import argparse
|
|
3
|
+
import arviz as az
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import matplotlib as mpl
|
|
6
|
+
mpl.use('Agg')
|
|
7
|
+
import matplotlib.pyplot as plt
|
|
8
|
+
from matplotlib.pyplot import figure
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
CompareMCMC_usage = '''
|
|
12
|
+
====================================== CompareMCMC example commands ======================================
|
|
13
|
+
|
|
14
|
+
TreeSAK CompareMCMC -mx IR_mcmc.txt -my AR_mcmc.txt -lx IR -ly AR -o convergence_plot.png -max 40 -fs 12
|
|
15
|
+
|
|
16
|
+
cd /Users/songweizhi/Desktop
|
|
17
|
+
TreeSAK CompareMCMC -mx /Users/songweizhi/Desktop/Sponge_r220/6_dating/MCMCTree/dating_outputs/topo2p10_clock3_nsample250000_run1_mcmc.txt -my /Users/songweizhi/Desktop/Sponge_r220/6_dating/MCMCTree/dating_outputs/topo2p10_clock3_nsample250000_run2_mcmc.txt -lx IR -ly AR -o convergence_plot.png -max 40 -fs 12
|
|
18
|
+
|
|
19
|
+
==========================================================================================================
|
|
20
|
+
'''
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def sep_path_basename_ext(file_in):
|
|
24
|
+
file_path, file_name = os.path.split(file_in)
|
|
25
|
+
if file_path == '':
|
|
26
|
+
file_path = '.'
|
|
27
|
+
file_basename, file_extension = os.path.splitext(file_name)
|
|
28
|
+
return file_path, file_basename, file_extension
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def CompareMCMC():
|
|
32
|
+
|
|
33
|
+
# mcmc_txt_x = args['mx']
|
|
34
|
+
# mcmc_txt_y = args['my']
|
|
35
|
+
# label_x = args['lx']
|
|
36
|
+
# label_y = args['ly']
|
|
37
|
+
# pwd_figure = args['o']
|
|
38
|
+
# max_axis_value = args['max']
|
|
39
|
+
# label_fs = args['fs']
|
|
40
|
+
|
|
41
|
+
label_fs = 16
|
|
42
|
+
file_x = '/Users/songweizhi/Desktop/x.txt'
|
|
43
|
+
file_y = '/Users/songweizhi/Desktop/y.txt'
|
|
44
|
+
pwd_figure = '/Users/songweizhi/Desktop/Figures.pdf'
|
|
45
|
+
min_value = 0
|
|
46
|
+
max_value = 1
|
|
47
|
+
max_axis_value = 1
|
|
48
|
+
label_x = []
|
|
49
|
+
num_list_x = []
|
|
50
|
+
x_err_l = []
|
|
51
|
+
x_err_r = []
|
|
52
|
+
line_num_index = 0
|
|
53
|
+
for line in open(file_x):
|
|
54
|
+
line_split = line.strip().split('\t')
|
|
55
|
+
if line_num_index > 0:
|
|
56
|
+
label_x.append(line_split[0])
|
|
57
|
+
num_list_x.append(float(line_split[1]))
|
|
58
|
+
x_err_l.append(float(line_split[1]) - float(line_split[2]))
|
|
59
|
+
x_err_r.append(float(line_split[3]) - float(line_split[1]))
|
|
60
|
+
line_num_index += 1
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
label_y = []
|
|
64
|
+
num_list_y = []
|
|
65
|
+
y_err_l = []
|
|
66
|
+
y_err_u = []
|
|
67
|
+
line_num_index = 0
|
|
68
|
+
for line in open(file_y):
|
|
69
|
+
line_split = line.strip().split('\t')
|
|
70
|
+
if line_num_index > 0:
|
|
71
|
+
label_y.append(line_split[0])
|
|
72
|
+
num_list_y.append(float(line_split[1]))
|
|
73
|
+
y_err_l.append(float(line_split[1]) - float(line_split[2]))
|
|
74
|
+
y_err_u.append(float(line_split[3]) - float(line_split[1]))
|
|
75
|
+
line_num_index += 1
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
figure(figsize=(6, 6), dpi=300)
|
|
83
|
+
plt.plot([min_value, max_value], [min_value, max_value], color='black', linestyle='dashed', linewidth=1, alpha=0.5)
|
|
84
|
+
plt.scatter(num_list_x, num_list_y, s=0)
|
|
85
|
+
plt.errorbar(num_list_x, num_list_y, xerr=[x_err_l, x_err_r], yerr=[y_err_l, y_err_u],
|
|
86
|
+
ls='none', ecolor='skyblue', elinewidth=1, alpha=0.5)
|
|
87
|
+
|
|
88
|
+
if max_axis_value is not None:
|
|
89
|
+
plt.xlim([0, max_axis_value])
|
|
90
|
+
plt.ylim([0, max_axis_value])
|
|
91
|
+
|
|
92
|
+
# Set the font size of xticks and yticks
|
|
93
|
+
plt.xticks(fontsize=label_fs)
|
|
94
|
+
plt.yticks(fontsize=label_fs)
|
|
95
|
+
plt.xlabel(label_x, fontsize=label_fs)
|
|
96
|
+
plt.ylabel(label_y, fontsize=label_fs)
|
|
97
|
+
|
|
98
|
+
# write out
|
|
99
|
+
plt.tight_layout()
|
|
100
|
+
plt.savefig(pwd_figure)
|
|
101
|
+
plt.close()
|
|
102
|
+
|
|
103
|
+
print('Plot exported to %s, done!' % pwd_figure)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
CompareMCMC()
|
|
107
|
+
|
|
108
|
+
# if __name__ == '__main__':
|
|
109
|
+
#
|
|
110
|
+
# # initialize the options parser
|
|
111
|
+
# parser = argparse.ArgumentParser()
|
|
112
|
+
# parser.add_argument('-mx', required=True, help='mcmc.txt for x axis')
|
|
113
|
+
# parser.add_argument('-my', required=True, help='mcmc.txt for y axis')
|
|
114
|
+
# parser.add_argument('-lx', required=False, default=None, help='label for x axis')
|
|
115
|
+
# parser.add_argument('-ly', required=False, default=None, help='label for y axis')
|
|
116
|
+
# parser.add_argument('-max', required=False, default=None, type=int, help='maximum axis value')
|
|
117
|
+
# parser.add_argument('-fs', required=False, default=16, type=int, help='label font size, default: 16')
|
|
118
|
+
# parser.add_argument('-o', required=True, help='output plot')
|
|
119
|
+
# args = vars(parser.parse_args())
|
|
120
|
+
# CompareMCMC(args)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: TreeSAK
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.49.0
|
|
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.0
|
|
@@ -94,8 +94,11 @@ TreeSAK/mad.py
|
|
|
94
94
|
TreeSAK/mcmc2tree.py
|
|
95
95
|
TreeSAK/mcmcTC copy.py
|
|
96
96
|
TreeSAK/mcmcTC.py
|
|
97
|
+
TreeSAK/mcmctree_vs_reltime.R
|
|
98
|
+
TreeSAK/mcmctree_vs_reltime.py
|
|
97
99
|
TreeSAK/merge_pdf.py
|
|
98
100
|
TreeSAK/pRTC.py
|
|
101
|
+
TreeSAK/parse_mcmctree.py
|
|
99
102
|
TreeSAK/parse_reltime.py
|
|
100
103
|
TreeSAK/phy2fa.py
|
|
101
104
|
TreeSAK/plot_distruibution_th.py
|
|
@@ -114,6 +117,7 @@ TreeSAK/subset_tree_stupid_old_way.py
|
|
|
114
117
|
TreeSAK/supertree.py
|
|
115
118
|
TreeSAK/tmp_1.py
|
|
116
119
|
TreeSAK/tmp_2.py
|
|
120
|
+
TreeSAK/tmp_3.py
|
|
117
121
|
TreeSAK/weighted_rand.rb
|
|
118
122
|
TreeSAK.egg-info/PKG-INFO
|
|
119
123
|
TreeSAK.egg-info/SOURCES.txt
|
|
@@ -899,6 +899,16 @@ if __name__ == '__main__':
|
|
|
899
899
|
args = vars(parser.parse_args())
|
|
900
900
|
parse_reltime.parse_reltime(args)
|
|
901
901
|
|
|
902
|
+
elif sys.argv[1] == 'mcmctree_vs_reltime':
|
|
903
|
+
from TreeSAK import mcmctree_vs_reltime
|
|
904
|
+
mcmctree_vs_reltime_parser = subparsers.add_parser('mcmctree_vs_reltime', usage=mcmctree_vs_reltime.mcmctree_vs_reltime_usage)
|
|
905
|
+
mcmctree_vs_reltime_parser.add_argument('-m', required=True, help='.out file from MCMCTree')
|
|
906
|
+
mcmctree_vs_reltime_parser.add_argument('-r', required=True, help='output from elTime')
|
|
907
|
+
mcmctree_vs_reltime_parser.add_argument('-n', required=True, help='interested nodes txt file')
|
|
908
|
+
mcmctree_vs_reltime_parser.add_argument('-o', required=True, help='output pdf')
|
|
909
|
+
args = vars(parser.parse_args())
|
|
910
|
+
mcmctree_vs_reltime.mcmctree_vs_reltime(args)
|
|
911
|
+
|
|
902
912
|
else:
|
|
903
913
|
print('Unrecognized module: %s, program exited!' % sys.argv[1])
|
|
904
914
|
exit()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|