Skip to content

Commit bd2bed1

Browse files
committed
BUG Fix concatenation of multiple FastQ files
Adds a test too.
1 parent 43c3bcb commit bd2bed1

File tree

10 files changed

+41
-24
lines changed

10 files changed

+41
-24
lines changed

ChangeLog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Version 1.0.0+
22
* Reintroduce zstd compression (after fixes upstream)
33
* Fix CIGAR interpretation (#109) occurring when I is present
4+
* Fix bug with external modules and multiple fastQ inputs
45

56
Version 1.0.0 2019-04-24 by luispedro
67
* Fix multiple features usage (#63)

NGLess/Data/FastQ/Utils.hs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,34 @@ module Data.FastQ.Utils
77
import qualified Data.Conduit as C
88
import qualified Data.Conduit.Binary as CB
99
import Data.Conduit ((.|))
10-
import System.IO (hClose)
11-
import Control.Monad
12-
import Control.Monad.Except
10+
import Control.Monad (forM_)
1311

1412
import Data.List (isSuffixOf)
1513

1614
import NGLess.NGError
1715

18-
import FileManagement
16+
import FileManagement (makeNGLTempFile)
1917
import Utils.Conduit (linesC)
20-
import Data.FastQ
18+
import Data.FastQ (FastQFilePath(..), fqDecodeC, fqEncodeC)
2119
import Data.Conduit.Algorithms.Async (asyncGzipTo, conduitPossiblyCompressedFile)
2220

2321
concatenateFQs :: [FastQFilePath] -> NGLessIO FastQFilePath
2422
concatenateFQs [] = throwShouldNotOccur "Empty argument to concatenateFQs"
2523
concatenateFQs [f] = return f
2624
concatenateFQs (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

NGLess/ExternalModules.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Control.Monad
2727
import System.Process
2828
import System.Environment (getEnvironment, getExecutablePath)
2929
import System.Directory (getDirectoryContents, doesFileExist, doesDirectoryExist)
30-
import System.Exit
30+
import System.Exit (ExitCode(..))
3131
import System.IO
3232
import System.FilePath
3333
import Data.Maybe

NGLess/FileManagement.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ checkFilenameLength base ext = if len > 240
9393
-- directory and deleting the file when necessary)
9494
--
9595
-- These files will be auto-removed when ngless exits
96-
openNGLTempFile' :: FilePath -> String -> String -> NGLessIO (ReleaseKey, (FilePath, Handle))
96+
openNGLTempFile' :: FilePath -- ^ basename
97+
-> String -- ^ prefix
98+
-> String -- ^ extension
99+
-> NGLessIO (ReleaseKey, (FilePath, Handle))
97100
openNGLTempFile' base prefix ext = do
98101
tdir <- nConfTemporaryDirectory <$> nglConfiguration
99102
liftIO $ createDirectoryIfMissing True tdir

docs/sources/whatsnew.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
What's New (History)
33
====================
44

5+
Post Version 1.0
6+
----------------
7+
8+
User-visible improvements
9+
~~~~~~~~~~~~~~~~~~~~~~~~~
10+
- ZSTD compression is available for output and intermediate files use it for
11+
reduced temporary space usage (and possibly faster processing).
12+
13+
Bugfixes
14+
~~~~~~~~
15+
16+
- Fix bug with external modules and multiple fastQ inputs.
17+
518
Version 1.0
619
-----------
720

tests/exampleExternalModule/example-cmd.ngl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
ngless '0.0'
1+
ngless '1.0'
22
import "example-cmd" version "0.0"
3+
import "mocat" version "0.6"
34

4-
input = fastq('sample.fq')
5+
input = load_mocat_sample('sample')
56

67
testing(input)
78

tests/exampleExternalModule/sample.fq

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../select/sample.fq
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../select/sample.fq
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../select/sample.fq

0 commit comments

Comments
 (0)