Skip to content

Commit

Permalink
module structure changes
Browse files Browse the repository at this point in the history
modules now express a supported reader type (or types) so that we don't
run them when there's a mismatch between source data and module (there
is at least one module that requires an aligned data source).

also made the module names case-insensitive on the command line and
check for unknown module at startup. app fails hard on any unknown
modules, but without dumping an exception or trying run the reader on an
empty module set.
  • Loading branch information
michaeljon committed May 27, 2022
1 parent 1b94999 commit d252be0
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Interfaces/IQcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public interface IQcModule

bool IsEnabledForAll { get; }

ReaderType SupportedReaders { get; }

void ProcessSequence(Sequence sequence);

void Reset();
Expand Down
1 change: 0 additions & 1 deletion Models/BamAlignment.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Text;

Expand Down
2 changes: 2 additions & 0 deletions Modules/AlignmentStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class AlignmentStatistics : IQcModule

public bool IsEnabledForAll => true;

public ReaderType SupportedReaders => ReaderType.AlignedReaders;

public string Description => "Calculates alignment statistics for SAM/BAM files";

public void ProcessSequence(Sequence sequence)
Expand Down
2 changes: 2 additions & 0 deletions Modules/BasicStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class BasicStatistics : IQcModule

public bool IsEnabledForAll => true;

public ReaderType SupportedReaders => ReaderType.AllReaders;

public void ProcessSequence(Sequence sequence)
{
var sequenceLength = sequence.Read.Length;
Expand Down
2 changes: 2 additions & 0 deletions Modules/KmerContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class KMerContent : IQcModule

public bool IsEnabledForAll => true;

public ReaderType SupportedReaders => ReaderType.AllReaders;

public object Data
{
get
Expand Down
2 changes: 2 additions & 0 deletions Modules/MeanQualityDistribution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class MeanQualityDistribution : IQcModule

public bool IsEnabledForAll => true;

public ReaderType SupportedReaders => ReaderType.AllReaders;

public object Data
{
get
Expand Down
34 changes: 25 additions & 9 deletions Modules/ModuleFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static Dictionary<string, IQcModule> ModuleMap

foreach (var module in modules)
{
moduleMap.Add(module.GetType().Name, module);
moduleMap.Add(module.GetType().Name.ToLowerInvariant(), module);
}
}

Expand All @@ -36,24 +36,40 @@ public static Dictionary<string, IQcModule> ModuleMap

public static IEnumerable<IQcModule> Create(CliOptions settings)
{
var moduleNames = new List<string>();
var modules = new List<IQcModule>();

if (settings.ModuleNames.Any() == false || settings.ModuleNames.First() == "all")
{
var moduleNames = new List<string>();
var modules = new List<IQcModule>();

foreach (var module in ModuleMap.Where(m => m.Value.IsEnabledForAll == true))
foreach (var module in ModuleMap.Where(m => m.Value.IsEnabledForAll == true && (m.Value.SupportedReaders & settings.Format) != 0))
{
moduleNames.Add(module.Key);
modules.Add(module.Value);
}

settings.ModuleNames = moduleNames;
return modules;
}
else
{
return settings.ModuleNames.Select(n => ModuleMap[n]);
foreach (var moduleName in settings.ModuleNames)
{
if (ModuleMap.ContainsKey(moduleName.ToLowerInvariant()) == false)
{
Console.Error.WriteLine($"Unknown module name {moduleName} requested.");
modules.Clear();
break;
}

var module = ModuleMap[moduleName.ToLowerInvariant()];

if (module != null)
{
moduleNames.Add(moduleName);
modules.Add(module);
}
}
}

settings.ModuleNames = moduleNames;
return modules;
}
}
}
2 changes: 2 additions & 0 deletions Modules/NCountsAtPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class NCountsAtPosition : IQcModule

public bool IsEnabledForAll => true;

public ReaderType SupportedReaders => ReaderType.AllReaders;

public object Data
{
get
Expand Down
2 changes: 2 additions & 0 deletions Modules/NullProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class NullProcessor : IQcModule

public bool IsEnabledForAll => false;

public ReaderType SupportedReaders => ReaderType.AllReaders;

public object Data => sequenceCount;

public void ProcessSequence(Sequence sequence)
Expand Down
2 changes: 2 additions & 0 deletions Modules/PerPositionQuality.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class PerPositionQuality : IQcModule

public bool IsEnabledForAll => true;

public ReaderType SupportedReaders => ReaderType.AllReaders;

public object Data
{
get
Expand Down
2 changes: 2 additions & 0 deletions Modules/PerPositionSequenceContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class PerPositionSequenceContent : IQcModule

public string Description => "Calculates ATCG counts at position along sequence";

public ReaderType SupportedReaders => ReaderType.AllReaders;

public bool IsEnabledForAll => true;

public object Data
Expand Down
2 changes: 2 additions & 0 deletions Modules/PerSequenceGcContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class PerSequenceGcContent : IQcModule

public bool IsEnabledForAll => true;

public ReaderType SupportedReaders => ReaderType.AllReaders;

public object Data => gcCounts.Select(a => Math.Round((double)a / (double)sequenceCount * 100.0, 3));

public void ProcessSequence(Sequence sequence)
Expand Down
2 changes: 2 additions & 0 deletions Modules/PolyX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class PolyX : IQcModule

public bool IsEnabledForAll => true;

public ReaderType SupportedReaders => ReaderType.AllReaders;

public object Data
{
get
Expand Down
2 changes: 2 additions & 0 deletions Modules/QualityDistribution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class QualityDistribution : IQcModule

public bool IsEnabledForAll => true;

public ReaderType SupportedReaders => ReaderType.AllReaders;

public object Data
{
get
Expand Down
2 changes: 2 additions & 0 deletions Modules/QualityDistributionByBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class QualityDistributionByBase : IQcModule

public bool IsEnabledForAll => true;

public ReaderType SupportedReaders => ReaderType.AllReaders;

public object Data
{
get
Expand Down
2 changes: 2 additions & 0 deletions Modules/SequenceLengthDistribution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class SequenceLengthDistribution : IQcModule

public bool IsEnabledForAll => true;

public ReaderType SupportedReaders => ReaderType.AllReaders;

public object Data
{
get
Expand Down
7 changes: 7 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using CommandLine;
Expand Down Expand Up @@ -72,6 +73,12 @@ private void Run()
using ISequenceReader? sequenceReader = ReaderFactory.Create(Settings);
IEnumerable<IQcModule>? modules = ModuleFactory.Create(Settings);

if (modules.Any() == false)
{
Console.Error.WriteLine($"No modules matched or at least one unknown module requested.");
return;
}

Console.Error.WriteLine($"Running modules:\n {string.Join("\n ", Settings.ModuleNames)}");

On(Settings.ShowProgress, () => progressBar = new TimedSequenceProgressBar(sequenceReader));
Expand Down
19 changes: 14 additions & 5 deletions Readers/ReaderType.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
using System;

namespace Ovation.FasterQC.Net
{
[Flags]
public enum ReaderType
{
Fastq,
Fastq = 1,

FastqGz = 2,

UnalignedReaders = Fastq | FastqGz,

Sam = 4,

FastqGz,
SamGz = 8,

Sam,
Bam = 16,

SamGz,
AlignedReaders = Sam | SamGz | Bam,

Bam
AllReaders = UnalignedReaders | AlignedReaders
}
}

0 comments on commit d252be0

Please sign in to comment.