Skip to content

Commit 53c595b

Browse files
authored
Merge branch 'master' into fix/empty-cohort-queries-guard
2 parents 97527cf + e07f14a commit 53c595b

34 files changed

Lines changed: 1440 additions & 598 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
__pycache__
44
*.pyc
55
dist
6+
.venv/
67
.coverage
78
coverage.xml
89
.ipynb_checkpoints/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ To get setup for development, see [this video if you prefer VS Code](https://you
4949
For detailed setup instructions, see:
5050
- [Linux setup guide](LINUX_SETUP.md)
5151
- [macOS setup guide](MACOS_SETUP.md)
52+
- [Google Colab (TPU) setup guide](docs/source/colab_tpu_runtime.rst)
5253
Detailed instructions can be found in the [Contributors guide](https://github.com/malariagen/malariagen-data-python/blob/master/CONTRIBUTING.md).
5354

5455
## AI use policy and guidelines

docs/source/colab_tpu_runtime.rst

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
Google Colab Installation Guide
2+
===============================
3+
Prerequisites
4+
-------------
5+
6+
Before installing the package, configure the runtime environment
7+
correctly:
8+
9+
1. Open a new notebook in Google Colab.
10+
2. Navigate to ``Runtime → Change runtime type``.
11+
3. Set the runtime configuration as follows:
12+
13+
- **Runtime type:** Python 3
14+
- **Hardware accelerator:** TPU
15+
- **TPU type:** v2-8
16+
17+
4. Click **Save** to apply the configuration.
18+
19+
Using the recommended TPU configuration ensures compatibility with
20+
workflows that may require TPU-based computation.
21+
22+
23+
Installation Procedure
24+
----------------------
25+
26+
In a new notebook cell, install the package:
27+
28+
.. code-block:: bash
29+
30+
!pip install malariagen_data
31+
32+
After installation completes, verify that the package is available:
33+
34+
.. code-block:: python
35+
36+
import malariagen_data
37+
38+
If the import executes without errors, the installation was successful.
39+
40+
If dependency-related warnings or conflicts occur, follow one of the
41+
resolution options described below.
42+
43+
44+
Resolution Options
45+
------------------
46+
47+
Resolution Option 1: Uninstall Panel
48+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49+
50+
If your notebook does not require ``panel``, uninstall it before
51+
installing ``malariagen_data``.
52+
53+
.. code-block:: bash
54+
55+
!pip uninstall -y panel
56+
!pip install malariagen_data
57+
58+
Verify installation:
59+
60+
.. code-block:: python
61+
62+
import malariagen_data
63+
64+
65+
Resolution Option 2: Install Compatible Panel Version
66+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67+
68+
If your workflow depends on ``panel``, install a compatible version:
69+
70+
.. code-block:: bash
71+
72+
!pip install panel==1.7.0
73+
!pip install malariagen_data
74+
75+
Restart the runtime:
76+
77+
``Runtime → Restart runtime``
78+
79+
Then verify:
80+
81+
.. code-block:: python
82+
83+
import malariagen_data
84+
85+
86+
Resolution Option 3: Install Required Blinker Version
87+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88+
89+
If a ``blinker`` version conflict occurs:
90+
91+
.. code-block:: bash
92+
93+
!pip install blinker==1.9.0 --ignore-installed
94+
!pip install malariagen_data
95+
96+
Restart the runtime and verify:
97+
98+
.. code-block:: python
99+
100+
import malariagen_data
101+
102+
103+
Final Verification
104+
------------------
105+
106+
After completing any of the procedures above:
107+
108+
- Ensure that ``malariagen_data`` installs without dependency errors.
109+
- Confirm that ``import malariagen_data`` runs successfully.
110+
- Restart the runtime whenever core dependencies are modified.
111+
- Avoid mixing incompatible package versions within the same Colab session.

malariagen_data/anoph/aim_data.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,4 @@ def plot_aim_heatmap(
341341

342342
if show: # pragma: no cover
343343
fig.show(renderer=renderer)
344-
return None
345-
else:
346-
return fig
344+
return fig

malariagen_data/anoph/base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,9 @@ def _read_sample_sets_manifest(self, *, single_release: str):
607607
# Get today's date in ISO format
608608
today_date_iso = date.today().isoformat()
609609
# Add an "unrestricted_use" column, set to True if terms-of-use expiry date <= today's date.
610-
df["unrestricted_use"] = df[terms_of_use_expiry_date_column].apply(
611-
lambda d: True if pd.isna(d) else (d <= today_date_iso)
612-
)
610+
# Vectorized operation: True if NaN, else (d <= today_date_iso)
611+
s = df[terms_of_use_expiry_date_column]
612+
df["unrestricted_use"] = s.isna() | (s <= today_date_iso)
613613
# Make the "unrestricted_use" column a nullable boolean, to allow missing data.
614614
df["unrestricted_use"] = df["unrestricted_use"].astype(pd.BooleanDtype())
615615

malariagen_data/anoph/cnv_data.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,7 @@ def plot_cnv_hmm_coverage_track(
810810

811811
if show:
812812
bkplt.show(fig)
813-
return None
814-
else:
815-
return fig
813+
return fig
816814

817815
@_check_types
818816
@doc(
@@ -884,9 +882,7 @@ def plot_cnv_hmm_coverage(
884882

885883
if show:
886884
bkplt.show(fig)
887-
return None
888-
else:
889-
return fig
885+
return fig
890886

891887
@_check_types
892888
@doc(
@@ -1028,9 +1024,7 @@ def plot_cnv_hmm_heatmap_track(
10281024

10291025
if show:
10301026
bkplt.show(fig)
1031-
return None
1032-
else:
1033-
return fig
1027+
return fig
10341028

10351029
@_check_types
10361030
@doc(
@@ -1100,6 +1094,4 @@ def plot_cnv_hmm_heatmap(
11001094

11011095
if show:
11021096
bkplt.show(fig)
1103-
return None
1104-
else:
1105-
return fig
1097+
return fig

malariagen_data/anoph/dipclust.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from typing import Optional, Tuple
23

34
import allel # type: ignore
@@ -188,13 +189,11 @@ def plot_diplotype_clustering(
188189

189190
if show: # pragma: no cover
190191
fig.show(renderer=renderer)
191-
return None
192-
else:
193-
return {
194-
"figure": fig,
195-
"dendro_sample_id_order": np.asarray(leaf_data["sample_id"].to_list()),
196-
"n_snps": n_snps_used,
197-
}
192+
return {
193+
"figure": fig,
194+
"dendro_sample_id_order": np.asarray(leaf_data["sample_id"].to_list()),
195+
"n_snps": n_snps_used,
196+
}
198197

199198
def diplotype_pairwise_distances(
200199
self,
@@ -540,8 +539,9 @@ def _insert_dipclust_snp_trace(
540539
figures.append(snp_trace)
541540
subplot_heights.append(snp_row_height * n_snps_transcript)
542541
else:
543-
print(
544-
f"No SNPs were found below {snp_filter_min_maf} allele frequency. Omitting SNP genotype plot."
542+
warnings.warn(
543+
f"No SNPs were found below {snp_filter_min_maf} allele frequency. Omitting SNP genotype plot.",
544+
stacklevel=2,
545545
)
546546
return figures, subplot_heights, n_snps_transcript
547547

@@ -607,8 +607,9 @@ def plot_diplotype_clustering_advanced(
607607
cnv_colorscale = cnv_params.colorscale_default
608608
if cohort_size and snp_transcript:
609609
cohort_size = None
610-
print(
611-
"Cohort size is not supported with amino acid heatmap. Overriding cohort size to None."
610+
warnings.warn(
611+
"Cohort size is not supported with amino acid heatmap. Overriding cohort size to None.",
612+
stacklevel=2,
612613
)
613614

614615
res = self.plot_diplotype_clustering(
@@ -797,6 +798,4 @@ def plot_diplotype_clustering_advanced(
797798

798799
if show:
799800
fig.show(renderer=renderer)
800-
return None
801-
else:
802-
return fig
801+
return fig

malariagen_data/anoph/distance.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,4 @@ def plot_njt(
614614

615615
if show: # pragma: no cover
616616
fig.show(renderer=renderer)
617-
return None
618-
else:
619-
return fig
617+
return fig

0 commit comments

Comments
 (0)