renamed module name from minimap2 to mmappy

minimap2 clashed with minimap2 from conda
This commit is contained in:
Heng Li
2017-09-16 23:29:41 -04:00
parent 06b79c4a52
commit 28fd3d63fd
8 changed files with 43 additions and 43 deletions

View File

@@ -1,6 +1,6 @@
=======================
Minimap2 Python Binding
=======================
===============================
Mmappy: Minimap2 Python Binding
===============================
`Minimap2 <https://github.com/lh3/minimap2>`_ is a fast and accurate pairwise
aligner for genomic and transcribed nucleotide sequences. This module wraps
@@ -21,7 +21,7 @@ or with `pip <https://en.wikipedia.org/wiki/Pip_(package_manager)>`_:
.. 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:

View File

@@ -1,5 +1,5 @@
#ifndef CMINIMAP2_H
#define CMINIMAP2_H
#ifndef CMMAPPY_H
#define CMMAPPY_H
#include <stdlib.h>
#include "minimap.h"

View File

@@ -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

View File

@@ -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

View File

@@ -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, &regs[i], &h)
cmmappy.mm_reg2hitpy(self._idx, &regs[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(&regs[i])
cmmappy.mm_free_reg1(&regs[i])
free(regs)