Skip to content
Snippets Groups Projects
Commit 4ab56195 authored by Martin Larralde's avatar Martin Larralde
Browse files

Manually define `std::unique` with concrete types to fix issue with Clang

parent a41a8dca
No related branches found
No related tags found
No related merge requests found
......@@ -6,15 +6,15 @@
# --- C imports --------------------------------------------------------------
cimport libcpp11.chrono
from cython.operator cimport dereference, postincrement
from cython.operator cimport dereference, preincrement, postincrement
from libc.string cimport memcpy
from libc.limits cimport INT_MAX
from libc.stdint cimport int64_t, uint64_t
from libc.stdlib cimport malloc, realloc, free
from libcpp cimport bool, nullptr
from libcpp.algorithm cimport sort, unique
from libcpp.algorithm cimport sort
from libcpp.deque cimport deque
from libcpp.utility cimport pair
from libcpp.utility cimport move, pair
from libcpp.functional cimport function
from libcpp.string cimport string
from libcpp.unordered_map cimport unordered_map
......@@ -46,7 +46,7 @@ from fastani.map.base_types cimport (
# HACK: we need kseq_t* as a template argument, which is not supported by
# Cython at the moment, so we just `typedef kseq_t* kseq_ptr_t` in
# an external C++ header to make Cython happy
from _utils cimport kseq_ptr_t, toupper, complement, distance
from _utils cimport kseq_ptr_t, toupper, complement, distance, unique_minimizers
from _unicode cimport *
......@@ -580,7 +580,12 @@ cdef class Mapper(_Parameterized):
# find the unique minimizers in thos that were just obtained
sort(query.minimizerTableQuery.begin(), query.minimizerTableQuery.end(), MinimizerInfo_t.lessByHash)
uniq_end_iter = unique(query.minimizerTableQuery.begin(), query.minimizerTableQuery.end(), MinimizerInfo_t.equalityByHash)
# manually implement `unique` as template instantiation has issues on OSX
it = query.minimizerTableQuery.begin()
uniq_end_iter = unique_minimizers(query.minimizerTableQuery.begin(), query.minimizerTableQuery.end())
# early return if no minimizers were found
query.sketchSize = distance(query.minimizerTableQuery.begin(), uniq_end_iter)
if query.sketchSize == 0:
return
......
......@@ -24,3 +24,9 @@ ZEXTERN int ZEXPORT gzread(gzFile file, void* buf, unsigned int len) {
ZEXTERN int ZEXPORT gzclose(gzFile file) {
return 0;
}
// Implementation from: https://en.cppreference.com/w/cpp/algorithm/
std::vector<skch::MinimizerInfo>::iterator unique_minimizers(std::vector<skch::MinimizerInfo>::iterator first, std::vector<skch::MinimizerInfo>::iterator last)
{
return std::unique(first, last, skch::MinimizerInfo::equalityByHash);
}
......@@ -2,6 +2,7 @@
#define __UTILS_HPP
#include <stdint.h>
#include <algorithm>
#include <chrono>
#include <limits>
#include <iostream>
......@@ -12,38 +13,39 @@
#include "map/include/base_types.hpp"
#include "map/include/winSketch.hpp"
#ifdef __cplusplus
extern "C" {
#endif
// compatibility layer for Cython
typedef kseq_t* kseq_ptr_t;
// efficient nucleotide complement with a lookup table
static const char COMPLEMENT_LOOKUP[128] = {
'\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
'\x08', '\t', '\n', '\x0', '\x0c', '\r', '\x0e', '\x0f',
'\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17',
'\x18', '\x19', '\x1a', '\x1', '\x1c', '\x1d', '\x1e', '\x1f',
' ', '!', '"', '#', '$', '%', '&', '\'',
'(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?',
'@', 'T', 'V', 'G', 'H', 'E', 'F', 'C',
'D', 'I', 'J', 'M', 'L', 'K', 'N', 'O',
'P', 'Q', 'Y', 'S', 'A', 'U', 'B', 'W',
'X', 'R', 'Z', '[', '\\', ']', '^', '_',
'`', 't', 'v', 'g', 'h', 'e', 'f', 'c',
'd', 'i', 'j', 'm', 'l', 'k', 'n', 'o',
'p', 'q', 'y', 's', 'a', 'u', 'b', 'w',
'x', 'r', 'z', '{', '|', '}', '~', '\x7f'
};
inline char complement(char base) {
return COMPLEMENT_LOOKUP[(size_t) (base & 0x7F)];
}
#ifdef __cplusplus
// compatibility layer for Cython
typedef kseq_t* kseq_ptr_t;
// efficient nucleotide complement with a lookup table
static const char COMPLEMENT_LOOKUP[128] = {
'\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
'\x08', '\t', '\n', '\x0', '\x0c', '\r', '\x0e', '\x0f',
'\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17',
'\x18', '\x19', '\x1a', '\x1', '\x1c', '\x1d', '\x1e', '\x1f',
' ', '!', '"', '#', '$', '%', '&', '\'',
'(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?',
'@', 'T', 'V', 'G', 'H', 'E', 'F', 'C',
'D', 'I', 'J', 'M', 'L', 'K', 'N', 'O',
'P', 'Q', 'Y', 'S', 'A', 'U', 'B', 'W',
'X', 'R', 'Z', '[', '\\', ']', '^', '_',
'`', 't', 'v', 'g', 'h', 'e', 'f', 'c',
'd', 'i', 'j', 'm', 'l', 'k', 'n', 'o',
'p', 'q', 'y', 's', 'a', 'u', 'b', 'w',
'x', 'r', 'z', '{', '|', '}', '~', '\x7f'
};
inline char complement(char base) {
return COMPLEMENT_LOOKUP[(size_t) (base & 0x7F)];
}
}
#endif // ifdef __cplusplus
// OSX seems to have trouble instantiating `std::unique` with our
// custom type, so here is a dedicated implementation
std::vector<skch::MinimizerInfo>::iterator unique_minimizers(std::vector<skch::MinimizerInfo>::iterator first, std::vector<skch::MinimizerInfo>::iterator last);
#endif // ifdef __UTILS_HPP
from libc.stdint cimport uint64_t
from libcpp.vector cimport vector
from kseq cimport kseq_t
from fastani.map.base_types cimport MappingResultsVector_t
from fastani.map.compute_map cimport Map
from fastani.map.map_parameters cimport Parameters
from fastani.map.win_sketch cimport Sketch
from fastani.map.base_types cimport (
MappingResultsVector_t,
MinimizerInfo as MinimizerInfo_t
)
cdef extern from *:
......@@ -36,4 +40,5 @@ cdef extern from "_utils.hpp" nogil:
ctypedef kseq_t* kseq_ptr_t
cdef vector[MinimizerInfo_t].iterator unique_minimizers(vector[MinimizerInfo_t].iterator, vector[MinimizerInfo_t].iterator)
int complement(int)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment