TreeSAK 1.48.1__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.
Files changed (129) hide show
  1. {TreeSAK-1.48.1/TreeSAK.egg-info → TreeSAK-1.49.0}/PKG-INFO +2 -2
  2. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/CompareMCMC.py +3 -0
  3. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/VERSION +5 -2
  4. TreeSAK-1.49.0/TreeSAK/VisHPD95.py +200 -0
  5. TreeSAK-1.49.0/TreeSAK/mcmctree_vs_reltime.R +44 -0
  6. TreeSAK-1.49.0/TreeSAK/mcmctree_vs_reltime.py +252 -0
  7. TreeSAK-1.48.1/TreeSAK/VisHPD95.py → TreeSAK-1.49.0/TreeSAK/parse_mcmctree.py +16 -17
  8. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/parse_reltime.py +6 -0
  9. TreeSAK-1.49.0/TreeSAK/tmp_3.py +120 -0
  10. {TreeSAK-1.48.1 → TreeSAK-1.49.0/TreeSAK.egg-info}/PKG-INFO +2 -2
  11. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK.egg-info/SOURCES.txt +4 -0
  12. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/bin/TreeSAK +10 -1
  13. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/LICENSE +0 -0
  14. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/MANIFEST.in +0 -0
  15. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/README.md +0 -0
  16. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ALE.py +0 -0
  17. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ALE1.py +0 -0
  18. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ALE2.py +0 -0
  19. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ALE2RTC.py +0 -0
  20. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ALE3.py +0 -0
  21. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ALE4.py +0 -0
  22. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ALE5.py +0 -0
  23. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ALE6.py +0 -0
  24. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ALE7.py +0 -0
  25. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ALE_backup.py +0 -0
  26. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/AssessCVG.py +0 -0
  27. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/AssessMarker.py +0 -0
  28. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/AssessMarkerDeltaLL.py +0 -0
  29. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/AssessMarkerPA.py +0 -0
  30. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/AssessPB.py +0 -0
  31. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/BMGE.jar +0 -0
  32. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/BMGE.py +0 -0
  33. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ConcateMSA.py +0 -0
  34. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ConvertMSA.py +0 -0
  35. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/Dir.rb +0 -0
  36. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ExtractMarkerSeq.py +0 -0
  37. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/FastRoot.py +0 -0
  38. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/FastRoot_backup.py +0 -0
  39. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/FigTree.py +0 -0
  40. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/GTDB_tree.py +0 -0
  41. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/GeneTree.py +0 -0
  42. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/KEGG_Luo17.py +0 -0
  43. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/LcaToLeaves.py +0 -0
  44. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/MarkerRef2Tree.py +0 -0
  45. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/MarkerRef2Tree_backup.py +0 -0
  46. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/MarkerSeq2Tree.py +0 -0
  47. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/MarkerSeq2Tree_backup.py +0 -0
  48. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ModifyTopo.py +0 -0
  49. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/Newick_tree_plotter.py +0 -0
  50. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/OMA.py +0 -0
  51. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/OMA2.py +0 -0
  52. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/OneLineAln.py +0 -0
  53. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/PB.py +0 -0
  54. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/PMSF.py +0 -0
  55. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/PhyloBiAssoc.R +0 -0
  56. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/PhyloBiAssoc.py +0 -0
  57. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/PlotMCMC.py +0 -0
  58. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/PlotMcmcNode.py +0 -0
  59. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/PlotMcmcNode_old.py +0 -0
  60. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/RootTree.py +0 -0
  61. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/RootTreeGTDB214.py +0 -0
  62. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/RootTreeGTDB220.py +0 -0
  63. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/SequentialDating.py +0 -0
  64. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/SingleAleHGT.py +0 -0
  65. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/SingleLinePhy.py +0 -0
  66. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/SliceMSA.py +0 -0
  67. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/SplitScore.py +0 -0
  68. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/SplitScore1.py +0 -0
  69. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/SplitScore1OMA.py +0 -0
  70. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/SplitScore2.py +0 -0
  71. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/TaxaCountStats.R +0 -0
  72. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/TaxonTree.py +0 -0
  73. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/TreeSAK_config.py +0 -0
  74. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/VisHPD95.R +0 -0
  75. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/__init__.py +0 -0
  76. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ale_parser.py +0 -0
  77. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/ale_splitter.py +0 -0
  78. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/alignment_pruner.pl +0 -0
  79. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/assessOG.py +0 -0
  80. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/catfasta2phy.py +0 -0
  81. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/cogTree.py +0 -0
  82. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/compare_trees.R +0 -0
  83. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/compare_trees.py +0 -0
  84. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/dating.py +0 -0
  85. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/dating_ss.py +0 -0
  86. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/deltall.py +0 -0
  87. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/do_rrtc.rb +0 -0
  88. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/fa2phy.py +0 -0
  89. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/format_leaf_name.py +0 -0
  90. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/gap_stats.py +0 -0
  91. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/get_SCG_tree.py +0 -0
  92. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/get_arCOG_seq.py +0 -0
  93. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/global_functions.py +0 -0
  94. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/gnm_leaves.py +0 -0
  95. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/iTOL.py +0 -0
  96. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/iTOL_gene_tree.py +0 -0
  97. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/keep_highest_rrtc.py +0 -0
  98. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/koTree.py +0 -0
  99. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/label_tree.R +0 -0
  100. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/label_tree.py +0 -0
  101. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/mad.py +0 -0
  102. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/mcmc2tree.py +0 -0
  103. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/mcmcTC copy.py +0 -0
  104. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/mcmcTC.py +0 -0
  105. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/merge_pdf.py +0 -0
  106. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/pRTC.py +0 -0
  107. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/phy2fa.py +0 -0
  108. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/plot_distruibution_th.py +0 -0
  109. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/prep_mcmctree_ctl.py +0 -0
  110. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/print_leaves.py +0 -0
  111. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/pruneMSA.py +0 -0
  112. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/recode.py +0 -0
  113. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/remove_bias.R +0 -0
  114. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/rename_leaves.py +0 -0
  115. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/replace_clade.py +0 -0
  116. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/root_with_out_group.py +0 -0
  117. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/run_TaxaCountStats_R_s1.py +0 -0
  118. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/subsample_drep_gnms.py +0 -0
  119. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/subset.py +0 -0
  120. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/subset_tree_stupid_old_way.py +0 -0
  121. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/supertree.py +0 -0
  122. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/tmp_1.py +0 -0
  123. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/tmp_2.py +0 -0
  124. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK/weighted_rand.rb +0 -0
  125. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK.egg-info/dependency_links.txt +0 -0
  126. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK.egg-info/requires.txt +0 -0
  127. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/TreeSAK.egg-info/top_level.txt +0 -0
  128. {TreeSAK-1.48.1 → TreeSAK-1.49.0}/setup.cfg +0 -0
  129. {TreeSAK-1.48.1 → 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.48.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.48.1
27
+ TreeSAK v1.49.0
@@ -13,6 +13,9 @@ CompareMCMC_usage = '''
13
13
 
14
14
  TreeSAK CompareMCMC -mx IR_mcmc.txt -my AR_mcmc.txt -lx IR -ly AR -o convergence_plot.png -max 40 -fs 12
15
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
+
16
19
  ==========================================================================================================
17
20
  '''
18
21
 
@@ -1,8 +1,11 @@
1
- 1.48.1
1
+ 1.49.0
2
+ - new module added: mcmctree_vs_reltime
3
+
4
+ 1.48.2
2
5
  - fixed bugs
3
6
 
4
7
  1.48.0
5
- - parse_reltime
8
+ - new module added: parse_reltime
6
9
 
7
10
  1.47.0
8
11
  - new module added: GeneTree
@@ -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']
@@ -124,7 +122,10 @@ def VisHPD95(args):
124
122
  plot_out = args['o']
125
123
  plot_width = args['x']
126
124
  plot_height = args['y']
127
- VisHPD95_R = args['VisHPD95_R']
125
+
126
+ pwd_current_file = os.path.realpath(__file__)
127
+ current_file_path = '/'.join(pwd_current_file.split('/')[:-1])
128
+ VisHPD95_R = '%s/VisHPD95.R' % current_file_path
128
129
 
129
130
  dm_out = '%s.txt' % plot_out
130
131
 
@@ -179,7 +180,6 @@ def VisHPD95(args):
179
180
 
180
181
  if __name__ == '__main__':
181
182
 
182
- # arguments for rename_seq_parser
183
183
  VisHPD95_parser = argparse.ArgumentParser()
184
184
  VisHPD95_parser.add_argument('-i', required=True, help='mcmc.txt file or folder')
185
185
  VisHPD95_parser.add_argument('-n', required=True, help='Nodes to plot')
@@ -188,7 +188,6 @@ if __name__ == '__main__':
188
188
  VisHPD95_parser.add_argument('-y', required=False, default=5,type=int, help='plot height, default: 5')
189
189
  VisHPD95_parser.add_argument('-o', required=True, help='Output plot')
190
190
  args = vars(VisHPD95_parser.parse_args())
191
- args['VisHPD95_R'] = config_dict['VisHPD95_R']
192
191
  VisHPD95(args)
193
192
 
194
193
  '''
@@ -129,7 +129,13 @@ if __name__ == '__main__':
129
129
  args = vars(parse_reltime_parser.parse_args())
130
130
  parse_reltime(args)
131
131
 
132
+
132
133
  '''
134
+
133
135
  cd /Users/songweizhi/Desktop
134
136
  python3 /Users/songweizhi/PycharmProjects/TreeSAK/TreeSAK/parse_reltime.py -i /Users/songweizhi/Desktop/Sponge_r220/6_dating/RelTime/topo2_p30_RelTime_JTT_Gamma4/topo2_p30_RelTime_Gamma4.txt -n yang_7.txt -o dbscc_age.txt
137
+
138
+ cd /Users/songweizhi/Desktop
139
+ TreeSAK parse_reltime -i /Users/songweizhi/Desktop/Sponge_r220/6_dating/RelTime/topo2_p30_RelTime_JTT_Gamma4/topo2_p30_RelTime_Gamma4.txt -n yang_7.txt -o dbscc_age.txt
140
+
135
141
  '''