Skip to content

Commit a94c818

Browse files
Correcting defect in string alignment commutativity
1 parent 6a05d45 commit a94c818

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/Alignment/Pairwise/Internal.hs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ directOptimization gap overlapλ _renderingFunction matrixFunction lhs rhs =
272272

273273

274274
{-# INLINEABLE measureCharacters #-}
275-
{-# SPECIALISE measureCharacters :: Vector SymbolContext -> Vector SymbolContext -> (Bool, [SymbolContext], [SymbolContext]) #-}
275+
{-# SPECIALISE measureCharacters :: Vector SymbolContext -> Vector SymbolContext -> (Ordering, [SymbolContext], [SymbolContext]) #-}
276276
measureCharacters
277277
:: Foldable f
278278
=> f SymbolContext
279279
-> f SymbolContext
280-
-> (Bool, [SymbolContext], [SymbolContext])
280+
-> (Ordering, [SymbolContext], [SymbolContext])
281281
measureCharacters lhs rhs =
282282
let f = maybe [] toList
283283
(b, x, y) = measureNullableCharacters (Just lhs) (Just rhs)
@@ -298,15 +298,15 @@ measureCharacters lhs rhs =
298298
--
299299
-- Handles equality of inputs by /not/ swapping.
300300
{-# INLINEABLE measureNullableCharacters #-}
301-
{-# SPECIALISE measureNullableCharacters :: Maybe (Vector SymbolContext) -> Maybe (Vector SymbolContext) -> (Bool, Maybe (Vector SymbolContext), Maybe (Vector SymbolContext)) #-}
301+
{-# SPECIALISE measureNullableCharacters :: Maybe (Vector SymbolContext) -> Maybe (Vector SymbolContext) -> (Ordering, Maybe (Vector SymbolContext), Maybe (Vector SymbolContext)) #-}
302302
measureNullableCharacters
303303
:: Foldable f
304304
=> Maybe (f SymbolContext)
305305
-> Maybe (f SymbolContext)
306-
-> (Bool, Maybe (f SymbolContext), Maybe (f SymbolContext))
306+
-> (Ordering, Maybe (f SymbolContext), Maybe (f SymbolContext))
307307
measureNullableCharacters lhs rhs
308-
| lhsOrdering == GT = ( True, rhs, lhs)
309-
| otherwise = (False, lhs, rhs)
308+
| lhsOrdering == GT = (lhsOrdering, rhs, lhs)
309+
| otherwise = (lhsOrdering, lhs, rhs)
310310
where
311311
lhsOrdering =
312312
-- First, compare inputs by length.
@@ -367,13 +367,11 @@ measureAndUngapCharacters gap char1 char2
367367
where
368368
(gapsChar1, ungappedChar1) = deleteGaps gap char1
369369
(gapsChar2, ungappedChar2) = deleteGaps gap char2
370+
needToSwap (v,_,_) = v == GT
370371
swapInputs =
371-
let needToSwap (x,_,_) = x
372-
ungappedLen1 = maybe 0 length ungappedChar1
373-
ungappedLen2 = maybe 0 length ungappedChar2
374-
in case ungappedLen1 `compare` ungappedLen2 of
375-
EQ | ungappedLen1 == 0 -> needToSwap $ measureNullableCharacters (Just char1) (Just char2)
376-
_ -> needToSwap $ measureNullableCharacters ungappedChar1 ungappedChar2
372+
case measureNullableCharacters ungappedChar1 ungappedChar2 of
373+
(EQ,_,_) -> needToSwap $ measureCharacters char1 char2
374+
x -> needToSwap x
377375

378376

379377
-- |

0 commit comments

Comments
 (0)