From 486af6fa2a50a72d1490c86bd2179e532ef0fe62 Mon Sep 17 00:00:00 2001 From: Blaise Li <blaise.li__git@nsup.org> Date: Thu, 6 Feb 2025 18:18:14 +0100 Subject: [PATCH] Can now process files given as command-line args. --- README.md | 8 +++++++- app/Main.hs | 21 ++++++++++++++++++++- remove-duplicates-from-sorted-fastq.cabal | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4fa9856..6cedfda 100644 --- a/README.md +++ b/README.md @@ -42,4 +42,10 @@ fastq file provided in the `test` directory: fastq-sort -s test/example.fq | remove-duplicates-from-sorted-fastq > test/dedup.fq -The resulting `test/dedup.fq` should be identical to `test/dedup_expected.fq`. +This can also be achieved in two steps: + + fastq-sort -s test/example.fq > test/sorted.fq + remove-duplicates-from-sorted-fastq test/sorted.fq > test/dedup.fq + +In both cases, the resulting `test/dedup.fq` should be identical to +`test/dedup_expected.fq`. diff --git a/app/Main.hs b/app/Main.hs index b635c63..5e67644 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,6 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} module Main where +import System.Environment (getArgs) -- For more efficient text manipulation import qualified Data.ByteString.Lazy.Char8 as C @@ -66,5 +67,23 @@ text-formatted fastq records into a single text. C.interact deals with the IO interaction, i.e. taking text from the outside world and returning text to it. -} +processStdin :: IO () +processStdin = C.interact (C.concat . processLines . C.lines) + +processPath :: String -> IO () +processPath path = do + fileContent <- (C.readFile path) + C.putStr ((C.concat . processLines . C.lines) fileContent) + +selectAction :: [String] -> IO () +selectAction [] = processStdin +selectAction (path : []) = do + processPath path +selectAction (path : nextArgs) = do + processPath path + selectAction nextArgs + main :: IO () -main = C.interact (C.concat . processLines . C.lines) +main = do + args <- getArgs + selectAction args diff --git a/remove-duplicates-from-sorted-fastq.cabal b/remove-duplicates-from-sorted-fastq.cabal index b94734b..dd57206 100644 --- a/remove-duplicates-from-sorted-fastq.cabal +++ b/remove-duplicates-from-sorted-fastq.cabal @@ -16,7 +16,7 @@ name: remove-duplicates-from-sorted-fastq -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change -version: 0.1.0.0 +version: 0.1.1.0 -- A short (one-line) description of the package. -- synopsis: -- GitLab