Skip to content

Commit 315b795

Browse files
committed
avoid direct float comparison
1 parent c61ca2f commit 315b795

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/melon/melon.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import numpy as np
44

5+
from math import isclose
56
from collections import defaultdict
67
from scipy.sparse import csr_matrix
78
from .utils import *
@@ -199,8 +200,8 @@ def parse_minimap(self):
199200
alignment = alignments.pop()
200201
if (
201202
max(alignment[2] / 0.995, alignment[2] + 50) > max_scores[alignment[0]]['AS'] or
202-
alignment[3] == max_scores[alignment[0]]['DE'] or
203-
alignment[4] == max_scores[alignment[0]]['ID']
203+
isclose(alignment[3], max_scores[alignment[0]]['DE']) or
204+
isclose(alignment[4], max_scores[alignment[0]]['ID'])
204205
):
205206
if (alignment[0], alignment[-1]) not in duplicates:
206207
self.alignments.append(alignment)
@@ -247,10 +248,7 @@ def run_em(self, max_iterations=1000, epsilon=1e-10):
247248
np.copyto(p_mappings_hist, p_mappings)
248249

249250
## return assignments
250-
assignments = []
251-
for p_read in p_reads.tocsr():
252-
p_read = p_read.toarray().squeeze()
253-
assignments.append(np.where(p_read == p_read.max())[0].tolist())
251+
assignments = [[index] for index in np.argmax(p_reads.toarray(), axis=1)]
254252

255253
ties = defaultdict(set)
256254
for qseqid, lineage in enumerate(assignments):

0 commit comments

Comments
 (0)