Skip to content

Commit

Permalink
added reverse complement
Browse files Browse the repository at this point in the history
  • Loading branch information
lh3 committed Feb 20, 2018
1 parent f434653 commit 7dc7097
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
12 changes: 10 additions & 2 deletions python/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ the following format:
It is effectively the PAF format without the QueryName and QueryLength columns
(the first two columns in PAF).

Function mappy.fastx_read
~~~~~~~~~~~~~~~~~~~~~~~~~
Miscellaneous Functions
~~~~~~~~~~~~~~~~~~~~~~~

.. code:: python
Expand All @@ -149,3 +149,11 @@ Function mappy.fastx_read
This generator function opens a FASTA/FASTQ file and *yields* a
:code:`(name,seq,qual)` tuple for each sequence entry. The input file may be
optionally gzip'd.

.. code:: python
mappy.revcomp(seq)
Return the reverse complement of DNA string :code:`seq`. This function
recognizes IUB code and preserves the letter cases. Uracil :code:`U` is
complemented to :code:`A`.
12 changes: 12 additions & 0 deletions python/cmappy.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,16 @@ static inline mm_reg1_t *mm_map_aux(const mm_idx_t *mi, const char *seq1, const
}
}

static inline uint8_t *mappy_revcomp(int len, uint8_t *seq)
{
int i;
for (i = 0; i < len>>1; ++i) {
uint8_t t = seq_comp_table[seq[i]];
seq[i] = seq_comp_table[seq[len - 1 - i]];
seq[len - 1 - i] = t;
}
if (len&1) seq[len>>1] = seq_comp_table[seq[len>>1]];
return seq;
}

#endif
1 change: 1 addition & 0 deletions python/cmappy.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,6 @@ cdef extern from "cmappy.h":
void mm_fastx_close(kseq_t *ks)
int kseq_read(kseq_t *seq)

uint8_t *mappy_revcomp(int l, uint8_t *seq)
int mm_verbose_level(int v)
void mm_reset_timer()
5 changes: 5 additions & 0 deletions python/mappy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ def fastx_read(fn):
yield name, seq, qual
cmappy.mm_fastx_close(ks)

def revcomp(seq):
cdef uint8_t *s
s = cmappy.mappy_revcomp(len(seq), str.encode(seq))
return s if isinstance(s, str) else s.decode()

def verbose(v=None):
if v is None: v = -1
return cmappy.mm_verbose_level(v)

0 comments on commit 7dc7097

Please sign in to comment.