Skip to content

Commit

Permalink
Start work on primer scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
b4winckler committed Mar 9, 2014
1 parent 4db767b commit 567340e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/Main.hs
Expand Up @@ -4,24 +4,12 @@ import Control.Applicative ((<$>), (<*>), pure)
import Options.Applicative ((<>), optional)
import Options.Applicative (Parser, command, info,
execParser, strOption, help, switch, help, helper,
fullDesc, progDesc, long, header,
subparser, flag)
fullDesc, progDesc, long, header, str,
subparser, flag, value, argument, metavar)

data IseqOptions = IseqOptions {
optVerbose :: Bool
, optOutput :: Maybe String
, optCommand :: Command
} deriving (Show)
import Options
import Scan (scan)

data Command =
CmdAlign { optAlignment :: Alignment }
| CmdMerge
deriving (Show)

data Alignment =
GlobalAlignment
| LocalAlignment
deriving (Show, Eq)


main :: IO ()
Expand All @@ -30,6 +18,11 @@ main = do
(fullDesc <> header "Tools for processing Illumina ?iSeq data"))
print o

case optCommand o of
CmdScan input primer -> scan o input primer
_ -> return ()


parser :: Parser IseqOptions
parser = IseqOptions
<$> switch (long "verbose" <> help "Be verbose")
Expand All @@ -38,6 +31,7 @@ parser = IseqOptions
command "align" (info alignOptParser $
progDesc "Align against database")
<> command "merge" (info mergeOptParser $ progDesc "Merge paired reads")
<> command "scan" (info scanOptParser $ progDesc "Scan for primer")
)

alignOptParser :: Parser Command
Expand All @@ -47,3 +41,9 @@ alignOptParser = CmdAlign

mergeOptParser :: Parser Command
mergeOptParser = pure CmdMerge

scanOptParser :: Parser Command
scanOptParser = CmdScan
<$> strOption (long "input" <> value "/dev/stdin"
<> help "Fasta file to scan")
<*> argument str (metavar "PRIMER" <> help "Primer sequence to scan for")
27 changes: 27 additions & 0 deletions src/Options.hs
@@ -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)

32 changes: 32 additions & 0 deletions src/Scan.hs
@@ -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

0 comments on commit 567340e

Please sign in to comment.