|
5 | 5 |
|
6 | 6 | import allel # type: ignore |
7 | 7 | import bokeh |
| 8 | +import dask |
8 | 9 | import dask.array as da |
9 | 10 | import numpy as np |
10 | 11 | import pandas as pd |
@@ -72,13 +73,13 @@ def __init__( |
72 | 73 | self._cache_snp_genotypes: Dict[ |
73 | 74 | base_params.sample_set, zarr.hierarchy.Group |
74 | 75 | ] = dict() |
75 | | - self._cache_site_filters: Dict[ |
76 | | - base_params.site_mask, zarr.hierarchy.Group |
77 | | - ] = dict() |
| 76 | + self._cache_site_filters: Dict[base_params.site_mask, zarr.hierarchy.Group] = ( |
| 77 | + dict() |
| 78 | + ) |
78 | 79 | self._cache_site_annotations: Optional[zarr.hierarchy.Group] = None |
79 | | - self._cache_locate_site_class: OrderedDict[ |
80 | | - Tuple[Any, ...], np.ndarray |
81 | | - ] = OrderedDict() |
| 80 | + self._cache_locate_site_class: OrderedDict[Tuple[Any, ...], np.ndarray] = ( |
| 81 | + OrderedDict() |
| 82 | + ) |
82 | 83 |
|
83 | 84 | # Create the SNP-calls cache as a per-instance lru_cache wrapping the |
84 | 85 | # bound method. Storing it on the instance (rather than using a |
@@ -253,8 +254,7 @@ def _site_filters_for_contig( |
253 | 254 | else: |
254 | 255 | if contig not in self.contigs: |
255 | 256 | raise ValueError( |
256 | | - f"Contig {contig!r} not found. " |
257 | | - f"Available contigs: {self.contigs}" |
| 257 | + f"Contig {contig!r} not found. Available contigs: {self.contigs}" |
258 | 258 | ) |
259 | 259 | root = self.open_site_filters(mask=mask) |
260 | 260 | z = root[f"{contig}/variants/{field}"] |
@@ -359,8 +359,7 @@ def _snp_sites_for_contig( |
359 | 359 | else: |
360 | 360 | if contig not in self.contigs: |
361 | 361 | raise ValueError( |
362 | | - f"Contig {contig!r} not found. " |
363 | | - f"Available contigs: {self.contigs}" |
| 362 | + f"Contig {contig!r} not found. Available contigs: {self.contigs}" |
364 | 363 | ) |
365 | 364 | root = self.open_snp_sites() |
366 | 365 | z = root[f"{contig}/variants/{field}"] |
@@ -488,8 +487,7 @@ def _snp_genotypes_for_contig( |
488 | 487 | else: |
489 | 488 | if contig not in self.contigs: |
490 | 489 | raise ValueError( |
491 | | - f"Contig {contig!r} not found. " |
492 | | - f"Available contigs: {self.contigs}" |
| 490 | + f"Contig {contig!r} not found. Available contigs: {self.contigs}" |
493 | 491 | ) |
494 | 492 | root = self.open_snp_genotypes(sample_set=sample_set) |
495 | 493 | z = root[f"{contig}/calldata/{field}"] |
@@ -612,12 +610,14 @@ def snp_genotypes( |
612 | 610 | ) |
613 | 611 |
|
614 | 612 | # Filter the Dask array using the boolean array. |
615 | | - d = da.compress(loc_samples, d, axis=1) |
| 613 | + with dask.config.set(**{"array.slicing.split_native_chunks": False}): |
| 614 | + d = da.compress(loc_samples, d, axis=1) |
616 | 615 |
|
617 | 616 | # Apply the sample_indices, if there are any. |
618 | 617 | # Note: this might need to apply to the result of an internal sample_query, e.g. `is_surveillance == True`. |
619 | 618 | if sample_indices is not None: |
620 | | - d = da.take(d, sample_indices, axis=1) |
| 619 | + with dask.config.set(**{"array.slicing.split_native_chunks": False}): |
| 620 | + d = da.take(d, sample_indices, axis=1) |
621 | 621 |
|
622 | 622 | return d |
623 | 623 |
|
@@ -648,8 +648,7 @@ def _snp_variants_for_contig( |
648 | 648 | else: |
649 | 649 | if contig not in self.contigs: |
650 | 650 | raise ValueError( |
651 | | - f"Contig {contig!r} not found. " |
652 | | - f"Available contigs: {self.contigs}" |
| 651 | + f"Contig {contig!r} not found. Available contigs: {self.contigs}" |
653 | 652 | ) |
654 | 653 | coords = dict() |
655 | 654 | data_vars = dict() |
@@ -1021,7 +1020,8 @@ def _locate_site_class( |
1021 | 1020 | chunks=chunks, |
1022 | 1021 | ) |
1023 | 1022 | idx = (pos - 1).compute() |
1024 | | - loc_ann = da.take(loc_ann, idx, axis=0) |
| 1023 | + with dask.config.set(**{"array.slicing.split_native_chunks": False}): |
| 1024 | + loc_ann = da.take(loc_ann, idx, axis=0) |
1025 | 1025 |
|
1026 | 1026 | # Compute site selection. |
1027 | 1027 | with self._dask_progress(desc=f"Locate {site_class} sites"): |
@@ -1066,8 +1066,7 @@ def _snp_calls_for_contig( |
1066 | 1066 | else: |
1067 | 1067 | if contig not in self.contigs: |
1068 | 1068 | raise ValueError( |
1069 | | - f"Contig {contig!r} not found. " |
1070 | | - f"Available contigs: {self.contigs}" |
| 1069 | + f"Contig {contig!r} not found. Available contigs: {self.contigs}" |
1071 | 1070 | ) |
1072 | 1071 |
|
1073 | 1072 | coords = dict() |
|
0 commit comments