@@ -7,37 +7,34 @@ module Data.FastQ.Utils
77import qualified Data.Conduit as C
88import qualified Data.Conduit.Binary as CB
99import Data.Conduit ((.|) )
10- import System.IO (hClose )
11- import Control.Monad
12- import Control.Monad.Except
10+ import Control.Monad (forM_ )
1311
1412import Data.List (isSuffixOf )
1513
1614import NGLess.NGError
1715
18- import FileManagement
16+ import FileManagement ( makeNGLTempFile )
1917import Utils.Conduit (linesC )
20- import Data.FastQ
18+ import Data.FastQ ( FastQFilePath ( .. ), fqDecodeC , fqEncodeC )
2119import Data.Conduit.Algorithms.Async (asyncGzipTo , conduitPossiblyCompressedFile )
2220
2321concatenateFQs :: [FastQFilePath ] -> NGLessIO FastQFilePath
2422concatenateFQs [] = throwShouldNotOccur " Empty argument to concatenateFQs"
2523concatenateFQs [f] = return f
2624concatenateFQs (FastQFilePath enc fp: rest) = do
27- (fres, h) <- openNGLTempFile " concatenate" fp " fq.gz"
28- let catTo f enc'
29- | enc /= enc' =
30- conduitPossiblyCompressedFile f
31- .| linesC
32- .| fqDecodeC enc'
33- .| fqEncodeC enc
34- .| asyncGzipTo h
35- | " .gz" `isSuffixOf` f = CB. sourceFile f .| CB. sinkHandle h
36- | otherwise = conduitPossiblyCompressedFile f .| asyncGzipTo h
37- C. runConduitRes $ catTo fp enc
38- forM_ rest $ \ (FastQFilePath enc' f') ->
39- C. runConduitRes (catTo f' enc')
40- liftIO $ hClose h
25+ fres <- makeNGLTempFile fp " concatenate" " fq.gz" $ \ hout -> do
26+ let catTo f enc'
27+ | enc /= enc' =
28+ conduitPossiblyCompressedFile f
29+ .| linesC
30+ .| fqDecodeC enc'
31+ .| fqEncodeC enc
32+ .| asyncGzipTo hout
33+ | " .gz" `isSuffixOf` f = CB. sourceFile f .| CB. sinkHandle hout
34+ | otherwise = conduitPossiblyCompressedFile f .| asyncGzipTo hout
35+ C. runConduitRes $ catTo fp enc
36+ forM_ rest $ \ (FastQFilePath enc' f') ->
37+ C. runConduitRes (catTo f' enc')
4138 return $ FastQFilePath enc fres
4239
4340
0 commit comments