@@ -94,15 +94,6 @@ def insert_branch_sites(ts, m=1):
94
94
return tables .tree_sequence ()
95
95
96
96
97
- @pytest .fixture ()
98
- def fx_ts_isolated_samples ():
99
- tables = tskit .Tree .generate_balanced (2 , span = 10 ).tree_sequence .dump_tables ()
100
- # This also tests sample nodes that are not a single block at
101
- # the start of the nodes table.
102
- tables .nodes .add_row (time = 0 , flags = tskit .NODE_IS_SAMPLE )
103
- return insert_branch_sites (tables .tree_sequence ())
104
-
105
-
106
97
class TestSimpleTs :
107
98
@pytest .fixture ()
108
99
def conversion (self , tmp_path ):
@@ -199,17 +190,28 @@ class TestTskitFormat:
199
190
"""Unit tests for TskitFormat without using full conversion."""
200
191
201
192
@pytest .fixture ()
202
- def fx_simple_ts (self , tmp_path ):
193
+ def fx_simple_ts (self ):
203
194
return simple_ts (add_individuals = True )
204
195
205
196
@pytest .fixture ()
206
- def fx_ts_2_diploids (self , tmp_path ):
197
+ def fx_ts_2_diploids (self ):
207
198
ts = msprime .sim_ancestry (2 , sequence_length = 10 , random_seed = 42 )
208
199
return add_mutations (ts )
209
200
210
201
@pytest .fixture ()
211
- def fx_no_individuals_ts (self , tmp_path ):
212
- return simple_ts (add_individuals = False )
202
+ def fx_ts_isolated_samples (self ):
203
+ tables = tskit .Tree .generate_balanced (2 , span = 10 ).tree_sequence .dump_tables ()
204
+ # This also tests sample nodes that are not a single block at
205
+ # the start of the nodes table.
206
+ tables .nodes .add_row (time = 0 , flags = tskit .NODE_IS_SAMPLE )
207
+ return insert_branch_sites (tables .tree_sequence ())
208
+
209
+ def test_path_or_ts_input (self , tmp_path , fx_simple_ts ):
210
+ f1 = tsk .TskitFormat (fx_simple_ts )
211
+ ts_path = tmp_path / "trees.ts"
212
+ fx_simple_ts .dump (ts_path )
213
+ f2 = tsk .TskitFormat (ts_path )
214
+ f1 .ts .tables .assert_equals (f2 .ts .tables )
213
215
214
216
def test_small_position_dtype (self ):
215
217
tables = tskit .TableCollection (sequence_length = 100 )
@@ -443,7 +445,7 @@ def test_isolated_as_missing(self, fx_ts_isolated_samples):
443
445
expected_gt_missing = np .array ([[1 ], [0 ], [- 1 ]])
444
446
nt .assert_array_equal (variant_data_missing .genotypes , expected_gt_missing )
445
447
446
- def test_genotype_dtype_i1 (self , tmp_path ):
448
+ def test_genotype_dtype_i1 (self ):
447
449
tables = tskit .TableCollection (sequence_length = 100 )
448
450
for _ in range (4 ):
449
451
tables .nodes .add_row (flags = tskit .NODE_IS_SAMPLE , time = 0 )
@@ -454,15 +456,13 @@ def test_genotype_dtype_i1(self, tmp_path):
454
456
tables .mutations .add_row (site = site_id , node = 0 , derived_state = "T" )
455
457
tables .sort ()
456
458
tree_sequence = tables .tree_sequence ()
457
- ts_path = tmp_path / "small_alleles.trees"
458
- tree_sequence .dump (ts_path )
459
459
460
- format_obj = tsk .TskitFormat (ts_path )
460
+ format_obj = tsk .TskitFormat (tree_sequence )
461
461
schema = format_obj .generate_schema ()
462
462
call_genotype_spec = next (s for s in schema .fields if s .name == "call_genotype" )
463
463
assert call_genotype_spec .dtype == "i1"
464
464
465
- def test_genotype_dtype_i4 (self , tmp_path ):
465
+ def test_genotype_dtype_i4 (self ):
466
466
tables = tskit .TableCollection (sequence_length = 100 )
467
467
for _ in range (4 ):
468
468
tables .nodes .add_row (flags = tskit .NODE_IS_SAMPLE , time = 0 )
@@ -475,10 +475,8 @@ def test_genotype_dtype_i4(self, tmp_path):
475
475
476
476
tables .sort ()
477
477
tree_sequence = tables .tree_sequence ()
478
- ts_path = tmp_path / "large_alleles.trees"
479
- tree_sequence .dump (ts_path )
480
478
481
- format_obj = tsk .TskitFormat (ts_path )
479
+ format_obj = tsk .TskitFormat (tree_sequence )
482
480
schema = format_obj .generate_schema ()
483
481
call_genotype_spec = next (s for s in schema .fields if s .name == "call_genotype" )
484
482
assert call_genotype_spec .dtype == "i4"
@@ -487,6 +485,7 @@ def test_genotype_dtype_i4(self, tmp_path):
487
485
@pytest .mark .parametrize (
488
486
"ts" ,
489
487
[
488
+ # Standard individuals-with-a-given-ploidy situation
490
489
add_mutations (
491
490
msprime .sim_ancestry (4 , ploidy = 1 , sequence_length = 10 , random_seed = 42 )
492
491
),
@@ -496,20 +495,20 @@ def test_genotype_dtype_i4(self, tmp_path):
496
495
add_mutations (
497
496
msprime .sim_ancestry (3 , ploidy = 12 , sequence_length = 10 , random_seed = 142 )
498
497
),
498
+ # No individuals, ploidy1
499
+ add_mutations (msprime .simulate (4 , length = 10 , random_seed = 412 )),
499
500
],
500
501
)
501
502
def test_against_tskit_vcf_output (ts , tmp_path ):
502
503
vcf_path = tmp_path / "ts.vcf"
503
- ts_path = tmp_path / "ts.trees"
504
- ts .dump (ts_path )
505
504
with open (vcf_path , "w" ) as f :
506
505
ts .write_vcf (f )
507
506
508
507
tskit_zarr = tmp_path / "tskit.zarr"
509
508
vcf_zarr = tmp_path / "vcf.zarr"
510
- tsk .convert (ts_path , tskit_zarr )
509
+ tsk .convert (ts , tskit_zarr , worker_processes = 0 )
511
510
512
- vcf .convert ([vcf_path ], vcf_zarr )
511
+ vcf .convert ([vcf_path ], vcf_zarr , worker_processes = 0 )
513
512
ds1 = sg .load_dataset (tskit_zarr )
514
513
ds2 = (
515
514
sg .load_dataset (vcf_zarr )
0 commit comments