From 8cb81133b01b608d8c7b903680e243a3dc483e8a Mon Sep 17 00:00:00 2001 From: Michaeljon Miller Date: Wed, 18 May 2022 11:37:16 -0700 Subject: [PATCH] adding read limiter... for dev speed --- Interfaces/ISequenceReader.cs | 2 +- Models/ReadFlag.cs | 2 ++ Modules/AlignmentStatistics.cs | 10 +++++++--- Program.cs | 2 +- Readers/BamReader.cs | 4 ++-- Readers/FastqLineReader.cs | 4 ++-- Readers/FastqReader.cs | 4 ++-- Readers/SamReader.cs | 4 ++-- Utils/CliOptions.cs | 5 ++++- Utils/PrettyPrintExtension.cs | 2 +- 10 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Interfaces/ISequenceReader.cs b/Interfaces/ISequenceReader.cs index 954aa5a..16778ab 100644 --- a/Interfaces/ISequenceReader.cs +++ b/Interfaces/ISequenceReader.cs @@ -4,7 +4,7 @@ namespace Ovation.FasterQC.Net { public interface ISequenceReader : IDisposable { - int SequencesRead { get; } + ulong SequencesRead { get; } bool ReadSequence(out Sequence? sequence); diff --git a/Models/ReadFlag.cs b/Models/ReadFlag.cs index 5af2fae..b9625b0 100644 --- a/Models/ReadFlag.cs +++ b/Models/ReadFlag.cs @@ -15,6 +15,8 @@ public enum ReadFlag : ushort /// Aligned = 2, + AlignedAndPaired = Aligned | Paired, + /// /// segment unmapped (read1 unmapped) /// diff --git a/Modules/AlignmentStatistics.cs b/Modules/AlignmentStatistics.cs index 994f7f7..bd69d23 100644 --- a/Modules/AlignmentStatistics.cs +++ b/Modules/AlignmentStatistics.cs @@ -9,13 +9,15 @@ public class AlignmentStatistics : IQcModule private ulong aligned; + private ulong alignedAndPaired; + private ulong segmentUnmapped; private ulong nextSegmentUnmapped; private ulong reverseComplemented; - private ulong nextSegmenteverseComplemented; + private ulong nextSegmentReverseComplemented; private ulong nonPrimaryAlignment; @@ -33,10 +35,11 @@ public void ProcessSequence(Sequence sequence) if ((sequence.ReadFlag & ReadFlag.Paired) != 0) paired++; if ((sequence.ReadFlag & ReadFlag.Aligned) != 0) aligned++; + if ((sequence.ReadFlag & ReadFlag.AlignedAndPaired) == ReadFlag.AlignedAndPaired) alignedAndPaired++; if ((sequence.ReadFlag & ReadFlag.SegmentUnmapped) != 0) segmentUnmapped++; if ((sequence.ReadFlag & ReadFlag.NextSegmentUnmapped) != 0) nextSegmentUnmapped++; if ((sequence.ReadFlag & ReadFlag.ReverseComplemented) != 0) reverseComplemented++; - if ((sequence.ReadFlag & ReadFlag.NextSegmentReverseComplemented) != 0) nextSegmenteverseComplemented++; + if ((sequence.ReadFlag & ReadFlag.NextSegmentReverseComplemented) != 0) nextSegmentReverseComplemented++; if ((sequence.ReadFlag & ReadFlag.NotPrimaryAlignment) != 0) nonPrimaryAlignment++; if ((sequence.ReadFlag & ReadFlag.FailedQualityChecks) != 0) failedQualityChecks++; if ((sequence.ReadFlag & ReadFlag.OpticalDuplicate) != 0) opticalDuplicate++; @@ -52,10 +55,11 @@ public void Reset() sequenceCount, paired, aligned, + alignedAndPaired, segmentUnmapped, nextSegmentUnmapped, reverseComplemented, - nextSegmenteverseComplemented, + nextSegmentReverseComplemented, nonPrimaryAlignment, failedQualityChecks, opticalDuplicate diff --git a/Program.cs b/Program.cs index a502ffe..80b5bba 100644 --- a/Program.cs +++ b/Program.cs @@ -50,7 +50,7 @@ private void Run() On(Settings.ShowProgress, () => progressBar = new TimedSequenceProgressBar(sequenceReader)); On(Settings.Verbose, () => Console.Error.WriteLine($"Processing {Settings.InputFilename}...")); - while (sequenceReader.ReadSequence(out Sequence? sequence)) + while (sequenceReader.ReadSequence(out Sequence? sequence) && sequenceReader.SequencesRead < Settings.ReadLimit) { ArgumentNullException.ThrowIfNull(sequence); diff --git a/Readers/BamReader.cs b/Readers/BamReader.cs index 5c6f5a0..fd548c6 100644 --- a/Readers/BamReader.cs +++ b/Readers/BamReader.cs @@ -18,9 +18,9 @@ public class BamReader : ISequenceReader private bool disposedValue; - private int sequencesRead = 0; + private ulong sequencesRead = 0; - public int SequencesRead => sequencesRead; + public ulong SequencesRead => sequencesRead; public BamReader(string bam) { diff --git a/Readers/FastqLineReader.cs b/Readers/FastqLineReader.cs index 07efeac..1943646 100644 --- a/Readers/FastqLineReader.cs +++ b/Readers/FastqLineReader.cs @@ -18,9 +18,9 @@ public class FastqLineReader : ISequenceReader private bool disposedValue; - private int sequencesRead = 0; + private ulong sequencesRead = 0; - public int SequencesRead => sequencesRead; + public ulong SequencesRead => sequencesRead; public double ApproximateCompletion => 100.0 * inputStream.Position / inputStream.Length; diff --git a/Readers/FastqReader.cs b/Readers/FastqReader.cs index bbdca57..28bf629 100644 --- a/Readers/FastqReader.cs +++ b/Readers/FastqReader.cs @@ -17,9 +17,9 @@ public class FastqReader : ISequenceReader private bool disposedValue; - private int sequencesRead = 0; + private ulong sequencesRead = 0; - public int SequencesRead => sequencesRead; + public ulong SequencesRead => sequencesRead; public double ApproximateCompletion => 100.0 * inputStream.Position / inputStream.Length; diff --git a/Readers/SamReader.cs b/Readers/SamReader.cs index ec20c03..9e1584f 100644 --- a/Readers/SamReader.cs +++ b/Readers/SamReader.cs @@ -19,9 +19,9 @@ public class SamReader : ISequenceReader private bool disposedValue; - private int sequencesRead = 0; + private ulong sequencesRead = 0; - public int SequencesRead => sequencesRead; + public ulong SequencesRead => sequencesRead; public SamReader(string sam, bool gzipped = true) { diff --git a/Utils/CliOptions.cs b/Utils/CliOptions.cs index a5639c2..9788025 100644 --- a/Utils/CliOptions.cs +++ b/Utils/CliOptions.cs @@ -25,7 +25,10 @@ public class CliOptions public ReaderType Format { get; set; } [Option('m', "modules", Required = false, HelpText = "Space-separated list of modules to run, or 'all'.")] - public IEnumerable ModuleNames { get; set; } + public IEnumerable ModuleNames { get; set; } = Array.Empty(); + + [Option('l', "read-limit", Required = false, HelpText = "Limit the number of reads processed")] + public ulong ReadLimit { get; set; } = ulong.MaxValue; public static CliOptions Settings { get; set; } = null!; diff --git a/Utils/PrettyPrintExtension.cs b/Utils/PrettyPrintExtension.cs index 43a962f..d9fe24c 100644 --- a/Utils/PrettyPrintExtension.cs +++ b/Utils/PrettyPrintExtension.cs @@ -2,7 +2,7 @@ namespace Ovation.FasterQC.Net.Utils { public static class PrettyPrintExtension { - public static string WithSsiUnits(this int n) + public static string WithSsiUnits(this ulong n) { return n switch {