Skip to content

Commit

Permalink
Merge pull request #15 from molgenis/feat/fixAllelicDepth
Browse files Browse the repository at this point in the history
Fix allelic balance calculation for empty AD
  • Loading branch information
dennishendriksen authored Oct 24, 2022
2 parents e2f6120 + 66bd98a commit e6dfc29
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/SampleDataParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,18 @@ export function parseFormatValue(token: string, formatMetadata: FieldMetadata):
return value;
}

export function calculateAlleleBalance(allelicDepth: number[]): ValueInteger {
const total = allelicDepth.reduce((x, y) => x + y);
return total != 0 ? allelicDepth[0] / total : null;
/**
* Calculate allele balance: allele depth of first allele divided by total allele depth
*
* @param allelicDepths allele depth values with each value an integer or null
* @return allele balance or null if 1) allele depth array contains a null value 2) total allele depth is zero
*/
export function calculateAlleleBalance(allelicDepths: ValueInteger[]): ValueInteger {
if (allelicDepths.includes(null)) {
return null;
}
const total = (allelicDepths as number[]).reduce((x, y) => x + y);
return total != 0 ? (allelicDepths as number[])[0] / total : null;
}

export function parseGenotype(token: string): Genotype {
Expand Down

0 comments on commit e6dfc29

Please sign in to comment.