treesak 1.51.2__py3-none-any.whl
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.
Potentially problematic release.
This version of treesak might be problematic. Click here for more details.
- TreeSAK/ALE.py +63 -0
- TreeSAK/ALE1.py +268 -0
- TreeSAK/ALE2.py +168 -0
- TreeSAK/ALE2RTC.py +30 -0
- TreeSAK/ALE3.py +205 -0
- TreeSAK/ALE4.py +636 -0
- TreeSAK/ALE5.py +210 -0
- TreeSAK/ALE6.py +401 -0
- TreeSAK/ALE7.py +126 -0
- TreeSAK/ALE_backup.py +1081 -0
- TreeSAK/AssessCVG.py +128 -0
- TreeSAK/AssessMarker.py +306 -0
- TreeSAK/AssessMarkerDeltaLL.py +257 -0
- TreeSAK/AssessMarkerPA.py +317 -0
- TreeSAK/AssessPB.py +130 -0
- TreeSAK/BMGE.jar +0 -0
- TreeSAK/BMGE.py +49 -0
- TreeSAK/CompareMCMC.py +138 -0
- TreeSAK/ConcateMSA.py +111 -0
- TreeSAK/ConvertMSA.py +135 -0
- TreeSAK/Dir.rb +82 -0
- TreeSAK/ExtractMarkerSeq.py +263 -0
- TreeSAK/FastRoot.py +1175 -0
- TreeSAK/FastRoot_backup.py +1122 -0
- TreeSAK/FigTree.py +34 -0
- TreeSAK/GTDB_tree.py +76 -0
- TreeSAK/GeneTree.py +142 -0
- TreeSAK/KEGG_Luo17.py +807 -0
- TreeSAK/LcaToLeaves.py +66 -0
- TreeSAK/MarkerRef2Tree.py +616 -0
- TreeSAK/MarkerRef2Tree_backup.py +628 -0
- TreeSAK/MarkerSeq2Tree.py +290 -0
- TreeSAK/MarkerSeq2Tree_backup.py +259 -0
- TreeSAK/ModifyTopo.py +116 -0
- TreeSAK/Newick_tree_plotter.py +79 -0
- TreeSAK/OMA.py +170 -0
- TreeSAK/OMA2.py +212 -0
- TreeSAK/OneLineAln.py +50 -0
- TreeSAK/PB.py +155 -0
- TreeSAK/PMSF.py +106 -0
- TreeSAK/PhyloBiAssoc.R +84 -0
- TreeSAK/PhyloBiAssoc.py +167 -0
- TreeSAK/PlotMCMC.py +41 -0
- TreeSAK/PlotMcmcNode.py +152 -0
- TreeSAK/PlotMcmcNode_old.py +252 -0
- TreeSAK/RootTree.py +101 -0
- TreeSAK/RootTreeGTDB214.py +288 -0
- TreeSAK/RootTreeGTDB220.py +300 -0
- TreeSAK/RootTreeGTDB226.py +300 -0
- TreeSAK/SequentialDating.py +16 -0
- TreeSAK/SingleAleHGT.py +157 -0
- TreeSAK/SingleLinePhy.py +50 -0
- TreeSAK/SliceMSA.py +142 -0
- TreeSAK/SplitScore.py +19 -0
- TreeSAK/SplitScore1.py +178 -0
- TreeSAK/SplitScore1OMA.py +148 -0
- TreeSAK/SplitScore2.py +597 -0
- TreeSAK/TaxaCountStats.R +256 -0
- TreeSAK/TaxonTree.py +47 -0
- TreeSAK/TreeSAK_config.py +32 -0
- TreeSAK/VERSION +158 -0
- TreeSAK/VisHPD95.R +45 -0
- TreeSAK/VisHPD95.py +200 -0
- TreeSAK/__init__.py +0 -0
- TreeSAK/ale_parser.py +74 -0
- TreeSAK/ale_splitter.py +63 -0
- TreeSAK/alignment_pruner.pl +1471 -0
- TreeSAK/assessOG.py +45 -0
- TreeSAK/catfasta2phy.py +140 -0
- TreeSAK/cogTree.py +185 -0
- TreeSAK/compare_trees.R +30 -0
- TreeSAK/compare_trees.py +255 -0
- TreeSAK/dating.py +264 -0
- TreeSAK/dating_ss.py +361 -0
- TreeSAK/deltall.py +82 -0
- TreeSAK/do_rrtc.rb +464 -0
- TreeSAK/fa2phy.py +42 -0
- TreeSAK/format_leaf_name.py +70 -0
- TreeSAK/gap_stats.py +38 -0
- TreeSAK/get_SCG_tree.py +742 -0
- TreeSAK/get_arCOG_seq.py +97 -0
- TreeSAK/global_functions.py +222 -0
- TreeSAK/gnm_leaves.py +43 -0
- TreeSAK/iTOL.py +791 -0
- TreeSAK/iTOL_gene_tree.py +80 -0
- TreeSAK/itol_msa_stats.py +56 -0
- TreeSAK/keep_highest_rrtc.py +37 -0
- TreeSAK/koTree.py +194 -0
- TreeSAK/label_tree.R +75 -0
- TreeSAK/label_tree.py +121 -0
- TreeSAK/mad.py +708 -0
- TreeSAK/mcmc2tree.py +58 -0
- TreeSAK/mcmcTC copy.py +92 -0
- TreeSAK/mcmcTC.py +104 -0
- TreeSAK/mcmctree_vs_reltime.R +44 -0
- TreeSAK/mcmctree_vs_reltime.py +252 -0
- TreeSAK/merge_pdf.py +32 -0
- TreeSAK/pRTC.py +56 -0
- TreeSAK/parse_mcmctree.py +198 -0
- TreeSAK/parse_reltime.py +141 -0
- TreeSAK/phy2fa.py +37 -0
- TreeSAK/plot_distruibution_th.py +165 -0
- TreeSAK/prep_mcmctree_ctl.py +92 -0
- TreeSAK/print_leaves.py +32 -0
- TreeSAK/pruneMSA.py +63 -0
- TreeSAK/recode.py +73 -0
- TreeSAK/remove_bias.R +112 -0
- TreeSAK/rename_leaves.py +77 -0
- TreeSAK/replace_clade.py +55 -0
- TreeSAK/root_with_out_group.py +84 -0
- TreeSAK/run_TaxaCountStats_R_s1.py +455 -0
- TreeSAK/subsample_drep_gnms.py +74 -0
- TreeSAK/subset.py +69 -0
- TreeSAK/subset_tree_stupid_old_way.py +193 -0
- TreeSAK/supertree.py +330 -0
- TreeSAK/tmp_1.py +19 -0
- TreeSAK/tmp_2.py +19 -0
- TreeSAK/tmp_3.py +120 -0
- TreeSAK/weighted_rand.rb +23 -0
- treesak-1.51.2.data/scripts/TreeSAK +950 -0
- treesak-1.51.2.dist-info/LICENSE +674 -0
- treesak-1.51.2.dist-info/METADATA +27 -0
- treesak-1.51.2.dist-info/RECORD +125 -0
- treesak-1.51.2.dist-info/WHEEL +5 -0
- treesak-1.51.2.dist-info/top_level.txt +1 -0
TreeSAK/iTOL.py
ADDED
|
@@ -0,0 +1,791 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import os.path
|
|
3
|
+
import random
|
|
4
|
+
import argparse
|
|
5
|
+
import seaborn as sns
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
'''
|
|
9
|
+
TreeSAK iTOL -ColorLabel -lg Mag_genus.txt -gc genus_color.txt-o ColorLabel_genus.txt
|
|
10
|
+
'''
|
|
11
|
+
|
|
12
|
+
iTOL_usage = '''
|
|
13
|
+
==================================== iTOL example commands ====================================
|
|
14
|
+
|
|
15
|
+
# Example commands
|
|
16
|
+
TreeSAK iTOL -Labels -ll new_Mag_name.txt -o Mag_name_iTOL_Labels.txt
|
|
17
|
+
TreeSAK iTOL -ColoredLabel -lg leaf_group.txt -gc group_color.txt -o iTOL_ColoredLabel.txt
|
|
18
|
+
TreeSAK iTOL -ColoredLabel -lg leaf_group.txt -gc group_color.txt -o iTOL_ColoredLabel.txt -ll new_Mag_name.txt
|
|
19
|
+
TreeSAK iTOL -Binary -lm Binary_matrix.txt -lt Enzyme -o Presence_Absence_iTOL.txt -cc "#F1BB83"
|
|
20
|
+
TreeSAK iTOL -Binary -lm Binary_matrix.txt -lt Enzyme -o Presence_Absence_iTOL.txt -cc col_color.txt
|
|
21
|
+
TreeSAK iTOL -BinaryID -id MagID.txt -lt dRep95 -o dRep95_representatives_iTOL.txt
|
|
22
|
+
TreeSAK iTOL -Heatmap -lm MagAbundance.txt -lt Abundance -o Heatmap_abundance.txt
|
|
23
|
+
TreeSAK iTOL -SimpleBar -lv MagSize.txt -scale 0-3-6-9 -lt Size -o SimpleBar_size.txt
|
|
24
|
+
TreeSAK iTOL -ColorStrip -lg MagTaxon.txt -lt Phylum -gc phylum_color.txt -o ColorStrip_taxon.txt
|
|
25
|
+
TreeSAK iTOL -ColorRange -lg MagTaxon.txt -lt Phylum -gc phylum_color.txt -o ColorRange_taxon.txt
|
|
26
|
+
TreeSAK iTOL -ColorRange -taxon Taxonomy.txt -rank f -lt Family -o ColorRange_taxon.txt
|
|
27
|
+
TreeSAK iTOL -ColorClade -lg Mag_genus.txt -gc genus_color.txt-o ColorClade_genus.txt
|
|
28
|
+
TreeSAK iTOL -ExternalShape -lm identity_matrix.txt -lt Identity -scale 25-50-75-100 -o ExternalShape_identity.txt
|
|
29
|
+
TreeSAK iTOL -PieChart -lv MagCompleteness.txt -lt Completeness -o PieChart_completeness.txt
|
|
30
|
+
TreeSAK iTOL -Collapse -lg MagTaxon.txt -o Collapse_by_taxon.txt
|
|
31
|
+
|
|
32
|
+
# Leaf-to-Group file format (-lg, tab separated, no header)
|
|
33
|
+
genome_1 Bacteria
|
|
34
|
+
genome_2 Archaea
|
|
35
|
+
|
|
36
|
+
# taxonomy file format (-taxon, tab separated, GTDB-format taxononomy string)
|
|
37
|
+
genome_1 d__Bacteria;p__Proteobacteria;c__Alphaproteobacteria;o__Dongiales;f__Dongiaceae;g__Dongia;s__Dongia mobilis
|
|
38
|
+
genome_2 d__Bacteria;p__Proteobacteria;c__Gammaproteobacteria;o__Arenicellales;f__LS-SOB;g__VYGS01;s__
|
|
39
|
+
|
|
40
|
+
# Group-to-Color and Column-to-Color file format (-gc and -cc, tab separated, no header)
|
|
41
|
+
bac #CCCC00
|
|
42
|
+
ar #9999FF
|
|
43
|
+
# Please note you can only specify one color for Binary data, provide with -gc lightblue or -gc "#85C1E9"
|
|
44
|
+
|
|
45
|
+
# Leaf-to-Value file format (-lv, tab separated, no header)
|
|
46
|
+
genome_1 6.15
|
|
47
|
+
genome_2 6.63
|
|
48
|
+
|
|
49
|
+
# Leaf-to-Matrix file format (-lm, tab separated, header required!!!)
|
|
50
|
+
Genome_id SampleA SampleB SampleC
|
|
51
|
+
genome_1 6.15 2.23 1.56
|
|
52
|
+
genome_2 6.63 1.72 2.55
|
|
53
|
+
|
|
54
|
+
===============================================================================================
|
|
55
|
+
'''
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def get_color_list(color_num):
|
|
59
|
+
|
|
60
|
+
if color_num <= 8:
|
|
61
|
+
color_list_combined = ['#3787c0', '#39399f', '#ffb939', '#399f39', '#9f399f', '#fb694a', '#9f9f39', '#959595']
|
|
62
|
+
|
|
63
|
+
elif 8 < color_num <= 16:
|
|
64
|
+
color_list_combined = ['#2b7bba', '#89bedc', '#2e2e99', '#8a8acc', '#ffa500', '#ffc55c', '#2e992e', '#8acc8a', '#992e99', '#cc8acc', '#d52221', '#fc8161', '#99992e', '#cccc8a', '#5c5c5c', '#adadad']
|
|
65
|
+
|
|
66
|
+
else:
|
|
67
|
+
color_num_each = math.ceil(color_num/8) + 2
|
|
68
|
+
color_list_1 = sns.color_palette('Blues', n_colors=color_num_each).as_hex()
|
|
69
|
+
color_list_2 = sns.light_palette('navy', n_colors=color_num_each).as_hex()
|
|
70
|
+
color_list_3 = sns.light_palette('orange', n_colors=color_num_each).as_hex()
|
|
71
|
+
color_list_4 = sns.light_palette('green', n_colors=color_num_each).as_hex()
|
|
72
|
+
color_list_5 = sns.light_palette('purple', n_colors=color_num_each).as_hex()
|
|
73
|
+
color_list_6 = sns.color_palette('Reds', n_colors=color_num_each).as_hex()
|
|
74
|
+
color_list_7 = sns.light_palette('olive', n_colors=color_num_each).as_hex()
|
|
75
|
+
color_list_8 = sns.color_palette('Greys', n_colors=color_num_each).as_hex()
|
|
76
|
+
|
|
77
|
+
color_list_combined = []
|
|
78
|
+
for color_list in [color_list_1, color_list_2, color_list_3, color_list_4, color_list_5, color_list_6, color_list_7, color_list_8]:
|
|
79
|
+
for color in color_list[2:][::-1]:
|
|
80
|
+
color_list_combined.append(color)
|
|
81
|
+
|
|
82
|
+
color_list_to_return = random.sample(color_list_combined, color_num)
|
|
83
|
+
|
|
84
|
+
color_list_to_return_sorted = []
|
|
85
|
+
for color_to_return in color_list_combined:
|
|
86
|
+
if color_to_return in color_list_to_return:
|
|
87
|
+
color_list_to_return_sorted.append(color_to_return)
|
|
88
|
+
|
|
89
|
+
random.shuffle(color_list_to_return_sorted)
|
|
90
|
+
|
|
91
|
+
return color_list_to_return_sorted
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def scale_str_to_size_list(scale_str):
|
|
95
|
+
|
|
96
|
+
scale_list = scale_str.split('-')
|
|
97
|
+
scale_list = [float(i) for i in scale_list]
|
|
98
|
+
|
|
99
|
+
shape_size_list = []
|
|
100
|
+
if scale_list[0] == 0:
|
|
101
|
+
shape_size_list = [0]
|
|
102
|
+
for each_value in scale_list[1:-1]:
|
|
103
|
+
current_size = each_value/scale_list[-1]
|
|
104
|
+
shape_size_list.append(current_size)
|
|
105
|
+
shape_size_list.append(1)
|
|
106
|
+
|
|
107
|
+
if scale_list[0] != 0:
|
|
108
|
+
shape_size_list = [0.1]
|
|
109
|
+
interval_num = len(scale_list) - 1
|
|
110
|
+
interval_value = (1 - 0.1)/interval_num
|
|
111
|
+
n = 1
|
|
112
|
+
for each_value in scale_list[1:-1]:
|
|
113
|
+
shape_size_list.append(interval_value * n + 0.1)
|
|
114
|
+
n += 1
|
|
115
|
+
shape_size_list.append(1)
|
|
116
|
+
|
|
117
|
+
return shape_size_list
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def iTOL(args):
|
|
121
|
+
|
|
122
|
+
# read in arguments
|
|
123
|
+
Labels = args['Labels']
|
|
124
|
+
ColoredLabel = args['ColoredLabel']
|
|
125
|
+
ColorStrip = args['ColorStrip']
|
|
126
|
+
ColorRange = args['ColorRange']
|
|
127
|
+
ColorClade = args['ColorClade']
|
|
128
|
+
ColorLabel = args['ColorLabel']
|
|
129
|
+
SimpleBar = args['SimpleBar']
|
|
130
|
+
Heatmap = args['Heatmap']
|
|
131
|
+
ExternalShape = args['ExternalShape']
|
|
132
|
+
Binary = args['Binary']
|
|
133
|
+
BinaryID = args['BinaryID']
|
|
134
|
+
Connection = args['Connection']
|
|
135
|
+
PieChart = args['PieChart']
|
|
136
|
+
Collapse = args['Collapse']
|
|
137
|
+
MultiStyleLabel = args['MultiStyleLabel']
|
|
138
|
+
leaf_id_txt = args['id']
|
|
139
|
+
LeafGroup = args['lg']
|
|
140
|
+
GroupColor = args['gc']
|
|
141
|
+
ColumnColor_txt = args['cc']
|
|
142
|
+
LeafValue = args['lv']
|
|
143
|
+
LeafLabel = args['ll']
|
|
144
|
+
LeafMatrix = args['lm']
|
|
145
|
+
d2r = args['dr']
|
|
146
|
+
scale_str = args['scale']
|
|
147
|
+
show_color_strip_legend = args['legend']
|
|
148
|
+
LegendTitle = args['lt']
|
|
149
|
+
show_strip_labels = args['show_strip_labels']
|
|
150
|
+
FileOut = args['o']
|
|
151
|
+
BinaryShape = args['BinaryShape']
|
|
152
|
+
BinaryColor = args['BinaryColor']
|
|
153
|
+
|
|
154
|
+
# General
|
|
155
|
+
STRIP_WIDTH = 100
|
|
156
|
+
MARGIN = 20
|
|
157
|
+
branch_width = 2
|
|
158
|
+
|
|
159
|
+
# SimpleBar
|
|
160
|
+
SimpleBar_COLOR = 'grey'
|
|
161
|
+
SimpleBar_WIDTH = 300
|
|
162
|
+
SimpleBar_HEIGHT_FACTOR = 0.8
|
|
163
|
+
SimpleBar_BORDER_WIDTH = 0
|
|
164
|
+
SimpleBar_SCALE_COLOR = '#696969'
|
|
165
|
+
SimpleBar_SCALE_WIDTH = 1
|
|
166
|
+
SimpleBar_SCALE_DASHED = 1
|
|
167
|
+
SimpleBar_SCALE_FontSize = 2
|
|
168
|
+
|
|
169
|
+
# Heatmap
|
|
170
|
+
Heatmap_STRIP_WIDTH = 30
|
|
171
|
+
|
|
172
|
+
# check the number of specified file type
|
|
173
|
+
True_num = 0
|
|
174
|
+
for file_type in [Labels, ColorStrip, ColorRange, SimpleBar, Heatmap, ExternalShape, Binary, BinaryID, PieChart, Collapse, ColorClade, ColorLabel, ColoredLabel]:
|
|
175
|
+
if file_type is True:
|
|
176
|
+
True_num += 1
|
|
177
|
+
|
|
178
|
+
if True_num == 0:
|
|
179
|
+
print('Please specify one file type, choose from -ColorStrip, -ColorRange, -SimpleBar, -Heatmap, -ExternalShape, -Binary, -BinaryID or -Collapse')
|
|
180
|
+
exit()
|
|
181
|
+
if True_num > 1:
|
|
182
|
+
print('Please specify one file type ONLY, choose from -ColorStrip, -ColorRange, -SimpleBar, -Heatmap, -ExternalShape, -Binary, -BinaryID or -Collapse')
|
|
183
|
+
exit()
|
|
184
|
+
|
|
185
|
+
####################################################################################################################
|
|
186
|
+
|
|
187
|
+
if ColoredLabel is True:
|
|
188
|
+
|
|
189
|
+
leaf_set = set()
|
|
190
|
+
leaf_label_dict = dict()
|
|
191
|
+
if LeafLabel is not None:
|
|
192
|
+
for each in open(LeafLabel):
|
|
193
|
+
each_split = each.strip().split('\t')
|
|
194
|
+
leaf_label_dict[each_split[0]] = each_split[1]
|
|
195
|
+
leaf_set.add(each_split[0])
|
|
196
|
+
|
|
197
|
+
leaf_group_dict = dict()
|
|
198
|
+
for each in open(LeafGroup):
|
|
199
|
+
each_split = each.strip().split('\t')
|
|
200
|
+
leaf_group_dict[each_split[0]] = each_split[1]
|
|
201
|
+
leaf_set.add(each_split[0])
|
|
202
|
+
|
|
203
|
+
group_color_dict = dict()
|
|
204
|
+
for each in open(GroupColor):
|
|
205
|
+
each_split = each.strip().split('\t')
|
|
206
|
+
group_color_dict[each_split[0]] = each_split[1]
|
|
207
|
+
|
|
208
|
+
FileOut_handle = open(FileOut, 'w')
|
|
209
|
+
FileOut_handle.write('DATASET_TEXT\n')
|
|
210
|
+
FileOut_handle.write('SEPARATOR TAB\n')
|
|
211
|
+
FileOut_handle.write('DATASET_LABEL\t%s\n' % 'ColoredLabel')
|
|
212
|
+
FileOut_handle.write('\nDATA\n')
|
|
213
|
+
for leaf in leaf_set:
|
|
214
|
+
leaf_label = leaf_label_dict.get(leaf, leaf)
|
|
215
|
+
leaf_group = leaf_group_dict.get(leaf, 'na')
|
|
216
|
+
leaf_color = group_color_dict.get(leaf_group, '#000000')
|
|
217
|
+
FileOut_handle.write('%s\t%s\t-1\t%s\tnormal\t1\t0\n' % (leaf, leaf_label, leaf_color))
|
|
218
|
+
FileOut_handle.close()
|
|
219
|
+
|
|
220
|
+
####################################################################################################################
|
|
221
|
+
|
|
222
|
+
# Prepare ColorStrip and ColorRange file
|
|
223
|
+
if (ColorStrip is True) or (ColorRange is True):
|
|
224
|
+
|
|
225
|
+
Leaf_to_Group_dict = {}
|
|
226
|
+
Group_list = []
|
|
227
|
+
for each_leaf in open(LeafGroup):
|
|
228
|
+
each_leaf_split = each_leaf.strip().split('\t')
|
|
229
|
+
Leaf_to_Group_dict[each_leaf_split[0]] = each_leaf_split[1]
|
|
230
|
+
if each_leaf_split[1] not in Group_list:
|
|
231
|
+
Group_list.append(each_leaf_split[1])
|
|
232
|
+
|
|
233
|
+
Group_to_Color_dict = {}
|
|
234
|
+
if GroupColor is None:
|
|
235
|
+
color_list = get_color_list(len(Group_list))
|
|
236
|
+
Group_to_Color_dict = dict(zip(Group_list, color_list))
|
|
237
|
+
else:
|
|
238
|
+
# get groups with provided color
|
|
239
|
+
Group_to_provided_Color_dict = dict()
|
|
240
|
+
group_with_provided_color_list = []
|
|
241
|
+
for each_group in open(GroupColor):
|
|
242
|
+
each_group_split = each_group.strip().split('\t')
|
|
243
|
+
group_id = each_group_split[0]
|
|
244
|
+
color_code = each_group_split[1]
|
|
245
|
+
if group_id in Group_list:
|
|
246
|
+
Group_to_provided_Color_dict[group_id] = color_code
|
|
247
|
+
group_with_provided_color_list.append(group_id)
|
|
248
|
+
|
|
249
|
+
# assign colors to the rest groups
|
|
250
|
+
group_without_color_list = []
|
|
251
|
+
for each_group in Group_list:
|
|
252
|
+
if each_group not in group_with_provided_color_list:
|
|
253
|
+
group_without_color_list.append(each_group)
|
|
254
|
+
if len(group_without_color_list) > 0:
|
|
255
|
+
color_list_unprovided = get_color_list(len(group_without_color_list))
|
|
256
|
+
Group_to_Color_dict_unprovided = dict(zip(group_without_color_list, color_list_unprovided))
|
|
257
|
+
for each_group in Group_to_Color_dict_unprovided:
|
|
258
|
+
Group_to_Color_dict[each_group] = Group_to_Color_dict_unprovided[each_group]
|
|
259
|
+
|
|
260
|
+
# combine two dict
|
|
261
|
+
for each_group in Group_to_provided_Color_dict:
|
|
262
|
+
Group_to_Color_dict[each_group] = Group_to_provided_Color_dict[each_group]
|
|
263
|
+
|
|
264
|
+
group_list = [i for i in Group_to_Color_dict]
|
|
265
|
+
color_list = [Group_to_Color_dict[i] for i in group_list]
|
|
266
|
+
|
|
267
|
+
FileOut_handle = open(FileOut, 'w')
|
|
268
|
+
|
|
269
|
+
# write out header
|
|
270
|
+
if ColorStrip is True:
|
|
271
|
+
FileOut_handle.write('DATASET_COLORSTRIP\n')
|
|
272
|
+
FileOut_handle.write('SEPARATOR TAB\n')
|
|
273
|
+
FileOut_handle.write('DATASET_LABEL\t%s\n' % LegendTitle)
|
|
274
|
+
FileOut_handle.write('SHOW_LABELS\t1\n')
|
|
275
|
+
FileOut_handle.write('LABEL_SHIFT\t30\n')
|
|
276
|
+
FileOut_handle.write('LABEL_ROTATION\t45\n')
|
|
277
|
+
FileOut_handle.write('SIZE_FACTOR\t2\n')
|
|
278
|
+
FileOut_handle.write('COLOR_BRANCHES\t0\n')
|
|
279
|
+
|
|
280
|
+
if ColorRange is True:
|
|
281
|
+
FileOut_handle.write('TREE_COLORS\n')
|
|
282
|
+
FileOut_handle.write('SEPARATOR TAB\n')
|
|
283
|
+
FileOut_handle.write('DATASET_LABEL\t%s_ColorRange\n' % LegendTitle)
|
|
284
|
+
|
|
285
|
+
# write out strip attributes
|
|
286
|
+
if ColorStrip is True:
|
|
287
|
+
FileOut_handle.write('\n# customize strip attributes here\n')
|
|
288
|
+
FileOut_handle.write('STRIP_WIDTH\t%s\n' % STRIP_WIDTH)
|
|
289
|
+
FileOut_handle.write('MARGIN\t%s\n' % MARGIN)
|
|
290
|
+
|
|
291
|
+
if show_color_strip_legend is False:
|
|
292
|
+
FileOut_handle.write('\n# customize labels on the trip\n')
|
|
293
|
+
if show_strip_labels is True:
|
|
294
|
+
FileOut_handle.write('SHOW_STRIP_LABELS\t1\n')
|
|
295
|
+
else:
|
|
296
|
+
FileOut_handle.write('SHOW_STRIP_LABELS\t0\n')
|
|
297
|
+
FileOut_handle.write('STRIP_LABEL_POSITION\tcenter\n')
|
|
298
|
+
FileOut_handle.write('STRIP_LABEL_ROTATION\t90\n')
|
|
299
|
+
else:
|
|
300
|
+
FileOut_handle.write('\n# uncomment to show labels on the trip\n')
|
|
301
|
+
if show_strip_labels is True:
|
|
302
|
+
FileOut_handle.write('# SHOW_STRIP_LABELS\t1\n')
|
|
303
|
+
else:
|
|
304
|
+
FileOut_handle.write('# SHOW_STRIP_LABELS\t0\n')
|
|
305
|
+
FileOut_handle.write('# STRIP_LABEL_POSITION\tcenter\n')
|
|
306
|
+
FileOut_handle.write('# STRIP_LABEL_ROTATION\t90\n')
|
|
307
|
+
|
|
308
|
+
# write out legend info
|
|
309
|
+
if show_color_strip_legend is True:
|
|
310
|
+
FileOut_handle.write('\n# customize legend\n')
|
|
311
|
+
FileOut_handle.write('LEGEND_TITLE\t%s\n' % LegendTitle)
|
|
312
|
+
FileOut_handle.write('LEGEND_SHAPES\t%s\n' % '\t'.join(['1' for i in Group_to_Color_dict]))
|
|
313
|
+
FileOut_handle.write('LEGEND_COLORS\t%s\n' % '\t'.join(color_list))
|
|
314
|
+
FileOut_handle.write('LEGEND_LABELS\t%s\n' % '\t'.join(group_list))
|
|
315
|
+
else:
|
|
316
|
+
FileOut_handle.write('\n# comment this section if you want to hide the legend\n')
|
|
317
|
+
FileOut_handle.write('LEGEND_TITLE\t%s\n' % LegendTitle)
|
|
318
|
+
FileOut_handle.write('LEGEND_SHAPES\t%s\n' % '\t'.join(['1' for i in Group_to_Color_dict]))
|
|
319
|
+
FileOut_handle.write('LEGEND_COLORS\t%s\n' % '\t'.join(color_list))
|
|
320
|
+
FileOut_handle.write('LEGEND_LABELS\t%s\n' % '\t'.join(group_list))
|
|
321
|
+
|
|
322
|
+
FileOut_handle.write('\n# provide data here\nDATA\n')
|
|
323
|
+
for leaf in Leaf_to_Group_dict:
|
|
324
|
+
node_group = Leaf_to_Group_dict[leaf]
|
|
325
|
+
leaf_color = Group_to_Color_dict[node_group]
|
|
326
|
+
|
|
327
|
+
if ColorStrip is True:
|
|
328
|
+
FileOut_handle.write('%s\t%s\t%s\n' % (leaf, leaf_color, node_group))
|
|
329
|
+
if ColorRange is True:
|
|
330
|
+
FileOut_handle.write('%s\trange\t%s\t%s\n' % (leaf, leaf_color, node_group))
|
|
331
|
+
FileOut_handle.close()
|
|
332
|
+
|
|
333
|
+
####################################################################################################################
|
|
334
|
+
|
|
335
|
+
# Prepare SimpleBar file
|
|
336
|
+
if SimpleBar is True:
|
|
337
|
+
|
|
338
|
+
if scale_str is None:
|
|
339
|
+
print('Please provide scale values for barchart, in format 0-3-6-9')
|
|
340
|
+
exit()
|
|
341
|
+
|
|
342
|
+
# read in leaf value into dict
|
|
343
|
+
leaf_value_dict = {}
|
|
344
|
+
max_value = None
|
|
345
|
+
for leaf_value in open(LeafValue):
|
|
346
|
+
leaf_value_split = leaf_value.strip().split('\t')
|
|
347
|
+
leaf_value_dict[leaf_value_split[0]] = float(leaf_value_split[1])
|
|
348
|
+
|
|
349
|
+
# get max value
|
|
350
|
+
if max_value == None:
|
|
351
|
+
max_value = float(leaf_value_split[1])
|
|
352
|
+
else:
|
|
353
|
+
if float(leaf_value_split[1]) > max_value:
|
|
354
|
+
max_value = float(leaf_value_split[1])
|
|
355
|
+
|
|
356
|
+
SimpleBar_FileOut_handle = open(FileOut, 'w')
|
|
357
|
+
SimpleBar_FileOut_handle.write('DATASET_SIMPLEBAR\n')
|
|
358
|
+
SimpleBar_FileOut_handle.write('# Reference: https://itol.embl.de/help/dataset_simplebar_template.txt\n')
|
|
359
|
+
SimpleBar_FileOut_handle.write('\nSEPARATOR TAB\n')
|
|
360
|
+
SimpleBar_FileOut_handle.write('\n# customize barchart attributes here\n')
|
|
361
|
+
SimpleBar_FileOut_handle.write('DATASET_LABEL\t%s\n' % LegendTitle)
|
|
362
|
+
SimpleBar_FileOut_handle.write('COLOR\t%s\n' % SimpleBar_COLOR)
|
|
363
|
+
SimpleBar_FileOut_handle.write('WIDTH\t%s\n' % SimpleBar_WIDTH)
|
|
364
|
+
SimpleBar_FileOut_handle.write('MARGIN\t%s\n' % MARGIN)
|
|
365
|
+
SimpleBar_FileOut_handle.write('HEIGHT_FACTOR\t%s\n' % SimpleBar_HEIGHT_FACTOR)
|
|
366
|
+
SimpleBar_FileOut_handle.write('BORDER_WIDTH\t%s\n' % SimpleBar_BORDER_WIDTH)
|
|
367
|
+
|
|
368
|
+
# write out scale attributes
|
|
369
|
+
scale_attributes_list = []
|
|
370
|
+
for scale_value in scale_str.split('-'):
|
|
371
|
+
scale_attributes = '%s-%s-%s-%s-%s-%s' % (scale_value, scale_value, SimpleBar_SCALE_COLOR, SimpleBar_SCALE_WIDTH, SimpleBar_SCALE_DASHED, SimpleBar_SCALE_FontSize)
|
|
372
|
+
scale_attributes_list.append(scale_attributes)
|
|
373
|
+
|
|
374
|
+
SimpleBar_FileOut_handle.write('\n# customize scale attributes here\n')
|
|
375
|
+
SimpleBar_FileOut_handle.write('# format: VALUE-LABEL-COLOR-WIDTH-DASHED-LABEL_SCALE_FACTOR, LABEL_SCALE_FACTOR controls font size\n')
|
|
376
|
+
SimpleBar_FileOut_handle.write('DATASET_SCALE\t%s\n' % '\t'.join(scale_attributes_list))
|
|
377
|
+
SimpleBar_FileOut_handle.write('\n# provide data here\n')
|
|
378
|
+
SimpleBar_FileOut_handle.write('DATA\n')
|
|
379
|
+
|
|
380
|
+
for leaf in leaf_value_dict:
|
|
381
|
+
SimpleBar_FileOut_handle.write('%s\t%s\n' % (leaf, leaf_value_dict[leaf]))
|
|
382
|
+
|
|
383
|
+
SimpleBar_FileOut_handle.close()
|
|
384
|
+
|
|
385
|
+
####################################################################################################################
|
|
386
|
+
|
|
387
|
+
# Prepare Binary file
|
|
388
|
+
if Binary is True:
|
|
389
|
+
|
|
390
|
+
Column_to_Color_dict = {}
|
|
391
|
+
ColumnColor = 'red'
|
|
392
|
+
if ColumnColor_txt is not None:
|
|
393
|
+
if os.path.isfile(ColumnColor_txt) is True:
|
|
394
|
+
for each_col in open(ColumnColor_txt):
|
|
395
|
+
each_col_split = each_col.strip().split('\t')
|
|
396
|
+
Column_to_Color_dict[each_col_split[0]] = each_col_split[1]
|
|
397
|
+
else:
|
|
398
|
+
ColumnColor = ColumnColor_txt
|
|
399
|
+
|
|
400
|
+
# get color
|
|
401
|
+
if GroupColor is not None:
|
|
402
|
+
if os.path.isfile(GroupColor) is True:
|
|
403
|
+
print('Only one color can be specified for Binary data, here are two examples:\n-gc lightblue\n-gc "#85C1E9"')
|
|
404
|
+
print('Program exited!')
|
|
405
|
+
exit()
|
|
406
|
+
else:
|
|
407
|
+
Binary_color = GroupColor
|
|
408
|
+
else:
|
|
409
|
+
Binary_color = 'red'
|
|
410
|
+
|
|
411
|
+
Binary_FileOut_handle = open(FileOut, 'w')
|
|
412
|
+
line_index = 0
|
|
413
|
+
for each_line in open(LeafMatrix):
|
|
414
|
+
each_line_split = each_line.strip().split('\t')
|
|
415
|
+
if line_index == 0:
|
|
416
|
+
|
|
417
|
+
# get header list
|
|
418
|
+
if each_line.startswith('\t'):
|
|
419
|
+
col_name_list = each_line_split
|
|
420
|
+
else:
|
|
421
|
+
col_name_list = each_line_split[1:]
|
|
422
|
+
|
|
423
|
+
col_color_list = [Column_to_Color_dict.get(i, ColumnColor) for i in col_name_list]
|
|
424
|
+
|
|
425
|
+
Binary_FileOut_handle.write('DATASET_BINARY\n\nSEPARATOR TAB\nDATASET_LABEL\t%s\nCOLOR\t%s\n' % (LegendTitle, Binary_color))
|
|
426
|
+
Binary_FileOut_handle.write('SHOW_LABELS\t1\nLABEL_ROTATION\t45\nLABEL_SHIFT\t5\n')
|
|
427
|
+
Binary_FileOut_handle.write('FIELD_LABELS\t%s\n' % '\t'.join(col_name_list))
|
|
428
|
+
Binary_FileOut_handle.write('FIELD_COLORS\t%s\n' % '\t'.join(col_color_list))
|
|
429
|
+
Binary_FileOut_handle.write('MARGIN\t10\n')
|
|
430
|
+
Binary_FileOut_handle.write('HORIZONTAL_GRID\t0\n')
|
|
431
|
+
Binary_FileOut_handle.write('VERTICAL_GRID\t0\n')
|
|
432
|
+
Binary_FileOut_handle.write('FIELD_SHAPES\t%s\n' % '\t'.join(['2'] * len(col_name_list)))
|
|
433
|
+
Binary_FileOut_handle.write('#1: rectangle\n')
|
|
434
|
+
Binary_FileOut_handle.write('#2: circle\n')
|
|
435
|
+
Binary_FileOut_handle.write('#3: star\n')
|
|
436
|
+
Binary_FileOut_handle.write('#4: right pointing triangle\n')
|
|
437
|
+
Binary_FileOut_handle.write('#5: left pointing triangle\n')
|
|
438
|
+
Binary_FileOut_handle.write('#6: check mark\n')
|
|
439
|
+
Binary_FileOut_handle.write('\nDATA\n')
|
|
440
|
+
else:
|
|
441
|
+
Binary_FileOut_handle.write(each_line)
|
|
442
|
+
line_index += 1
|
|
443
|
+
Binary_FileOut_handle.close()
|
|
444
|
+
|
|
445
|
+
####################################################################################################################
|
|
446
|
+
|
|
447
|
+
# Prepare BinaryID file
|
|
448
|
+
if BinaryID is True:
|
|
449
|
+
BinaryID_FileOut_handle = open(FileOut, 'w')
|
|
450
|
+
BinaryID_FileOut_handle.write('DATASET_BINARY\n\nSEPARATOR TAB\nDATASET_LABEL\t%s\nCOLOR\tred\n' % LegendTitle)
|
|
451
|
+
BinaryID_FileOut_handle.write('SHOW_LABELS\t1\nLABEL_ROTATION\t45\nLABEL_SHIFT\t5\n')
|
|
452
|
+
BinaryID_FileOut_handle.write('FIELD_LABELS\t%s\n' % LegendTitle)
|
|
453
|
+
BinaryID_FileOut_handle.write('FIELD_COLORS\t%s\n' % BinaryColor)
|
|
454
|
+
BinaryID_FileOut_handle.write('# FIELD_SHAPES: 1: rectangle; 2: circle; 3: star; 4: right pointing triangle; 5: left pointing triangle; 6: check mark\n')
|
|
455
|
+
BinaryID_FileOut_handle.write('FIELD_SHAPES\t%s\n' % BinaryShape)
|
|
456
|
+
BinaryID_FileOut_handle.write('MARGIN\t10\n')
|
|
457
|
+
BinaryID_FileOut_handle.write('HORIZONTAL_GRID\t0\n')
|
|
458
|
+
BinaryID_FileOut_handle.write('VERTICAL_GRID\t0\n')
|
|
459
|
+
BinaryID_FileOut_handle.write('\nDATA\n')
|
|
460
|
+
for each_line in open(leaf_id_txt):
|
|
461
|
+
leaf_id = each_line.strip().split()[0]
|
|
462
|
+
BinaryID_FileOut_handle.write('%s\t1\n' % leaf_id)
|
|
463
|
+
BinaryID_FileOut_handle.close()
|
|
464
|
+
|
|
465
|
+
####################################################################################################################
|
|
466
|
+
|
|
467
|
+
# Prepare Heatmap file
|
|
468
|
+
if Heatmap is True:
|
|
469
|
+
|
|
470
|
+
n = 0
|
|
471
|
+
col_name_list = []
|
|
472
|
+
leaf_matrix_dict = {}
|
|
473
|
+
for leaf_matrix in open(LeafMatrix):
|
|
474
|
+
leaf_matrix_split = leaf_matrix.strip().split('\t')
|
|
475
|
+
if n == 0:
|
|
476
|
+
col_name_list = leaf_matrix_split[1:]
|
|
477
|
+
else:
|
|
478
|
+
leaf_matrix_dict[leaf_matrix_split[0]] = leaf_matrix_split[1:]
|
|
479
|
+
n += 1
|
|
480
|
+
|
|
481
|
+
Heatmap_FileOut_handle = open(FileOut, 'w')
|
|
482
|
+
Heatmap_FileOut_handle.write('DATASET_HEATMAP\n')
|
|
483
|
+
Heatmap_FileOut_handle.write('# Reference https://itol.embl.de/help/dataset_heatmap_template.txt\n')
|
|
484
|
+
Heatmap_FileOut_handle.write('\nSEPARATOR TAB\n')
|
|
485
|
+
Heatmap_FileOut_handle.write('\n# customize heatmap attributes here\n')
|
|
486
|
+
Heatmap_FileOut_handle.write('MARGIN\t%s\n' % MARGIN)
|
|
487
|
+
Heatmap_FileOut_handle.write('STRIP_WIDTH\t%s\n' % Heatmap_STRIP_WIDTH)
|
|
488
|
+
Heatmap_FileOut_handle.write('\n# customize legend here\n')
|
|
489
|
+
Heatmap_FileOut_handle.write('AUTO_LEGEND\t1\n')
|
|
490
|
+
Heatmap_FileOut_handle.write('DATASET_LABEL\t%s\n' % LegendTitle)
|
|
491
|
+
Heatmap_FileOut_handle.write('USE_MID_COLOR\t1\n')
|
|
492
|
+
Heatmap_FileOut_handle.write('COLOR_MIN\t#2980B9\n')
|
|
493
|
+
Heatmap_FileOut_handle.write('COLOR_MID\t#ECF0F1\n')
|
|
494
|
+
Heatmap_FileOut_handle.write('COLOR_MAX\t#E74C3C\n')
|
|
495
|
+
Heatmap_FileOut_handle.write('\n# customize value range here. By default, color gradients will be calculated based on dataset values\n')
|
|
496
|
+
Heatmap_FileOut_handle.write('# USER_MIN_VALUE 0\n')
|
|
497
|
+
Heatmap_FileOut_handle.write('# USER_MID_VALUE 5\n')
|
|
498
|
+
Heatmap_FileOut_handle.write('# USER_MAX_VALUE 10\n')
|
|
499
|
+
Heatmap_FileOut_handle.write('\n# customize column name here\n')
|
|
500
|
+
Heatmap_FileOut_handle.write('FIELD_LABELS\t%s\n' % '\t'.join(col_name_list))
|
|
501
|
+
Heatmap_FileOut_handle.write('\n# Provide data here\n')
|
|
502
|
+
Heatmap_FileOut_handle.write('DATA\n')
|
|
503
|
+
for leaf in leaf_matrix_dict:
|
|
504
|
+
Heatmap_FileOut_handle.write('%s\t%s\n' % (leaf, '\t'.join(leaf_matrix_dict[leaf])))
|
|
505
|
+
Heatmap_FileOut_handle.close()
|
|
506
|
+
|
|
507
|
+
####################################################################################################################
|
|
508
|
+
|
|
509
|
+
if Labels is True:
|
|
510
|
+
if os.path.isfile(LeafLabel) is False:
|
|
511
|
+
print('leaf to label file not found, please provide with -ll, program exited!')
|
|
512
|
+
exit()
|
|
513
|
+
|
|
514
|
+
# write out header
|
|
515
|
+
Labels_FileOut_handle = open(FileOut, 'w')
|
|
516
|
+
Labels_FileOut_handle.write('LABELS\nSEPARATOR TAB\nDATA\n')
|
|
517
|
+
for each_ll in open(LeafLabel):
|
|
518
|
+
Labels_FileOut_handle.write(each_ll)
|
|
519
|
+
Labels_FileOut_handle.close()
|
|
520
|
+
|
|
521
|
+
####################################################################################################################
|
|
522
|
+
|
|
523
|
+
if Connection is True:
|
|
524
|
+
|
|
525
|
+
if os.path.isfile(d2r) is False:
|
|
526
|
+
print('donor to recipient file not found, please provide with -dr, program exited!')
|
|
527
|
+
exit()
|
|
528
|
+
|
|
529
|
+
Connection_FileOut_handle = open(FileOut, 'w')
|
|
530
|
+
Connection_FileOut_handle.write('DATASET_CONNECTION\nSEPARATOR TAB\nDATASET_LABEL\tdemo_connections\n')
|
|
531
|
+
Connection_FileOut_handle.write('COLOR\t#ff0ff0\nDRAW_ARROWS\t1\nARROW_SIZE\t60\nLOOP_SIZE\t100\n')
|
|
532
|
+
Connection_FileOut_handle.write('MAXIMUM_LINE_WIDTH\t10\nCURVE_ANGLE\t45\nCENTER_CURVES\t1\nALIGN_TO_LABELS\t0\nDATA\n')
|
|
533
|
+
for each_connection in open(d2r):
|
|
534
|
+
Connection_FileOut_handle.write(each_connection)
|
|
535
|
+
Connection_FileOut_handle.close()
|
|
536
|
+
|
|
537
|
+
####################################################################################################################
|
|
538
|
+
|
|
539
|
+
# Prepare PieChart file
|
|
540
|
+
if PieChart is True:
|
|
541
|
+
PieChart_FileOut_handle = open(FileOut, 'w')
|
|
542
|
+
PieChart_FileOut_handle.write('DATASET_PIECHART\n')
|
|
543
|
+
PieChart_FileOut_handle.write('SEPARATOR TAB\n')
|
|
544
|
+
PieChart_FileOut_handle.write('DATASET_LABEL\t%s\n' % LegendTitle)
|
|
545
|
+
PieChart_FileOut_handle.write('COLOR\t#ff0000\n')
|
|
546
|
+
PieChart_FileOut_handle.write('FIELD_COLORS\t#5DADE2\t#FFFFFF\n')
|
|
547
|
+
PieChart_FileOut_handle.write('FIELD_LABELS\tf1\tf2\n')
|
|
548
|
+
PieChart_FileOut_handle.write('MARGIN\t10\n\n')
|
|
549
|
+
PieChart_FileOut_handle.write('DATA\n')
|
|
550
|
+
for each in open(LeafValue):
|
|
551
|
+
each_split = each.strip().split('\t')
|
|
552
|
+
node_id = each_split[0]
|
|
553
|
+
node_value = float(each_split[1])
|
|
554
|
+
PieChart_FileOut_handle.write('%s\t-1\t1\t%s\t%s\n' % (node_id, node_value, (100 - node_value)))
|
|
555
|
+
PieChart_FileOut_handle.close()
|
|
556
|
+
|
|
557
|
+
####################################################################################################################
|
|
558
|
+
|
|
559
|
+
if (ColorClade is True) or (ColorLabel is True):
|
|
560
|
+
|
|
561
|
+
# get group_to_leaf_dict
|
|
562
|
+
group_set = set()
|
|
563
|
+
group_to_leaf_dict = dict()
|
|
564
|
+
node_to_group_dict = dict()
|
|
565
|
+
for each_line in open(LeafGroup):
|
|
566
|
+
each_line_split = each_line.strip().split('\t')
|
|
567
|
+
node_id = each_line_split[0]
|
|
568
|
+
node_group = each_line_split[1]
|
|
569
|
+
group_set.add(node_group)
|
|
570
|
+
node_to_group_dict[node_id] = node_group
|
|
571
|
+
if node_group not in group_to_leaf_dict:
|
|
572
|
+
group_to_leaf_dict[node_group] = [node_id]
|
|
573
|
+
else:
|
|
574
|
+
group_to_leaf_dict[node_group].append(node_id)
|
|
575
|
+
|
|
576
|
+
group_list = sorted(list(group_set))
|
|
577
|
+
|
|
578
|
+
Group_to_Color_dict = dict()
|
|
579
|
+
|
|
580
|
+
# get groups with provided color
|
|
581
|
+
Group_to_provided_Color_dict = dict()
|
|
582
|
+
group_with_provided_color_list = []
|
|
583
|
+
for each_group in open(GroupColor):
|
|
584
|
+
each_group_split = each_group.strip().split('\t')
|
|
585
|
+
group_id = each_group_split[0]
|
|
586
|
+
color_code = each_group_split[1]
|
|
587
|
+
if group_id in group_list:
|
|
588
|
+
Group_to_provided_Color_dict[group_id] = color_code
|
|
589
|
+
group_with_provided_color_list.append(group_id)
|
|
590
|
+
|
|
591
|
+
# assign colors to the rest groups
|
|
592
|
+
group_without_color_list = []
|
|
593
|
+
for each_group in group_list:
|
|
594
|
+
if each_group not in group_with_provided_color_list:
|
|
595
|
+
group_without_color_list.append(each_group)
|
|
596
|
+
if len(group_without_color_list) > 0:
|
|
597
|
+
color_list_unprovided = get_color_list(len(group_without_color_list))
|
|
598
|
+
Group_to_Color_dict_unprovided = dict(zip(group_without_color_list, color_list_unprovided))
|
|
599
|
+
for each_group in Group_to_Color_dict_unprovided:
|
|
600
|
+
Group_to_Color_dict[each_group] = Group_to_Color_dict_unprovided[each_group]
|
|
601
|
+
|
|
602
|
+
# combine two dict
|
|
603
|
+
for each_group in Group_to_provided_Color_dict:
|
|
604
|
+
Group_to_Color_dict[each_group] = Group_to_provided_Color_dict[each_group]
|
|
605
|
+
|
|
606
|
+
ColorClade_Label_FileOut_handle = open(FileOut, 'w')
|
|
607
|
+
ColorClade_Label_FileOut_handle.write('TREE_COLORS\n')
|
|
608
|
+
ColorClade_Label_FileOut_handle.write('SEPARATOR TAB\n')
|
|
609
|
+
ColorClade_Label_FileOut_handle.write('\nDATA\n')
|
|
610
|
+
for grp in group_to_leaf_dict:
|
|
611
|
+
group_member = group_to_leaf_dict[grp]
|
|
612
|
+
group_color = Group_to_Color_dict[grp]
|
|
613
|
+
concate_str = '|'.join(group_member)
|
|
614
|
+
if ColorClade is True:
|
|
615
|
+
ColorClade_Label_FileOut_handle.write('%s\tclade\t%s\tnormal\t%s\n' % (concate_str, group_color, branch_width))
|
|
616
|
+
if ColorLabel is True:
|
|
617
|
+
ColorClade_Label_FileOut_handle.write('%s\tlabel\t%s\tnormal\t%s\n' % (concate_str, group_color, branch_width))
|
|
618
|
+
ColorClade_Label_FileOut_handle.close()
|
|
619
|
+
|
|
620
|
+
####################################################################################################################
|
|
621
|
+
|
|
622
|
+
# Prepare Collapse file
|
|
623
|
+
if Collapse is True:
|
|
624
|
+
|
|
625
|
+
corresponding_label_file = '%s.label.txt' % FileOut
|
|
626
|
+
|
|
627
|
+
# read in grouping file
|
|
628
|
+
group_to_leaf_dict = dict()
|
|
629
|
+
for each_line in open(LeafGroup):
|
|
630
|
+
each_line_split = each_line.strip().split('\t')
|
|
631
|
+
leaf_id = each_line_split[0]
|
|
632
|
+
node_group = each_line_split[1]
|
|
633
|
+
if node_group not in group_to_leaf_dict:
|
|
634
|
+
group_to_leaf_dict[node_group] = [leaf_id]
|
|
635
|
+
else:
|
|
636
|
+
group_to_leaf_dict[node_group].append(leaf_id)
|
|
637
|
+
|
|
638
|
+
Collapse_FileOut_handle = open(FileOut, 'w')
|
|
639
|
+
Collapse_FileOut_handle.write('COLLAPSE\n')
|
|
640
|
+
Collapse_FileOut_handle.write('DATA\n')
|
|
641
|
+
label_FileOut_handle = open(corresponding_label_file, 'w')
|
|
642
|
+
label_FileOut_handle.write('LABELS\n')
|
|
643
|
+
label_FileOut_handle.write('SEPARATOR TAB\n')
|
|
644
|
+
label_FileOut_handle.write('DATA\n')
|
|
645
|
+
for each_group in group_to_leaf_dict:
|
|
646
|
+
group_member = group_to_leaf_dict[each_group]
|
|
647
|
+
concate_str = '|'.join(group_member)
|
|
648
|
+
Collapse_FileOut_handle.write(concate_str + '\n')
|
|
649
|
+
label_FileOut_handle.write('%s\t%s\n' % (concate_str, each_group))
|
|
650
|
+
Collapse_FileOut_handle.close()
|
|
651
|
+
label_FileOut_handle.close()
|
|
652
|
+
|
|
653
|
+
print('iTOL files exported to:\n%s\n%s' % (FileOut, corresponding_label_file))
|
|
654
|
+
|
|
655
|
+
####################################################################################################################
|
|
656
|
+
|
|
657
|
+
# Prepare ExternalShape file
|
|
658
|
+
if MultiStyleLabel is True:
|
|
659
|
+
MultiStyleLabel_FileOut_handle = open(FileOut, 'w')
|
|
660
|
+
MultiStyleLabel_FileOut_handle.write('MULTI_STYLE\n')
|
|
661
|
+
MultiStyleLabel_FileOut_handle.write('SEPARATOR TAB\n')
|
|
662
|
+
MultiStyleLabel_FileOut_handle.write('#each line in the DATA section defines the style for one label part (specified in the first field)\n')
|
|
663
|
+
MultiStyleLabel_FileOut_handle.write('\n')
|
|
664
|
+
MultiStyleLabel_FileOut_handle.write('\n')
|
|
665
|
+
MultiStyleLabel_FileOut_handle.write('DATA\n')
|
|
666
|
+
MultiStyleLabel_FileOut_handle.close()
|
|
667
|
+
|
|
668
|
+
####################################################################################################################
|
|
669
|
+
|
|
670
|
+
# Prepare ExternalShape file
|
|
671
|
+
if ExternalShape is True:
|
|
672
|
+
|
|
673
|
+
# read in leaf matrix into dict
|
|
674
|
+
n = 0
|
|
675
|
+
col_name_list = []
|
|
676
|
+
leaf_matrix_dict = {}
|
|
677
|
+
for leaf_matrix in open(LeafMatrix):
|
|
678
|
+
leaf_matrix_split = leaf_matrix.strip().split('\t')
|
|
679
|
+
if n == 0:
|
|
680
|
+
col_name_list = leaf_matrix_split[1:]
|
|
681
|
+
else:
|
|
682
|
+
leaf_matrix_dict[leaf_matrix_split[0]] = leaf_matrix_split[1:]
|
|
683
|
+
n += 1
|
|
684
|
+
|
|
685
|
+
Column_to_Color_dict = {}
|
|
686
|
+
if ColumnColor_txt is not None:
|
|
687
|
+
for each_col in open(ColumnColor_txt):
|
|
688
|
+
each_col_split = each_col.strip().split('\t')
|
|
689
|
+
Column_to_Color_dict[each_col_split[0]] = each_col_split[1]
|
|
690
|
+
|
|
691
|
+
# check if all columns in data matrix are in Column_to_Color_dict
|
|
692
|
+
if ColumnColor_txt is not None:
|
|
693
|
+
unfound_cols = []
|
|
694
|
+
for each_col_header in col_name_list:
|
|
695
|
+
if each_col_header not in Column_to_Color_dict:
|
|
696
|
+
unfound_cols.append(each_col_header)
|
|
697
|
+
if len(unfound_cols) > 0:
|
|
698
|
+
print('Color code for the following columns are not provided, program exited!')
|
|
699
|
+
print(','.join(unfound_cols))
|
|
700
|
+
exit()
|
|
701
|
+
|
|
702
|
+
ExternalShape_FileOut_handle = open(FileOut, 'w')
|
|
703
|
+
ExternalShape_FileOut_handle.write('DATASET_EXTERNALSHAPE\n')
|
|
704
|
+
ExternalShape_FileOut_handle.write('# Reference https://itol.embl.de/help/dataset_external_shapes_template.txt\n')
|
|
705
|
+
ExternalShape_FileOut_handle.write('\nSEPARATOR TAB\n')
|
|
706
|
+
|
|
707
|
+
# define scale here
|
|
708
|
+
if scale_str is None:
|
|
709
|
+
print('Please provide scale values for ExternalShapes, e.g., 25-50-75-100, 2-4-6-8-10')
|
|
710
|
+
exit()
|
|
711
|
+
|
|
712
|
+
scale_list = scale_str.split('-')
|
|
713
|
+
LEGEND_SHAPES_list = ['2'] * len(scale_list)
|
|
714
|
+
LEGEND_COLORS_list = ['grey'] * len(scale_list)
|
|
715
|
+
SHAPE_SCALES_list = scale_str_to_size_list(scale_str)
|
|
716
|
+
|
|
717
|
+
ExternalShape_FileOut_handle.write('LEGEND_TITLE\t%s\n' % LegendTitle)
|
|
718
|
+
ExternalShape_FileOut_handle.write('LEGEND_SHAPES\t%s\n' % '\t'.join(LEGEND_SHAPES_list))
|
|
719
|
+
ExternalShape_FileOut_handle.write('LEGEND_COLORS\t%s\n' % '\t'.join(LEGEND_COLORS_list))
|
|
720
|
+
ExternalShape_FileOut_handle.write('LEGEND_LABELS\t%s\n' % '\t'.join(scale_list))
|
|
721
|
+
ExternalShape_FileOut_handle.write('LEGEND_SHAPE_SCALES\t%s\n' % '\t'.join(str(i) for i in SHAPE_SCALES_list))
|
|
722
|
+
ExternalShape_FileOut_handle.write('\n# customize attributes here\n')
|
|
723
|
+
ExternalShape_FileOut_handle.write('VERTICAL_GRID\t0\n')
|
|
724
|
+
ExternalShape_FileOut_handle.write('HORIZONTAL_GRID\t0\n')
|
|
725
|
+
ExternalShape_FileOut_handle.write('SHAPE_TYPE\t2\n')
|
|
726
|
+
ExternalShape_FileOut_handle.write('COLOR_FILL\t1\n')
|
|
727
|
+
ExternalShape_FileOut_handle.write('SHAPE_SPACING\t1\n')
|
|
728
|
+
ExternalShape_FileOut_handle.write('SHOW_LABELS\t0\n')
|
|
729
|
+
ExternalShape_FileOut_handle.write('SHOW_VALUES\t0\n')
|
|
730
|
+
ExternalShape_FileOut_handle.write('DASHED_LINES\t0\n')
|
|
731
|
+
|
|
732
|
+
if LegendTitle is None:
|
|
733
|
+
ExternalShape_FileOut_handle.write('DATASET_LABEL\tExternalShape\n')
|
|
734
|
+
else:
|
|
735
|
+
ExternalShape_FileOut_handle.write('DATASET_LABEL\t%s\n' % LegendTitle)
|
|
736
|
+
|
|
737
|
+
# write column header/color information
|
|
738
|
+
ExternalShape_FileOut_handle.write('\n# customize column header/color here\n')
|
|
739
|
+
ExternalShape_FileOut_handle.write('FIELD_LABELS\t%s\n' % '\t'.join(col_name_list))
|
|
740
|
+
|
|
741
|
+
color_list = get_color_list(len(col_name_list))
|
|
742
|
+
random.shuffle(color_list)
|
|
743
|
+
if ColumnColor_txt is not None:
|
|
744
|
+
color_list = [Column_to_Color_dict[i] for i in col_name_list]
|
|
745
|
+
ExternalShape_FileOut_handle.write('FIELD_COLORS\t%s\n' % '\t'.join(color_list))
|
|
746
|
+
ExternalShape_FileOut_handle.write('\n# Provide data here\n')
|
|
747
|
+
ExternalShape_FileOut_handle.write('DATA\n')
|
|
748
|
+
for leaf in leaf_matrix_dict:
|
|
749
|
+
ExternalShape_FileOut_handle.write('%s\t%s\n' % (leaf, '\t'.join(leaf_matrix_dict[leaf])))
|
|
750
|
+
|
|
751
|
+
ExternalShape_FileOut_handle.close()
|
|
752
|
+
|
|
753
|
+
####################################################################################################################
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
if __name__ == '__main__':
|
|
757
|
+
|
|
758
|
+
iTOL_parser = argparse.ArgumentParser(usage=iTOL_usage)
|
|
759
|
+
iTOL_parser.add_argument('-Labels', required=False, action='store_true', help='Labels')
|
|
760
|
+
iTOL_parser.add_argument('-ColoredLabel', required=False, action='store_true', help='ColoredLabel')
|
|
761
|
+
iTOL_parser.add_argument('-MultiStyleLabel', required=False, action='store_true', help='MultiStyleLabel')
|
|
762
|
+
iTOL_parser.add_argument('-ColorStrip', required=False, action='store_true', help='ColorStrip')
|
|
763
|
+
iTOL_parser.add_argument('-ColorRange', required=False, action='store_true', help='ColorRange')
|
|
764
|
+
iTOL_parser.add_argument('-ColorClade', required=False, action='store_true', help='ColorClade')
|
|
765
|
+
iTOL_parser.add_argument('-ColorLabel', required=False, action='store_true', help='ColorLabel')
|
|
766
|
+
iTOL_parser.add_argument('-ColorLeafLabel', required=False, action='store_true', help='ColorLabel')
|
|
767
|
+
iTOL_parser.add_argument('-SimpleBar', required=False, action='store_true', help='SimpleBar')
|
|
768
|
+
iTOL_parser.add_argument('-Heatmap', required=False, action='store_true', help='Heatmap')
|
|
769
|
+
iTOL_parser.add_argument('-ExternalShape', required=False, action='store_true', help='ExternalShape')
|
|
770
|
+
iTOL_parser.add_argument('-Binary', required=False, action='store_true', help='Binary')
|
|
771
|
+
iTOL_parser.add_argument('-BinaryID', required=False, action='store_true', help='Binary specified IDs as 1')
|
|
772
|
+
iTOL_parser.add_argument('-BinaryShape', required=False, default='2', help='Binary Shape, choose from 1(rectangle), 2(circle), 3(star), 4, 5 and 6, default is 2')
|
|
773
|
+
iTOL_parser.add_argument('-BinaryColor', required=False, default='red', help='Binary Color, default is red')
|
|
774
|
+
iTOL_parser.add_argument('-Connection', required=False, action='store_true', help='Connection')
|
|
775
|
+
iTOL_parser.add_argument('-PieChart', required=False, action='store_true', help='PieChart')
|
|
776
|
+
iTOL_parser.add_argument('-Collapse', required=False, action='store_true', help='Collapse')
|
|
777
|
+
iTOL_parser.add_argument('-id', required=False, default=None, help='File contains leaf id')
|
|
778
|
+
iTOL_parser.add_argument('-ll', required=False, default=None, help='Leaf Label')
|
|
779
|
+
iTOL_parser.add_argument('-lg', required=False, default=None, help='Leaf Group')
|
|
780
|
+
iTOL_parser.add_argument('-gc', required=False, default=None, help='Specify Group/column Color (optional)')
|
|
781
|
+
iTOL_parser.add_argument('-cc', required=False, default=None, help='Specify Column Color (for ExternalShape format) (optional)')
|
|
782
|
+
iTOL_parser.add_argument('-lv', required=False, default=None, help='Leaf Value')
|
|
783
|
+
iTOL_parser.add_argument('-lm', required=False, default=None, help='Leaf Matrix')
|
|
784
|
+
iTOL_parser.add_argument('-dr', required=False, default=None, help='Donor to Recipient')
|
|
785
|
+
iTOL_parser.add_argument('-scale', required=False, default=None, help='Scale Values, in format 0-3-6-9')
|
|
786
|
+
iTOL_parser.add_argument('-lt', required=False, default=None, help='Legend Title')
|
|
787
|
+
iTOL_parser.add_argument('-legend', required=False, action='store_true', help='show legend for ColorStrip')
|
|
788
|
+
iTOL_parser.add_argument('-show_strip_labels', required=False, action='store_true', help='SHOW_STRIP_LABELS')
|
|
789
|
+
iTOL_parser.add_argument('-o', required=True, help='Output filename')
|
|
790
|
+
args = vars(iTOL_parser.parse_args())
|
|
791
|
+
iTOL(args)
|