1
1
from functools import cached_property
2
2
3
- import tskit
4
- import numpy as np
5
3
import numba
4
+ import numpy as np
6
5
import pandas as pd
7
- import numba
6
+ import tskit
8
7
9
8
spec = [
10
9
("num_edges" , numba .int64 ),
@@ -44,7 +43,7 @@ def __init__(
44
43
self .in_range = np .zeros (2 , dtype = np .int64 )
45
44
self .out_range = np .zeros (2 , dtype = np .int64 )
46
45
47
- def next (self ):
46
+ def next (self ): # noqa
48
47
left = self .interval [1 ]
49
48
j = self .in_range [1 ]
50
49
k = self .out_range [1 ]
@@ -221,7 +220,7 @@ def mutations_df(self):
221
220
unknown = tskit .is_unknown_time (mutations_time )
222
221
mutations_time [unknown ] = self .ts .nodes_time [mutations_node [unknown ]]
223
222
224
- node_flag = ts .nodes_flags [mutations_node ]
223
+ # node_flag = ts.nodes_flags[mutations_node]
225
224
position = ts .sites_position [ts .mutations_site ]
226
225
227
226
tables = self .ts .tables
@@ -341,18 +340,22 @@ def nodes_df(self):
341
340
child_left , child_right = self .child_bounds (
342
341
ts .num_nodes , ts .edges_left , ts .edges_right , ts .edges_child
343
342
)
343
+ is_sample = np .zeros (ts .num_nodes )
344
+ is_sample [ts .samples ()] = 1
344
345
df = pd .DataFrame (
345
346
{
346
347
"time" : ts .nodes_time ,
347
348
"num_mutations" : self .nodes_num_mutations ,
348
349
"ancestors_span" : child_right - child_left ,
350
+ "is_sample" : is_sample ,
349
351
}
350
352
)
351
353
return df .astype (
352
354
{
353
355
"time" : "float64" ,
354
356
"num_mutations" : "int" ,
355
357
"ancestors_span" : "float64" ,
358
+ "is_sample" : "bool" ,
356
359
}
357
360
)
358
361
@@ -437,6 +440,23 @@ def make_sliding_windows(self, iterable, size, overlap=0):
437
440
end += step
438
441
yield iterable [start :]
439
442
443
+ def calc_mean_node_arity (self ):
444
+ span_sums = np .bincount (
445
+ self .ts .edges_parent ,
446
+ weights = self .ts .edges_right - self .ts .edges_left ,
447
+ minlength = self .ts .num_nodes ,
448
+ )
449
+ node_spans = self .ts .sample_count_stat (
450
+ [self .ts .samples ()],
451
+ lambda x : (x > 0 ),
452
+ 1 ,
453
+ polarised = True ,
454
+ span_normalise = False ,
455
+ strict = False ,
456
+ mode = "node" ,
457
+ )[:, 0 ]
458
+ return span_sums / node_spans
459
+
440
460
def calc_site_tree_index (self ):
441
461
return (
442
462
np .searchsorted (
@@ -459,20 +479,3 @@ def calc_mutations_per_tree(self):
459
479
mutations_per_tree = np .zeros (self .ts .num_trees , dtype = np .int64 )
460
480
mutations_per_tree [unique_values ] = counts
461
481
return mutations_per_tree
462
-
463
- def calc_mean_node_arity (self ):
464
- span_sums = np .bincount (
465
- self .ts .edges_parent ,
466
- weights = self .ts .edges_right - self .ts .edges_left ,
467
- minlength = self .ts .num_nodes ,
468
- )
469
- node_spans = self .ts .sample_count_stat (
470
- [self .ts .samples ()],
471
- lambda x : (x > 0 ),
472
- 1 ,
473
- polarised = True ,
474
- span_normalise = False ,
475
- strict = False ,
476
- mode = "node" ,
477
- )[:, 0 ]
478
- return span_sums / node_spans
0 commit comments