From ccaa02de609571287f6b3e7684e6e70bf2bad237 Mon Sep 17 00:00:00 2001 From: John Lees Date: Fri, 7 Feb 2020 14:30:50 +0000 Subject: [PATCH] Handle sketchlib import error --- PopPUNK/__main__.py | 2 ++ PopPUNK/sketchlib.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/PopPUNK/__main__.py b/PopPUNK/__main__.py index 2e9a292b..23f0c5c8 100644 --- a/PopPUNK/__main__.py +++ b/PopPUNK/__main__.py @@ -211,6 +211,8 @@ def main(): kmers = np.arange(args.min_k, args.max_k + 1, args.k_step) # Dict of DB access functions for assign_query (which is out of scope) + if no_sketchlib: + args.use_mash = True dbFuncs = setupDBFuncs(args, kmers, args.min_kmer_count) createDatabaseDir = dbFuncs['createDatabaseDir'] constructDatabase = dbFuncs['constructDatabase'] diff --git a/PopPUNK/sketchlib.py b/PopPUNK/sketchlib.py index 260b9e66..df40cd36 100644 --- a/PopPUNK/sketchlib.py +++ b/PopPUNK/sketchlib.py @@ -21,9 +21,15 @@ import sharedmem import networkx as nx from scipy import optimize -import h5py -import pp_sketchlib +# Try to import sketchlib +try: + no_sketchlib = False + import pp_sketchlib + import h5py +except ImportError as e: + sys.stderr.write("Sketchlib backend not available") + no_sketchlib = True from .mash import fitKmerCurve from .utils import iterDistRows