treesumstats 0.2__tar.gz → 0.3__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.
- {treesumstats-0.2 → treesumstats-0.3}/PKG-INFO +39 -22
- {treesumstats-0.2 → treesumstats-0.3}/README.md +38 -21
- {treesumstats-0.2 → treesumstats-0.3}/setup.py +1 -1
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats/subtree_sumstats.py +111 -36
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats.egg-info/PKG-INFO +39 -22
- {treesumstats-0.2 → treesumstats-0.3}/LICENSE +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/setup.cfg +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats/__init__.py +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats/balance_sumstats.py +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats/basic_sumstats.py +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats/branch_sumstats.py +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats/calculator.py +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats/event_time_sumstats.py +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats/help.py +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats/ltt_sumstats.py +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats/resolution_sumstats.py +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats/sumstats.py +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats/transmission_chain_sumstats.py +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats/tree_manager.py +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats.egg-info/SOURCES.txt +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats.egg-info/dependency_links.txt +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats.egg-info/entry_points.txt +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats.egg-info/requires.txt +0 -0
- {treesumstats-0.2 → treesumstats-0.3}/treesumstats.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: treesumstats
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3
|
|
4
4
|
Summary: Encoding phylogenetic trees with summary statistics.
|
|
5
5
|
Home-page: https://github.com/evolbioinfo/treesumstats
|
|
6
6
|
Author: Anna Zhukova
|
|
@@ -250,11 +250,11 @@ The top part includes times <= T/3, the middle one > T/3 and <= 2T/3, the bottom
|
|
|
250
250
|
Implemented in [_treesumstats.subtree_sumstats.SubtreeFeatureCalculator_](treesumstats/subtree_sumstats.py).
|
|
251
251
|
|
|
252
252
|
In some of the following statistics reshuffled subtrees are mentioned.
|
|
253
|
-
To construct a _reshuffled subtree_ of a certain kind (cherry, triplet, etc.) from a real one we keep one of its (randomly chosen)
|
|
254
|
-
while for each other
|
|
255
|
-
(i) the time at the beginning of its branch is as close as possible to the time at the beginning of the real
|
|
256
|
-
(ii) while all the
|
|
257
|
-
(iii) there are no two
|
|
253
|
+
To construct a _reshuffled subtree_ of a certain kind (cherry, triplet, etc.) from a real one we keep one of its (randomly chosen) locally (with respect to the subtree) external node,
|
|
254
|
+
while for each other locally external node from the real subtree we replace it with a node of globally (with respect to the forest) the same type (external or internal), for which:
|
|
255
|
+
(i) the time at the beginning of its branch is as close as possible to the time at the beginning of the real node's branch,
|
|
256
|
+
(ii) while all the locally external nodes in the reshuffled subtree are different and
|
|
257
|
+
(iii) there are no two locally external nodes in the reshuffled subtree that used to belong to the same real subtree of this kind
|
|
258
258
|
(unless there were not enough tips, e.g., 8 tips in total and only 2 ladderized quartets in the forest).
|
|
259
259
|
|
|
260
260
|
We consider the following 2-tip, 3-tip and 4-tip subtrees to calculate the summary statistics:
|
|
@@ -267,39 +267,56 @@ We consider the following 2-tip, 3-tip and 4-tip subtrees to calculate the summa
|
|
|
267
267
|
* 4L: fully resolved ladderized quartet
|
|
268
268
|
* 4B: fully resolved balanced quartet (with two cherries as children)
|
|
269
269
|
|
|
270
|
-
|
|
270
|
+
We also consider fully internal-node subtrees:
|
|
271
|
+
* I: fully unresolved subtree (or size 2 or more) whose locally external nodes are globally internal sibling nodes.
|
|
271
272
|
|
|
272
|
-
|
|
273
|
+
In the following statistics (spanning several list positions) XT must be replaced by one of the following values: 2, 3U, 3L, 4U, 4U3U1, 4U211, 4L or 4B, while X must be replaced by either I or one of the XT values.
|
|
274
|
+
|
|
275
|
+
1-8. **frac_tips_in_XT:** fraction of forest tips that are found in subtrees of type XT.
|
|
273
276
|
9. **frac_tips_in_O:** fraction of forest tips that are not part of any subtree of size 2, 3 or 4.
|
|
274
277
|
|
|
275
|
-
10-17. **
|
|
278
|
+
10-17. **n_tips_in_XT:** number of forest tips that are found in subtrees of type XT.
|
|
276
279
|
18. **n_tips_in_O:** number of forest tips that are not part of any subtree of size 2, 3 or 4.
|
|
280
|
+
19. **frac_inodes_with_sibling_inodes:** fraction of forest non-root internal nodes that have internal siblings.
|
|
281
|
+
20. **frac_inodes_without_sibling_inodes:** fraction of forest non-root internal nodes that do not have internal siblings.
|
|
282
|
+
19. **n_inodes_with_sibling_inodes:** number of forest non-root internal nodes that have internal siblings.
|
|
283
|
+
20. **n_inodes_without_sibling_inodes:** number of forest non-root internal nodes that do not have internal siblings.
|
|
284
|
+
|
|
285
|
+
21-29. **time_diff_in_X_real_mean:** mean among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
286
|
+
|
|
287
|
+
30-38. **time_diff_in_X_real_min:** minimum among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
288
|
+
|
|
289
|
+
39-47. **time_diff_in_X_real_max:** maximum among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
290
|
+
|
|
291
|
+
48-56. **time_diff_in_X_real_var:** variance among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
292
|
+
|
|
293
|
+
57-65. **time_diff_in_X_real_median:** median among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
277
294
|
|
|
278
|
-
|
|
295
|
+
66-74. **time_diff_in_X_random_mean:** mean among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
279
296
|
|
|
280
|
-
|
|
297
|
+
75-83. **time_diff_in_X_random_min:** minimum among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
281
298
|
|
|
282
|
-
|
|
299
|
+
84-93. **time_diff_in_X_random_max:** maximum among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
283
300
|
|
|
284
|
-
|
|
301
|
+
94-103. **time_diff_in_X_random_var:** variance among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
285
302
|
|
|
286
|
-
|
|
303
|
+
104-112. **time_diff_in_X_random_median:** median among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
287
304
|
|
|
288
|
-
|
|
305
|
+
113-184. **time_diff_in_X_real_percN:** Nth percentile (where N can be 1, 5, 10, 25, 75, 90, 95 or 99) among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
289
306
|
|
|
290
|
-
|
|
307
|
+
184-255. **time_diff_in_X_random_percN:** Nth percentile (where N can be 1, 5, 10, 25, 75, 90, 95 or 99) among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
291
308
|
|
|
292
|
-
|
|
309
|
+
256-264. **time_diff_in_X_random_vs_real_n_less:** number of subtrees of type X whose average locally external node sampling time differences is smaller in real subtrees than in the corresponding reshuffled ones.
|
|
293
310
|
|
|
294
|
-
|
|
311
|
+
265-273. **time_diff_in_X_random_vs_real_n_more:** number of subtrees of type X whose average locally external node sampling time differences is larger in real subtrees than in the corresponding reshuffled ones.
|
|
295
312
|
|
|
296
|
-
|
|
313
|
+
274-282. **time_diff_in_X_random_vs_real_frac_less:** fraction of subtrees of type X whose average locally external node sampling time differences is smaller in real subtrees than in the corresponding reshuffled ones.
|
|
297
314
|
|
|
298
|
-
|
|
315
|
+
283-291. **time_diff_in_X_random_vs_real_frac_more:** fraction of subtrees of type X whose average locally external node sampling time differences is larger in real subtrees than in the corresponding reshuffled ones.
|
|
299
316
|
|
|
300
|
-
|
|
317
|
+
292-301. **time_diff_in_X_random_vs_real_pval_less:** p-value of the sign test checking that for subtrees of type X, their average locally external node sampling time differences are indistinguishable in real subtrees and in the corresponding reshuffled ones (the alternative hypothesis is that some real ones are smaller).
|
|
301
318
|
|
|
302
|
-
|
|
319
|
+
302-310. **time_diff_in_X_random_vs_real_pval_more:** p-value of the sign test checking that for subtrees of type X, their average locally external node sampling time differences are indistinguishable in real subtrees and in the corresponding reshuffled ones (the alternative hypothesis is that some real ones are larger).
|
|
303
320
|
|
|
304
321
|
|
|
305
322
|
## Input data
|
|
@@ -228,11 +228,11 @@ The top part includes times <= T/3, the middle one > T/3 and <= 2T/3, the bottom
|
|
|
228
228
|
Implemented in [_treesumstats.subtree_sumstats.SubtreeFeatureCalculator_](treesumstats/subtree_sumstats.py).
|
|
229
229
|
|
|
230
230
|
In some of the following statistics reshuffled subtrees are mentioned.
|
|
231
|
-
To construct a _reshuffled subtree_ of a certain kind (cherry, triplet, etc.) from a real one we keep one of its (randomly chosen)
|
|
232
|
-
while for each other
|
|
233
|
-
(i) the time at the beginning of its branch is as close as possible to the time at the beginning of the real
|
|
234
|
-
(ii) while all the
|
|
235
|
-
(iii) there are no two
|
|
231
|
+
To construct a _reshuffled subtree_ of a certain kind (cherry, triplet, etc.) from a real one we keep one of its (randomly chosen) locally (with respect to the subtree) external node,
|
|
232
|
+
while for each other locally external node from the real subtree we replace it with a node of globally (with respect to the forest) the same type (external or internal), for which:
|
|
233
|
+
(i) the time at the beginning of its branch is as close as possible to the time at the beginning of the real node's branch,
|
|
234
|
+
(ii) while all the locally external nodes in the reshuffled subtree are different and
|
|
235
|
+
(iii) there are no two locally external nodes in the reshuffled subtree that used to belong to the same real subtree of this kind
|
|
236
236
|
(unless there were not enough tips, e.g., 8 tips in total and only 2 ladderized quartets in the forest).
|
|
237
237
|
|
|
238
238
|
We consider the following 2-tip, 3-tip and 4-tip subtrees to calculate the summary statistics:
|
|
@@ -245,39 +245,56 @@ We consider the following 2-tip, 3-tip and 4-tip subtrees to calculate the summa
|
|
|
245
245
|
* 4L: fully resolved ladderized quartet
|
|
246
246
|
* 4B: fully resolved balanced quartet (with two cherries as children)
|
|
247
247
|
|
|
248
|
-
|
|
248
|
+
We also consider fully internal-node subtrees:
|
|
249
|
+
* I: fully unresolved subtree (or size 2 or more) whose locally external nodes are globally internal sibling nodes.
|
|
249
250
|
|
|
250
|
-
|
|
251
|
+
In the following statistics (spanning several list positions) XT must be replaced by one of the following values: 2, 3U, 3L, 4U, 4U3U1, 4U211, 4L or 4B, while X must be replaced by either I or one of the XT values.
|
|
252
|
+
|
|
253
|
+
1-8. **frac_tips_in_XT:** fraction of forest tips that are found in subtrees of type XT.
|
|
251
254
|
9. **frac_tips_in_O:** fraction of forest tips that are not part of any subtree of size 2, 3 or 4.
|
|
252
255
|
|
|
253
|
-
10-17. **
|
|
256
|
+
10-17. **n_tips_in_XT:** number of forest tips that are found in subtrees of type XT.
|
|
254
257
|
18. **n_tips_in_O:** number of forest tips that are not part of any subtree of size 2, 3 or 4.
|
|
258
|
+
19. **frac_inodes_with_sibling_inodes:** fraction of forest non-root internal nodes that have internal siblings.
|
|
259
|
+
20. **frac_inodes_without_sibling_inodes:** fraction of forest non-root internal nodes that do not have internal siblings.
|
|
260
|
+
19. **n_inodes_with_sibling_inodes:** number of forest non-root internal nodes that have internal siblings.
|
|
261
|
+
20. **n_inodes_without_sibling_inodes:** number of forest non-root internal nodes that do not have internal siblings.
|
|
262
|
+
|
|
263
|
+
21-29. **time_diff_in_X_real_mean:** mean among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
264
|
+
|
|
265
|
+
30-38. **time_diff_in_X_real_min:** minimum among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
266
|
+
|
|
267
|
+
39-47. **time_diff_in_X_real_max:** maximum among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
268
|
+
|
|
269
|
+
48-56. **time_diff_in_X_real_var:** variance among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
270
|
+
|
|
271
|
+
57-65. **time_diff_in_X_real_median:** median among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
255
272
|
|
|
256
|
-
|
|
273
|
+
66-74. **time_diff_in_X_random_mean:** mean among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
257
274
|
|
|
258
|
-
|
|
275
|
+
75-83. **time_diff_in_X_random_min:** minimum among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
259
276
|
|
|
260
|
-
|
|
277
|
+
84-93. **time_diff_in_X_random_max:** maximum among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
261
278
|
|
|
262
|
-
|
|
279
|
+
94-103. **time_diff_in_X_random_var:** variance among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
263
280
|
|
|
264
|
-
|
|
281
|
+
104-112. **time_diff_in_X_random_median:** median among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
265
282
|
|
|
266
|
-
|
|
283
|
+
113-184. **time_diff_in_X_real_percN:** Nth percentile (where N can be 1, 5, 10, 25, 75, 90, 95 or 99) among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
267
284
|
|
|
268
|
-
|
|
285
|
+
184-255. **time_diff_in_X_random_percN:** Nth percentile (where N can be 1, 5, 10, 25, 75, 90, 95 or 99) among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
269
286
|
|
|
270
|
-
|
|
287
|
+
256-264. **time_diff_in_X_random_vs_real_n_less:** number of subtrees of type X whose average locally external node sampling time differences is smaller in real subtrees than in the corresponding reshuffled ones.
|
|
271
288
|
|
|
272
|
-
|
|
289
|
+
265-273. **time_diff_in_X_random_vs_real_n_more:** number of subtrees of type X whose average locally external node sampling time differences is larger in real subtrees than in the corresponding reshuffled ones.
|
|
273
290
|
|
|
274
|
-
|
|
291
|
+
274-282. **time_diff_in_X_random_vs_real_frac_less:** fraction of subtrees of type X whose average locally external node sampling time differences is smaller in real subtrees than in the corresponding reshuffled ones.
|
|
275
292
|
|
|
276
|
-
|
|
293
|
+
283-291. **time_diff_in_X_random_vs_real_frac_more:** fraction of subtrees of type X whose average locally external node sampling time differences is larger in real subtrees than in the corresponding reshuffled ones.
|
|
277
294
|
|
|
278
|
-
|
|
295
|
+
292-301. **time_diff_in_X_random_vs_real_pval_less:** p-value of the sign test checking that for subtrees of type X, their average locally external node sampling time differences are indistinguishable in real subtrees and in the corresponding reshuffled ones (the alternative hypothesis is that some real ones are smaller).
|
|
279
296
|
|
|
280
|
-
|
|
297
|
+
302-310. **time_diff_in_X_random_vs_real_pval_more:** p-value of the sign test checking that for subtrees of type X, their average locally external node sampling time differences are indistinguishable in real subtrees and in the corresponding reshuffled ones (the alternative hypothesis is that some real ones are larger).
|
|
281
298
|
|
|
282
299
|
|
|
283
300
|
## Input data
|
|
@@ -18,7 +18,7 @@ setup(
|
|
|
18
18
|
'Topic :: Software Development',
|
|
19
19
|
'Topic :: Software Development :: Libraries :: Python Modules',
|
|
20
20
|
],
|
|
21
|
-
version='0.
|
|
21
|
+
version='0.3',
|
|
22
22
|
description='Encoding phylogenetic trees with summary statistics.',
|
|
23
23
|
author='Anna Zhukova',
|
|
24
24
|
author_email='anna.zhukova@pasteur.fr',
|
|
@@ -9,7 +9,8 @@ from treesumstats.tree_manager import annotate_forest_with_time, TIME
|
|
|
9
9
|
|
|
10
10
|
OTHER_CONFIGURATION_LABEL = 'O'
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
TIP_TOPOLOGY_LABELS = ['2', '3U', '3L', '4U', '4U3U1', '4U211', '4L', '4B', 'O']
|
|
13
|
+
TOPOLOGY_LABELS = TIP_TOPOLOGY_LABELS + ['I']
|
|
13
14
|
|
|
14
15
|
TIP = 1
|
|
15
16
|
|
|
@@ -32,7 +33,9 @@ CONFIG_ORDER = [TIP, CHERRY, TRIPLET_UNRESOLVED, TRIPLET_LADDER,
|
|
|
32
33
|
|
|
33
34
|
TOPOLOGY_LABEL2KEY = {'2': CHERRY, '3U': TRIPLET_UNRESOLVED, '3L': TRIPLET_LADDER, '4U': QUARTET_UNRESOLVED,
|
|
34
35
|
'4U3U1': QUARTET_TRIPLET_UNRESOLVED_TIP, '4U211': QUARTET_CHERRY_TIP_TIP,
|
|
35
|
-
'4L': QUARTET_LADDER, '4B': QUARTET_BALANCED, 'O':
|
|
36
|
+
'4L': QUARTET_LADDER, '4B': QUARTET_BALANCED, 'O': 2}
|
|
37
|
+
|
|
38
|
+
KEY2TOPOLOGY_LABEL = {v: k for (k, v) in TOPOLOGY_LABEL2KEY.items()}
|
|
36
39
|
|
|
37
40
|
TOPOLOGY_LABEL2N = {'2': 2, '3U': 3, '3L': 3, '4U': 4,
|
|
38
41
|
'4U3U1': 4, '4U211': 4,
|
|
@@ -43,7 +46,8 @@ TOPOLOGY_LABEL2NAME = {'2': 'cherries', '3U': 'unresolved triplets', '3L': 'reso
|
|
|
43
46
|
'4U3U1': 'partially resolved quartets with an unresolved triplet and a tip as children',
|
|
44
47
|
'4U211': 'partially resolved quartets with a cherry and two tips as three children',
|
|
45
48
|
'4L': 'ladderized fully resolved quartets',
|
|
46
|
-
'4B': 'balanced quartets (with two cherries as children)'
|
|
49
|
+
'4B': 'balanced quartets (with two cherries as children)',
|
|
50
|
+
'I': 'cherries or fully unresolved n-tip subtrees (n > 2) whose external nodes were internal in the global forest'}
|
|
47
51
|
|
|
48
52
|
|
|
49
53
|
TIP_TIME_PERCENTILES = [1, 5, 10, 25, 75, 90, 95, 99]
|
|
@@ -71,6 +75,27 @@ def get_config2tips(forest):
|
|
|
71
75
|
c.del_feature(feature)
|
|
72
76
|
return topo2tips
|
|
73
77
|
|
|
78
|
+
|
|
79
|
+
def pick_siblings(forest, include_polytomies=True):
|
|
80
|
+
"""
|
|
81
|
+
Picks internal sibling motifs in the given forest.
|
|
82
|
+
|
|
83
|
+
:param include_polytomies: bool, whether to include nodes with > 2 children into consideration.
|
|
84
|
+
:param forest: list(ete3.Tree), the forest of interest
|
|
85
|
+
:return: iterator of Motif motifs
|
|
86
|
+
"""
|
|
87
|
+
result = []
|
|
88
|
+
for tree in forest:
|
|
89
|
+
for root in tree.traverse():
|
|
90
|
+
if root.is_leaf() or not include_polytomies and len(root.children) != 2:
|
|
91
|
+
continue
|
|
92
|
+
siblings = [_ for _ in root.children if not _.is_leaf()]
|
|
93
|
+
if len(siblings) < 2:
|
|
94
|
+
continue
|
|
95
|
+
result.append(siblings)
|
|
96
|
+
return result
|
|
97
|
+
|
|
98
|
+
|
|
74
99
|
def get_reshuffled_configs(real_configs, all_tips_sorted):
|
|
75
100
|
"""
|
|
76
101
|
Creates reshuffled configs. For each real config a reshuffled one is constructed by
|
|
@@ -135,19 +160,21 @@ def get_avg_time_diff(times):
|
|
|
135
160
|
return 2 * diff_sum / n / (n - 1)
|
|
136
161
|
|
|
137
162
|
|
|
138
|
-
|
|
139
|
-
|
|
140
163
|
class SubtreeFeatureCalculator(FeatureCalculator):
|
|
141
164
|
"""Computes tree topology-related summary statistics."""
|
|
142
165
|
|
|
143
166
|
def __init__(self):
|
|
167
|
+
self._n_inodes = None
|
|
168
|
+
self._sibling_inodes = None
|
|
144
169
|
self._topo2diffs = None
|
|
145
170
|
self._topo2diffs_random = None
|
|
146
171
|
self._all_tips = None
|
|
147
172
|
self._forest = None
|
|
148
173
|
self._topo2tips = None
|
|
149
174
|
self._n_tips = None
|
|
150
|
-
self.
|
|
175
|
+
self._sibling_inodes_random = None
|
|
176
|
+
self._topo2inodes_random = None
|
|
177
|
+
self._all_inodes = None
|
|
151
178
|
|
|
152
179
|
def help(self, feature_name, *args, **kwargs):
|
|
153
180
|
if 'tips_in_' in feature_name:
|
|
@@ -157,49 +184,61 @@ class SubtreeFeatureCalculator(FeatureCalculator):
|
|
|
157
184
|
return f'{measure} of forest tips that are not part of any subtree of size 2, 3 or 4.'
|
|
158
185
|
return f'{measure} of forest tips that are found in {TOPOLOGY_LABEL2NAME[conf]}.'
|
|
159
186
|
|
|
187
|
+
if 'inodes_with_sibling_inodes' in feature_name:
|
|
188
|
+
measure = 'fraction' if feature_name.startswith('frac') else 'number'
|
|
189
|
+
return f'{measure} of forest non-root internal nodes that have internal node siblings.'
|
|
190
|
+
if 'inodes_without_sibling_inodes' in feature_name:
|
|
191
|
+
measure = 'fraction' if feature_name.startswith('frac') else 'number'
|
|
192
|
+
return f'{measure} of forest non-root internal nodes that do not have internal node siblings.'
|
|
193
|
+
|
|
160
194
|
if feature_name.startswith('time_diff_in_'):
|
|
161
195
|
conf = feature_name[feature_name.find('time_diff_in_') + len('time_diff_in_'):].split('_')[0]
|
|
162
196
|
is_real='real' in feature_name
|
|
163
197
|
|
|
164
|
-
reshuffling_expl = '(To construct a reshuffled subtree of a certain kind from a real one we keep one of its (randomly chosen)
|
|
165
|
-
'while for each
|
|
166
|
-
'(i) the time at the beginning of its branch is as close as possible to the time at the beginning of the real
|
|
167
|
-
'(ii) while all the
|
|
168
|
-
'and (iii) there are no two
|
|
169
|
-
'(unless there were not enough
|
|
198
|
+
reshuffling_expl = '(To construct a reshuffled subtree of a certain kind from a real one we keep one of its (randomly chosen) locally external (with respect to the subtree) nodes, ' \
|
|
199
|
+
'while for each of its other locally external node we replace it with a node of the same global type (internal or external, with respect to the global forest), for which:' \
|
|
200
|
+
'(i) the time at the beginning of its branch is as close as possible to the time at the beginning of the real locally external node\'s branch, ' \
|
|
201
|
+
'(ii) while all the locally external nodes in the reshuffled subtree are different ' \
|
|
202
|
+
'and (iii) there are no two locally external nodes in the reshuffled subtree that used to belong to the same real subtree of this kind ' \
|
|
203
|
+
'(unless there were not enough such nodes, e.g., 8 tips in total and only 2 4-tip subtrees in the forest).'
|
|
170
204
|
|
|
171
205
|
flavour = feature_name.split('_')[-1]
|
|
172
206
|
if flavour in BASIC_METRIC2FUN or 'perc' in flavour:
|
|
173
207
|
res = f'{BASIC_METRIC2HELP[flavour]}' if flavour in BASIC_METRIC2FUN \
|
|
174
208
|
else f'{re.findall(r'\d+', flavour)[0]}th percentile'
|
|
175
|
-
res += f' of average of all
|
|
209
|
+
res += f' of average of all external node pair sampling time differences in a {TOPOLOGY_LABEL2NAME[conf]} among all {'' if is_real else 'reshuffled'}' \
|
|
176
210
|
f'{TOPOLOGY_LABEL2NAME[conf]} in the forest.'
|
|
177
211
|
if not is_real:
|
|
178
212
|
res += reshuffling_expl
|
|
179
213
|
return res
|
|
180
214
|
else:
|
|
181
|
-
if '
|
|
215
|
+
if 'random_vs_real_n_' in feature_name:
|
|
216
|
+
less_or_more = 'smaller' if 'less' == feature_name.split('_')[-1] else 'larger'
|
|
182
217
|
return f'number of {TOPOLOGY_LABEL2NAME[conf]}, ' \
|
|
183
|
-
'for which their average
|
|
218
|
+
f'for which their average external node sampling time difference is {less_or_more} in real subtrees than ' \
|
|
184
219
|
f'in the corresponding reshuffled ones. {reshuffling_expl}'
|
|
185
|
-
elif '
|
|
220
|
+
elif 'random_vs_real_frac_' in feature_name:
|
|
221
|
+
less_or_more = 'smaller' if 'less' == feature_name.split('_')[-1] else 'larger'
|
|
186
222
|
return f'fraction of {TOPOLOGY_LABEL2NAME[conf]}, ' \
|
|
187
|
-
'for which their average
|
|
223
|
+
f'for which their average external node sampling time difference is {less_or_more} in real subtrees than ' \
|
|
188
224
|
f'in the corresponding reshuffled ones. {reshuffling_expl}'
|
|
189
|
-
elif '
|
|
225
|
+
elif 'random_vs_real_pval_' in feature_name:
|
|
226
|
+
less_or_more = 'smaller' if 'less' == feature_name.split('_')[-1] else 'larger'
|
|
190
227
|
return f'p-value of the sign test checking that for {TOPOLOGY_LABEL2NAME[conf]}, ' \
|
|
191
|
-
'their average
|
|
228
|
+
'their average external node sampling time differences are indistinguishable in real subtrees and ' \
|
|
192
229
|
f'in the corresponding reshuffled ones ' \
|
|
193
|
-
f'(the alternative hypothesis is that some real ones are
|
|
230
|
+
f'(the alternative hypothesis is that some real ones are {less_or_more}). {reshuffling_expl}'
|
|
194
231
|
|
|
195
232
|
return None
|
|
196
233
|
|
|
197
234
|
def feature_names(self):
|
|
198
235
|
return [f'frac_tips_in_{conf}' for conf in TOPOLOGY_LABELS] \
|
|
199
236
|
+ [f'n_tips_in_{conf}' for conf in TOPOLOGY_LABELS] \
|
|
237
|
+
+ [f'frac_inodes_{wwo}_sibling_inodes' for wwo in ('with', 'without')] \
|
|
238
|
+
+ [f'n_inodes_{wwo}_sibling_inodes' for wwo in ('with', 'without')] \
|
|
200
239
|
+ [f'time_diff_in_{conf}_{type}_{flavour}' for type in ('real', 'random') for flavour in BASIC_ARRAY_METRICS for conf in TOPOLOGY_LABELS if conf != OTHER_CONFIGURATION_LABEL] \
|
|
201
240
|
+ [f'time_diff_in_{conf}_{type}_perc{p}' for type in ('real', 'random') for p in TIP_TIME_PERCENTILES for conf in TOPOLOGY_LABELS if conf != OTHER_CONFIGURATION_LABEL] \
|
|
202
|
-
+ [f'time_diff_in_{conf}_random_vs_real_{metric}
|
|
241
|
+
+ [f'time_diff_in_{conf}_random_vs_real_{metric}_{how}' for metric in ('n', 'frac', 'pval') for conf in TOPOLOGY_LABELS if conf != OTHER_CONFIGURATION_LABEL for how in ('less', 'more')]
|
|
203
242
|
|
|
204
243
|
def set_forest(self, forest, **kwargs):
|
|
205
244
|
self._forest = forest
|
|
@@ -207,9 +246,13 @@ class SubtreeFeatureCalculator(FeatureCalculator):
|
|
|
207
246
|
self._topo2tips = None
|
|
208
247
|
self._n_tips = None
|
|
209
248
|
self._all_tips = None
|
|
210
|
-
self.
|
|
249
|
+
self._all_inodes = None
|
|
250
|
+
self._sibling_inodes_random = None
|
|
211
251
|
self._topo2diffs = None
|
|
212
252
|
self._topo2diffs_random = None
|
|
253
|
+
self._sibling_inodes = None
|
|
254
|
+
self._topo2inodes_random = None
|
|
255
|
+
self._n_inodes = None
|
|
213
256
|
|
|
214
257
|
@property
|
|
215
258
|
def n_tips(self):
|
|
@@ -217,18 +260,36 @@ class SubtreeFeatureCalculator(FeatureCalculator):
|
|
|
217
260
|
self._n_tips = sum(len(tree) for tree in self._forest)
|
|
218
261
|
return self._n_tips
|
|
219
262
|
|
|
263
|
+
@property
|
|
264
|
+
def n_inodes(self):
|
|
265
|
+
if self._n_inodes is None:
|
|
266
|
+
self._n_inodes = sum(sum(1 for n in tree.traverse() if not n.is_leaf() and not n.is_root()) for tree in self._forest)
|
|
267
|
+
return self._n_inodes
|
|
268
|
+
|
|
220
269
|
def conf2tips(self, config_type, is_real=True):
|
|
221
270
|
if is_real:
|
|
222
271
|
if self._topo2tips is None:
|
|
223
272
|
self._topo2tips = get_config2tips(self._forest)
|
|
224
273
|
return self._topo2tips[config_type]
|
|
225
274
|
|
|
226
|
-
if self.
|
|
227
|
-
self.
|
|
228
|
-
if config_type not in self.
|
|
229
|
-
self.
|
|
230
|
-
|
|
231
|
-
return self.
|
|
275
|
+
if self._sibling_inodes_random is None:
|
|
276
|
+
self._sibling_inodes_random = dict()
|
|
277
|
+
if config_type not in self._sibling_inodes_random:
|
|
278
|
+
self._sibling_inodes_random[config_type] = get_reshuffled_configs(self.conf2tips(config_type, is_real=True),
|
|
279
|
+
self.all_tips)
|
|
280
|
+
return self._sibling_inodes_random[config_type]
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def sibling_inodes(self, is_real=True):
|
|
284
|
+
if is_real:
|
|
285
|
+
if self._sibling_inodes is None:
|
|
286
|
+
self._sibling_inodes = pick_siblings(self._forest)
|
|
287
|
+
return self._sibling_inodes
|
|
288
|
+
|
|
289
|
+
if self._sibling_inodes_random is None:
|
|
290
|
+
self._sibling_inodes_random = []
|
|
291
|
+
self._sibling_inodes_random = get_reshuffled_configs(self.sibling_inodes(is_real=True), self.all_inodes)
|
|
292
|
+
return self._sibling_inodes_random
|
|
232
293
|
|
|
233
294
|
def conf2time_diffs(self, config_type, is_real=True):
|
|
234
295
|
if is_real:
|
|
@@ -254,12 +315,26 @@ class SubtreeFeatureCalculator(FeatureCalculator):
|
|
|
254
315
|
self._all_tips = sorted([t for tree in self._forest for t in tree], key=lambda _: getattr(_, TIME) - _.dist)
|
|
255
316
|
return self._all_tips
|
|
256
317
|
|
|
318
|
+
@property
|
|
319
|
+
def all_inodes(self):
|
|
320
|
+
if self._all_inodes is None:
|
|
321
|
+
self._all_inodes = sorted([n for tree in self._forest for n in tree.traverse() if not n.is_leaf() and not n.is_root()],
|
|
322
|
+
key=lambda _: getattr(_, TIME) - _.dist)
|
|
323
|
+
return self._all_inodes
|
|
324
|
+
|
|
257
325
|
def calculate(self, feature_name, **kwargs):
|
|
258
326
|
if 'tips_in_' in feature_name:
|
|
259
327
|
conf = feature_name[feature_name.find('tips_in_') + len('tips_in_'):]
|
|
260
328
|
denominator = self.n_tips if feature_name.startswith('frac') else 1
|
|
261
329
|
return len(self.conf2tips(TOPOLOGY_LABEL2KEY[conf], is_real=True)) * TOPOLOGY_LABEL2N[conf] / denominator
|
|
262
330
|
|
|
331
|
+
if 'inodes_with_sibling_inodes' in feature_name:
|
|
332
|
+
denominator = self.n_inodes if feature_name.startswith('frac') else 1
|
|
333
|
+
return sum(len(_) for _ in self.sibling_inodes(is_real=True)) / denominator
|
|
334
|
+
if 'inodes_without_sibling_inodes' in feature_name:
|
|
335
|
+
denominator = self.n_inodes if feature_name.startswith('frac') else 1
|
|
336
|
+
return (self.n_inodes - sum(len(_) for _ in self.sibling_inodes(is_real=True))) / denominator
|
|
337
|
+
|
|
263
338
|
if feature_name.startswith('time_diff_in_'):
|
|
264
339
|
conf = feature_name[feature_name.find('time_diff_in_') + len('time_diff_in_'):].split('_')[0]
|
|
265
340
|
time_diffs = self.conf2time_diffs(TOPOLOGY_LABEL2KEY[conf], is_real='real' in feature_name)
|
|
@@ -274,12 +349,12 @@ class SubtreeFeatureCalculator(FeatureCalculator):
|
|
|
274
349
|
return np.percentile(time_diffs, perc) if n else 0
|
|
275
350
|
else:
|
|
276
351
|
time_diffs_random = self.conf2time_diffs(TOPOLOGY_LABEL2KEY[conf], is_real=False)
|
|
277
|
-
|
|
278
|
-
if
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
352
|
+
is_less = 'less' == feature_name.split('_')[-1]
|
|
353
|
+
n_random_vs_real = ((time_diffs_random < time_diffs) if is_less else (time_diffs_random > time_diffs)).sum()
|
|
354
|
+
if 'random_vs_real_n_' in feature_name:
|
|
355
|
+
return n_random_vs_real
|
|
356
|
+
elif 'random_vs_real_frac_' in feature_name:
|
|
357
|
+
return n_random_vs_real / n if n else 0
|
|
358
|
+
elif 'random_vs_real_pval_' in feature_name:
|
|
359
|
+
return scipy.stats.binomtest(n_random_vs_real, n=n, p=0.5, alternative='less').pvalue if n else 1
|
|
285
360
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: treesumstats
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3
|
|
4
4
|
Summary: Encoding phylogenetic trees with summary statistics.
|
|
5
5
|
Home-page: https://github.com/evolbioinfo/treesumstats
|
|
6
6
|
Author: Anna Zhukova
|
|
@@ -250,11 +250,11 @@ The top part includes times <= T/3, the middle one > T/3 and <= 2T/3, the bottom
|
|
|
250
250
|
Implemented in [_treesumstats.subtree_sumstats.SubtreeFeatureCalculator_](treesumstats/subtree_sumstats.py).
|
|
251
251
|
|
|
252
252
|
In some of the following statistics reshuffled subtrees are mentioned.
|
|
253
|
-
To construct a _reshuffled subtree_ of a certain kind (cherry, triplet, etc.) from a real one we keep one of its (randomly chosen)
|
|
254
|
-
while for each other
|
|
255
|
-
(i) the time at the beginning of its branch is as close as possible to the time at the beginning of the real
|
|
256
|
-
(ii) while all the
|
|
257
|
-
(iii) there are no two
|
|
253
|
+
To construct a _reshuffled subtree_ of a certain kind (cherry, triplet, etc.) from a real one we keep one of its (randomly chosen) locally (with respect to the subtree) external node,
|
|
254
|
+
while for each other locally external node from the real subtree we replace it with a node of globally (with respect to the forest) the same type (external or internal), for which:
|
|
255
|
+
(i) the time at the beginning of its branch is as close as possible to the time at the beginning of the real node's branch,
|
|
256
|
+
(ii) while all the locally external nodes in the reshuffled subtree are different and
|
|
257
|
+
(iii) there are no two locally external nodes in the reshuffled subtree that used to belong to the same real subtree of this kind
|
|
258
258
|
(unless there were not enough tips, e.g., 8 tips in total and only 2 ladderized quartets in the forest).
|
|
259
259
|
|
|
260
260
|
We consider the following 2-tip, 3-tip and 4-tip subtrees to calculate the summary statistics:
|
|
@@ -267,39 +267,56 @@ We consider the following 2-tip, 3-tip and 4-tip subtrees to calculate the summa
|
|
|
267
267
|
* 4L: fully resolved ladderized quartet
|
|
268
268
|
* 4B: fully resolved balanced quartet (with two cherries as children)
|
|
269
269
|
|
|
270
|
-
|
|
270
|
+
We also consider fully internal-node subtrees:
|
|
271
|
+
* I: fully unresolved subtree (or size 2 or more) whose locally external nodes are globally internal sibling nodes.
|
|
271
272
|
|
|
272
|
-
|
|
273
|
+
In the following statistics (spanning several list positions) XT must be replaced by one of the following values: 2, 3U, 3L, 4U, 4U3U1, 4U211, 4L or 4B, while X must be replaced by either I or one of the XT values.
|
|
274
|
+
|
|
275
|
+
1-8. **frac_tips_in_XT:** fraction of forest tips that are found in subtrees of type XT.
|
|
273
276
|
9. **frac_tips_in_O:** fraction of forest tips that are not part of any subtree of size 2, 3 or 4.
|
|
274
277
|
|
|
275
|
-
10-17. **
|
|
278
|
+
10-17. **n_tips_in_XT:** number of forest tips that are found in subtrees of type XT.
|
|
276
279
|
18. **n_tips_in_O:** number of forest tips that are not part of any subtree of size 2, 3 or 4.
|
|
280
|
+
19. **frac_inodes_with_sibling_inodes:** fraction of forest non-root internal nodes that have internal siblings.
|
|
281
|
+
20. **frac_inodes_without_sibling_inodes:** fraction of forest non-root internal nodes that do not have internal siblings.
|
|
282
|
+
19. **n_inodes_with_sibling_inodes:** number of forest non-root internal nodes that have internal siblings.
|
|
283
|
+
20. **n_inodes_without_sibling_inodes:** number of forest non-root internal nodes that do not have internal siblings.
|
|
284
|
+
|
|
285
|
+
21-29. **time_diff_in_X_real_mean:** mean among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
286
|
+
|
|
287
|
+
30-38. **time_diff_in_X_real_min:** minimum among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
288
|
+
|
|
289
|
+
39-47. **time_diff_in_X_real_max:** maximum among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
290
|
+
|
|
291
|
+
48-56. **time_diff_in_X_real_var:** variance among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
292
|
+
|
|
293
|
+
57-65. **time_diff_in_X_real_median:** median among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
277
294
|
|
|
278
|
-
|
|
295
|
+
66-74. **time_diff_in_X_random_mean:** mean among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
279
296
|
|
|
280
|
-
|
|
297
|
+
75-83. **time_diff_in_X_random_min:** minimum among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
281
298
|
|
|
282
|
-
|
|
299
|
+
84-93. **time_diff_in_X_random_max:** maximum among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
283
300
|
|
|
284
|
-
|
|
301
|
+
94-103. **time_diff_in_X_random_var:** variance among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
285
302
|
|
|
286
|
-
|
|
303
|
+
104-112. **time_diff_in_X_random_median:** median among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
287
304
|
|
|
288
|
-
|
|
305
|
+
113-184. **time_diff_in_X_real_percN:** Nth percentile (where N can be 1, 5, 10, 25, 75, 90, 95 or 99) among all subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
289
306
|
|
|
290
|
-
|
|
307
|
+
184-255. **time_diff_in_X_random_percN:** Nth percentile (where N can be 1, 5, 10, 25, 75, 90, 95 or 99) among all reshuffled subtrees of type X in the forest, of average of all locally external node pair sampling time differences in the subtree.
|
|
291
308
|
|
|
292
|
-
|
|
309
|
+
256-264. **time_diff_in_X_random_vs_real_n_less:** number of subtrees of type X whose average locally external node sampling time differences is smaller in real subtrees than in the corresponding reshuffled ones.
|
|
293
310
|
|
|
294
|
-
|
|
311
|
+
265-273. **time_diff_in_X_random_vs_real_n_more:** number of subtrees of type X whose average locally external node sampling time differences is larger in real subtrees than in the corresponding reshuffled ones.
|
|
295
312
|
|
|
296
|
-
|
|
313
|
+
274-282. **time_diff_in_X_random_vs_real_frac_less:** fraction of subtrees of type X whose average locally external node sampling time differences is smaller in real subtrees than in the corresponding reshuffled ones.
|
|
297
314
|
|
|
298
|
-
|
|
315
|
+
283-291. **time_diff_in_X_random_vs_real_frac_more:** fraction of subtrees of type X whose average locally external node sampling time differences is larger in real subtrees than in the corresponding reshuffled ones.
|
|
299
316
|
|
|
300
|
-
|
|
317
|
+
292-301. **time_diff_in_X_random_vs_real_pval_less:** p-value of the sign test checking that for subtrees of type X, their average locally external node sampling time differences are indistinguishable in real subtrees and in the corresponding reshuffled ones (the alternative hypothesis is that some real ones are smaller).
|
|
301
318
|
|
|
302
|
-
|
|
319
|
+
302-310. **time_diff_in_X_random_vs_real_pval_more:** p-value of the sign test checking that for subtrees of type X, their average locally external node sampling time differences are indistinguishable in real subtrees and in the corresponding reshuffled ones (the alternative hypothesis is that some real ones are larger).
|
|
303
320
|
|
|
304
321
|
|
|
305
322
|
## Input data
|
|
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
|