Skip to content

Commit 87f7b54

Browse files
hyanwongmergify[bot]
authored andcommitted
Warn if no inference sites
1 parent 269d8d1 commit 87f7b54

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
[0.2.4] - 2022-06-xx
33
********************
44

5+
**Features**
6+
7+
- matching routines warn if no inference sites
8+
(:pr:`685`, :issue:`683` :user:`hyanwong`)
9+
510
**Fixes**
611

712
- sample_data.subset() now accepts a sequence_length (:pr:`681`, :user:`hyanwong`)

tests/test_inference.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io
2323
import itertools
2424
import json
25+
import logging
2526
import os.path
2627
import random
2728
import string
@@ -729,6 +730,14 @@ class TestZeroInferenceSites:
729730
Tests for the degenerate case in which we have no inference sites.
730731
"""
731732

733+
@classmethod
734+
def setup_class(cls):
735+
logging.disable(logging.CRITICAL)
736+
737+
@classmethod
738+
def teardown_class(cls):
739+
logging.disable(logging.NOTSET)
740+
732741
def verify(self, genotypes):
733742
genotypes = np.array(genotypes, dtype=np.int8)
734743
m = genotypes.shape[0]
@@ -774,6 +783,18 @@ def test_three_sites(self):
774783
self.verify([[1, 1], [1, 1], [1, 1]])
775784

776785

786+
class TestZeroInferenceSitesWarning:
787+
def test_warning_match_ancestors(self, caplog):
788+
with tsinfer.SampleData(sequence_length=10) as sd:
789+
sd.add_site(1, [0, 0])
790+
ancestors = tsinfer.generate_ancestors(sd)
791+
with caplog.at_level(logging.WARNING):
792+
ats = tsinfer.match_ancestors(sd, ancestors)
793+
assert caplog.text.count("No sites used") == 1
794+
_ = tsinfer.match_samples(sd, ats)
795+
assert caplog.text.count("No sites used") == 2
796+
797+
777798
def random_string(rng, max_len=10):
778799
"""
779800
Uses the specified random generator to generate a random string.

tsinfer/inference.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,8 @@ def __init__(
10271027
self.path_compression = path_compression
10281028
self.num_samples = self.sample_data.num_samples
10291029
self.num_sites = len(inference_site_position)
1030+
if self.num_sites == 0:
1031+
logging.warning("No sites used for inference")
10301032
num_intervals = max(self.num_sites - 1, 0)
10311033
self.progress_monitor = _get_progress_monitor(progress_monitor)
10321034
self.match_progress = None # Allocated by subclass

0 commit comments

Comments
 (0)