TreeSAK 1.43.1__tar.gz → 1.44.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 (111) hide show
  1. {TreeSAK-1.43.1/TreeSAK.egg-info → TreeSAK-1.44.0}/PKG-INFO +2 -2
  2. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ALE6.py +101 -20
  3. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ALE7.py +4 -4
  4. TreeSAK-1.44.0/TreeSAK/FunTree.py +191 -0
  5. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/VERSION +4 -1
  6. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/supertree.py +1 -1
  7. {TreeSAK-1.43.1 → TreeSAK-1.44.0/TreeSAK.egg-info}/PKG-INFO +2 -2
  8. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK.egg-info/SOURCES.txt +1 -0
  9. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/bin/TreeSAK +18 -0
  10. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/LICENSE +0 -0
  11. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/MANIFEST.in +0 -0
  12. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/README.md +0 -0
  13. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ALE.py +0 -0
  14. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ALE1.py +0 -0
  15. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ALE2.py +0 -0
  16. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ALE2RTC.py +0 -0
  17. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ALE3.py +0 -0
  18. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ALE4.py +0 -0
  19. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ALE5.py +0 -0
  20. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ALE_backup.py +0 -0
  21. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/AssessCVG.py +0 -0
  22. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/AssessMarker.py +0 -0
  23. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/AssessMarkerDeltaLL.py +0 -0
  24. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/AssessMarkerPA.py +0 -0
  25. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/AssessPB.py +0 -0
  26. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/BMGE.jar +0 -0
  27. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/BMGE.py +0 -0
  28. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/CompareMCMC.py +0 -0
  29. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ConcateMSA.py +0 -0
  30. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ConvertMSA.py +0 -0
  31. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/Dir.rb +0 -0
  32. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ExtractMarkerSeq.py +0 -0
  33. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/FastRoot.py +0 -0
  34. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/FastRoot_backup.py +0 -0
  35. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/GTDB_tree.py +0 -0
  36. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/KEGG_Luo17.py +0 -0
  37. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/LcaToLeaves.py +0 -0
  38. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/MarkerRef2Tree.py +0 -0
  39. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/MarkerRef2Tree_backup.py +0 -0
  40. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/MarkerSeq2Tree.py +0 -0
  41. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ModifyTopo.py +0 -0
  42. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/Newick_tree_plotter.py +0 -0
  43. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/OMA.py +0 -0
  44. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/OMA2.py +0 -0
  45. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/OneLineAln.py +0 -0
  46. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/PB.py +0 -0
  47. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/PMSF.py +0 -0
  48. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/PhyloBiAssoc.R +0 -0
  49. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/PhyloBiAssoc.py +0 -0
  50. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/PlotMCMC.py +0 -0
  51. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/PlotMcmcNode.py +0 -0
  52. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/RootTree.py +0 -0
  53. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/RootTreeGTDB214.py +0 -0
  54. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/RootTreeGTDB220.py +0 -0
  55. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/SequentialDating.py +0 -0
  56. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/SingleAleHGT.py +0 -0
  57. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/SingleLinePhy.py +0 -0
  58. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/SliceMSA.py +0 -0
  59. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/SplitScore.py +0 -0
  60. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/SplitScore1.py +0 -0
  61. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/SplitScore1OMA.py +0 -0
  62. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/SplitScore2.py +0 -0
  63. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/TaxaCountStats.R +0 -0
  64. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/TaxonTree.py +0 -0
  65. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/TreeSAK_config.py +0 -0
  66. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/VisHPD95.R +0 -0
  67. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/VisHPD95.py +0 -0
  68. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/__init__.py +0 -0
  69. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ale_parser.py +0 -0
  70. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/ale_splitter.py +0 -0
  71. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/alignment_pruner.pl +0 -0
  72. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/catfasta2phy.py +0 -0
  73. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/compare_trees.R +0 -0
  74. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/compare_trees.py +0 -0
  75. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/dating.py +0 -0
  76. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/dating_ss.py +0 -0
  77. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/deltall.py +0 -0
  78. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/do_rrtc.rb +0 -0
  79. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/fa2phy.py +0 -0
  80. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/format_leaf_name.py +0 -0
  81. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/gap_stats.py +0 -0
  82. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/get_SCG_tree.py +0 -0
  83. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/get_arCOG_seq.py +0 -0
  84. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/global_functions.py +0 -0
  85. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/iTOL.py +0 -0
  86. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/keep_highest_rrtc.py +0 -0
  87. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/label_tree.R +0 -0
  88. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/label_tree.py +0 -0
  89. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/mad.py +0 -0
  90. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/mcmc2tree.py +0 -0
  91. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/mcmcTC.py +0 -0
  92. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/merge_pdf.py +0 -0
  93. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/pRTC.py +0 -0
  94. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/plot_distruibution_th.py +0 -0
  95. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/prep_mcmctree_ctl.py +0 -0
  96. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/print_leaves.py +0 -0
  97. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/pruneMSA.py +0 -0
  98. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/recode.py +0 -0
  99. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/rename_leaves.py +0 -0
  100. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/replace_clade.py +0 -0
  101. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/root_with_out_group.py +0 -0
  102. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/run_TaxaCountStats_R_s1.py +0 -0
  103. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/subsample_drep_gnms.py +0 -0
  104. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/subset.py +0 -0
  105. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/subset_tree_stupid_old_way.py +0 -0
  106. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK/weighted_rand.rb +0 -0
  107. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK.egg-info/dependency_links.txt +0 -0
  108. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK.egg-info/requires.txt +0 -0
  109. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/TreeSAK.egg-info/top_level.txt +0 -0
  110. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/setup.cfg +0 -0
  111. {TreeSAK-1.43.1 → TreeSAK-1.44.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: TreeSAK
3
- Version: 1.43.1
3
+ Version: 1.44.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.43.1
27
+ TreeSAK v1.44.0
@@ -19,12 +19,22 @@ TreeSAK ALE6 -1 ALE1_op_dir -3 ALE3_op_dir_30 -s species_tree.rooted.treefile -o
19
19
  -s: the tree used as input for ALE2
20
20
 
21
21
  # To be added:
22
- A dereplication step to the produced faa file.
22
+ 1. A dereplication step to the produced faa file.
23
23
 
24
24
  ===================================================================================================
25
25
  '''
26
26
 
27
27
 
28
+ def sep_path_basename_ext(file_in):
29
+
30
+ f_path, f_name = os.path.split(file_in)
31
+ if f_path == '':
32
+ f_path = '.'
33
+ f_base, f_ext = os.path.splitext(f_name)
34
+
35
+ return f_name, f_path, f_base, f_ext[1:]
36
+
37
+
28
38
  def get_internal_node_leaves(ale_species_tree_file, internal_node_id):
29
39
 
30
40
  ale_species_tree = Tree(ale_species_tree_file, format=1)
@@ -48,18 +58,20 @@ def ALE6(args):
48
58
  cog_annotation_wd = args['cog']
49
59
  kegg_annotation_wd = args['kegg']
50
60
 
51
- GeneContent_txt = '%s/GeneContent.txt' % ale3_op_dir
52
- SpeciesTreeRef = '%s/SpeciesTreeRef.newick' % ale3_op_dir
61
+ GeneContent_txt = '%s/GeneContent.txt' % ale3_op_dir
62
+ SpeciesTreeRef = '%s/SpeciesTreeRef.newick' % ale3_op_dir
63
+ transfer_propensity_txt = '%s/Transfer_propensity.txt' % ale3_op_dir
53
64
 
54
65
  ################################################## define op files #################################################
55
66
 
56
- faa_dir = '%s/faa_files' % op_dir
57
- cog_dir = '%s/annotation_COG' % op_dir
58
- kegg_dir = '%s/annotation_KEGG' % op_dir
59
- cog_df_txt = '%s/annotation_COG.txt' % op_dir
60
- cog_df_desc_txt = '%s/annotation_COG_desc.txt' % op_dir
61
- kegg_df_txt = '%s/annotation_KEGG.txt' % op_dir
62
- kegg_df_desc_txt = '%s/annotation_KEGG_desc.txt' % op_dir
67
+ faa_dir = '%s/faa_files' % op_dir
68
+ cog_dir = '%s/annotation_COG' % op_dir
69
+ kegg_dir = '%s/annotation_KEGG' % op_dir
70
+ cog_df_txt = '%s/annotation_COG.txt' % op_dir
71
+ cog_df_desc_txt = '%s/annotation_COG_desc.txt' % op_dir
72
+ kegg_df_txt = '%s/annotation_KEGG.txt' % op_dir
73
+ kegg_df_desc_txt = '%s/annotation_KEGG_desc.txt' % op_dir
74
+ fun_transfer_propensity_txt = '%s/function_transfer_propensity_weighted.txt' % op_dir
63
75
 
64
76
  ########################################## get the id of nodes to process ##########################################
65
77
 
@@ -138,7 +150,8 @@ def ALE6(args):
138
150
  for each_prot_family in branch_content:
139
151
  each_prot_family_faa = '%s/%s.faa' % (ale1_op_dir, each_prot_family)
140
152
  for each_seq in SeqIO.parse(each_prot_family_faa, 'fasta'):
141
- seq_gnm = '_'.join(each_seq.id.split('_')[:-1])
153
+ seq_id = each_seq.id
154
+ seq_gnm = '_'.join(seq_id.split('_')[:-1])
142
155
  if seq_gnm in branch_child_set_original_name:
143
156
  branch_faa_handle.write('>%s %s\n' % (each_seq.id, each_prot_family))
144
157
  branch_faa_handle.write('%s\n' % each_seq.seq)
@@ -146,8 +159,9 @@ def ALE6(args):
146
159
  branch_faa_handle.close()
147
160
 
148
161
  # Read in COG annotation results
162
+ fun_to_gene_dict = dict()
149
163
  annotation_dict_cog = dict()
150
- id_to_fun_dict_cog = dict()
164
+ fun_id_to_desc_dict = dict()
151
165
  if cog_annotation_wd is not None:
152
166
 
153
167
  print('Reading in COG annotation results')
@@ -167,13 +181,18 @@ def ALE6(args):
167
181
  if line_index > 0:
168
182
  each_line_split = each_line.strip().split('\t')
169
183
  if len(each_line_split) == 4:
170
- annotation_dict_cog[gnm_id][each_line_split[0]] = each_line_split[1]
171
- id_to_fun_dict_cog[each_line_split[1]] = each_line_split[3]
184
+ gene_id = each_line_split[0]
185
+ cog_id = each_line_split[1]
186
+ cog_desc = each_line_split[3]
187
+ annotation_dict_cog[gnm_id][gene_id] = cog_id
188
+ fun_id_to_desc_dict[cog_id] = cog_desc
189
+ if cog_id not in fun_to_gene_dict:
190
+ fun_to_gene_dict[cog_id] = set()
191
+ fun_to_gene_dict[cog_id].add(gene_id)
172
192
  line_index += 1
173
193
 
174
194
  # Read in KEGG annotation results
175
195
  annotation_dict_kegg = dict()
176
- id_to_fun_dict_kegg = dict()
177
196
  if kegg_annotation_wd is not None:
178
197
 
179
198
  print('Reading in KEGG annotation results')
@@ -198,7 +217,10 @@ def ALE6(args):
198
217
  ko_d_id = each_line_split[4][2:]
199
218
  ko_d_desc = each_line_split[8]
200
219
  annotation_dict_kegg[gnm_id][gene_id] = ko_d_id
201
- id_to_fun_dict_kegg[ko_d_id] = ko_d_desc
220
+ fun_id_to_desc_dict[ko_d_id] = ko_d_desc
221
+ if ko_d_id not in fun_to_gene_dict:
222
+ fun_to_gene_dict[ko_d_id] = set()
223
+ fun_to_gene_dict[ko_d_id].add(gene_id)
202
224
  line_index += 1
203
225
 
204
226
  cog_dod = dict()
@@ -229,20 +251,20 @@ def ALE6(args):
229
251
  cog_annotation_txt = '%s/%s_COG.txt' % (cog_dir, each_branch)
230
252
  cog_annotation_txt_handle = open(cog_annotation_txt, 'w')
231
253
  for each_cog in sorted(list(branch_cog_set)):
232
- cog_annotation_txt_handle.write('%s\t%s\n' % (each_cog, id_to_fun_dict_cog[each_cog]))
254
+ cog_annotation_txt_handle.write('%s\t%s\n' % (each_cog, fun_id_to_desc_dict[each_cog]))
233
255
  cog_annotation_txt_handle.close()
234
256
 
235
257
  if len(branch_kegg_set) > 0:
236
258
  kegg_annotation_txt = '%s/%s_KEGG.txt' % (kegg_dir, each_branch)
237
259
  kegg_annotation_txt_handle = open(kegg_annotation_txt, 'w')
238
260
  for each_kegg in sorted(list(branch_kegg_set)):
239
- kegg_annotation_txt_handle.write('%s\t%s\n' % (each_kegg, id_to_fun_dict_kegg[each_kegg]))
261
+ kegg_annotation_txt_handle.write('%s\t%s\n' % (each_kegg, fun_id_to_desc_dict[each_kegg]))
240
262
  kegg_annotation_txt_handle.close()
241
263
 
242
264
  all_identified_cog_list_sorted = sorted(list(all_identified_cog_set))
243
265
  all_identified_kegg_list_sorted = sorted(list(all_identified_kegg_set))
244
- all_identified_cog_list_sorted_desc = [('%s__%s' % (i, id_to_fun_dict_cog[i])) for i in all_identified_cog_list_sorted]
245
- all_identified_kegg_list_sorted_desc = [('%s__%s' % (i, id_to_fun_dict_kegg[i])) for i in all_identified_kegg_list_sorted]
266
+ all_identified_cog_list_sorted_desc = [('%s__%s' % (i, fun_id_to_desc_dict[i])) for i in all_identified_cog_list_sorted]
267
+ all_identified_kegg_list_sorted_desc = [('%s__%s' % (i, fun_id_to_desc_dict[i])) for i in all_identified_kegg_list_sorted]
246
268
 
247
269
  # write out COG dataframe
248
270
  if len(all_identified_cog_set) > 0:
@@ -284,8 +306,67 @@ def ALE6(args):
284
306
  kegg_df_desc_txt_handle.close()
285
307
  print('Annotation matrix exported to: %s' % kegg_df_txt)
286
308
 
309
+ ################################# get transfer propensity of individual functions ##################################
310
+
311
+ print('Getting transfer propensity of individual function')
312
+
313
+ # get gene_to_oma_dict
314
+ faa_file_re = '%s/*.faa' % ale1_op_dir
315
+ faa_file_list = glob.glob(faa_file_re)
316
+ gene_to_oma_dict = dict()
317
+ for faa_file in faa_file_list:
318
+ _, _, faa_base, _ = sep_path_basename_ext(faa_file)
319
+ for each_seq in SeqIO.parse(faa_file, 'fasta'):
320
+ seq_id = each_seq.id
321
+ gene_to_oma_dict[seq_id] = faa_base
322
+
323
+ # get oma_to_transfer_propensity_dict
324
+ oma_to_transfer_propensity_dict = dict()
325
+ line_index = 0
326
+ for each_oma in open(transfer_propensity_txt):
327
+ if line_index > 0:
328
+ each_oma_split = each_oma.strip().split('\t')
329
+ oma_id = each_oma_split[0]
330
+ transfer_propensity = float(each_oma_split[1])
331
+ oma_to_transfer_propensity_dict[oma_id] = transfer_propensity
332
+ line_index += 1
333
+
334
+ fun_transfer_propensity_txt_handle = open(fun_transfer_propensity_txt, 'w')
335
+ fun_transfer_propensity_txt_handle.write('ID\tWeighted_transfer_propensity\tDescription\n')
336
+ oma_weighted_transfer_propensity_dict = dict()
337
+ for fun_id in sorted(list(fun_to_gene_dict.keys())):
338
+ current_fun_gene_set = fun_to_gene_dict[fun_id]
339
+ current_fun_oma_stats_dict = dict()
340
+ for gene_id in current_fun_gene_set:
341
+ gene_oma = gene_to_oma_dict.get(gene_id, 'na')
342
+ if gene_oma not in current_fun_oma_stats_dict:
343
+ current_fun_oma_stats_dict[gene_oma] = 1
344
+ else:
345
+ current_fun_oma_stats_dict[gene_oma] += 1
346
+
347
+ total_transfer_propensity = 0
348
+ total_oma_num = 0
349
+ for oma_id in current_fun_oma_stats_dict:
350
+ oma_num = current_fun_oma_stats_dict[oma_id]
351
+ oma_transfer_propensity = oma_to_transfer_propensity_dict.get(oma_id, 'na')
352
+ if oma_transfer_propensity != 'na':
353
+ total_transfer_propensity += (oma_num*oma_transfer_propensity)
354
+ total_oma_num += oma_num
355
+
356
+ oma_transfer_propensity_weighted = 'na'
357
+ if total_oma_num != 0:
358
+ oma_transfer_propensity_weighted = total_transfer_propensity/total_oma_num
359
+ oma_transfer_propensity_weighted = float("{0:.3f}".format(oma_transfer_propensity_weighted))
360
+
361
+ if oma_transfer_propensity_weighted != 'na':
362
+ oma_weighted_transfer_propensity_dict[fun_id] = oma_transfer_propensity_weighted
363
+ fun_transfer_propensity_txt_handle.write('%s\t%s\t%s\n' % (fun_id, oma_transfer_propensity_weighted, fun_id_to_desc_dict[fun_id]))
364
+
365
+ fun_transfer_propensity_txt_handle.close()
366
+
287
367
  print('Done!')
288
368
 
369
+
289
370
  if __name__ == '__main__':
290
371
 
291
372
  ALE6_parser = argparse.ArgumentParser()
@@ -20,10 +20,10 @@ TreeSAK ALE7 -6 ALE6_op_dir -fun arCOG07811,K01995 -node 359,466,470 -o Fun_PA.t
20
20
 
21
21
  def ALE7(args):
22
22
 
23
- ale6_op_dir = args['6']
24
- interested_fun_txt = args['fun']
25
- interested_gnm_txt = args['node']
26
- op_txt = args['o']
23
+ ale6_op_dir = args['6']
24
+ interested_fun_txt = args['fun']
25
+ interested_gnm_txt = args['node']
26
+ op_txt = args['o']
27
27
 
28
28
  if os.path.isdir(ale6_op_dir) is False:
29
29
  print('%s not found, program exited!' % ale6_op_dir)
@@ -0,0 +1,191 @@
1
+ import os
2
+ import glob
3
+ import argparse
4
+ from Bio import SeqIO
5
+ import multiprocessing as mp
6
+
7
+
8
+ FunTree_usage = '''
9
+ ====================== FunTree example commands ======================
10
+
11
+ TreeSAK FunTree -i combined.faa -fun K01995,K01996,K01997,K01998,K01999 -kegg KEGG_wd -o interested_fun_seq_dir -bmge -t 12 -f
12
+
13
+ cd /scratch/PI/ocessongwz/Sponge_r220/4_OMA_wd/OMA_wd/Output
14
+ python3 FunTree.py -i /scratch/PI/ocessongwz/Sponge_r220/3_combined_genomes_50_5_dRep97_291.faa -fun K01995,K01996,K01997,K01998,K01999 -kegg /scratch/PI/ocessongwz/Sponge_r220/3_combined_genomes_50_5_dRep97_291_KEGG_wd -o interested_fun_tree_branched_chain_aa_transport_system -bmge -t 12 -f
15
+
16
+ /scratch/PI/ocessongwz/Sponge_r220/3_combined_genomes_50_5_dRep97_291_arCOG_wd
17
+
18
+ ======================================================================
19
+ '''
20
+
21
+
22
+ def select_seq(seq_file, seq_id_set, output_file):
23
+ output_file_handle = open(output_file, 'w')
24
+ for seq_record in SeqIO.parse(seq_file, 'fasta'):
25
+ seq_id = seq_record.id
26
+ if seq_id in seq_id_set:
27
+ SeqIO.write(seq_record, output_file_handle, 'fasta-2line')
28
+ output_file_handle.close()
29
+
30
+
31
+ def FunTree(args):
32
+
33
+ combined_faa = args['i']
34
+ cog_annotation_wd = args['cog']
35
+ kegg_annotation_wd = args['kegg']
36
+ interested_fun_txt = args['fun']
37
+ op_dir = args['o']
38
+ trim_with_bmge = args['bmge']
39
+ trim_model = args['bmge_m']
40
+ entropy_score_cutoff = args['bmge_esc']
41
+ iqtree_model = args['iqtree_m']
42
+ force_overwrite = args['f']
43
+ num_of_threads = args['t']
44
+
45
+ # specify path to BMGE.jar
46
+ current_file_path = '/'.join(os.path.realpath(__file__).split('/')[:-1])
47
+ pwd_bmge_jar = '%s/BMGE.jar' % current_file_path
48
+
49
+ interested_fun_set = set()
50
+ if os.path.isfile(interested_fun_txt) is False:
51
+ if ',' in interested_fun_txt:
52
+ interested_fun_set = interested_fun_txt.split(',')
53
+ else:
54
+ interested_fun_set.add(interested_fun_txt)
55
+ else:
56
+ for each_fun in open(interested_fun_txt):
57
+ interested_fun_set.add(each_fun.strip().split()[0])
58
+
59
+ ################################################################################
60
+
61
+ faa_dir = '%s/dir_1_faa' % op_dir
62
+ aln_dir = '%s/dir_2_msa' % op_dir
63
+ trimmed_aln_dir = '%s/dir_3_trimmed_msa' % op_dir
64
+ tree_dir = '%s/dir_4_tree' % op_dir
65
+ cmd_1_mafft_txt = '%s/cmd_1_mafft.txt' % op_dir
66
+ cmd_2_trim_txt = '%s/cmd_2_trim.txt' % op_dir
67
+ cmd_3_tree_txt = '%s/cmd_3_tree.txt' % op_dir
68
+
69
+ ################################################################################
70
+
71
+ # create output folder
72
+ if os.path.isdir(op_dir) is True:
73
+ if force_overwrite is True:
74
+ os.system('rm -r %s' % op_dir)
75
+ else:
76
+ print('%s exist, program exited!' % op_dir)
77
+ exit()
78
+
79
+ os.mkdir(op_dir)
80
+ os.mkdir(faa_dir)
81
+ os.mkdir(aln_dir)
82
+ os.mkdir(trimmed_aln_dir)
83
+ os.mkdir(tree_dir)
84
+
85
+ ################################################################################
86
+
87
+ fun_to_gene_dict = dict()
88
+ if kegg_annotation_wd is not None:
89
+
90
+ print('Reading in KEGG annotation results')
91
+ file_re = '%s/*KEGG_wd/*_ko_assignment_ABCD.txt' % (kegg_annotation_wd)
92
+ file_list = glob.glob(file_re)
93
+
94
+ if len(file_list) == 0:
95
+ print('KEGG annotation file not detected, program exited!')
96
+ exit()
97
+
98
+ for each_file in file_list:
99
+ line_index = 0
100
+ for each_line in open(each_file):
101
+ if line_index > 0:
102
+ each_line_split = each_line.strip().split('\t')
103
+ if len(each_line_split) == 9:
104
+ gene_id = each_line_split[0]
105
+ ko_d_id = each_line_split[4][2:]
106
+ if ko_d_id in interested_fun_set:
107
+ if ko_d_id not in fun_to_gene_dict:
108
+ fun_to_gene_dict[ko_d_id] = set()
109
+ fun_to_gene_dict[ko_d_id].add(gene_id)
110
+ line_index += 1
111
+
112
+ cmd_list_mafft = []
113
+ cmd_list_trim = []
114
+ cmd_list_tree = []
115
+ cmd_1_mafft_txt_handle = open(cmd_1_mafft_txt, 'w')
116
+ cmd_2_trim_txt_handle = open(cmd_2_trim_txt, 'w')
117
+ cmd_3_tree_txt_handle = open(cmd_3_tree_txt, 'w')
118
+ for each_fun in sorted(fun_to_gene_dict):
119
+
120
+ # define file name
121
+ fun_faa = '%s/%s.faa' % (faa_dir, each_fun)
122
+ current_gene_tree_dir = '%s/%s' % (tree_dir, each_fun)
123
+ fun_aln = '%s/%s.aln' % (aln_dir, each_fun)
124
+ fun_aln_trimmed = '%s/%s_trimal.aln' % (trimmed_aln_dir, each_fun)
125
+ if trim_with_bmge is True:
126
+ fun_aln_trimmed = '%s/%s_bmge.aln' % (trimmed_aln_dir, each_fun)
127
+
128
+ # extract sequences
129
+ current_fun_gene_set = fun_to_gene_dict[each_fun]
130
+ select_seq(combined_faa, current_fun_gene_set, fun_faa)
131
+
132
+ os.system('mkdir %s' % current_gene_tree_dir)
133
+
134
+ # prepare commands
135
+ mafft_cmd = 'mafft-einsi --thread %s --quiet %s > %s' % (1, fun_faa, fun_aln)
136
+ trim_cmd = 'trimal -in %s -out %s -automated1' % (fun_aln, fun_aln_trimmed)
137
+ if trim_with_bmge is True:
138
+ trim_cmd = 'java -jar %s -i %s -m %s -t AA -h %s -of %s' % (pwd_bmge_jar, fun_aln, trim_model, entropy_score_cutoff, fun_aln_trimmed)
139
+ infer_tree_cmd = 'iqtree2 -s %s --seqtype AA -m %s -B 1000 --wbtl --bnni --prefix %s/%s -T %s --quiet' % (fun_aln_trimmed, iqtree_model, current_gene_tree_dir, each_fun, num_of_threads)
140
+
141
+ # add commands to list
142
+ cmd_list_mafft.append(mafft_cmd)
143
+ cmd_list_trim.append(trim_cmd)
144
+ cmd_list_tree.append(infer_tree_cmd)
145
+
146
+ # write out commands
147
+ cmd_1_mafft_txt_handle.write(mafft_cmd + '\n')
148
+ cmd_2_trim_txt_handle.write(trim_cmd + '\n')
149
+ cmd_3_tree_txt_handle.write(infer_tree_cmd + '\n')
150
+
151
+ cmd_1_mafft_txt_handle.close()
152
+ cmd_2_trim_txt_handle.close()
153
+ cmd_3_tree_txt_handle.close()
154
+
155
+ # run mafft commands
156
+ print('Running mafft with %s cores for %s commands' % (num_of_threads, len(cmd_list_mafft)))
157
+ pool = mp.Pool(processes=num_of_threads)
158
+ pool.map(os.system, cmd_list_mafft)
159
+ pool.close()
160
+ pool.join()
161
+
162
+ # run trim commands
163
+ print('Trimming with %s cores for %s commands' % (num_of_threads, len(cmd_list_trim)))
164
+ pool = mp.Pool(processes=num_of_threads)
165
+ pool.map(os.system, cmd_list_trim)
166
+ pool.close()
167
+ pool.join()
168
+
169
+ # run iqtree commands
170
+ print('Running iqtree with %s cores' % num_of_threads)
171
+ for each_iqtree_cmd in sorted(cmd_list_tree):
172
+ print(each_iqtree_cmd)
173
+ os.system(each_iqtree_cmd)
174
+
175
+
176
+ if __name__ == '__main__':
177
+
178
+ FunTree_parser = argparse.ArgumentParser()
179
+ FunTree_parser.add_argument('-i', required=True, help='orthologous gene sequence')
180
+ FunTree_parser.add_argument('-fun', required=True, help='interested functions')
181
+ FunTree_parser.add_argument('-cog', required=False, default=None, help='COG annotation results')
182
+ FunTree_parser.add_argument('-kegg', required=False, default=None, help='KEGG annotation results')
183
+ FunTree_parser.add_argument('-o', required=True, help='output directory')
184
+ FunTree_parser.add_argument('-bmge', required=False, action="store_true", help='trim with BMGE, default is trimal')
185
+ FunTree_parser.add_argument('-bmge_m', required=False, default='BLOSUM30', help='trim model, default: BLOSUM30')
186
+ FunTree_parser.add_argument('-bmge_esc', required=False, default='0.55', help='entropy score cutoff, default: 0.55')
187
+ FunTree_parser.add_argument('-iqtree_m', required=False, default='LG+G+I', help='iqtree_model, default: LG+G+I')
188
+ FunTree_parser.add_argument('-f', required=False, action="store_true", help='force overwrite')
189
+ FunTree_parser.add_argument('-t', required=False, type=int, default=1, help='num of threads, default: 1')
190
+ args = vars(FunTree_parser.parse_args())
191
+ FunTree(args)
@@ -1,4 +1,7 @@
1
- 1.43.1
1
+ 1.44.0
2
+ - new module added: FunTree
3
+
4
+ 1.43.3
2
5
  - fixed bugs
3
6
 
4
7
  1.43.0
@@ -160,7 +160,7 @@ def supertree(args):
160
160
  fa_file_list = ['.'.join(os.path.basename(i).split('.')[:-1]) for i in glob.glob(fa_file_re)]
161
161
 
162
162
  if len(fa_file_list) == 0:
163
- print('No file found in %s, progeam exited!' % oma_op_fasta)
163
+ print('No file found in %s, program exited!' % oma_op_fasta)
164
164
  exit()
165
165
 
166
166
  ################################################################################
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: TreeSAK
3
- Version: 1.43.1
3
+ Version: 1.44.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.43.1
27
+ TreeSAK v1.44.0
@@ -26,6 +26,7 @@ TreeSAK/Dir.rb
26
26
  TreeSAK/ExtractMarkerSeq.py
27
27
  TreeSAK/FastRoot.py
28
28
  TreeSAK/FastRoot_backup.py
29
+ TreeSAK/FunTree.py
29
30
  TreeSAK/GTDB_tree.py
30
31
  TreeSAK/KEGG_Luo17.py
31
32
  TreeSAK/LcaToLeaves.py
@@ -72,6 +72,7 @@ def print_main_help():
72
72
  ModifyTopo -> Modify tree topology
73
73
  GeneRax -> (to be added) Run GeneRax
74
74
  ALE -> Modules for running ALE
75
+ FunTree -> Infer tree for individual COG/KEGG function
75
76
  RootTree -> Root tree with outgroup leaves
76
77
  RootTreeGTDB214 -> Root tree by GTDB taxonomy (r214)
77
78
  RootTreeGTDB220 -> Root tree by GTDB taxonomy (r220)
@@ -824,6 +825,23 @@ if __name__ == '__main__':
824
825
  args = vars(parser.parse_args())
825
826
  mcmc2tree.mcmc2tree(args)
826
827
 
828
+ elif sys.argv[1] == 'FunTree':
829
+ from TreeSAK import FunTree
830
+ FunTree_parser = subparsers.add_parser('FunTree', usage=FunTree.FunTree_usage)
831
+ FunTree_parser.add_argument('-i', required=True, help='orthologous gene sequence')
832
+ FunTree_parser.add_argument('-fun', required=True, help='interested functions')
833
+ FunTree_parser.add_argument('-cog', required=False, default=None, help='COG annotation results')
834
+ FunTree_parser.add_argument('-kegg', required=False, default=None, help='KEGG annotation results')
835
+ FunTree_parser.add_argument('-o', required=True, help='output directory')
836
+ FunTree_parser.add_argument('-bmge', required=False, action="store_true", help='trim with BMGE, default is trimal')
837
+ FunTree_parser.add_argument('-bmge_m', required=False, default='BLOSUM30', help='trim model, default: BLOSUM30')
838
+ FunTree_parser.add_argument('-bmge_esc', required=False, default='0.55', help='entropy score cutoff, default: 0.55')
839
+ FunTree_parser.add_argument('-iqtree_m', required=False, default='LG+G+I', help='iqtree_model, default: LG+G+I')
840
+ FunTree_parser.add_argument('-f', required=False, action="store_true", help='force overwrite')
841
+ FunTree_parser.add_argument('-t', required=False, type=int, default=1, help='num of threads, default: 1')
842
+ args = vars(parser.parse_args())
843
+ FunTree.FunTree(args)
844
+
827
845
  else:
828
846
  print('Unrecognized module: %s, program exited' % sys.argv[1])
829
847
  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