@@ -27,17 +27,19 @@ import System.Random (mkStdGen, setStdGen)
2727import Text.Printf (printf )
2828import qualified Text.PrettyPrint.ANSI.Leijen as PP
2929
30- data OutFormat = EigenstratFormat String String | PlinkFormat String String | FreqSumFormat deriving (Show )
30+ data OutFormat = EigenstratFormat FilePath | PlinkFormat FilePath | FreqSumFormat deriving (Show )
3131
32- data ProgOpt = ProgOpt CallingMode Bool (Maybe Int ) Int TransitionsMode FilePath OutFormat (Either [String ] FilePath )
33- -- optCallingMode :: CallingMode,
34- -- optKeepInCongruentReads :: Bool,
35- -- optSeed :: Maybe Int,
36- -- optMinDepth :: Int,
37- -- optTransitionsMode :: TransitionsMode,
38- -- optSnpFile :: FilePath,
39- -- optOutFormat :: OutFormat,
40- -- optSampleNames :: Either [String] FilePath
32+ data ProgOpt = ProgOpt {
33+ optCallingMode :: CallingMode ,
34+ optKeepInCongruentReads :: Bool ,
35+ optSeed :: Maybe Int ,
36+ optMinDepth :: Int ,
37+ optTransitionsMode :: TransitionsMode ,
38+ optSnpFile :: FilePath ,
39+ optOutFormat :: OutFormat ,
40+ optSampleNames :: Either [String ] FilePath ,
41+ optPopName :: String
42+ }
4143
4244data ReadStats = ReadStats {
4345 rsTotalSites :: IORef Int ,
@@ -55,11 +57,12 @@ data Env = Env {
5557 envOutFormat :: OutFormat ,
5658 envSnpFile :: FilePath ,
5759 envSampleNames :: [String ],
60+ envPopName :: String ,
5861 envStats :: ReadStats
5962}
6063
6164instance Show Env where
62- show (Env m r d t o sf sn _) = show (m, r, d, t, o, sf, sn)
65+ show (Env m r d t o sf sn pn _) = show (m, r, d, t, o, sf, sn, pn )
6366
6467type App = ReaderT Env (SafeT IO )
6568
@@ -74,8 +77,15 @@ parserInfo = OP.info (pure (.) <*> versionInfoOpt <*> OP.helper <*> argParser)
7477 (OP. progDescDoc (Just programHelpDoc))
7578
7679argParser :: OP. Parser ProgOpt
77- argParser = ProgOpt <$> parseCallingMode <*> parseKeepIncongruentReads <*> parseSeed <*> parseMinDepth <*>
78- parseTransitionsMode <*> parseSnpFile <*> parseFormat <*> parseSampleNames
80+ argParser = ProgOpt <$> parseCallingMode
81+ <*> parseKeepIncongruentReads
82+ <*> parseSeed
83+ <*> parseMinDepth
84+ <*> parseTransitionsMode
85+ <*> parseSnpFile
86+ <*> parseFormat
87+ <*> parseSampleNames
88+ <*> parsePopName
7989 where
8090 parseCallingMode = parseRandomCalling <|> parseMajorityCalling <|> parseRandomDiploidCalling
8191 parseRandomCalling = OP. flag' RandomCalling (OP. long " randomHaploid" <>
@@ -140,7 +150,7 @@ argParser = ProgOpt <$> parseCallingMode <*> parseKeepIncongruentReads <*> parse
140150 \X is converted to 23, Y to 24 and MT to 90. This is the most widely used encoding in Eigenstrat \
141151 \databases for human data, so using a SNP file with that encoding will automatically be correctly aligned \
142152 \to pileup data with actual chromosome names X, Y and MT (or chrX, chrY and chrMT, respectively)." )
143- parseFormat = (EigenstratFormat <$> parseEigenstratPrefix <*> parseSamplePopName ) <|> (PlinkFormat <$> parsePlinkPrefix <*> parseSamplePopName ) <|> pure FreqSumFormat
153+ parseFormat = (EigenstratFormat <$> parseEigenstratPrefix) <|> (PlinkFormat <$> parsePlinkPrefix) <|> pure FreqSumFormat
144154 parseEigenstratPrefix = OP. strOption (OP. long " eigenstratOut" <> OP. short ' e' <>
145155 OP. metavar " <FILE_PREFIX>" <>
146156 OP. help " Set Eigenstrat as output format. Specify the filenames for the EigenStrat \
@@ -162,7 +172,7 @@ argParser = ProgOpt <$> parseCallingMode <*> parseKeepIncongruentReads <*> parse
162172 parseSampleNameFile = OP. option (Right <$> OP. str) (OP. long " sampleNameFile" <> OP. metavar " <FILE>" <>
163173 OP. help " give the names of the samples in a file with one name per \
164174 \line" )
165- parseSamplePopName = OP. strOption (OP. long " samplePopName" <> OP. value " Unknown" <> OP. showDefault <>
175+ parsePopName = OP. strOption (OP. long " samplePopName" <> OP. value " Unknown" <> OP. showDefault <>
166176 OP. metavar " POP" <>
167177 OP. help " specify the population name of the samples, which is included\
168178 \ in the output *.ind.txt file in Eigenstrat output. This will be ignored if the output \
@@ -191,7 +201,7 @@ programHelpDoc =
191201initialiseEnvironment :: ProgOpt -> IO Env
192202initialiseEnvironment args = do
193203 let (ProgOpt callingMode keepInCongruentReads seed minDepth
194- transitionsMode snpFile outFormat sampleNames) = args
204+ transitionsMode snpFile outFormat sampleNames popName ) = args
195205 case seed of
196206 Nothing -> return ()
197207 Just seed_ -> liftIO . setStdGen $ mkStdGen seed_
@@ -201,7 +211,7 @@ initialiseEnvironment args = do
201211 let n = length sampleNamesList
202212 readStats <- ReadStats <$> newIORef 0 <*> makeVec n <*> makeVec n <*> makeVec n <*> makeVec n
203213 return $ Env callingMode keepInCongruentReads minDepth transitionsMode
204- outFormat snpFile sampleNamesList readStats
214+ outFormat snpFile sampleNamesList popName readStats
205215 where
206216 makeVec n = do
207217 v <- V. new n
@@ -214,10 +224,11 @@ runMain = do
214224 snpFile <- asks envSnpFile
215225 freqSumProducer <- pileupToFreqSum snpFile pileupProducer
216226 outFormat <- asks envOutFormat
227+ popName <- asks envPopName
217228 case outFormat of
218229 FreqSumFormat -> outputFreqSum freqSumProducer
219- EigenstratFormat outPrefix popName -> outputEigenStratOrPlink outPrefix popName False freqSumProducer
220- PlinkFormat outPrefix popName -> outputEigenStratOrPlink outPrefix popName True freqSumProducer
230+ EigenstratFormat outPrefix -> outputEigenStratOrPlink outPrefix popName False freqSumProducer
231+ PlinkFormat outPrefix -> outputEigenStratOrPlink outPrefix popName True freqSumProducer
221232 outputStats
222233
223234pileupToFreqSum :: FilePath -> Producer PileupRow (SafeT IO ) () ->
0 commit comments