Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
PyFastANI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Larralde
PyFastANI
Commits
4ab56195
Commit
4ab56195
authored
3 years ago
by
Martin Larralde
Browse files
Options
Downloads
Patches
Plain Diff
Manually define `std::unique` with concrete types to fix issue with Clang
parent
a41a8dca
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
pyfastani/_fastani.pyx
+10
-5
10 additions, 5 deletions
pyfastani/_fastani.pyx
pyfastani/_utils.cpp
+6
-0
6 additions, 0 deletions
pyfastani/_utils.cpp
pyfastani/_utils.hpp
+33
-31
33 additions, 31 deletions
pyfastani/_utils.hpp
pyfastani/_utils.pxd
+6
-1
6 additions, 1 deletion
pyfastani/_utils.pxd
with
55 additions
and
37 deletions
pyfastani/_fastani.pyx
+
10
−
5
View file @
4ab56195
...
@@ -6,15 +6,15 @@
...
@@ -6,15 +6,15 @@
# --- C imports --------------------------------------------------------------
# --- C imports --------------------------------------------------------------
cimport
libcpp11.chrono
cimport
libcpp11.chrono
from
cython.operator
cimport
dereference
,
postincrement
from
cython.operator
cimport
dereference
,
preincrement
,
postincrement
from
libc.string
cimport
memcpy
from
libc.string
cimport
memcpy
from
libc.limits
cimport
INT_MAX
from
libc.limits
cimport
INT_MAX
from
libc.stdint
cimport
int64_t
,
uint64_t
from
libc.stdint
cimport
int64_t
,
uint64_t
from
libc.stdlib
cimport
malloc
,
realloc
,
free
from
libc.stdlib
cimport
malloc
,
realloc
,
free
from
libcpp
cimport
bool
,
nullptr
from
libcpp
cimport
bool
,
nullptr
from
libcpp.algorithm
cimport
sort
,
unique
from
libcpp.algorithm
cimport
sort
from
libcpp.deque
cimport
deque
from
libcpp.deque
cimport
deque
from
libcpp.utility
cimport
pair
from
libcpp.utility
cimport
move
,
pair
from
libcpp.functional
cimport
function
from
libcpp.functional
cimport
function
from
libcpp.string
cimport
string
from
libcpp.string
cimport
string
from
libcpp.unordered_map
cimport
unordered_map
from
libcpp.unordered_map
cimport
unordered_map
...
@@ -46,7 +46,7 @@ from fastani.map.base_types cimport (
...
@@ -46,7 +46,7 @@ from fastani.map.base_types cimport (
# HACK: we need kseq_t* as a template argument, which is not supported by
# 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
# Cython at the moment, so we just `typedef kseq_t* kseq_ptr_t` in
# an external C++ header to make Cython happy
# 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
*
from
_unicode
cimport
*
...
@@ -580,7 +580,12 @@ cdef class Mapper(_Parameterized):
...
@@ -580,7 +580,12 @@ cdef class Mapper(_Parameterized):
# find the unique minimizers in thos that were just obtained
# find the unique minimizers in thos that were just obtained
sort
(
query
.
minimizerTableQuery
.
begin
(),
query
.
minimizerTableQuery
.
end
(),
MinimizerInfo_t
.
lessByHash
)
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
)
query
.
sketchSize
=
distance
(
query
.
minimizerTableQuery
.
begin
(),
uniq_end_iter
)
if
query
.
sketchSize
==
0
:
if
query
.
sketchSize
==
0
:
return
return
...
...
This diff is collapsed.
Click to expand it.
pyfastani/_utils.cpp
+
6
−
0
View file @
4ab56195
...
@@ -24,3 +24,9 @@ ZEXTERN int ZEXPORT gzread(gzFile file, void* buf, unsigned int len) {
...
@@ -24,3 +24,9 @@ ZEXTERN int ZEXPORT gzread(gzFile file, void* buf, unsigned int len) {
ZEXTERN
int
ZEXPORT
gzclose
(
gzFile
file
)
{
ZEXTERN
int
ZEXPORT
gzclose
(
gzFile
file
)
{
return
0
;
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
);
}
This diff is collapsed.
Click to expand it.
pyfastani/_utils.hpp
+
33
−
31
View file @
4ab56195
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#define __UTILS_HPP
#define __UTILS_HPP
#include
<stdint.h>
#include
<stdint.h>
#include
<algorithm>
#include
<chrono>
#include
<chrono>
#include
<limits>
#include
<limits>
#include
<iostream>
#include
<iostream>
...
@@ -12,38 +13,39 @@
...
@@ -12,38 +13,39 @@
#include
"map/include/base_types.hpp"
#include
"map/include/base_types.hpp"
#include
"map/include/winSketch.hpp"
#include
"map/include/winSketch.hpp"
#ifdef __cplusplus
extern
"C"
{
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
#endif // ifdef __UTILS_HPP
This diff is collapsed.
Click to expand it.
pyfastani/_utils.pxd
+
6
−
1
View file @
4ab56195
from
libc.stdint
cimport
uint64_t
from
libc.stdint
cimport
uint64_t
from
libcpp.vector
cimport
vector
from
kseq
cimport
kseq_t
from
kseq
cimport
kseq_t
from
fastani.map.base_types
cimport
MappingResultsVector_t
from
fastani.map.compute_map
cimport
Map
from
fastani.map.compute_map
cimport
Map
from
fastani.map.map_parameters
cimport
Parameters
from
fastani.map.map_parameters
cimport
Parameters
from
fastani.map.win_sketch
cimport
Sketch
from
fastani.map.win_sketch
cimport
Sketch
from
fastani.map.base_types
cimport
(
MappingResultsVector_t
,
MinimizerInfo
as
MinimizerInfo_t
)
cdef
extern
from
*
:
cdef
extern
from
*
:
...
@@ -36,4 +40,5 @@ cdef extern from "_utils.hpp" nogil:
...
@@ -36,4 +40,5 @@ cdef extern from "_utils.hpp" nogil:
ctypedef
kseq_t
*
kseq_ptr_t
ctypedef
kseq_t
*
kseq_ptr_t
cdef
vector
[
MinimizerInfo_t
].
iterator
unique_minimizers
(
vector
[
MinimizerInfo_t
].
iterator
,
vector
[
MinimizerInfo_t
].
iterator
)
int
complement
(
int
)
int
complement
(
int
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment