From 3544c60c718fa002b4a79d2b49359548d2d2b0b4 Mon Sep 17 00:00:00 2001 From: Heng Li Date: Sat, 16 Sep 2017 20:09:17 -0400 Subject: [PATCH] allow to test if index is present --- python/README.md | 1 + python/minimap2.pyx | 3 +++ python/mm2-lite.py | 3 +++ setup.py | 2 +- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/python/README.md b/python/README.md index 5868f04..fa08b06 100644 --- a/python/README.md +++ b/python/README.md @@ -23,6 +23,7 @@ The following Python program shows the key functionality of this module: ```python import minimap2 as mm a = mm.Aligner("test/MT-human.fa") +if not a: raise Exception("ERROR: failed to load/build index") for hit in a.map("GGTTAAATACAGACCAAGAGCCTTCAAAGCCCTCAGTAAGTTGCAATACTTAATTTCTGT"): print("{}\t{}\t{}\t{}".format(hit.ctg, hit.r_st, hit.r_en, hit.cigar_str)) ``` diff --git a/python/minimap2.pyx b/python/minimap2.pyx index a6dbf1f..8dd1408 100644 --- a/python/minimap2.pyx +++ b/python/minimap2.pyx @@ -110,6 +110,9 @@ cdef class Aligner: if self._idx is not NULL: cminimap2.mm_idx_destroy(self._idx) + def __bool__(self): + return (self._idx != NULL) + def map(self, seq, buf=None): cdef cminimap2.mm_reg1_t *regs cdef cminimap2.mm_hitpy_t h diff --git a/python/mm2-lite.py b/python/mm2-lite.py index 01f8031..b9c495b 100755 --- a/python/mm2-lite.py +++ b/python/mm2-lite.py @@ -40,6 +40,9 @@ def main(argv): print("Usage: mm2-lite.py | ") sys.exit(1) a = mm.Aligner(args[0]) # load/build index + if not a: + print("ERROR: failed to load/build index") + return for name, seq, qual in readfq(open(args[1])): # read one sequence for h in a.map(seq): # traverse hits print('{}\t{}\t{}'.format(name, len(seq), h)) diff --git a/setup.py b/setup.py index e7acda1..395d137 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ sys.path.append('python') setup( name = 'minimap2', - version = '2.1.1', + version = '2.2rc', url = 'https://github.com/lh3/minimap2', description = 'Minimap2 python binding', author = 'Heng Li',