Skip to content

Commit

Permalink
Merge pull request #11 from michaeljon/issue-9
Browse files Browse the repository at this point in the history
issue-9: add sam/bam stats
  • Loading branch information
michaeljon authored May 18, 2022
2 parents d96134e + 2df4fc5 commit 664dab1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
5 changes: 1 addition & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ obj/
!.vscode/launch.json
!.vscode/extensions.json

results.json

*.gz
*.bam
tmp/*
64 changes: 64 additions & 0 deletions Modules/AlignmentStatistics.cs
Original file line number Diff line number Diff line change
@@ -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
};
}
}
1 change: 1 addition & 0 deletions Modules/ModuleFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class ModuleFactory
{
private static readonly Dictionary<string, IQcModule> moduleMap = new()
{
["AlignmentStatistics"] = new AlignmentStatistics(),
["BasicStatistics"] = new BasicStatistics(),
["KMerContent"] = new KMerContent(),
["NCountsAtPosition"] = new NCountsAtPosition(),
Expand Down

0 comments on commit 664dab1

Please sign in to comment.