{-# LANGUAGE DeriveGeneric #-}

-- |
-- Module      :  SLynx.Options
-- Description :  SLynx general options
-- Copyright   :  (c) Dominik Schrempf 2021
-- License     :  GPL-3.0-or-later
--
-- Maintainer  :  dominik.schrempf@gmail.com
-- Stability   :  unstable
-- Portability :  portable
--
-- Creation date: Sat Sep  7 18:55:03 2019.
module SLynx.Options
  ( Arguments (..),
    CommandArguments (..),
    parseArguments,
  )
where

import ELynx.Data.Alphabet.Alphabet
import ELynx.Tools
import Options.Applicative
import SLynx.Concatenate.Options
import SLynx.Examine.Options
import SLynx.Filter.Options
import SLynx.Simulate.Options
import SLynx.SubSample.Options
import SLynx.Translate.Options

-- | The different SLynx commands and their arguments.
data CommandArguments
  = Concatenate ConcatenateArguments
  | Examine ExamineArguments
  | FilterCols FilterColsArguments
  | FilterRows FilterRowsArguments
  | Simulate SimulateArguments
  | SubSample SubSampleArguments
  | Translate TranslateArguments
  deriving (CommandArguments -> CommandArguments -> Bool
(CommandArguments -> CommandArguments -> Bool)
-> (CommandArguments -> CommandArguments -> Bool)
-> Eq CommandArguments
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CommandArguments -> CommandArguments -> Bool
$c/= :: CommandArguments -> CommandArguments -> Bool
== :: CommandArguments -> CommandArguments -> Bool
$c== :: CommandArguments -> CommandArguments -> Bool
Eq, Int -> CommandArguments -> ShowS
[CommandArguments] -> ShowS
CommandArguments -> String
(Int -> CommandArguments -> ShowS)
-> (CommandArguments -> String)
-> ([CommandArguments] -> ShowS)
-> Show CommandArguments
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CommandArguments] -> ShowS
$cshowList :: [CommandArguments] -> ShowS
show :: CommandArguments -> String
$cshow :: CommandArguments -> String
showsPrec :: Int -> CommandArguments -> ShowS
$cshowsPrec :: Int -> CommandArguments -> ShowS
Show, (forall x. CommandArguments -> Rep CommandArguments x)
-> (forall x. Rep CommandArguments x -> CommandArguments)
-> Generic CommandArguments
forall x. Rep CommandArguments x -> CommandArguments
forall x. CommandArguments -> Rep CommandArguments x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CommandArguments x -> CommandArguments
$cfrom :: forall x. CommandArguments -> Rep CommandArguments x
Generic)

instance Reproducible CommandArguments where
  inFiles :: CommandArguments -> [String]
inFiles (Concatenate ConcatenateArguments
a) = ConcatenateArguments -> [String]
forall a. Reproducible a => a -> [String]
inFiles ConcatenateArguments
a
  inFiles (Examine ExamineArguments
a) = ExamineArguments -> [String]
forall a. Reproducible a => a -> [String]
inFiles ExamineArguments
a
  inFiles (FilterCols FilterColsArguments
a) = FilterColsArguments -> [String]
forall a. Reproducible a => a -> [String]
inFiles FilterColsArguments
a
  inFiles (FilterRows FilterRowsArguments
a) = FilterRowsArguments -> [String]
forall a. Reproducible a => a -> [String]
inFiles FilterRowsArguments
a
  inFiles (Simulate SimulateArguments
a) = SimulateArguments -> [String]
forall a. Reproducible a => a -> [String]
inFiles SimulateArguments
a
  inFiles (SubSample SubSampleArguments
a) = SubSampleArguments -> [String]
forall a. Reproducible a => a -> [String]
inFiles SubSampleArguments
a
  inFiles (Translate TranslateArguments
a) = TranslateArguments -> [String]
forall a. Reproducible a => a -> [String]
inFiles TranslateArguments
a

  outSuffixes :: CommandArguments -> [String]
outSuffixes (Concatenate ConcatenateArguments
a) = ConcatenateArguments -> [String]
forall a. Reproducible a => a -> [String]
outSuffixes ConcatenateArguments
a
  outSuffixes (Examine ExamineArguments
a) = ExamineArguments -> [String]
forall a. Reproducible a => a -> [String]
outSuffixes ExamineArguments
a
  outSuffixes (FilterCols FilterColsArguments
a) = FilterColsArguments -> [String]
forall a. Reproducible a => a -> [String]
outSuffixes FilterColsArguments
a
  outSuffixes (FilterRows FilterRowsArguments
a) = FilterRowsArguments -> [String]
forall a. Reproducible a => a -> [String]
outSuffixes FilterRowsArguments
a
  outSuffixes (Simulate SimulateArguments
a) = SimulateArguments -> [String]
forall a. Reproducible a => a -> [String]
outSuffixes SimulateArguments
a
  outSuffixes (SubSample SubSampleArguments
a) = SubSampleArguments -> [String]
forall a. Reproducible a => a -> [String]
outSuffixes SubSampleArguments
a
  outSuffixes (Translate TranslateArguments
a) = TranslateArguments -> [String]
forall a. Reproducible a => a -> [String]
outSuffixes TranslateArguments
a

  getSeed :: CommandArguments -> Maybe SeedOpt
