TreeSAK 1.8.3__tar.gz → 1.9.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.8.3/TreeSAK.egg-info → TreeSAK-1.9.0}/PKG-INFO +2 -2
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/README.md +0 -6
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/AssessMarkerDeltaLL.py +9 -2
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/AssessMarkerPA.py +5 -3
- TreeSAK-1.9.0/TreeSAK/Dating.py +168 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/Marker2Tree.py +1 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/VERSION +4 -1
- TreeSAK-1.9.0/TreeSAK/global_functions.py +222 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0/TreeSAK.egg-info}/PKG-INFO +2 -2
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK.egg-info/SOURCES.txt +2 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/bin/TreeSAK +18 -2
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/.gitignore +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/LICENSE +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/MANIFEST.in +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/AssessCVG.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/AssessMarker.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/ConvertMSA.py +13 -13
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/KEGG_Luo17.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/OneLineAln.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/SliceMSA.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/TreeSAK_config copy.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/TreeSAK_config.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/__init__.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/compare_trees.R +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/compare_trees.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/format_leaf_name.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/get_arCOG_seq.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/iTOL.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/parse_deltall_stdout.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/rename_leaves.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/subset_tree.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK/test_1.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK.egg-info/dependency_links.txt +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK.egg-info/requires.txt +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/TreeSAK.egg-info/top_level.txt +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/bin/__init__.py +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/images/Bioinformatics.jpg +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/images/windows_cmds.docx +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/images/windows_cmds.pdf +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.0}/setup.cfg +0 -0
- {TreeSAK-1.8.3 → TreeSAK-1.9.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.9.0
|
|
4
4
|
Summary: BioSAK
|
|
5
5
|
Home-page: https://github.com/songweizhi/TreeSAK
|
|
6
6
|
Author: Weizhi Song
|
|
@@ -10,5 +10,5 @@ Keywords: Bioinformatics
|
|
|
10
10
|
Platform: UNKNOWN
|
|
11
11
|
License-File: LICENSE
|
|
12
12
|
|
|
13
|
-
TreeSAK v1.
|
|
13
|
+
TreeSAK v1.9.0
|
|
14
14
|
|
|
@@ -31,11 +31,8 @@ TreeSAK modules
|
|
|
31
31
|
...::: TreeSAK v1.7.7 :::...
|
|
32
32
|
|
|
33
33
|
Marker-related
|
|
34
|
-
parse_deltall_stdout -> Parse stdout of deltaLL.rb
|
|
35
34
|
get_arCOG_seq -> Retrieve arCOG sequences
|
|
36
|
-
Marker2Tree -> Marker to Tree
|
|
37
35
|
AssessMarkerPA -> Assess Markers by P/A among groups
|
|
38
|
-
AssessMarkerDeltaLL -> Assess Markers by DeltaLL
|
|
39
36
|
|
|
40
37
|
Multiple Sequence Alignment
|
|
41
38
|
ConvertMSA -> Convert MSA format
|
|
@@ -48,6 +45,3 @@ TreeSAK modules
|
|
|
48
45
|
compare_trees -> Compare trees with Mantel test
|
|
49
46
|
rename_leaves -> Rename tree leaves
|
|
50
47
|
FLN -> Format leaf names (e.g. remove spaces in names)
|
|
51
|
-
|
|
52
|
-
Dating-related
|
|
53
|
-
AssessCVG -> Assess dating convergence
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import glob
|
|
2
3
|
import argparse
|
|
4
|
+
from Bio import SeqIO
|
|
5
|
+
from Bio import AlignIO
|
|
3
6
|
|
|
4
7
|
|
|
5
8
|
AssessMarkerDeltaLL_usage = '''
|
|
@@ -8,9 +11,9 @@ AssessMarkerDeltaLL_usage = '''
|
|
|
8
11
|
Dependencies: iqtree
|
|
9
12
|
|
|
10
13
|
# example commands
|
|
11
|
-
TreeSAK AssessMarkerDeltaLL -deltall
|
|
14
|
+
TreeSAK AssessMarkerDeltaLL -deltall DeltaLL_stdout.txt -o op_dir -c 25-50-75-100 -mmn 20 -aln trimmed_aln_dir -jst 6 -qsub -f
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
================================================================================================
|
|
14
17
|
'''
|
|
15
18
|
|
|
16
19
|
|
|
@@ -236,6 +239,10 @@ def AssessMarkerDeltaLL(args):
|
|
|
236
239
|
else:
|
|
237
240
|
print('Job script for running iqtree exported to %s' % pwd_iqtree_js)
|
|
238
241
|
|
|
242
|
+
# prepare files for performing dating
|
|
243
|
+
print('Preparing files for performing dating')
|
|
244
|
+
|
|
245
|
+
|
|
239
246
|
|
|
240
247
|
if __name__ == '__main__':
|
|
241
248
|
|
|
@@ -2,6 +2,7 @@ import os
|
|
|
2
2
|
import glob
|
|
3
3
|
import argparse
|
|
4
4
|
from Bio import SeqIO
|
|
5
|
+
from Bio import AlignIO
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
AssessMarkerPA_usage = '''
|
|
@@ -255,9 +256,10 @@ def AssessMarkerPA(args):
|
|
|
255
256
|
pwd_qualified_marker_id_txt_handle.write('%s\n' % '\n'.join(qualified_marker_set))
|
|
256
257
|
|
|
257
258
|
# concatenate qualified alignments
|
|
258
|
-
catfasta2phyml_cmd = 'perl %s --sequential --concatenate %s/*.aln > %s 2> %s' % (catfasta2phyml_pl, pwd_qualified_marker_dir, pwd_qualified_marker_phy, pwd_qualified_marker_partition)
|
|
259
|
-
print('running: ' + catfasta2phyml_cmd)
|
|
260
|
-
os.system(catfasta2phyml_cmd)
|
|
259
|
+
#catfasta2phyml_cmd = 'perl %s --sequential --concatenate %s/*.aln > %s 2> %s' % (catfasta2phyml_pl, pwd_qualified_marker_dir, pwd_qualified_marker_phy, pwd_qualified_marker_partition)
|
|
260
|
+
#print('running: ' + catfasta2phyml_cmd)
|
|
261
|
+
#os.system(catfasta2phyml_cmd)
|
|
262
|
+
catfasta2phy(pwd_qualified_marker_dir, 'aln', pwd_qualified_marker_phy, pwd_qualified_marker_partition)
|
|
261
263
|
|
|
262
264
|
# write out iqtree js
|
|
263
265
|
guide_tree_dir = 'qualified_marker_PA_%s_guide_tree' % each_cutoff
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import argparse
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Dating_usage = '''
|
|
6
|
+
============================= Dating example commands =============================
|
|
7
|
+
|
|
8
|
+
Dependencies:
|
|
9
|
+
|
|
10
|
+
# example commands
|
|
11
|
+
TreeSAK Dating -deltall DeltaLL_stdout.txt -aod s11_marker_sets_by_DeltaLL -o s12_dating_wd -c 25-50-75-100 -mmn 20 -f
|
|
12
|
+
|
|
13
|
+
===================================================================================
|
|
14
|
+
'''
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def sep_path_basename_ext(file_in):
|
|
18
|
+
|
|
19
|
+
# separate path and file name
|
|
20
|
+
file_path, file_name = os.path.split(file_in)
|
|
21
|
+
if file_path == '':
|
|
22
|
+
file_path = '.'
|
|
23
|
+
|
|
24
|
+
# separate file basename and extension
|
|
25
|
+
file_basename, file_extension = os.path.splitext(file_name)
|
|
26
|
+
|
|
27
|
+
return file_path, file_basename, file_extension
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def submit_js(js):
|
|
31
|
+
current_wd = os.getcwd()
|
|
32
|
+
js_path, js_basename, js_ext = sep_path_basename_ext(js)
|
|
33
|
+
os.chdir(js_path)
|
|
34
|
+
os.system('qsub %s%s' % (js_basename, js_ext))
|
|
35
|
+
os.chdir(current_wd)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def Dating(args):
|
|
39
|
+
|
|
40
|
+
deltall_stdout_txt = args['deltall']
|
|
41
|
+
aod = args['aod']
|
|
42
|
+
op_dir = args['o']
|
|
43
|
+
deltall_keep_pct_str = args['c']
|
|
44
|
+
min_marker_num = args['mmn']
|
|
45
|
+
js_cpu_num = args['jst']
|
|
46
|
+
force_overwrite = args['f']
|
|
47
|
+
|
|
48
|
+
deltall_keep_pct_list = [int(i) for i in deltall_keep_pct_str.split('-')]
|
|
49
|
+
deltall_stdout_path, deltall_stdout_basename, deltall_stdout_ext = sep_path_basename_ext(deltall_stdout_txt)
|
|
50
|
+
|
|
51
|
+
# create dir
|
|
52
|
+
if os.path.isdir(op_dir) is True:
|
|
53
|
+
if force_overwrite is True:
|
|
54
|
+
os.system('rm -r %s' % op_dir)
|
|
55
|
+
else:
|
|
56
|
+
print('output folder detected, program exited!')
|
|
57
|
+
exit()
|
|
58
|
+
os.system('mkdir %s' % op_dir)
|
|
59
|
+
|
|
60
|
+
# read in deltall_stdout_txt
|
|
61
|
+
deltall_op_dict = dict()
|
|
62
|
+
for each_line in open(deltall_stdout_txt):
|
|
63
|
+
if not ((each_line.startswith('WARNING:')) or (each_line.startswith('awk:'))):
|
|
64
|
+
each_line_split = each_line.strip().split('\t')
|
|
65
|
+
marker_id = each_line_split[0]
|
|
66
|
+
value = float(each_line_split[1])
|
|
67
|
+
if marker_id not in deltall_op_dict:
|
|
68
|
+
deltall_op_dict[marker_id] = [value]
|
|
69
|
+
else:
|
|
70
|
+
deltall_op_dict[marker_id].append(value)
|
|
71
|
+
|
|
72
|
+
# assigned score to marker
|
|
73
|
+
metric_1_dict = dict()
|
|
74
|
+
metric_2_dict = dict()
|
|
75
|
+
for each_marker in deltall_op_dict:
|
|
76
|
+
metric_1_value = float("{0:.2f}".format(deltall_op_dict[each_marker][0]))
|
|
77
|
+
metric_2_value = float("{0:.2f}".format(deltall_op_dict[each_marker][1]))
|
|
78
|
+
metric_1_dict[each_marker] = metric_1_value
|
|
79
|
+
metric_2_dict[each_marker] = metric_2_value
|
|
80
|
+
|
|
81
|
+
metric_1_dict_sorted = {k: v for k, v in sorted(metric_1_dict.items(), key=lambda item: item[1])[::-1]}
|
|
82
|
+
metric_2_dict_sorted = {k: v for k, v in sorted(metric_2_dict.items(), key=lambda item: item[1])}
|
|
83
|
+
|
|
84
|
+
metric_1_score_dict = dict()
|
|
85
|
+
metric_1_score = 1
|
|
86
|
+
for each_marker_1 in metric_1_dict_sorted:
|
|
87
|
+
metric_1_score_dict[each_marker_1] = metric_1_score
|
|
88
|
+
metric_1_score += 1
|
|
89
|
+
|
|
90
|
+
metric_2_score_dict = dict()
|
|
91
|
+
metric_2_score = 1
|
|
92
|
+
for each_marker_2 in metric_2_dict_sorted:
|
|
93
|
+
metric_2_score_dict[each_marker_2] = metric_2_score
|
|
94
|
+
metric_2_score += 1
|
|
95
|
+
|
|
96
|
+
overall_score_dict = dict()
|
|
97
|
+
for each_marker in deltall_op_dict:
|
|
98
|
+
metric_score_1 = metric_1_score_dict[each_marker]
|
|
99
|
+
metric_score_2 = metric_2_score_dict[each_marker]
|
|
100
|
+
metric_score_overall = metric_score_1 + metric_score_2
|
|
101
|
+
overall_score_dict[each_marker] = metric_score_overall
|
|
102
|
+
marker_list_sorted_by_deltall = [k for k, v in sorted(overall_score_dict.items(), key=lambda item: item[1])]
|
|
103
|
+
|
|
104
|
+
# get qualified marker list
|
|
105
|
+
for each_keep_pct in deltall_keep_pct_list:
|
|
106
|
+
marker_num_to_keep = round(len(marker_list_sorted_by_deltall)*each_keep_pct/100)
|
|
107
|
+
|
|
108
|
+
if marker_num_to_keep < min_marker_num:
|
|
109
|
+
print('Ignored DeltaLL cutoff at %s , the number of qualified markers (%s) less than %s' % (each_keep_pct, marker_num_to_keep, min_marker_num))
|
|
110
|
+
else:
|
|
111
|
+
pwd_aln_concatenated = '%s/%s_DeltaLL_%s_concatenated.phy' % (aod, deltall_stdout_basename.split('_DeltaLL_stdout')[0], each_keep_pct)
|
|
112
|
+
pwd_c60_tree_file = '%s/%s_DeltaLL_%s_iqtree_C60_PMSF/concatenated.treefile' % (aod, deltall_stdout_basename.split('_DeltaLL_stdout')[0], each_keep_pct)
|
|
113
|
+
current_dating_wd = '%s/%s_DeltaLL_%s' % (op_dir, deltall_stdout_basename.split('_DeltaLL_stdout')[0], each_keep_pct)
|
|
114
|
+
pwd_c60_tree_file_renamed = '%s/concatenated_raw.treefile' % current_dating_wd
|
|
115
|
+
pwd_to_do_note_txt = '%s/to_do.txt' % current_dating_wd
|
|
116
|
+
pwd_dating_js = '%s/js_%s_DeltaLL_%s_dating.sh' % (op_dir, deltall_stdout_basename.split('_DeltaLL_stdout')[0], each_keep_pct)
|
|
117
|
+
|
|
118
|
+
print('Alignment:\t%s' % pwd_aln_concatenated)
|
|
119
|
+
print('Tree file:\t%s' % pwd_c60_tree_file)
|
|
120
|
+
print('Dating wd:\t%s' % current_dating_wd)
|
|
121
|
+
print()
|
|
122
|
+
|
|
123
|
+
# create dating wd and copy file into it
|
|
124
|
+
os.mkdir(current_dating_wd)
|
|
125
|
+
os.system('cp %s %s' % (pwd_c60_tree_file, pwd_c60_tree_file_renamed))
|
|
126
|
+
os.system('cp %s %s/' % (pwd_aln_concatenated, current_dating_wd))
|
|
127
|
+
|
|
128
|
+
# write out to do
|
|
129
|
+
with open(pwd_to_do_note_txt, 'w') as pwd_to_do_note_txt_handle:
|
|
130
|
+
pwd_to_do_note_txt_handle.write('1. Root the tree in iTOL\n')
|
|
131
|
+
pwd_to_do_note_txt_handle.write('2. Replace the eukaryotic clade with the one has EU time constraints using TreeGraph2\n')
|
|
132
|
+
pwd_to_do_note_txt_handle.write('3. Add time constraints to the tree\n')
|
|
133
|
+
pwd_to_do_note_txt_handle.write('4. Renamed the modified tree to concatenated_modified.treefile\n')
|
|
134
|
+
|
|
135
|
+
# write job script
|
|
136
|
+
with open(pwd_dating_js, 'w') as pwd_dating_js_handle:
|
|
137
|
+
dating_cmd = ''
|
|
138
|
+
pwd_dating_js_handle.write('cd %s/%s\n' % (os.getcwd(), current_dating_wd))
|
|
139
|
+
pwd_dating_js_handle.write(dating_cmd + '\n')
|
|
140
|
+
|
|
141
|
+
if submit_job is True:
|
|
142
|
+
print(pwd_dating_js)
|
|
143
|
+
submit_js(pwd_dating_js)
|
|
144
|
+
else:
|
|
145
|
+
print('Job script for dating exported to %s' % pwd_dating_js)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
if __name__ == '__main__':
|
|
149
|
+
|
|
150
|
+
# initialize the options parser
|
|
151
|
+
parser = argparse.ArgumentParser()
|
|
152
|
+
parser.add_argument('-deltall', required=True, help='DeltaLL stdout')
|
|
153
|
+
parser.add_argument('-aod', required=True, help='AssessMarkerDeltaLL output dir')
|
|
154
|
+
parser.add_argument('-o', required=True, help='dating wd')
|
|
155
|
+
parser.add_argument('-c', required=False, default='25-50-75-100', help='cutoffs, default: 25-50-75-100')
|
|
156
|
+
parser.add_argument('-mmn', required=False, default=20, type=int, help='minimal marker number, default: 20')
|
|
157
|
+
parser.add_argument('-jst', required=False, default='6', help='threads to request in job script, for performing dating')
|
|
158
|
+
parser.add_argument('-f', required=False, action="store_true", help='force overwrite')
|
|
159
|
+
args = vars(parser.parse_args())
|
|
160
|
+
Dating(args)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
'''
|
|
164
|
+
|
|
165
|
+
cd /Users/songweizhi/Desktop/dating_test
|
|
166
|
+
python3 /Users/songweizhi/PycharmProjects/TreeSAK/TreeSAK/Dating.py -deltall Marker_set_2_Betts_2018_29_arCOG_Marker2Tree_e30/s10_assess_marker_deltaLL/PA_75_DeltaLL_stdout.txt -aod Marker_set_2_Betts_2018_29_arCOG_Marker2Tree_e30/s11_marker_sets_by_DeltaLL -o Marker_set_2_Betts_2018_29_arCOG_Marker2Tree_e30/s12_dating_wd -c 25-50-75-100 -mmn 20 -f
|
|
167
|
+
|
|
168
|
+
'''
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import glob
|
|
3
|
+
import shutil
|
|
4
|
+
from Bio import SeqIO
|
|
5
|
+
from Bio import AlignIO
|
|
6
|
+
import matplotlib as mpl
|
|
7
|
+
mpl.use('Agg')
|
|
8
|
+
import matplotlib.pyplot as plt
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
time_format = '[%Y-%m-%d %H:%M:%S] '
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def is_number(s):
|
|
15
|
+
try:
|
|
16
|
+
float(s)
|
|
17
|
+
return True
|
|
18
|
+
except ValueError:
|
|
19
|
+
return False
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def force_create_folder(folder_to_create):
|
|
23
|
+
if os.path.isdir(folder_to_create):
|
|
24
|
+
shutil.rmtree(folder_to_create, ignore_errors=True)
|
|
25
|
+
if os.path.isdir(folder_to_create):
|
|
26
|
+
shutil.rmtree(folder_to_create, ignore_errors=True)
|
|
27
|
+
if os.path.isdir(folder_to_create):
|
|
28
|
+
shutil.rmtree(folder_to_create, ignore_errors=True)
|
|
29
|
+
if os.path.isdir(folder_to_create):
|
|
30
|
+
shutil.rmtree(folder_to_create, ignore_errors=True)
|
|
31
|
+
|
|
32
|
+
os.mkdir(folder_to_create)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def sep_path_basename_ext(file_in):
|
|
36
|
+
|
|
37
|
+
# separate path and file name
|
|
38
|
+
file_path, file_name = os.path.split(file_in)
|
|
39
|
+
if file_path == '':
|
|
40
|
+
file_path = '.'
|
|
41
|
+
|
|
42
|
+
# separate file basename and extension
|
|
43
|
+
file_basename, file_ext = os.path.splitext(file_name)
|
|
44
|
+
|
|
45
|
+
return file_path, file_basename, file_ext
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def get_no_hidden_folder_list(wd):
|
|
49
|
+
folder_list = []
|
|
50
|
+
for each_folder in os.listdir(wd):
|
|
51
|
+
if not each_folder.startswith('.'):
|
|
52
|
+
folder_list.append(each_folder)
|
|
53
|
+
return folder_list
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def unique_list_elements(list_input):
|
|
57
|
+
|
|
58
|
+
list_output = []
|
|
59
|
+
for each_element in list_input:
|
|
60
|
+
if each_element not in list_output:
|
|
61
|
+
list_output.append(each_element)
|
|
62
|
+
|
|
63
|
+
return list_output
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def ctg_depth_and_gbk_to_gene_depth(ctg_depth_file, gbk_file, skip_depth_file_header, gene_depth_file_folder):
|
|
67
|
+
|
|
68
|
+
gbk_file_path, gbk_file_basename, gbk_file_extension = sep_path_basename_ext(gbk_file)
|
|
69
|
+
pwd_depth_file = '%s/%s.depth' % (gene_depth_file_folder, gbk_file_basename)
|
|
70
|
+
|
|
71
|
+
# read in depth
|
|
72
|
+
ctg_depth_dict = {}
|
|
73
|
+
line = 0
|
|
74
|
+
for ctg in open(ctg_depth_file):
|
|
75
|
+
|
|
76
|
+
ctg_split = ctg.strip().split('\t')
|
|
77
|
+
|
|
78
|
+
if skip_depth_file_header is True:
|
|
79
|
+
if line > 0:
|
|
80
|
+
ctg_depth_dict[ctg_split[0]] = float(ctg_split[1])
|
|
81
|
+
else:
|
|
82
|
+
ctg_depth_dict[ctg_split[0]] = float(ctg_split[1])
|
|
83
|
+
|
|
84
|
+
line += 1
|
|
85
|
+
|
|
86
|
+
# get gene depth
|
|
87
|
+
gene_depth_file_handle = open(pwd_depth_file, 'w')
|
|
88
|
+
gene_depth_file_handle.write('Gene\tDepth\n')
|
|
89
|
+
for seq_record in SeqIO.parse(gbk_file, 'genbank'):
|
|
90
|
+
|
|
91
|
+
seq_id = seq_record.id
|
|
92
|
+
seq_depth = ctg_depth_dict[seq_id]
|
|
93
|
+
|
|
94
|
+
for feature in seq_record.features:
|
|
95
|
+
if feature.type == 'CDS':
|
|
96
|
+
gene_id = feature.qualifiers['locus_tag'][0]
|
|
97
|
+
for_out = '%s\t%s\n' % (gene_id, seq_depth)
|
|
98
|
+
gene_depth_file_handle.write(for_out)
|
|
99
|
+
|
|
100
|
+
gene_depth_file_handle.close()
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def barh_plotter(num_list, label_list, query_seq_num, query_ko_NA, fig_width, fig_height, plot_file):
|
|
104
|
+
|
|
105
|
+
fig, ax = plt.subplots()
|
|
106
|
+
fig.set_size_inches(fig_width, fig_height)
|
|
107
|
+
|
|
108
|
+
y_pos = range(len(num_list))
|
|
109
|
+
ax.barh(y_pos, num_list, height=0.8, align='center', alpha=0.2, linewidth=0)
|
|
110
|
+
ax.set_yticks([]) # not show yticks
|
|
111
|
+
ax.invert_xaxis() # line up bar on right
|
|
112
|
+
ax.invert_yaxis() # put first number on top
|
|
113
|
+
ax.axis('tight') # remove extra spaces at the top and bottom, equal to: ax.margins(0, 0)
|
|
114
|
+
# ax.margins(0, 0.01) # customize space percentage
|
|
115
|
+
|
|
116
|
+
ax.set_xlabel('Number of gene')
|
|
117
|
+
ax.set_title('Query genes number: %s, genes without KO: %s' % (query_seq_num, query_ko_NA))
|
|
118
|
+
|
|
119
|
+
ax2 = ax.twinx()
|
|
120
|
+
ax2.set_ylim(ax.get_ylim())
|
|
121
|
+
ax2.set_yticks(y_pos)
|
|
122
|
+
ax2.set_yticklabels(label_list)
|
|
123
|
+
|
|
124
|
+
plt.tight_layout()
|
|
125
|
+
plt.savefig(plot_file, dpi=300)
|
|
126
|
+
plt.close()
|
|
127
|
+
plt.clf()
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def AnnotateNorm(file_in, skip_header, value_column, Divisor_value, file_out, file_out_header):
|
|
131
|
+
|
|
132
|
+
file_out_handle = open(file_out, 'w')
|
|
133
|
+
file_out_handle.write(file_out_header)
|
|
134
|
+
line_num = 0
|
|
135
|
+
for each_line in open(file_in):
|
|
136
|
+
|
|
137
|
+
each_line_split = each_line.strip().split('\t')
|
|
138
|
+
value_str = each_line_split[value_column - 1]
|
|
139
|
+
|
|
140
|
+
if (skip_header is True and line_num > 0) or (skip_header is False):
|
|
141
|
+
value_pct = float(value_str) * 100 / Divisor_value
|
|
142
|
+
each_line_split[value_column - 1] = str(float("{0:.2f}".format(value_pct)))
|
|
143
|
+
file_out_handle.write('%s\n' % '\t'.join(each_line_split))
|
|
144
|
+
|
|
145
|
+
line_num += 1
|
|
146
|
+
|
|
147
|
+
file_out_handle.close()
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def get_gene_list_TotalDepth(gene_list, gene_to_depth_dict):
|
|
151
|
+
|
|
152
|
+
total_depth = 0
|
|
153
|
+
for gene in gene_list:
|
|
154
|
+
gene_depth = gene_to_depth_dict[gene]
|
|
155
|
+
total_depth += gene_depth
|
|
156
|
+
|
|
157
|
+
return total_depth
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def catfasta2phy(msa_dir, msa_ext, concatenated_msa_phy, partition_file):
|
|
161
|
+
|
|
162
|
+
concatenated_msa_fasta = '%s.fasta' % concatenated_msa_phy
|
|
163
|
+
msa_file_re = '%s/*.%s' % (msa_dir, msa_ext)
|
|
164
|
+
msa_file_list = [os.path.basename(file_name) for file_name in glob.glob(msa_file_re)]
|
|
165
|
+
msa_file_list_sorted = sorted(msa_file_list)
|
|
166
|
+
|
|
167
|
+
complete_gnm_set = set()
|
|
168
|
+
for each_msa_file in msa_file_list:
|
|
169
|
+
pwd_msa = '%s/%s' % (msa_dir, each_msa_file)
|
|
170
|
+
for each_seq in SeqIO.parse(pwd_msa, 'fasta'):
|
|
171
|
+
complete_gnm_set.add(each_seq.id)
|
|
172
|
+
|
|
173
|
+
complete_gnm_list_sorted = sorted([i for i in complete_gnm_set])
|
|
174
|
+
|
|
175
|
+
# initialize concatenated msa dict
|
|
176
|
+
gnm_to_seq_dict = {i: '' for i in complete_gnm_list_sorted}
|
|
177
|
+
msa_len_dict = dict()
|
|
178
|
+
for each_msa_file in msa_file_list_sorted:
|
|
179
|
+
gene_id = each_msa_file.split('.' + msa_ext)[0]
|
|
180
|
+
|
|
181
|
+
# read in msa
|
|
182
|
+
current_msa_len = 0
|
|
183
|
+
current_msa_len_set = set()
|
|
184
|
+
pwd_current_msa = '%s/%s' % (msa_dir, each_msa_file)
|
|
185
|
+
current_msa_seq_dict = dict()
|
|
186
|
+
for each_seq in SeqIO.parse(pwd_current_msa, 'fasta'):
|
|
187
|
+
complete_gnm_set.add(each_seq.id)
|
|
188
|
+
current_msa_seq_dict[each_seq.id] = str(each_seq.seq)
|
|
189
|
+
current_msa_len_set.add(len(each_seq.seq))
|
|
190
|
+
current_msa_len = len(each_seq.seq)
|
|
191
|
+
|
|
192
|
+
if len(current_msa_len_set) != 1:
|
|
193
|
+
print('Sequences with different length were found in %s, program exited!' % each_msa_file)
|
|
194
|
+
exit()
|
|
195
|
+
|
|
196
|
+
msa_len_dict[gene_id] = current_msa_len
|
|
197
|
+
|
|
198
|
+
# add sequence to concatenated msa dict
|
|
199
|
+
for each_gnm in complete_gnm_list_sorted:
|
|
200
|
+
msa_seq = current_msa_seq_dict.get(each_gnm, current_msa_len*'-')
|
|
201
|
+
gnm_to_seq_dict[each_gnm] += msa_seq
|
|
202
|
+
|
|
203
|
+
# write out concatenated msa
|
|
204
|
+
concatenated_msa_handle = open(concatenated_msa_fasta, 'w')
|
|
205
|
+
for each_gnm in complete_gnm_list_sorted:
|
|
206
|
+
concatenated_msa_handle.write('>%s\n' % each_gnm)
|
|
207
|
+
concatenated_msa_handle.write('%s\n' % gnm_to_seq_dict[each_gnm])
|
|
208
|
+
concatenated_msa_handle.close()
|
|
209
|
+
|
|
210
|
+
# write out partition file
|
|
211
|
+
end_pos = 0
|
|
212
|
+
partition_file_handle = open(partition_file, 'w')
|
|
213
|
+
for each_m in msa_file_list_sorted:
|
|
214
|
+
gene_id = each_m.split('.' + msa_ext)[0]
|
|
215
|
+
current_m_len = msa_len_dict[gene_id]
|
|
216
|
+
partition_file_handle.write('%s = %s-%s\n' % (each_m, (end_pos + 1), (end_pos + current_m_len)))
|
|
217
|
+
end_pos += current_m_len
|
|
218
|
+
partition_file_handle.close()
|
|
219
|
+
|
|
220
|
+
# convert msa in fasta to phy
|
|
221
|
+
AlignIO.convert(concatenated_msa_fasta, 'fasta', concatenated_msa_phy, 'phylip-relaxed')
|
|
222
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: TreeSAK
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.9.0
|
|
4
4
|
Summary: BioSAK
|
|
5
5
|
Home-page: https://github.com/songweizhi/TreeSAK
|
|
6
6
|
Author: Weizhi Song
|
|
@@ -10,5 +10,5 @@ Keywords: Bioinformatics
|
|
|
10
10
|
Platform: UNKNOWN
|
|
11
11
|
License-File: LICENSE
|
|
12
12
|
|
|
13
|
-
TreeSAK v1.
|
|
13
|
+
TreeSAK v1.9.0
|
|
14
14
|
|
|
@@ -8,6 +8,7 @@ TreeSAK/AssessMarker.py
|
|
|
8
8
|
TreeSAK/AssessMarkerDeltaLL.py
|
|
9
9
|
TreeSAK/AssessMarkerPA.py
|
|
10
10
|
TreeSAK/ConvertMSA.py
|
|
11
|
+
TreeSAK/Dating.py
|
|
11
12
|
TreeSAK/KEGG_Luo17.py
|
|
12
13
|
TreeSAK/Marker2Tree.py
|
|
13
14
|
TreeSAK/OneLineAln.py
|
|
@@ -20,6 +21,7 @@ TreeSAK/compare_trees.R
|
|
|
20
21
|
TreeSAK/compare_trees.py
|
|
21
22
|
TreeSAK/format_leaf_name.py
|
|
22
23
|
TreeSAK/get_arCOG_seq.py
|
|
24
|
+
TreeSAK/global_functions.py
|
|
23
25
|
TreeSAK/iTOL.py
|
|
24
26
|
TreeSAK/parse_deltall_stdout.py
|
|
25
27
|
TreeSAK/rename_leaves.py
|
|
@@ -35,9 +35,7 @@ def print_main_help():
|
|
|
35
35
|
Marker-related
|
|
36
36
|
parse_deltall_stdout -> Parse stdout of deltaLL.rb
|
|
37
37
|
get_arCOG_seq -> Retrieve arCOG sequences
|
|
38
|
-
Marker2Tree -> Marker to Tree
|
|
39
38
|
AssessMarkerPA -> Assess Markers by P/A among groups
|
|
40
|
-
AssessMarkerDeltaLL -> Assess Markers by DeltaLL
|
|
41
39
|
|
|
42
40
|
Multiple Sequence Alignment
|
|
43
41
|
ConvertMSA -> Convert MSA format
|
|
@@ -54,6 +52,11 @@ def print_main_help():
|
|
|
54
52
|
Dating-related
|
|
55
53
|
AssessCVG -> Assess dating convergence
|
|
56
54
|
|
|
55
|
+
Dating workflow
|
|
56
|
+
Marker2Tree -> Marker to Tree
|
|
57
|
+
AssessMarkerDeltaLL -> Assess Markers by DeltaLL
|
|
58
|
+
Dating -> Perform dating
|
|
59
|
+
|
|
57
60
|
''' % version(config_dict)
|
|
58
61
|
|
|
59
62
|
print(help_message)
|
|
@@ -242,6 +245,19 @@ if __name__ == '__main__':
|
|
|
242
245
|
args = vars(parser.parse_args())
|
|
243
246
|
AssessMarkerDeltaLL.AssessMarkerDeltaLL(args)
|
|
244
247
|
|
|
248
|
+
elif sys.argv[1] == 'Dating':
|
|
249
|
+
from TreeSAK import Dating
|
|
250
|
+
Dating_parser = subparsers.add_parser('Dating', usage=Dating.Dating_usage)
|
|
251
|
+
Dating_parser.add_argument('-deltall', required=True, help='DeltaLL stdout')
|
|
252
|
+
Dating_parser.add_argument('-aod', required=True, help='AssessMarkerDeltaLL output dir')
|
|
253
|
+
Dating_parser.add_argument('-o', required=True, help='dating wd')
|
|
254
|
+
Dating_parser.add_argument('-c', required=False, default='25-50-75-100', help='cutoffs, default: 25-50-75-100')
|
|
255
|
+
Dating_parser.add_argument('-mmn', required=False, default=20, type=int, help='minimal marker number, default: 20')
|
|
256
|
+
Dating_parser.add_argument('-jst', required=False, default='6', help='threads to request in job script, for performing dating')
|
|
257
|
+
Dating_parser.add_argument('-f', required=False, action="store_true", help='force overwrite')
|
|
258
|
+
args = vars(parser.parse_args())
|
|
259
|
+
Dating.Dating(args)
|
|
260
|
+
|
|
245
261
|
else:
|
|
246
262
|
print('Unrecognized command: %s, program exited' % sys.argv[1])
|
|
247
263
|
exit()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -5,19 +5,6 @@ from Bio import SeqIO
|
|
|
5
5
|
from Bio import AlignIO
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
def sep_path_basename_ext(file_in):
|
|
9
|
-
|
|
10
|
-
# separate path and file name
|
|
11
|
-
file_path, file_name = os.path.split(file_in)
|
|
12
|
-
if file_path == '':
|
|
13
|
-
file_path = '.'
|
|
14
|
-
|
|
15
|
-
# separate file basename and extension
|
|
16
|
-
file_basename, file_extension = os.path.splitext(file_name)
|
|
17
|
-
|
|
18
|
-
return file_path, file_basename, file_extension
|
|
19
|
-
|
|
20
|
-
|
|
21
8
|
ConvertMSA_usage = '''
|
|
22
9
|
================================= ConvertMSA example commands =================================
|
|
23
10
|
|
|
@@ -32,6 +19,19 @@ fasta, phylip, phylip-relaxed, phylip-sequential, clustal
|
|
|
32
19
|
'''
|
|
33
20
|
|
|
34
21
|
|
|
22
|
+
def sep_path_basename_ext(file_in):
|
|
23
|
+
|
|
24
|
+
# separate path and file name
|
|
25
|
+
file_path, file_name = os.path.split(file_in)
|
|
26
|
+
if file_path == '':
|
|
27
|
+
file_path = '.'
|
|
28
|
+
|
|
29
|
+
# separate file basename and extension
|
|
30
|
+
file_basename, file_extension = os.path.splitext(file_name)
|
|
31
|
+
|
|
32
|
+
return file_path, file_basename, file_extension
|
|
33
|
+
|
|
34
|
+
|
|
35
35
|
def ConvertMSA(args):
|
|
36
36
|
|
|
37
37
|
aln_in = args['i']
|
|
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
|