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

Fix some Cython warnings in `pyfastani/__init__.pyx`

parent b7250862
No related branches found
No related tags found
No related merge requests found
# coding: utf-8 # coding: utf-8
# cython: language_level=3, linetrace=True, language=cpp # cython: language_level=3, linetrace=True, language=cpp, binding=False
"""Bindings to FastANI, a method for fast whole-genome similarity estimation. """Bindings to FastANI, a method for fast whole-genome similarity estimation.
""" """
...@@ -193,9 +193,9 @@ cdef class Sketch: ...@@ -193,9 +193,9 @@ cdef class Sketch:
""" """
assert self._sk != nullptr assert self._sk != nullptr
cdef object contig
cdef const unsigned char[::1] seq cdef const unsigned char[::1] seq
cdef kseq_t kseq cdef kseq_t kseq
cdef ContigInfo_t info
cdef size_t seql_total = 0 cdef size_t seql_total = 0
cdef Parameters_t* param = &self._param cdef Parameters_t* param = &self._param
...@@ -216,13 +216,6 @@ cdef class Sketch: ...@@ -216,13 +216,6 @@ cdef class Sketch:
# get a memory view of the sequence # get a memory view of the sequence
seq = contig seq = contig
# store the contig name and size
# (we just use the same name for all contigs)
# <-- actually useless, only useful for reporting
# info.name = string(name)
# info.len = seq.shape[0]
# self._sk.metadata.push_back(info)
# check the sequence is large enough to compute minimizers # check the sequence is large enough to compute minimizers
if seq.shape[0] >= param.windowSize and seq.shape[0] >= param.kmerSize: if seq.shape[0] >= param.windowSize and seq.shape[0] >= param.kmerSize:
with nogil: with nogil:
...@@ -391,8 +384,7 @@ cdef class Mapper: ...@@ -391,8 +384,7 @@ cdef class Mapper:
@staticmethod @staticmethod
cdef void _query_fragment( cdef void _query_fragment(
int i, int i,
seqno_t seqno_t seq_counter,
seq_counter,
const unsigned char[::1] seq, const unsigned char[::1] seq,
int min_read_length, int min_read_length,
Map_t* map, Map_t* map,
...@@ -418,19 +410,21 @@ cdef class Mapper: ...@@ -418,19 +410,21 @@ cdef class Mapper:
assert self._sk != nullptr assert self._sk != nullptr
cdef int i # fragment counter cdef int i # fragment counter
cdef kseq_t kseq # cdef kseq_t kseq
cdef Map_t* map cdef Map_t* map
cdef MappingResultsVector_t final_mappings cdef MappingResultsVector_t final_mappings
cdef vector[CGI_Results] results cdef vector[CGI_Results] results
cdef CGI_Results result
cdef object contig cdef object contig
cdef const unsigned char[::1] seq cdef const unsigned char[::1] seq
cdef uint64_t seql cdef uint64_t seql = 0
cdef int fragment_count = 0 cdef uint64_t min_length
cdef int seq_counter = 0 cdef uint64_t shared_length
cdef int fragment_count
cdef uint64_t total_fragments = 0 cdef uint64_t total_fragments = 0
cdef Parameters_t p = self._param cdef Parameters_t p = self._param
cdef list hits = [] cdef list hits = []
cdef ofstream out = ofstream() cdef ofstream out
# create a new mapper with the given mapping result vector # create a new mapper with the given mapping result vector
map = new Map_t(p, self._sk[0], total_fragments, 0) map = new Map_t(p, self._sk[0], total_fragments, 0)
...@@ -473,37 +467,37 @@ cdef class Mapper: ...@@ -473,37 +467,37 @@ cdef class Mapper:
# record the number of fragments # record the number of fragments
total_fragments += fragment_count total_fragments += fragment_count
else: else:
fragmentCount = 0
warnings.warn(UserWarning, ( warnings.warn(UserWarning, (
"Mapper received a short sequence relative to parameters, " "Mapper received a short sequence relative to parameters, "
"mapping will not be computed." "mapping will not be computed."
)) ))
# compute core genomic identity after successful mapping # compute core genomic identity after successful mapping
computeCGI( with nogil:
p, computeCGI(
final_mappings, p,
map[0], final_mappings,
self._sk[0], map[0],
total_fragments, # total query fragments self._sk[0],
0, # queryFileNo, only used for visualization, ignored total_fragments, # total query fragments
string(), # fileName, only used for reporting, ignored 0, # queryFileNo, only used for visualization, ignored
results, string(), # fileName, only used for reporting, ignored
) results,
)
# free the map # free the map
del map del map
# build and return the list of hits # build and return the list of hits
for res in results: for result in results:
assert res.refGenomeId < self._lengths.size() assert result.refGenomeId < self._lengths.size()
assert res.refGenomeId < len(self._names) assert result.refGenomeId < len(self._names)
min_length = min(seql, self._lengths[res.refGenomeId]) min_length = min(seql, self._lengths[result.refGenomeId])
shared_length = res.countSeq * p.minReadLength shared_length = result.countSeq * p.minReadLength
if shared_length >= min_length * p.minFraction: if shared_length >= min_length * p.minFraction:
hits.append(Hit( hits.append(Hit(
name=self._names[res.refGenomeId], name=self._names[result.refGenomeId],
identity=res.identity, identity=result.identity,
matches=res.countSeq, matches=result.countSeq,
fragments=res.totalQueryFragments, fragments=result.totalQueryFragments,
)) ))
return hits return hits
...@@ -580,7 +574,7 @@ cdef class Hit: ...@@ -580,7 +574,7 @@ cdef class Hit:
self.identity = identity self.identity = identity
def __repr__(self): def __repr__(self):
ty = type(self).__name__ cdef str ty = type(self).__name__
return "{}(name={!r}, identity={!r} matches={!r}, fragments={!r})".format( return "{}(name={!r}, identity={!r} matches={!r}, fragments={!r})".format(
ty, self.name, self.identity, self.matches, self.fragments ty, self.name, self.identity, self.matches, self.fragments
) )
......
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