Skip to content

Commit e183ea9

Browse files
authored
Merge pull request #134 from dengzq1234/main
correct data_matrix handling
2 parents 5bbd3bb + 18d851e commit e183ea9

File tree

8 files changed

+25
-24
lines changed

8 files changed

+25
-24
lines changed
-382 Bytes
Binary file not shown.

docs/build/doctrees/index.doctree

0 Bytes
Binary file not shown.

docs/build/html/_sources/documentations.rst.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ TreeProfiler requires
2323
- scipy >= 1.8.0
2424
- matplotlib >= 3.4
2525
- pymc >= 5.0.0
26-
- aesara
2726
- pastml (custom)
2827

2928
Quick install via pip
@@ -34,9 +33,6 @@ Quick install via pip
3433
pip install --force-reinstall "git+https://github.com/etetoolkit/ete.git@ete4_treeprofiler"
3534

3635

37-
# Install TreeProfiler dependencies
38-
pip install biopython selenium scipy matplotlib pymc aesara
39-
4036
# Install custom pastml package for ete4
4137
pip install "git+https://github.com/dengzq1234/pastml.git@pastml2ete4"
4238

docs/build/html/documentations.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ <h2><a class="toc-backref" href="#id8" role="doc-backlink">Dependencies</a><a cl
232232
<li><p>scipy &gt;= 1.8.0</p></li>
233233
<li><p>matplotlib &gt;= 3.4</p></li>
234234
<li><p>pymc &gt;= 5.0.0</p></li>
235-
<li><p>aesara</p></li>
236235
<li><p>pastml (custom)</p></li>
237236
</ul>
238237
</dd>
@@ -244,9 +243,6 @@ <h2><a class="toc-backref" href="#id9" role="doc-backlink">Quick install via pip
244243
<span class="n">pip</span> <span class="n">install</span> <span class="o">--</span><span class="n">force</span><span class="o">-</span><span class="n">reinstall</span> <span class="s2">&quot;git+https://github.com/etetoolkit/ete.git@ete4_treeprofiler&quot;</span>
245244

246245

247-
<span class="c1"># Install TreeProfiler dependencies</span>
248-
<span class="n">pip</span> <span class="n">install</span> <span class="n">biopython</span> <span class="n">selenium</span> <span class="n">scipy</span> <span class="n">matplotlib</span> <span class="n">pymc</span> <span class="n">aesara</span>
249-
250246
<span class="c1"># Install custom pastml package for ete4</span>
251247
<span class="n">pip</span> <span class="n">install</span> <span class="s2">&quot;git+https://github.com/dengzq1234/pastml.git@pastml2ete4&quot;</span>
252248

docs/build/html/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/source/documentations.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ TreeProfiler requires
2323
- scipy >= 1.8.0
2424
- matplotlib >= 3.4
2525
- pymc >= 5.0.0
26-
- aesara
2726
- pastml (custom)
2827

2928
Quick install via pip
@@ -34,9 +33,6 @@ Quick install via pip
3433
pip install --force-reinstall "git+https://github.com/etetoolkit/ete.git@ete4_treeprofiler"
3534

3635

37-
# Install TreeProfiler dependencies
38-
pip install biopython selenium scipy matplotlib pymc aesara
39-
4036
# Install custom pastml package for ete4
4137
pip install "git+https://github.com/dengzq1234/pastml.git@pastml2ete4"
4238

treeprofiler/tree_annotate.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ def run_tree_annotate(tree, input_annotated_tree=False,
694694
return annotated_tree, prop2type
695695

696696

697-
def run_array_annotate(tree, array_dict, num_stat='none', column2method={}):
697+
def run_array_annotate(tree, array_dict, num_stat='none', column2method={}, prop2type={}):
698698
matrix_props = list(array_dict.keys())
699699
# annotate to the leaves
700700
start = time.time()
@@ -708,17 +708,20 @@ def run_array_annotate(tree, array_dict, num_stat='none', column2method={}):
708708
for node in tree.traverse():
709709
if not node.is_leaf:
710710
for prop in matrix_props:
711+
711712
# get the array from the children leaf nodes
712713
arrays = [child.get_prop(prop) for child in node.leaves() if child.get_prop(prop) is not None]
713714

714715
if column2method.get(prop) is not None:
715716
num_stat = column2method.get(prop)
716717

717718
stats = compute_matrix_statistics(arrays, num_stat=num_stat)
719+
718720
if stats:
719721
for stat, value in stats.items():
722+
720723
node.add_prop(utils.add_suffix(prop, stat), value.tolist())
721-
#prop2type[utils.add_suffix(prop, stat)] = float
724+
prop2type[utils.add_suffix(prop, stat)] = list
722725
end = time.time()
723726
logger.info(f'Time for run_array_annotate to run: {end - start}')
724727
return tree
@@ -915,7 +918,7 @@ def run(args):
915918
)
916919

