Skip to content

Commit

Permalink
fixed mqd computations
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljon committed May 19, 2022
1 parent ec7dcd3 commit 0d7b86b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"-o",
"./tmp/bob.json",
"-m",
"BasicStatistics",
"NCountsAtPosition"
"MeanQualityDistribution"
],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
Expand Down
4 changes: 3 additions & 1 deletion Modules/BasicStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace Ovation.FasterQC.Net
{
public class BasicStatistics : IQcModule
{
private const byte ILLUMINA_BASE_ADJUSTMENT = 33;

private ulong sequenceCount;

private int minimumReadLength = int.MaxValue;
Expand Down Expand Up @@ -87,7 +89,7 @@ public void Reset()
nCount,
xCount,

minimumQuality,
minimumQuality = Math.Min(minimumQuality - ILLUMINA_BASE_ADJUSTMENT, 0),

gcContent = Math.Round((double)(cCount + gCount) / (double)totalBases * 100.0, 3),

Expand Down
27 changes: 14 additions & 13 deletions Modules/MeanQualityDistribution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class MeanQualityDistribution : IQcModule
// position and fix it when someone asks
private readonly ulong[] qualityScores = new ulong[128];

private byte lowestScore = byte.MaxValue;
private uint lowestMean = uint.MaxValue;

private byte highestScore = byte.MinValue;
private uint highestMean = uint.MinValue;

public string Name => "meanQualityDistribution";

Expand All @@ -28,9 +28,9 @@ public object Data
{
return new
{
lowestScore = lowestScore - ILLUMINA_BASE_ADJUSTMENT,
highestScore = highestScore - ILLUMINA_BASE_ADJUSTMENT,
distribution = qualityScores.Skip(lowestScore).Take(highestScore - lowestScore + 1)
lowestMean = lowestMean - ILLUMINA_BASE_ADJUSTMENT,
highestMean = highestMean - ILLUMINA_BASE_ADJUSTMENT,
distribution = qualityScores.Skip((int)lowestMean).Take((int)(highestMean - lowestMean + 1))
};
}
}
Expand All @@ -43,16 +43,17 @@ public void ProcessSequence(Sequence sequence)
var count = 0;

var qual = sequence.Quality;
for (var q = 0; q < sequenceLength; q++)
for (var i = 0; i < sequenceLength; i++)
{
lowestScore = Math.Min(lowestScore, qual[q]);
highestScore = Math.Max(highestScore, qual[q]);

sum += qual[q];
sum += qual[i];
count++;
}

var mean = sum / count;
var mean = (uint)(sum / count);

lowestMean = Math.Min(lowestMean, mean);
highestMean = Math.Max(highestMean, mean);

qualityScores[mean]++;
}

Expand All @@ -63,8 +64,8 @@ public void Reset()
qualityScores[p] = 0;
}

lowestScore = byte.MaxValue;
highestScore = byte.MinValue;
lowestMean = uint.MaxValue;
highestMean = uint.MinValue;
}
}
}

0 comments on commit 0d7b86b

Please sign in to comment.