diff --git a/.gitignore b/.gitignore index 81b3fc9..bf6fcdf 100644 --- a/.gitignore +++ b/.gitignore @@ -13,7 +13,4 @@ obj/ !.vscode/launch.json !.vscode/extensions.json -results.json - -*.gz -*.bam +tmp/* diff --git a/Modules/AlignmentStatistics.cs b/Modules/AlignmentStatistics.cs new file mode 100644 index 0000000..994f7f7 --- /dev/null +++ b/Modules/AlignmentStatistics.cs @@ -0,0 +1,64 @@ + +namespace Ovation.FasterQC.Net +{ + public class AlignmentStatistics : IQcModule + { + private ulong sequenceCount; + + private ulong paired; + + private ulong aligned; + + private ulong segmentUnmapped; + + private ulong nextSegmentUnmapped; + + private ulong reverseComplemented; + + private ulong nextSegmenteverseComplemented; + + private ulong nonPrimaryAlignment; + + private ulong failedQualityChecks; + + private ulong opticalDuplicate; + + public string Name => "alignmentStatistics"; + + public string Description => "Calculates alignment statistics for SAM/BAM files"; + + public void ProcessSequence(Sequence sequence) + { + sequenceCount++; + + if ((sequence.ReadFlag & ReadFlag.Paired) != 0) paired++; + if ((sequence.ReadFlag & ReadFlag.Aligned) != 0) aligned++; + 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.NotPrimaryAlignment) != 0) nonPrimaryAlignment++; + if ((sequence.ReadFlag & ReadFlag.FailedQualityChecks) != 0) failedQualityChecks++; + if ((sequence.ReadFlag & ReadFlag.OpticalDuplicate) != 0) opticalDuplicate++; + } + + public void Reset() + { + sequenceCount = 0; + } + + public object Data => new + { + sequenceCount, + paired, + aligned, + segmentUnmapped, + nextSegmentUnmapped, + reverseComplemented, + nextSegmenteverseComplemented, + nonPrimaryAlignment, + failedQualityChecks, + opticalDuplicate + }; + } +} \ No newline at end of file diff --git a/Modules/ModuleFactory.cs b/Modules/ModuleFactory.cs index 13ea7b3..6f70f5a 100644 --- a/Modules/ModuleFactory.cs +++ b/Modules/ModuleFactory.cs @@ -8,6 +8,7 @@ public static class ModuleFactory { private static readonly Dictionary moduleMap = new() { + ["AlignmentStatistics"] = new AlignmentStatistics(), ["BasicStatistics"] = new BasicStatistics(), ["KMerContent"] = new KMerContent(), ["NCountsAtPosition"] = new NCountsAtPosition(),