Skip to content

Commit

Permalink
Merge pull request #575 from malariagen/GH363_skip_sets_missing_CNV_HMM
Browse files Browse the repository at this point in the history
Skip sample sets missing CNV HMM
  • Loading branch information
leehart authored Aug 9, 2024
2 parents 2d11916 + 05052fa commit 76fa2b2
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions malariagen_data/anoph/cnv_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def coverage_calls_analysis_ids(self) -> Tuple[str, ...]:
@check_types
@doc(
summary="Open CNV HMM zarr.",
returns="Zarr hierarchy.",
returns="Zarr hierarchy or None.",
)
def open_cnv_hmm(self, sample_set: base_params.sample_set) -> zarr.hierarchy.Group:
try:
Expand All @@ -80,8 +80,15 @@ def open_cnv_hmm(self, sample_set: base_params.sample_set) -> zarr.hierarchy.Gro
release = self.lookup_release(sample_set=sample_set)
release_path = self._release_to_path(release)
path = f"{self._base_path}/{release_path}/cnv/{sample_set}/hmm/zarr"

# If CNV HMM data exists for this sample set then return the zarr,
# Otherwise return None.
store = init_zarr_store(fs=self._fs, path=path)
root = zarr.open_consolidated(store=store)
try:
root = zarr.open_consolidated(store=store)
except FileNotFoundError:
root = None

self._cache_cnv_hmm[sample_set] = root
return root

Expand All @@ -94,6 +101,10 @@ def _cnv_hmm_dataset(self, *, contig, sample_set, inline_array, chunks):
debug("open zarr")
root = self.open_cnv_hmm(sample_set=sample_set)

# If CNV HMM data doesn't exist for this sample set then return None.
if root is None:
return None

debug("variant arrays")
pos = root[f"{contig}/variants/POS"]
coords["variant_position"] = (
Expand Down Expand Up @@ -189,8 +200,17 @@ def cnv_hmm(
inline_array=inline_array,
chunks=chunks,
)

# If no CNV HMM dataset was found then skip
if y is None:
continue

ly.append(y)

if len(ly) == 0:
# Bail out, no data for given sample sets and analysis.
raise ValueError("No data found for requested sample sets.")

debug("concatenate data from multiple sample sets")
x = simple_xarray_concat(ly, dim=DIM_SAMPLE)

Expand Down

0 comments on commit 76fa2b2

Please sign in to comment.