Skip to content

Commit

Permalink
Refactor RawScoreGeneScorer to require AcmgAssignmentCalculator
Browse files Browse the repository at this point in the history
Merge changes from PvalueGeneScorer into RawScoreGeneScorer
Delete PvalueGeneScorer.java
Update VariantDataService to extend ClinVarDao (a bit ikky, but there you go)
  • Loading branch information
julesjacobsen committed Feb 23, 2024
1 parent 1e3ea65 commit e7d0089
Show file tree
Hide file tree
Showing 14 changed files with 349 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.monarchinitiative.exomiser.core.analysis.sample.PedigreeSampleValidator;
import org.monarchinitiative.exomiser.core.analysis.sample.Sample;
import org.monarchinitiative.exomiser.core.analysis.util.*;
import org.monarchinitiative.exomiser.core.analysis.util.acmg.*;
import org.monarchinitiative.exomiser.core.filters.*;
import org.monarchinitiative.exomiser.core.genome.*;
import org.monarchinitiative.exomiser.core.model.*;
Expand All @@ -40,7 +41,6 @@
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.stream.Collectors.toConcurrentMap;
Expand Down Expand Up @@ -129,9 +129,7 @@ public AnalysisResults run(Sample sample, Analysis analysis) {

// If no variant steps have been run and there is a VCF present, don't load it here - See issues #129, #478
List<Gene> genesToScore = variantsLoaded ? getGenesWithVariants(allGenes) : allGenes.values().stream().filter(genesToScore()).toList();
// Temporarily add a new PValueGeneScorer so as not to break semver will revert to RawScoreGeneScorer in 14.0.0
CombinedScorePvalueCalculator combinedScorePvalueCalculator = buildCombinedScorePvalueCalculator(sample, analysis, genesToScore.size());
GeneScorer geneScorer = new PvalueGeneScorer(probandIdentifier, sample.getSex(), inheritanceModeAnnotator, combinedScorePvalueCalculator);
GeneScorer geneScorer = buildGeneScorer(sample, analysis, genesToScore, probandIdentifier, inheritanceModeAnnotator);

logger.info("Scoring genes");
List<Gene> genes = geneScorer.scoreGenes(genesToScore);
Expand All @@ -154,6 +152,15 @@ public AnalysisResults run(Sample sample, Analysis analysis) {
return analysisResults;
}

private GeneScorer buildGeneScorer(Sample sample, Analysis analysis, List<Gene> genesToScore, String probandIdentifier, InheritanceModeAnnotator inheritanceModeAnnotator) {
CombinedScorePvalueCalculator combinedScorePvalueCalculator = buildCombinedScorePvalueCalculator(sample, analysis, genesToScore.size());

AcmgEvidenceAssigner acmgEvidenceAssigner = new Acmg2015EvidenceAssigner(probandIdentifier, inheritanceModeAnnotator.getPedigree(), genomeAnalysisService);
AcmgAssignmentCalculator acmgAssignmentCalculator = new AcmgAssignmentCalculator(acmgEvidenceAssigner, new Acmg2020PointsBasedClassifier());

return new RawScoreGeneScorer(probandIdentifier, sample.getSex(), inheritanceModeAnnotator, combinedScorePvalueCalculator, acmgAssignmentCalculator);
}

private List<FilterResultCount> collectFilterCounts(List<AnalysisStep> analysisSteps) {
// build filter counts
List<FilterType> filterStepTypes = analysisSteps.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,18 @@ protected List<VariantEvaluation> findContributingVariantsForInheritanceMode(Mod
//It is critical only the PASS variants are used in the scoring
.filter(VariantEvaluation::passedFilters)
.filter(variantEvaluation -> variantEvaluation.isCompatibleWith(modeOfInheritance))
.collect(toUnmodifiableList());
.toList();
//note these need to be filtered for the relevant ModeOfInheritance before being checked for the contributing variants
if (variantsCompatibleWithMode.isEmpty()) {
return variantsCompatibleWithMode;
}
switch (modeOfInheritance) {
case AUTOSOMAL_RECESSIVE:
return findAutosomalRecessiveContributingVariants(modeOfInheritance, variantsCompatibleWithMode);
case X_RECESSIVE:
return findXRecessiveContributingVariants(modeOfInheritance, variantsCompatibleWithMode);
case ANY:
return findIncompletePenetranceContributingVariants(modeOfInheritance, variantsCompatibleWithMode);
default:
return findNonAutosomalRecessiveContributingVariants(modeOfInheritance, variantsCompatibleWithMode);
}
return switch (modeOfInheritance) {
case AUTOSOMAL_RECESSIVE ->
findAutosomalRecessiveContributingVariants(modeOfInheritance, variantsCompatibleWithMode);
case X_RECESSIVE -> findXRecessiveContributingVariants(modeOfInheritance, variantsCompatibleWithMode);
case ANY -> findIncompletePenetranceContributingVariants(modeOfInheritance, variantsCompatibleWithMode);
default -> findNonAutosomalRecessiveContributingVariants(modeOfInheritance, variantsCompatibleWithMode);
};

}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class RawScoreGeneScorer implements GeneScorer {
private final ContributingAlleleCalculator contributingAlleleCalculator;
private final GenePriorityScoreCalculator genePriorityScoreCalculator;

private final CombinedScorePvalueCalculator pValueCalculator;
private final AcmgAssignmentCalculator acmgAssignmentCalculator;

/**
Expand All @@ -63,25 +64,27 @@ public class RawScoreGeneScorer implements GeneScorer {
* @throws NullPointerException if any input arguments are null.
* @since 10.0.0
*/
public RawScoreGeneScorer(String probandId, Sex probandSex, InheritanceModeAnnotator inheritanceModeAnnotator) {
public RawScoreGeneScorer(String probandId, Sex probandSex, InheritanceModeAnnotator inheritanceModeAnnotator, CombinedScorePvalueCalculator pValueCalculator, AcmgAssignmentCalculator acmgAssignmentCalculator) {
Objects.requireNonNull(probandId);
Objects.requireNonNull(inheritanceModeAnnotator);
this.inheritanceModes = inheritanceModeAnnotator.getDefinedModes();
this.contributingAlleleCalculator = new ContributingAlleleCalculator(probandId, probandSex, inheritanceModeAnnotator);
this.genePriorityScoreCalculator = new GenePriorityScoreCalculator();
AcmgEvidenceAssigner acmgEvidenceAssigner = new Acmg2015EvidenceAssigner(probandId, inheritanceModeAnnotator.getPedigree());
AcmgEvidenceClassifier acmgEvidenceClassifier = new Acmg2020PointsBasedClassifier();
this.acmgAssignmentCalculator = new AcmgAssignmentCalculator(acmgEvidenceAssigner, acmgEvidenceClassifier);
this.pValueCalculator = Objects.requireNonNull(pValueCalculator);
this.acmgAssignmentCalculator = Objects.requireNonNull(acmgAssignmentCalculator);
}

@Override
public List<Gene> scoreGenes(List<Gene> genes) {
for (Gene gene : genes) {
List<GeneScore> geneScores = scoreGene().apply(gene);
gene.addGeneScores(geneScores);
}
Collections.sort(genes);
return genes;
return genes.stream()
.parallel()
.map(gene -> {
List<GeneScore> geneScores = scoreGene().apply(gene);
gene.addGeneScores(geneScores);
return gene;
})
.sorted()
.toList();
}

/**
Expand Down Expand Up @@ -122,23 +125,31 @@ private GeneScore calculateGeneScore(Gene gene, ModeOfInheritance modeOfInherita

GenePriorityScoreCalculator.GenePriorityScore priorityScore = genePriorityScoreCalculator.calculateGenePriorityScore(gene, modeOfInheritance);

List<ModelPhenotypeMatch<Disease>> compatibleDiseaseMatches = priorityScore.getCompatibleDiseaseMatches();

List<AcmgAssignment> acmgAssignments = acmgAssignmentCalculator.calculateAcmgAssignments(modeOfInheritance, gene, contributingVariants, compatibleDiseaseMatches);

// double variantScore = acmgAssignments.stream()
// .mapToDouble(acmgAssignment -> acmgAssignment.acmgEvidence().postProbPath())
// .average()
// .orElse(0.1); // 0.1 is the equivalent of a 0-point VUS

double variantScore = contributingVariants.stream()
.mapToDouble(VariantEvaluation::getVariantScore)
.average()
.orElse(0);

double combinedScore = GeneScorer.calculateCombinedScore(variantScore, priorityScore.getScore(), gene.getPriorityResults().keySet());

List<ModelPhenotypeMatch<Disease>> compatibleDiseaseMatches = priorityScore.getCompatibleDiseaseMatches();

List<AcmgAssignment> acmgAssignments = acmgAssignmentCalculator.calculateAcmgAssignments(modeOfInheritance, gene, contributingVariants, compatibleDiseaseMatches);
double pValue = pValueCalculator.calculatePvalueFromCombinedScore(combinedScore);

return GeneScore.builder()
.geneIdentifier(gene.getGeneIdentifier())
.modeOfInheritance(modeOfInheritance)
.variantScore(variantScore)
.phenotypeScore(priorityScore.getScore())
.combinedScore(combinedScore)
.pValue(pValue)
.contributingVariants(contributingVariants)
// TODO this would be a good place to put a contributingModel
// i.e. from HiPhivePrioritiserResult see issue #363
Expand Down
Loading

0 comments on commit e7d0089

Please sign in to comment.