Skip to content
Snippets Groups Projects
Commit e987c136 authored by Amandine  PERRIN's avatar Amandine PERRIN
Browse files

Change clustering progressbar stategy

Before, we used a pool of size 1 to run mmseqs_clust inside, and showed a progress bar in the main thread.
Now, run_mmseqs_clust runs in the main thread, and a progressbar is running in a separate thread, that is stoped when mmseqs_clust has finished.
parent 8f5e0e9d
Branches
Tags
No related merge requests found
...@@ -41,8 +41,9 @@ April 2017 ...@@ -41,8 +41,9 @@ April 2017
""" """
import logging import logging
import os import os
import sys
import time import time
import multiprocessing import threading
import progressbar import progressbar
import copy import copy
...@@ -202,21 +203,27 @@ def do_pangenome(outdir, prt_bank, mmseqdb, min_id, clust_mode, threads, start, ...@@ -202,21 +203,27 @@ def do_pangenome(outdir, prt_bank, mmseqdb, min_id, clust_mode, threads, start,
"it to a pangenome file.").format(mmseqclust)) "it to a pangenome file.").format(mmseqclust))
else: else:
logger.info("Clustering proteins...") logger.info("Clustering proteins...")
if not quiet: try:
stop_bar = False
if quiet:
widgets = []
# If not quiet, start a progress bar while clustering proteins. We cannot guess
# how many time it will take, so we start an "infinite" bar, and send it a signal
# when it has to stop. If quiet, we start a thread that will immediatly stop
else:
widgets = [progressbar.BouncingBar(marker=progressbar.RotatingMarker(markers="◐◓◑◒")), widgets = [progressbar.BouncingBar(marker=progressbar.RotatingMarker(markers="◐◓◑◒")),
" - ", progressbar.Timer()] " - ", progressbar.Timer()]
bar = progressbar.ProgressBar(widgets=widgets, max_value=20, term_width=50) x = threading.Thread(target=utils.thread_progressbar, args=(widgets, lambda : stop_bar,))
pool = multiprocessing.Pool(1) x.start()
args = [mmseqdb, mmseqclust, tmpdir, logmmseq, min_id, threads, clust_mode] args = (mmseqdb, mmseqclust, tmpdir, logmmseq, min_id, threads, clust_mode)
final = pool.map_async(run_mmseqs_clust, [args], chunksize=1) run_mmseqs_clust(args)
pool.close() except KeyboardInterrupt: # pragma: no cover
if not quiet: stop_bar = True
while True: x.join()
if final.ready(): sys.exit(1)
break # Clustering done, stop bar and join (if quiet, it was already finished, so we just join it)
bar.update() stop_bar = True
bar.finish() x.join()
pool.join()
# Convert output to tsv file (one line per comparison done) # Convert output to tsv file (one line per comparison done)
# # Convert output to tsv file (one line per comparison done) # # Convert output to tsv file (one line per comparison done)
# -> returns (families, outfile) # -> returns (families, outfile)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment