Skip to content

Commit

Permalink
ENH Really return filename from write()
Browse files Browse the repository at this point in the history
The previous code did not actually do it
  • Loading branch information
luispedro committed Apr 25, 2022
1 parent 3606da4 commit 0a5c8d1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions NGLess/Interpretation/Write.hs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ executeWrite (NGOList el) args = do
let args' = filter (\(a,_) -> (a /= "ofile")) args
fps = map ((\fname -> replace "{index}" fname templateFP) . show) [1..length el]
zipWithM_ (\e fp -> executeWrite e (("ofile", NGOFilename fp):args')) el fps
return NGOVoid
return (NGOFilename templateFP)

executeWrite (NGOReadSet _ rs) args = do
opts <- parseWriteOptions args
Expand Down Expand Up @@ -204,7 +204,8 @@ executeWrite (NGOReadSet _ rs) args = do
cp2 <- moveOrCopyCompressFQs (snd <$> pairs) fname2
cp3 <- moveOrCopyCompressFQs singletons fname3
liftIO $ cp1 `concurrently_` cp2 `concurrently_` cp3
return NGOVoid
return (NGOFilename ofile)

executeWrite el@(NGOMappedReadSet _ iout _) args = do
opts <- parseWriteOptions args
fp <- asFile iout
Expand All @@ -229,7 +230,7 @@ executeWrite el@(NGOMappedReadSet _ iout _) args = do
| otherwise -> convertSamToBam fp
s -> throwScriptError ("write does not accept format {" ++ T.unpack s ++ "} with input type " ++ show el)
moveOrCopyCompress (woCanMove opts) orig (woOFile opts)
return NGOVoid
return (NGOFilename $ woOFile opts)

executeWrite (NGOCounts iout) args = do
opts <- parseWriteOptions args
Expand All @@ -253,15 +254,15 @@ executeWrite (NGOCounts iout) args = do
.| byteLineSinkHandle ohand
moveOrCopyCompress True comma (woOFile opts)
f -> throwScriptError ("Invalid format in write: {"++T.unpack f++"}.\n\tWhen writing counts, only accepted values are {tsv} (TAB separated values; default) or {csv} (COMMA separated values).")
return NGOVoid
return (NGOFilename $ woOFile opts)
where
tabToComma :: ByteLine -> ByteLine
tabToComma (ByteLine line) = ByteLine $ B8.map (\case { '\t' -> ','; c -> c }) line

executeWrite (NGOFilename fp) args = do
opts <- parseWriteOptions args
moveOrCopyCompress (woCanMove opts) fp (woOFile opts)
return NGOVoid
return (NGOFilename $ woOFile opts)

executeWrite v _ = throwShouldNotOccur ("Error: executeWrite of " ++ show v ++ " not implemented yet.")

Expand Down

0 comments on commit 0a5c8d1

Please sign in to comment.