diff --git a/MANIFEST.in b/MANIFEST.in index 192afe6..c1e8b53 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,8 +4,8 @@ include ksw2_dispatch.c include getopt.c include main.c include README.md -include python/minimap2.c -include python/cminimap2.h -include python/cminimap2.pxd -include python/minimap2.pyx +include python/mmappy.c +include python/cmmappy.h +include python/cmmappy.pxd +include python/mmappy.pyx include python/README.rst diff --git a/Makefile b/Makefile index d133774..2549f08 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ ksw2_dispatch.o:ksw2_dispatch.c ksw2.h $(CC) -c $(CFLAGS) $(CPPFLAGS) -DKSW_CPU_DISPATCH $(INCLUDES) $< -o $@ clean: - rm -fr gmon.out *.o a.out $(PROG) $(PROG_EXTRA) *~ *.a *.dSYM build dist minimap2.so minimap2.c python/minimap2.c minimap2.egg* + rm -fr gmon.out *.o a.out $(PROG) $(PROG_EXTRA) *~ *.a *.dSYM build dist mmappy.so mmappy.c python/mmappy.c mmappy.egg* depend: (LC_ALL=C; export LC_ALL; makedepend -Y -- $(CFLAGS) $(CPPFLAGS) -- *.c) diff --git a/python/README.rst b/python/README.rst index 27a1cd3..f31fb2f 100644 --- a/python/README.rst +++ b/python/README.rst @@ -1,6 +1,6 @@ -======================= -Minimap2 Python Binding -======================= +=============================== +Mmappy: Minimap2 Python Binding +=============================== `Minimap2 `_ is a fast and accurate pairwise aligner for genomic and transcribed nucleotide sequences. This module wraps @@ -21,7 +21,7 @@ or with `pip `_: .. code:: shell - pip install --user minimap2 + pip install --user mmappy Usage ----- @@ -30,7 +30,7 @@ The following Python program shows the key functionality of this module: .. code:: python - import minimap2 as mm + import mmappy as mm a = mm.Aligner("test/MT-human.fa") # load or build index if not a: raise Exception("ERROR: failed to load/build index") for hit in a.map("GGTTAAATACAGACCAAGAGCCTTCAAAGCCCTCAGTAAGTTGCAATACTTAATTTCTGT"): @@ -86,7 +86,7 @@ Arguments: This method maps :code:`seq` against the index. It *yields* a generator, generating a series of :code:`Alignment` objects. -Class minimap2.Alignment +Class mmappy.Alignment ~~~~~~~~~~~~~~~~~~~~~~~~ This class has the following properties: diff --git a/python/cminimap2.h b/python/cmmappy.h similarity index 95% rename from python/cminimap2.h rename to python/cmmappy.h index 2eb9faa..0bedf74 100644 --- a/python/cminimap2.h +++ b/python/cmmappy.h @@ -1,5 +1,5 @@ -#ifndef CMINIMAP2_H -#define CMINIMAP2_H +#ifndef CMMAPPY_H +#define CMMAPPY_H #include #include "minimap.h" diff --git a/python/cminimap2.pxd b/python/cmmappy.pxd similarity index 95% rename from python/cminimap2.pxd rename to python/cmmappy.pxd index f371427..f1b7820 100644 --- a/python/cminimap2.pxd +++ b/python/cmmappy.pxd @@ -62,7 +62,7 @@ cdef extern from "minimap.h": void mm_mapopt_update(mm_mapopt_t *opt, const mm_idx_t *mi) # - # Mapping (key struct defined in cminimap2.h below) + # Mapping (key struct defined in cmmappy.h below) # ctypedef struct mm_reg1_t: pass @@ -77,7 +77,7 @@ cdef extern from "minimap.h": # # Helper header (because it is hard to expose mm_reg1_t with Cython # -cdef extern from "cminimap2.h": +cdef extern from "cmmappy.h": ctypedef struct mm_hitpy_t: const char *ctg int32_t ctg_start, ctg_end diff --git a/python/mm2-lite.py b/python/mm2-lite.py index b9c495b..b294e32 100755 --- a/python/mm2-lite.py +++ b/python/mm2-lite.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys, getopt -import minimap2 as mm +import mmappy as mm def readfq(fp): # multi-line fasta/fastq parser last = None diff --git a/python/minimap2.pyx b/python/mmappy.pyx similarity index 75% rename from python/minimap2.pyx rename to python/mmappy.pyx index 399ce9c..f677be6 100644 --- a/python/minimap2.pyx +++ b/python/mmappy.pyx @@ -1,6 +1,6 @@ from libc.stdint cimport uint8_t, int8_t from libc.stdlib cimport free -cimport cminimap2 +cimport cmmappy cdef class Alignment: cdef int _ctg_len, _r_st, _r_en @@ -69,23 +69,23 @@ cdef class Alignment: str(self._blen - self._NM), str(self._blen), str(self._mapq), "NM:i:" + str(self._NM), tp, "cg:Z:" + self.cigar_str]) cdef class ThreadBuffer: - cdef cminimap2.mm_tbuf_t *_b + cdef cmmappy.mm_tbuf_t *_b def __cinit__(self): - self._b = cminimap2.mm_tbuf_init() + self._b = cmmappy.mm_tbuf_init() def __dealloc__(self): - cminimap2.mm_tbuf_destroy(self._b) + cmmappy.mm_tbuf_destroy(self._b) cdef class Aligner: - cdef cminimap2.mm_idx_t *_idx - cdef cminimap2.mm_idxopt_t idx_opt - cdef cminimap2.mm_mapopt_t map_opt + cdef cmmappy.mm_idx_t *_idx + cdef cmmappy.mm_idxopt_t idx_opt + cdef cmmappy.mm_mapopt_t map_opt def __cinit__(self, fn_idx_in, preset=None, k=None, w=None, min_cnt=None, min_chain_score=None, min_dp_score=None, bw=None, best_n=None, n_threads=3, fn_idx_out=None): - cminimap2.mm_set_opt(NULL, &self.idx_opt, &self.map_opt) # set the default options + cmmappy.mm_set_opt(NULL, &self.idx_opt, &self.map_opt) # set the default options if preset is not None: - cminimap2.mm_set_opt(str.encode(preset), &self.idx_opt, &self.map_opt) # apply preset + cmmappy.mm_set_opt(str.encode(preset), &self.idx_opt, &self.map_opt) # apply preset self.map_opt.flag |= 4 # always perform alignment self.idx_opt.batch_size = 0x7fffffffffffffffL # always build a uni-part index if k is not None: self.idx_opt.k = k @@ -96,40 +96,40 @@ cdef class Aligner: if bw is not None: self.map_opt.bw = bw if best_n is not None: self.best_n = best_n - cdef cminimap2.mm_idx_reader_t *r; + cdef cmmappy.mm_idx_reader_t *r; if fn_idx_out is None: - r = cminimap2.mm_idx_reader_open(str.encode(fn_idx_in), &self.idx_opt, NULL) + r = cmmappy.mm_idx_reader_open(str.encode(fn_idx_in), &self.idx_opt, NULL) else: - r = cminimap2.mm_idx_reader_open(str.encode(fn_idx_in), &self.idx_opt, fn_idx_out) + r = cmmappy.mm_idx_reader_open(str.encode(fn_idx_in), &self.idx_opt, fn_idx_out) if r is not NULL: - self._idx = cminimap2.mm_idx_reader_read(r, n_threads) # NB: ONLY read the first part - cminimap2.mm_idx_reader_close(r) - cminimap2.mm_mapopt_update(&self.map_opt, self._idx) + self._idx = cmmappy.mm_idx_reader_read(r, n_threads) # NB: ONLY read the first part + cmmappy.mm_idx_reader_close(r) + cmmappy.mm_mapopt_update(&self.map_opt, self._idx) def __dealloc__(self): if self._idx is not NULL: - cminimap2.mm_idx_destroy(self._idx) + cmmappy.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 + cdef cmmappy.mm_reg1_t *regs + cdef cmmappy.mm_hitpy_t h cdef ThreadBuffer b cdef int n_regs if self._idx is NULL: return None if buf is None: b = ThreadBuffer() else: b = buf - regs = cminimap2.mm_map(self._idx, len(seq), str.encode(seq), &n_regs, b._b, &self.map_opt, NULL) + regs = cmmappy.mm_map(self._idx, len(seq), str.encode(seq), &n_regs, b._b, &self.map_opt, NULL) for i in range(n_regs): - cminimap2.mm_reg2hitpy(self._idx, ®s[i], &h) + cmmappy.mm_reg2hitpy(self._idx, ®s[i], &h) cigar = [] for k in range(h.n_cigar32): c = h.cigar32[k] cigar.append([c>>4, c&0xf]) yield Alignment(h.ctg, h.ctg_len, h.ctg_start, h.ctg_end, h.strand, h.qry_start, h.qry_end, h.mapq, cigar, h.is_primary, h.blen, h.NM, h.trans_strand) - cminimap2.mm_free_reg1(®s[i]) + cmmappy.mm_free_reg1(®s[i]) free(regs) diff --git a/setup.py b/setup.py index b15c31e..0fab4bb 100644 --- a/setup.py +++ b/setup.py @@ -9,9 +9,9 @@ cmdclass = {} try: from Cython.Build import build_ext except ImportError: # without Cython - module_src = 'python/minimap2.c' + module_src = 'python/mmappy.c' else: # with Cython - module_src = 'python/minimap2.pyx' + module_src = 'python/mmappy.pyx' cmdclass['build_ext'] = build_ext import sys @@ -22,8 +22,8 @@ def readme(): return f.read() setup( - name = 'minimap2', - version = '2.2rc', + name = 'mmappy', + version = '2.2rc1', url = 'https://github.com/lh3/minimap2', description = 'Minimap2 python binding', long_description = readme(), @@ -31,13 +31,13 @@ setup( author_email = 'lh3@me.com', license = 'MIT', keywords = ['bioinformatics', 'sequence-alignment'], - ext_modules = [Extension('minimap2', + ext_modules = [Extension('mmappy', sources = [module_src, 'align.c', 'bseq.c', 'chain.c', 'format.c', 'hit.c', 'index.c', 'ksw2_extd2_sse.c', 'ksw2_exts2_sse.c', 'ksw2_extz2_sse.c', 'ksw2_ll_sse.c', 'kalloc.c', 'kthread.c', 'map.c', 'misc.c', 'sdust.c', 'sketch.c'], depends = ['minimap.h', 'bseq.h', 'kalloc.h', 'kdq.h', 'khash.h', 'kseq.h', 'ksort.h', 'ksw2.h', 'kthread.h', 'kvec.h', 'mmpriv.h', 'sdust.h', - 'python/cminimap2.h', 'python/cminimap2.pxd'], + 'python/cmmappy.h', 'python/cmmappy.pxd'], extra_compile_args = ['-msse4'], # WARNING: ancient x86_64 CPUs don't have SSE4 include_dirs = ['.'], libraries = ['z', 'm', 'pthread'])],