Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4db767b
commit 567340e
Showing
3 changed files
with
75 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Options ( | ||
IseqOptions(..) | ||
, Command(..) | ||
, Alignment(..) | ||
) where | ||
|
||
|
||
data IseqOptions = IseqOptions { | ||
optVerbose :: Bool | ||
, optOutput :: Maybe FilePath | ||
, optCommand :: Command | ||
} deriving (Show) | ||
|
||
data Command = | ||
CmdAlign { optAlignment :: Alignment } | ||
| CmdMerge | ||
| CmdScan { | ||
optInput :: FilePath | ||
, optPrimer :: String | ||
} | ||
deriving (Show) | ||
|
||
data Alignment = | ||
GlobalAlignment | ||
| LocalAlignment | ||
deriving (Show, Eq) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{-# LANGUAGE BangPatterns #-} | ||
|
||
module Scan (bestMatchWithin, editDist, scan) where | ||
|
||
import Data.List (tails, minimumBy) | ||
import Data.Ord (comparing) | ||
|
||
import Options | ||
|
||
|
||
-- Find position within n characters from start of y that minimizes edit | ||
-- distance to x. | ||
bestMatchWithin :: Eq a => Int -> [a] -> [a] -> (Int, Int) | ||
bestMatchWithin n x y = minimumBy (comparing snd) $ zip [1..] distances | ||
where | ||
distances = map (editDist x) (take (max 1 $ n+1) $ tails y) | ||
|
||
|
||
-- Edit distance between two lists | ||
editDist :: Eq a => [a] -> [a] -> Int | ||
editDist = go 0 | ||
where | ||
go !n [] _ = n | ||
go !n xs [] = n + length xs | ||
go !n xa@(x:xs) ya@(y:ys) | ||
| x == y = go n xs ys | ||
| otherwise = minimum [ go (n+1) xa ys -- deletion | ||
, go (n+1) xs ya -- insertion | ||
, go (n+1) xs ys ] -- substitution | ||
|
||
|
||
scan = undefined |