Skip to content

Commit

Permalink
BUG Fix select normalization
Browse files Browse the repository at this point in the history
The code is slightly hacky now in terms of internal API, but externally,
it works well.
  • Loading branch information
luispedro committed Nov 9, 2018
1 parent 912df97 commit 71b842e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions NGLess/Data/Sam.hs
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,23 @@ X sequence mismatch.
--}

matchSize :: SamLine -> Either NGError Int
matchSize = matchSize' . samCigar
matchSize' cigar
matchSize = matchSize' False . samCigar

matchSize' includeSoft cigar
| B8.null cigar = return 0
| otherwise = case B8.readInt cigar of
Nothing -> throwDataError ("could not parse cigar '"++B8.unpack cigar ++"'")
Just (n,code_rest) -> do
let code = B8.head code_rest
rest = B8.tail code_rest
n' = if code `elem` ("M=XS" :: String) then n else 0
r <- matchSize' rest
n' = case code of
'M' -> n
'=' -> n
'X' -> n
'S'
| includeSoft -> n
_ -> 0
r <- matchSize' includeSoft rest
return (n' + r)

matchIdentity :: SamLine -> Either NGError Double
Expand Down
4 changes: 2 additions & 2 deletions NGLess/Interpretation/Select.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ matchConditions doReinject conds sg = reinjectSequences doReinject (matchConditi

_fixCigar :: B.ByteString -> Int -> Either NGError B.ByteString
_fixCigar prev n = do
prevM <- matchSize' prev
prevM <- matchSize' True prev
if prevM == n
then return prev
else do
let prev' = B8.map (\c -> if c == 'H' then 'S' else c) prev
prevM' <- matchSize' prev'
prevM' <- matchSize' True prev'
if prevM' == n
then return prev'
else throwDataError ("Cannot fix CIGAR string \"" ++ B8.unpack prev ++ "\" to represent a sequence of length " ++ show n)
Expand Down

0 comments on commit 71b842e

Please sign in to comment.