Skip to content

Commit c6616a2

Browse files
authored
Merge pull request #937 from 31puneet/fix/g123-empty-array-guard
fix: add guard for empty array in g123 when window_size exceeds avail
2 parents c5a3b19 + 5c4944a commit c6616a2

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

malariagen_data/anoph/g123.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ def _g123_gwss(
133133
chunks=chunks,
134134
)
135135

136+
if gt.shape[0] < window_size:
137+
raise ValueError(
138+
f"Not enough sites ({gt.shape[0]}) for window size "
139+
f"({window_size}). Please reduce the window size or "
140+
f"use different site selection criteria."
141+
)
142+
136143
with self._spinner("Compute G123"):
137144
g123 = allel.moving_statistic(gt, statistic=_garud_g123, size=window_size)
138145
x = allel.moving_statistic(pos, statistic=np.mean, size=window_size)
@@ -240,6 +247,12 @@ def _g123_calibration(
240247

241248
calibration_runs: Dict[str, np.ndarray] = dict()
242249
for window_size in self._progress(window_sizes, desc="Compute G123"):
250+
if gt.shape[0] < window_size:
251+
raise ValueError(
252+
f"Not enough sites ({gt.shape[0]}) for window size "
253+
f"({window_size}). Please reduce the window size or "
254+
f"use different site selection criteria."
255+
)
243256
g123 = allel.moving_statistic(gt, statistic=_garud_g123, size=window_size)
244257
calibration_runs[str(window_size)] = g123
245258

tests/anoph/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2260,7 +2260,7 @@ def init_hap_sites(self):
22602260
path=path,
22612261
contigs=self.contigs,
22622262
snp_sites=self.snp_sites,
2263-
p_site=np.random.random(),
2263+
p_site=np.random.uniform(0.5, 1.0),
22642264
)
22652265

22662266
def init_haplotypes(self):

0 commit comments

Comments
 (0)