getSeed (Concatenate ConcatenateArguments
a) = ConcatenateArguments -> Maybe SeedOpt
forall a. Reproducible a => a -> Maybe SeedOpt
getSeed ConcatenateArguments
a
  getSeed (Examine ExamineArguments
a) = ExamineArguments -> Maybe SeedOpt
forall a. Reproducible a => a -> Maybe SeedOpt
getSeed ExamineArguments
a
  getSeed (FilterCols FilterColsArguments
a) = FilterColsArguments -> Maybe SeedOpt
forall a. Reproducible a => a -> Maybe SeedOpt
getSeed FilterColsArguments
a
  getSeed (FilterRows FilterRowsArguments
a) = FilterRowsArguments -> Maybe SeedOpt
forall a. Reproducible a => a -> Maybe SeedOpt
getSeed FilterRowsArguments
a
  getSeed (Simulate SimulateArguments
a) = SimulateArguments -> Maybe SeedOpt
forall a. Reproducible a => a -> Maybe SeedOpt
getSeed SimulateArguments
a
  getSeed (SubSample SubSampleArguments
a) = SubSampleArguments -> Maybe SeedOpt
forall a. Reproducible a => a -> Maybe SeedOpt
getSeed SubSampleArguments
a
  getSeed (Translate TranslateArguments
a) = TranslateArguments -> Maybe SeedOpt
forall a. Reproducible a => a -> Maybe SeedOpt
getSeed TranslateArguments
a

  setSeed :: CommandArguments -> SeedOpt -> CommandArguments
setSeed (Concatenate ConcatenateArguments
a) = ConcatenateArguments -> CommandArguments
Concatenate (ConcatenateArguments -> CommandArguments)
-> (SeedOpt -> ConcatenateArguments) -> SeedOpt -> CommandArguments
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConcatenateArguments -> SeedOpt -> ConcatenateArguments
forall a. Reproducible a => a -> SeedOpt -> a
setSeed ConcatenateArguments
a
  setSeed (Examine ExamineArguments
a) = ExamineArguments -> CommandArguments
Examine (ExamineArguments -> CommandArguments)
-> (SeedOpt -> ExamineArguments) -> SeedOpt -> CommandArguments
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExamineArguments -> SeedOpt -> ExamineArguments
forall a. Reproducible a => a -> SeedOpt -> a
setSeed ExamineArguments
a
  setSeed (FilterCols FilterColsArguments
a) = FilterColsArguments -> CommandArguments
FilterCols (FilterColsArguments -> CommandArguments)
-> (SeedOpt -> FilterColsArguments) -> SeedOpt -> CommandArguments
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilterColsArguments -> SeedOpt -> FilterColsArguments
forall a. Reproducible a => a -> SeedOpt -> a
setSeed FilterColsArguments
a
  setSeed (FilterRows FilterRowsArguments
a) = FilterRowsArguments -> CommandArguments
FilterRows (FilterRowsArguments -> CommandArguments)
-> (SeedOpt -> FilterRowsArguments) -> SeedOpt -> CommandArguments
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilterRowsArguments -> SeedOpt -> FilterRowsArguments
forall a. Reproducible a => a -> SeedOpt -> a
setSeed FilterRowsArguments
a
  setSeed (Simulate SimulateArguments
a) = SimulateArguments -> CommandArguments
Simulate (SimulateArguments -> CommandArguments)
-> (SeedOpt -> SimulateArguments) -> SeedOpt -> CommandArguments
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimulateArguments -> SeedOpt -> SimulateArguments
forall a. Reproducible a => a -> SeedOpt -> a
setSeed SimulateArguments
a
  setSeed (SubSample SubSampleArguments
a) = SubSampleArguments -> CommandArguments
SubSample (SubSampleArguments -> CommandArguments)
-> (SeedOpt -> SubSampleArguments) -> SeedOpt -> CommandArguments
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SubSampleArguments -> SeedOpt -> SubSampleArguments
forall a. Reproducible a => a -> SeedOpt -> a
setSeed SubSampleArguments
a
  setSeed (Translate TranslateArguments
a) = TranslateArguments -> CommandArguments
Translate (TranslateArguments -> CommandArguments)
-> (SeedOpt -> TranslateArguments) -> SeedOpt -> CommandArguments
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TranslateArguments -> SeedOpt -> TranslateArguments
forall a. Reproducible a => a -> SeedOpt -> a
setSeed TranslateArguments
a

  parser :: Parser CommandArguments
parser = Parser CommandArguments
commandArguments

  cmdName :: String
cmdName = String
"slynx"

  cmdDsc :: [String]
cmdDsc = [String
"Analyze, and simulate multi sequence alignments."]

  cmdFtr :: [String]
