Skip to content

Commit

Permalink
feat: tweak parameters of QC rules. remove unused config values
Browse files Browse the repository at this point in the history
  • Loading branch information
rneher committed Aug 21, 2020
1 parent 8d49eee commit b78b143
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 22 deletions.
9 changes: 3 additions & 6 deletions packages/web/src/algorithms/QC/ruleMixedSites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import type { AnalysisResult, NucleotideSubstitution } from 'src/algorithms/type

export interface QCRulesConfigMixedSites {
mixedSitesThreshold: number
scoreWeight: number
scoreBias: number
scoreMax: number
}

export function ruleMixedSites(
{ nucleotideComposition }: AnalysisResult,
_1: NucleotideSubstitution[],
{ mixedSitesThreshold, scoreWeight, scoreBias, scoreMax }: QCRulesConfigMixedSites,
{ mixedSitesThreshold, scoreMax }: QCRulesConfigMixedSites,
) {
const goodBases = new Set(['A', 'C', 'G', 'T', 'N', '-'])

Expand All @@ -21,9 +19,8 @@ export function ruleMixedSites(
.reduce((a, b) => a + nucleotideComposition[b], 0)

let scoreRaw = 0
if (totalMixedSites > mixedSitesThreshold) {
scoreRaw = (totalMixedSites - mixedSitesThreshold) * scoreWeight - scoreBias
}
scoreRaw = 100 * (totalMixedSites / mixedSitesThreshold)

const score = clamp(scoreRaw, 0, scoreMax)

return { score, totalMixedSites, mixedSitesThreshold }
Expand Down
11 changes: 4 additions & 7 deletions packages/web/src/algorithms/QC/ruleSnpClusters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ export function processSNPClusters(snpClusters: number[][]): ClusteredSNPs[] {
export interface QCRulesConfigSNPClusters {
windowSize: number
clusterCutOff: number
totalSNPsThreshold: number
scoreWeight: number
scoreBias: number
scoreMax: number
}

Expand All @@ -62,19 +60,18 @@ export function ruleSnpClusters(
privateMutations: NucleotideSubstitution[],
config: QCRulesConfigSNPClusters,
) {
const { totalSNPsThreshold, scoreWeight, scoreBias, scoreMax } = config
const { scoreWeight, scoreMax } = config

const snpClusters = findSNPClusters(data, privateMutations, config)
const clusteredSNPs = processSNPClusters(snpClusters)
const totalSNPs = clusteredSNPs.reduce((acc, { numberOfSNPs }) => acc + numberOfSNPs, 0)

let scoreRaw = 0
if (totalSNPs > totalSNPsThreshold) {
scoreRaw = (totalSNPs - totalSNPsThreshold) * scoreWeight - scoreBias
}
scoreRaw = snpClusters.length * scoreWeight

const score = clamp(scoreRaw, 0, scoreMax)

return { score, totalSNPs, totalSNPsThreshold, clusteredSNPs }
return { score, totalSNPs, clusteredSNPs }
}

export type QCResultSNPClusters = ReturnType<typeof ruleSnpClusters>
6 changes: 1 addition & 5 deletions packages/web/src/algorithms/QC/runQC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@ const qcRulesConfigDefault: QCRulesConfig = {
},
snpClusters: {
enabled: true,
totalSNPsThreshold: 0,
windowSize: 100, // window along the genome to look for a cluster
clusterCutOff: 4, // number of mutations within that window to trigger a cluster
scoreWeight: 1,
scoreBias: 0,
scoreWeight: 50, // each cluster counts for 50
scoreMax: Infinity,
},
mixedSites: {
enabled: true,
mixedSitesThreshold: 10, // number of non-ACGTN sites to trigger warning
scoreWeight: 1,
scoreBias: 0,
scoreMax: Infinity,
},
} as const
Expand Down
3 changes: 2 additions & 1 deletion packages/web/src/helpers/formatQCMixedSites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export function formatQCMixedSites<TFunction extends TFunctionInterface>(
}

const { score, totalMixedSites, mixedSitesThreshold } = mixedSites
return t('Too many mixed sites: Total mixed: {{total}} ({{allowed}} allowed). QC score: {{score}}', {
return t('{{warn}} mixed sites: Total mixed: {{total}} ({{allowed}} allowed). QC score: {{score}}', {
warn: score > 100 ? 'Too many' : 'Found',
total: totalMixedSites,
allowed: mixedSitesThreshold,
score: round(score),
Expand Down
6 changes: 3 additions & 3 deletions packages/web/src/helpers/formatQCSNPClusters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export function formatQCSNPClusters<TFunction extends TFunctionInterface>(
return undefined
}

const { score, totalSNPs, totalSNPsThreshold } = snpClusters
return t('Too many SNP clusters. Total clusters: {{total}} ({{allowed}} allowed). QC score: {{score}}', {
const { score, totalSNPs } = snpClusters
return t('Found {{nClusters}} SNP clusters with total of {{total}} mutations. QC score: {{score}}', {
total: totalSNPs,
allowed: totalSNPsThreshold,
nClusters: snpClusters.clusteredSNPs.length,
score: round(score),
})
}

0 comments on commit b78b143

Please sign in to comment.