{-| This program reads a Fasta file, and generates a corresponding qual
    file with made-up quality values.  Useful when you want to combine 
    sequences with and without quality in the same analysis.
-}

{-# Language DeriveDataTypeable #-}

module Main where

import System.Console.CmdArgs
import qualified Data.ByteString.Lazy as B
import System.IO (stdin,stdout)
import Bio.Sequence

version = "fakequal v0.1.4, copyright 2010 Ketil Malde"

data Opts = O { qval :: Int, input :: [FilePath] } 
          deriving (Show,Data,Typeable)

myopts = O { qval = 15 &= help "value to use for quality" &= typ "Int" &= name "q"
           , input = def &= args &= typFile }
         &= program "fakequal" 
         &= summary "generate fake quality information for fasta files"

main = do
  cf <- cmdArgs myopts
  -- print cf
  ss <- if null (input cf) then hReadFasta stdin
        else concat `fmap` mapM readFasta (input cf)
  hWriteQual stdout (map (addqual $ qval cf) ss)

addqual :: Int -> Sequence t -> Sequence t
addqual q (Seq h s _) = Seq h s (Just $ B.map (const $ fromIntegral q) s)