917920
if args.data_matrix:
918-
annotated_tree = run_array_annotate(annotated_tree, array_dict, num_stat=args.num_stat, column2method=column2method)
921+
annotated_tree = run_array_annotate(annotated_tree, array_dict, num_stat=args.num_stat, column2method=column2method, prop2type=prop2type)
919922
# update prop2type
920923
for filename in array_dict.keys():
921924
prop2type[filename] = list
@@ -954,12 +957,20 @@ def run(args):
954957
list_keys = [key for key, value in prop2type.items() if value == list]
955958
# Replace all commas in the tree with '||'
956959
list_sep = '||'
957-
for node in annotated_tree.leaves():
958-
for key in list_keys:
959-
if node.props.get(key):
960-
cont2str = list(map(str, node.props.get(key)))
961-
list2str = list_sep.join(cont2str)
962-
node.add_prop(key, list2str)
960+
if args.data_matrix and args.num_stat != 'none':
961+
for node in annotated_tree.traverse():
962+
for key in list_keys:
963+
if node.props.get(key):
964+
cont2str = list(map(str, node.props.get(key)))
965+
list2str = list_sep.join(cont2str)
966+
node.add_prop(key, list2str)
967+
else:
968+
for node in annotated_tree.leaves():
969+
for key in list_keys:
970+
if node.props.get(key):
971+
cont2str = list(map(str, node.props.get(key)))
972+
list2str = list_sep.join(cont2str)
973+
node.add_prop(key, list2str)
963974

964975

965976
avail_props = list(prop2type.keys())

treeprofiler/tree_plot.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,11 +2260,13 @@ def process_color_configuration(node2matrix, profiling_props=None):
22602260
if internal_num_rep != 'none':
22612261
representative_prop = utils.add_suffix(profiling_prop, internal_num_rep)
22622262
prop_value = node.props.get(representative_prop)
2263+
22632264
if prop_value is not None:
22642265
if isinstance(prop_value, list) or prop2type.get(representative_prop) == list:
22652266
list_props.add(profiling_prop)
22662267
if not eteformat_flag:
22672268
prop_value = prop_value.split(list_sep)
2269+
22682270
prop_value = list(map(float, prop_value))
22692271
if node.name not in node2matrix_list[profiling_prop]:
22702272
node2matrix_list[profiling_prop][node.name] = []
@@ -2281,14 +2283,14 @@ def process_color_configuration(node2matrix, profiling_props=None):
22812283
if single_props:
22822284
minval_single, maxval_single, value2color_single, gradientscolor = process_color_configuration(node2matrix_single, profiling_props)
22832285
else:
2284-
minval_single, maxval_single, value2color_single, gradientscolor = None, None, None
2286+
minval_single, maxval_single, value2color_single, gradientscolor = None, None, None, None
22852287

22862288
if list_props:
22872289
# Process list values for each profiling_prop
22882290
results_list = {}
22892291
for prop in profiling_props:
22902292
if prop in list_props:
2291-
minval_list, maxval_list, value2color_list = process_color_configuration(node2matrix_list[prop], profiling_props)
2293+
minval_list, maxval_list, value2color_list, gradientscolor = process_color_configuration(node2matrix_list[prop], profiling_props)
22922294
results_list[prop] = (node2matrix_list[prop], minval_list, maxval_list, value2color_list)
22932295
else:
22942296
results_list[prop] = (None, None, None, None)

0 commit comments

Comments
 (0)