@@ -29,6 +29,12 @@ def test_missing_dependency():
29
29
)
30
30
31
31
32
+ def tskit_model_mapping (ind_nodes , ind_names = None ):
33
+ if ind_names is None :
34
+ ind_names = ["tsk{j}" for j in range (len (ind_nodes ))]
35
+ return tskit .VcfModelMapping (ind_nodes , ind_names )
36
+
37
+
32
38
def add_mutations (ts ):
33
39
# Add some mutation to the tree sequence. This guarantees that
34
40
# we have variation at all sites > 0.
@@ -311,6 +317,23 @@ def test_iter_field(self, fx_simple_ts):
311
317
with pytest .raises (ValueError , match = "Unknown field" ):
312
318
list (format_obj .iter_field ("unknown_field" , None , 0 , 3 ))
313
319
320
+ def test_zero_samples (self , fx_simple_ts ):
321
+ model_mapping = tskit_model_mapping (np .array ([]))
322
+ with pytest .raises (ValueError , match = "at least one sample" ):
323
+ tsk .TskitFormat (fx_simple_ts , model_mapping = model_mapping )
324
+
325
+ def test_no_valid_samples (self , fx_simple_ts ):
326
+ model_mapping = fx_simple_ts .map_to_vcf_model ()
327
+ model_mapping .individuals_nodes [:] = - 1
328
+ with pytest .raises (ValueError , match = "at least one valid sample" ):
329
+ tsk .TskitFormat (fx_simple_ts , model_mapping = model_mapping )
330
+
331
+ def test_model_size_mismatch (self , fx_simple_ts ):
332
+ model_mapping = fx_simple_ts .map_to_vcf_model ()
333
+ model_mapping .individuals_name = ["x" ]
334
+ with pytest .raises (ValueError , match = "match number of samples" ):
335
+ tsk .TskitFormat (fx_simple_ts , model_mapping = model_mapping )
336
+
314
337
@pytest .mark .parametrize (
315
338
("ind_nodes" , "expected_gts" ),
316
339
[
@@ -347,10 +370,7 @@ def test_iter_field(self, fx_simple_ts):
347
370
],
348
371
)
349
372
def test_iter_alleles_and_genotypes (self , fx_simple_ts , ind_nodes , expected_gts ):
350
- model_mapping = tskit .VcfModelMapping (
351
- ind_nodes , ["tsk{j}" for j in range (len (ind_nodes ))]
352
- )
353
-
373
+ model_mapping = tskit_model_mapping (ind_nodes )
354
374
format_obj = tsk .TskitFormat (fx_simple_ts , model_mapping = model_mapping )
355
375
356
376
shape = (2 , 2 ) # (num_samples, max_ploidy)
@@ -375,9 +395,7 @@ def test_iter_alleles_and_genotypes(self, fx_simple_ts, ind_nodes, expected_gts)
375
395
def test_iter_alleles_and_genotypes_missing_node (self , fx_ts_2_diploids ):
376
396
# Test with node ID that doesn't exist in tree sequence (out of range)
377
397
ind_nodes = np .array ([[10 , 11 ], [12 , 13 ]], dtype = np .int32 )
378
- model_mapping = tskit .VcfModelMapping (
379
- ind_nodes , ["tsk{j}" for j in range (len (ind_nodes ))]
380
- )
398
+ model_mapping = tskit_model_mapping (ind_nodes )
381
399
format_obj = tsk .TskitFormat (fx_ts_2_diploids , model_mapping = model_mapping )
382
400
shape = (2 , 2 )
383
401
with pytest .raises (
@@ -387,9 +405,7 @@ def test_iter_alleles_and_genotypes_missing_node(self, fx_ts_2_diploids):
387
405
388
406
def test_isolated_as_missing (self , fx_ts_isolated_samples ):
389
407
ind_nodes = np .array ([[0 ], [1 ], [3 ]])
390
- model_mapping = tskit .VcfModelMapping (
391
- ind_nodes , ["tsk{j}" for j in range (len (ind_nodes ))]
392
- )
408
+ model_mapping = tskit_model_mapping (ind_nodes )
393
409
394
410
format_obj_default = tsk .TskitFormat (
395
411
fx_ts_isolated_samples ,
0 commit comments