Skip to content

Commit

Permalink
Make vafThreshold an option
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Nov 11, 2015
1 parent 2a198b7 commit d61795e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/main/CoverageTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,13 @@ const SHOW_MISMATCHES = true;
// reads supporting that mismatch.
const MISMATCH_THRESHOLD = 1;

// Color the reference base in the bar chart when the Variant Allele Fraction
// exceeds this amount.
const REF_COLOR_VAF_THRESHOLD = 0.2;

/**
* Extract summary statistics from the read data.
*/
function extractSummaryStatistics(reads: Array<Alignment>,
contig: string,
referenceSource: TwoBitSource) {
referenceSource: TwoBitSource,
vafColorThreshold: number) {
var binCounts = ({}: {[key: number]: BinSummary});

// This is written in an imperative style (instead of with _.groupBy)
Expand Down Expand Up @@ -93,7 +90,9 @@ function extractSummaryStatistics(reads: Array<Alignment>,
var ref = referenceSource.getRangeAsString(
{contig, start: position - 1, stop: position - 1});
var mismatchCount = _.reduce(mismatches, (x, y) => x + y);
if (mismatchCount > REF_COLOR_VAF_THRESHOLD * count) {
var mostFrequentMismatch = _.max(mismatches);
if (mostFrequentMismatch > MISMATCH_THRESHOLD &&
mismatchCount > vafColorThreshold * count) {
mismatches[ref] = count - mismatchCount;
}
});
Expand Down Expand Up @@ -222,6 +221,9 @@ type Props = {
range: GenomeRange;
source: AlignmentDataSource;
referenceSource: TwoBitSource;
options: {
vafColorThreshold: number
}
};

type State = {
Expand All @@ -234,6 +236,7 @@ class CoverageTrack extends React.Component {
props: Props;
state: State;
tiles: CoverageTiledCanvas;
static defaultOptions: Object;

constructor(props: Props) {
super(props);
Expand All @@ -256,7 +259,11 @@ class CoverageTrack extends React.Component {
var updateState = () => {
var ci = new ContigInterval(this.props.range.contig, 0, Number.MAX_VALUE),
reads = this.props.source.getAlignmentsInRange(ci),
{binCounts, maxCoverage} = extractSummaryStatistics(reads, this.props.range.contig, this.props.referenceSource);
{binCounts, maxCoverage} = extractSummaryStatistics(
reads,
this.props.range.contig,
this.props.referenceSource,
this.props.options.vafColorThreshold);

var padding = 10; // TODO: move into style
var yScale = scale.linear()
Expand Down Expand Up @@ -346,6 +353,13 @@ class CoverageTrack extends React.Component {
}

CoverageTrack.displayName = 'coverage';
CoverageTrack.defaultOptions = {
// Color the reference base in the bar chart when the Variant Allele Fraction
// exceeds this amount. When there are >=2 agreeing mismatches, they are
// always rendered. But for mismatches below this threshold, the reference is
// not colored in the bar chart. This draws attention to high-VAF mismatches.
vafColorThreshold: 0.2
};


module.exports = CoverageTrack;

0 comments on commit d61795e

Please sign in to comment.