cmdFtr =
    [ String
"",
      String
"Available sequence file formats:"
    ]
      [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
fs
      [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String
"", String
"Available alphabets:"]
      [String] -> [String] -> [String]
forall a. [a] -> [a] -> [a]
++ [String]
as
    where
      toListItem :: ShowS
toListItem = (String
"  - " String -> ShowS
forall a. [a] -> [a] -> [a]
++)
      fs :: [String]
fs = ShowS -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map ShowS
toListItem [String
"FASTA"]
      as :: [String]
as = (Alphabet -> String) -> [Alphabet] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (ShowS
toListItem ShowS -> (Alphabet -> String) -> Alphabet -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Alphabet -> String
alphabetDescription) ([Alphabet]
forall a. (Bounded a, Enum a) => [a]
allValues :: [Alphabet])

instance FromJSON CommandArguments

instance ToJSON CommandArguments

concatenateCommand :: Mod CommandFields CommandArguments
concatenateCommand :: Mod CommandFields CommandArguments
concatenateCommand = (ConcatenateArguments -> CommandArguments)
-> Mod CommandFields CommandArguments
forall a b. Reproducible a => (a -> b) -> Mod CommandFields b
createCommandReproducible ConcatenateArguments -> CommandArguments
Concatenate

examineCommand :: Mod CommandFields CommandArguments
examineCommand :: Mod CommandFields CommandArguments
examineCommand = (ExamineArguments -> CommandArguments)
-> Mod CommandFields CommandArguments
forall a b. Reproducible a => (a -> b) -> Mod CommandFields b
createCommandReproducible ExamineArguments -> CommandArguments
Examine

filterColumnsCommand :: Mod CommandFields CommandArguments
filterColumnsCommand :: Mod CommandFields CommandArguments
filterColumnsCommand = (FilterColsArguments -> CommandArguments)
-> Mod CommandFields CommandArguments
forall a b. Reproducible a => (a -> b) -> Mod CommandFields b
createCommandReproducible FilterColsArguments -> CommandArguments
FilterCols

filterRowsCommand :: Mod CommandFields CommandArguments
filterRowsCommand :: Mod CommandFields CommandArguments
filterRowsCommand = (FilterRowsArguments -> CommandArguments)
-> Mod CommandFields CommandArguments
forall a b. Reproducible a => (a -> b) -> Mod CommandFields b
createCommandReproducible FilterRowsArguments -> CommandArguments
FilterRows

simulateCommand :: Mod CommandFields CommandArguments
simulateCommand :: Mod CommandFields CommandArguments
simulateCommand = (SimulateArguments -> CommandArguments)
-> Mod CommandFields CommandArguments
forall a b. Reproducible a => (a -> b) -> Mod CommandFields b
createCommandReproducible SimulateArguments -> CommandArguments
Simulate

subSampleCommand :: Mod CommandFields CommandArguments
subSampleCommand :: Mod CommandFields CommandArguments
subSampleCommand = (SubSampleArguments -> CommandArguments)
-> Mod CommandFields CommandArguments
forall a b. Reproducible a => (a -> b) -> Mod CommandFields b
createCommandReproducible SubSampleArguments -> CommandArguments
SubSample

translateCommand :: Mod CommandFields CommandArguments
translateCommand :: Mod CommandFields CommandArguments
translateCommand = (TranslateArguments -> CommandArguments)
-> Mod CommandFields CommandArguments
forall a b. Reproducible a => (a -> b) -> Mod CommandFields b
createCommandReproducible TranslateArguments -> CommandArguments
Translate

commandArguments :: Parser CommandArguments
commandArguments :: Parser CommandArguments
commandArguments =
  Mod CommandFields CommandArguments -> Parser CommandArguments
forall a. Mod CommandFields a -> Parser a
hsubparser (Mod CommandFields CommandArguments -> Parser CommandArguments)
-> Mod CommandFields CommandArguments -> Parser CommandArguments
forall a b. (a -> b) -> a -> b
$
    Mod CommandFields CommandArguments
concatenateCommand
      Mod CommandFields CommandArguments
-> Mod CommandFields CommandArguments
-> Mod CommandFields CommandArguments
forall a. Semigroup a => a -> a -> a
<> Mod CommandFields CommandArguments
examineCommand
      Mod CommandFields CommandArguments
-> Mod CommandFields CommandArguments
-> Mod CommandFields CommandArguments
forall a. Semigroup a => a -> a -> a
<> Mod CommandFields CommandArguments
filterColumnsCommand
      Mod CommandFields CommandArguments
-> Mod CommandFields CommandArguments
-> Mod CommandFields CommandArguments
forall a. Semigroup a => a -> a -> a
<> Mod CommandFields CommandArguments
filterRowsCommand
      Mod CommandFields CommandArguments
-> Mod CommandFields CommandArguments
-> Mod CommandFields CommandArguments
forall a. Semigroup a => a -> a -> a
<> Mod CommandFields CommandArguments
simulateCommand
      Mod CommandFields CommandArguments
-> Mod CommandFields CommandArguments
-> Mod CommandFields CommandArguments
forall a. Semigroup a => a -> a -> a
<> Mod CommandFields CommandArguments
subSampleCommand
      Mod CommandFields CommandArguments
-> Mod CommandFields CommandArguments
-> Mod CommandFields CommandArguments
forall a. Semigroup a => a -> a -> a
<> Mod CommandFields CommandArguments
translateCommand