Skip to content

Commit 674169f

Browse files
authored
Small simplification to progress monitoring within plot_njt (#643)
* begin njt refactoring * refactor plot_njt * fix docs * tweak * add tests * fix nan comparisons * poetry update * consistent color for NA * fix karyotype categorical * fix warning * fix haplotype networks * simplify progress * add example
1 parent 319df58 commit 674169f

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

malariagen_data/anoph/distance.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -363,26 +363,18 @@ def _njt(
363363
)
364364
D = squareform(dist)
365365

366-
# Progress doesn't mix well with debug logging.
367-
show_progress = self._show_progress and not self._debug
368-
369366
# anjl supports passing in a progress bar function to get progress on the
370367
# neighbour-joining iterations.
371-
if show_progress:
372-
progress = self._tqdm_class
373-
progress_options = dict(
374-
desc="Construct neighbour-joining tree", leave=False
375-
)
376-
else:
377-
progress = None
378-
progress_options = dict()
368+
progress_options = dict(desc="Construct neighbour-joining tree", leave=False)
379369

380370
# Decide which algorithm to use and run the neighbour-joining.
381371
if algorithm == "rapid":
382-
Z = anjl.rapid_nj(D=D, progress=progress, progress_options=progress_options)
372+
Z = anjl.rapid_nj(
373+
D=D, progress=self._progress, progress_options=progress_options
374+
)
383375
else:
384376
Z = anjl.canonical_nj(
385-
D=D, progress=progress, progress_options=progress_options
377+
D=D, progress=self._progress, progress_options=progress_options
386378
)
387379

388380
return dict(

notebooks/plot_njt.ipynb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,23 @@
266266
")"
267267
]
268268
},
269+
{
270+
"cell_type": "code",
271+
"execution_count": null,
272+
"id": "18fde26a-339a-44a1-a91f-425f22ed96d1",
273+
"metadata": {},
274+
"outputs": [],
275+
"source": [
276+
"ag3.plot_njt(\n",
277+
" region=\"3L:15,000,000-15,100,000\",\n",
278+
" sample_sets=\"3.0\",\n",
279+
" n_snps=1_000,\n",
280+
" color=\"taxon\",\n",
281+
" metric=\"euclidean\",\n",
282+
" algorithm=\"canonical\",\n",
283+
")"
284+
]
285+
},
269286
{
270287
"cell_type": "code",
271288
"execution_count": null,

0 commit comments

Comments
 (0)