{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module SLynx.Translate.Translate
( translateCmd,
)
where
import Control.Monad.Trans.Reader
import ELynx.Data.Character.Codon
import ELynx.Data.Sequence.Sequence
import ELynx.Data.Sequence.Translate
import ELynx.Export.Sequence.Fasta
import ELynx.Tools
import SLynx.Tools
import SLynx.Translate.Options
translateSeqs :: Int -> UniversalCode -> [Sequence] -> [Sequence]
translateSeqs :: Int -> UniversalCode -> [Sequence] -> [Sequence]
translateSeqs Int
rf UniversalCode
uc = (Sequence -> Sequence) -> [Sequence] -> [Sequence]
forall a b. (a -> b) -> [a] -> [b]
map (UniversalCode -> Int -> Sequence -> Sequence
translateSeq UniversalCode
uc Int
rf)
translateCmd :: ELynx TranslateArguments ()
translateCmd :: ELynx TranslateArguments ()
translateCmd = do
(TranslateArguments Alphabet
al FilePath
inFile Int
rf UniversalCode
uc) <- Environment TranslateArguments -> TranslateArguments
forall a. Environment a -> a
localArguments (Environment TranslateArguments -> TranslateArguments)
-> ReaderT
(Environment TranslateArguments)
IO
(Environment TranslateArguments)
-> ReaderT (Environment TranslateArguments) IO TranslateArguments
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReaderT
(Environment TranslateArguments)
IO
(Environment TranslateArguments)
forall (m :: * -> *) r. Monad m => ReaderT r m r
ask
FilePath -> ELynx TranslateArguments ()
forall e.
(HasLock e, HasLogHandles e, HasVerbosity e) =>
FilePath -> Logger e ()
logInfoS (FilePath -> ELynx TranslateArguments ())
-> FilePath -> ELynx TranslateArguments ()
forall a b. (a -> b) -> a -> b
$ FilePath
" Universal code: " FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> UniversalCode -> FilePath
forall a. Show a => a -> FilePath
show UniversalCode
uc FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath
"."
FilePath -> ELynx TranslateArguments ()
forall e.
(HasLock e, HasLogHandles e, HasVerbosity e) =>
FilePath -> Logger e ()
logInfoS (FilePath -> ELynx TranslateArguments ())
-> FilePath -> ELynx TranslateArguments ()
forall a b. (a -> b) -> a -> b
$ FilePath
" Reading frame: " FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> Int -> FilePath
forall a. Show a => a -> FilePath
show Int
rf FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath
"."
FilePath -> ELynx TranslateArguments ()
forall e.
(HasLock e, HasLogHandles e, HasVerbosity e) =>
FilePath -> Logger e ()
logInfoS FilePath
""
[Sequence]
ss <- Alphabet
-> FilePath -> Logger (Environment TranslateArguments) [Sequence]
forall e.
(HasLock e, HasLogHandles e, HasVerbosity e) =>
Alphabet -> FilePath -> Logger e [Sequence]
readSeqs Alphabet
al FilePath
inFile
let result :: ByteString
result = [Sequence] -> ByteString
sequencesToFasta ([Sequence] -> ByteString) -> [Sequence] -> ByteString
forall a b. (a -> b) -> a -> b
$ Int -> UniversalCode -> [Sequence] -> [Sequence]
translateSeqs Int
rf UniversalCode
uc [Sequence]
ss
FilePath -> ByteString -> FilePath -> ELynx TranslateArguments ()
forall a.
Reproducible a =>
FilePath -> ByteString -> FilePath -> ELynx a ()
out FilePath
"translated sequences" ByteString
result FilePath
"fasta"