Skip to content

Commit

Permalink
adding read limiter... for dev speed
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljon committed May 18, 2022
1 parent 664dab1 commit 8cb8113
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Interfaces/ISequenceReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Ovation.FasterQC.Net
{
public interface ISequenceReader : IDisposable
{
int SequencesRead { get; }
ulong SequencesRead { get; }

bool ReadSequence(out Sequence? sequence);

Expand Down
2 changes: 2 additions & 0 deletions Models/ReadFlag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public enum ReadFlag : ushort
/// </summary>
Aligned = 2,

AlignedAndPaired = Aligned | Paired,

/// <summary>
/// segment unmapped (read1 unmapped)
/// </summary>
Expand Down
10 changes: 7 additions & 3 deletions Modules/AlignmentStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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++;
Expand All @@ -52,10 +55,11 @@ public void Reset()
sequenceCount,
paired,
aligned,
alignedAndPaired,
segmentUnmapped,
nextSegmentUnmapped,
reverseComplemented,
nextSegmenteverseComplemented,
nextSegmentReverseComplemented,
nonPrimaryAlignment,
failedQualityChecks,
opticalDuplicate
Expand Down
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions Readers/BamReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions Readers/FastqLineReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Readers/FastqReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Readers/SamReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
5 changes: 4 additions & 1 deletion Utils/CliOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> ModuleNames { get; set; }
public IEnumerable<string> ModuleNames { get; set; } = Array.Empty<string>();

[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!;

Expand Down
2 changes: 1 addition & 1 deletion Utils/PrettyPrintExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 8cb8113

Please sign in to comment.