{-# LANGUAGE DeriveGeneric #-}
module SLynx.SubSample.Options
( SubSampleArguments (..),
subSampleArguments,
getOutSuffixes,
)
where
import Data.Aeson
import qualified Data.Text as T
import qualified Data.Text.Lazy as LT
import qualified Data.Text.Lazy.Builder as LT
import qualified Data.Text.Lazy.Builder.Int as LT
import ELynx.Alphabet.Alphabet
import ELynx.Tools.Options
import ELynx.Tools.Reproduction
import GHC.Generics
import Options.Applicative
import SLynx.Tools
data SubSampleArguments = SubSampleArguments
{ SubSampleArguments -> Alphabet
ssAlphabet :: Alphabet,
SubSampleArguments -> FilePath
ssInFile :: FilePath,
SubSampleArguments -> Int
ssNSites :: Int,
SubSampleArguments -> Int
ssNAlignments :: Int,
SubSampleArguments -> SeedOpt
ssMbSeed :: SeedOpt
}
deriving (SubSampleArguments -> SubSampleArguments -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SubSampleArguments -> SubSampleArguments -> Bool
$c/= :: SubSampleArguments -> SubSampleArguments -> Bool
== :: SubSampleArguments -> SubSampleArguments -> Bool
$c== :: SubSampleArguments -> SubSampleArguments -> Bool
Eq, Int -> SubSampleArguments -> ShowS
[SubSampleArguments] -> ShowS
SubSampleArguments -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [SubSampleArguments] -> ShowS
$cshowList :: [SubSampleArguments] -> ShowS
show :: SubSampleArguments -> FilePath
$cshow :: SubSampleArguments -> FilePath
showsPrec :: Int -> SubSampleArguments -> ShowS
$cshowsPrec :: Int -> SubSampleArguments -> ShowS
Show, forall x. Rep SubSampleArguments x -> SubSampleArguments
forall x. SubSampleArguments -> Rep SubSampleArguments x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep SubSampleArguments x -> SubSampleArguments
$cfrom :: forall x. SubSampleArguments -> Rep SubSampleArguments x
Generic)
getOutSuffixes :: Int -> String -> [String]
getOutSuffixes :: Int -> FilePath -> [FilePath]
getOutSuffixes Int
n FilePath
suffix =
[FilePath
"." forall a. [a] -> [a] -> [a]
++ forall {a}. Integral a => a -> FilePath
digitStr Int
i forall a. [a] -> [a] -> [a]
++ FilePath
"." forall a. [a] -> [a] -> [a]
++ FilePath
suffix | Int
i <- [Int
0 .. Int
n forall a. Num a => a -> a -> a
- Int
1]]
where
nDigits :: Int
nDigits = forall a b. (RealFrac a, Integral b) => a -> b
ceiling forall a b. (a -> b) -> a -> b
$ forall a. Floating a => a -> a -> a
logBase (Double
10 :: Double) (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
n)
digitStr :: a -> FilePath
digitStr a
i =
Text -> FilePath
T.unpack forall a b. (a -> b) -> a -> b
$
Int -> Char -> Text -> Text
T.justifyRight Int
nDigits Char
'0' (Text -> Text
LT.toStrict forall a b. (a -> b) -> a -> b
$ Builder -> Text
LT.toLazyText forall a b. (a -> b) -> a -> b
$ forall a. Integral a => a -> Builder
LT.decimal a
i)
instance Reproducible SubSampleArguments where
inFiles :: SubSampleArguments -> [FilePath]
inFiles = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. SubSampleArguments -> FilePath
ssInFile
outSuffixes :: SubSampleArguments -> [FilePath]
outSuffixes SubSampleArguments
a = Int -> FilePath -> [FilePath]
getOutSuffixes (SubSampleArguments -> Int
ssNAlignments SubSampleArguments
a) FilePath
"fasta"
getSeed :: SubSampleArguments -> Maybe SeedOpt
getSeed = forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. SubSampleArguments -> SeedOpt
ssMbSeed
setSeed :: SubSampleArguments -> SeedOpt -> SubSampleArguments
setSeed SubSampleArguments
a SeedOpt
s = SubSampleArguments
a {ssMbSeed :: SeedOpt
ssMbSeed = SeedOpt
s}
parser :: Parser SubSampleArguments
parser = Parser SubSampleArguments
subSampleArguments
cmdName :: FilePath
cmdName = FilePath
"sub-sample"
cmdDsc :: [FilePath]
cmdDsc = [FilePath
"Sub-sample columns from multi sequence alignments."]
cmdFtr :: [FilePath]
cmdFtr =
[ FilePath
"Create a given number of multi sequence alignments, each of which contains a given number of random sites drawn from the original multi sequence alignment."
]
instance FromJSON SubSampleArguments
instance ToJSON SubSampleArguments
subSampleArguments :: Parser SubSampleArguments
subSampleArguments :: Parser SubSampleArguments
subSampleArguments =
Alphabet -> FilePath -> Int -> Int -> SeedOpt -> SubSampleArguments
SubSampleArguments
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Alphabet
alphabetOpt
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser FilePath
filePathArg
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Int
subSampleNSitesOpt
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Int
subSampleNAlignmentsOpt
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser SeedOpt
seedOpt
subSampleNSitesOpt :: Parser Int
subSampleNSitesOpt :: Parser Int
subSampleNSitesOpt =
forall a. ReadM a -> Mod OptionFields a -> Parser a
option forall a. Read a => ReadM a
auto forall a b. (a -> b) -> a -> b
$
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"number-of-sites"
forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'n'
forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"INT"
forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. FilePath -> Mod f a
help
FilePath
"Number of sites randomly drawn with replacement"
subSampleNAlignmentsOpt :: Parser Int
subSampleNAlignmentsOpt :: Parser Int
subSampleNAlignmentsOpt =
forall a. ReadM a -> Mod OptionFields a -> Parser a
option forall a. Read a => ReadM a
auto forall a b. (a -> b) -> a -> b
$
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"number-of-alignments"
forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'm'
forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"INT"
forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Number of multi sequence alignments to be created"
filePathArg :: Parser FilePath
filePathArg :: Parser FilePath
filePathArg =
forall s. IsString s => Mod ArgumentFields s -> Parser s
strArgument forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"INPUT-FILE" forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Read sequences from INPUT-FILE"