Skip to content

Commit

Permalink
Fix for issue #481 where TSV and VCF results files would contain no d…
Browse files Browse the repository at this point in the history
…ata when the analysis `inheritanceModes` was empty.
  • Loading branch information
julesjacobsen committed Jun 30, 2023
1 parent 4135cbd commit d31cf8f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,12 +359,22 @@ public List<GeneScore> getGeneScores() {
* @return A list of {@link GeneScore} with a compatible mode of inheritance.
*/
public List<GeneScore> getCompatibleGeneScores() {
return this.geneScoreMap.entrySet().stream()
.filter(entry -> this.inheritanceModes.contains(entry.getKey()))
// An explanation about the logic here: If the Analysis.inheritanceModes is empty or no MOI dependent analysis
// step has been run the (compatible) inheritanceModes will be empty. The GeneScorer will always give a gene a
// GeneScore but in this case it will have an MOI.ANY. So, in the case that no compatible inheritanceModes are
// present, the ANY GeneScore should be returned here otherwise the ResultsWriters relying on this method
// (TSV and VCF) will return empty data. See issue https://github.com/exomiser/Exomiser/issues/481
return inheritanceModes.isEmpty() ? anyMoiScoreOrEmptyList() : geneScoreMap.entrySet().stream()
.filter(entry -> inheritanceModes.contains(entry.getKey()))
.map(Map.Entry::getValue)
.collect(Collectors.toUnmodifiableList());
}

private List<GeneScore> anyMoiScoreOrEmptyList() {
GeneScore geneScore = geneScoreMap.get(ModeOfInheritance.ANY);
return geneScore != null ? List.of(geneScore) : List.of();
}

public GeneScore getGeneScoreForMode(ModeOfInheritance modeOfInheritance) {
Objects.requireNonNull(modeOfInheritance);
return geneScoreMap.getOrDefault(modeOfInheritance, GeneScore.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@

package org.monarchinitiative.exomiser.core.writers;

import de.charite.compbio.jannovar.mendel.ModeOfInheritance;
import org.monarchinitiative.exomiser.api.v1.OutputProto;
import org.monarchinitiative.exomiser.core.analysis.Analysis;
import org.monarchinitiative.exomiser.core.analysis.AnalysisResults;
import org.monarchinitiative.exomiser.core.analysis.util.InheritanceModeOptions;
import org.monarchinitiative.exomiser.core.model.Gene;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;
import java.util.Collections;

/**
* Facade for handling writing out {@link org.monarchinitiative.exomiser.core.analysis.AnalysisResults}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,31 @@ public void testGetCompatibleGeneScores() throws Exception {
.addMixIn(Variant.class, JsonVariantMixin.class)
.setDefaultPropertyInclusion(JsonInclude.Include.NON_DEFAULT)
.writerWithDefaultPrettyPrinter();
System.out.println(objectWriter.writeValueAsString(instance));

assertThat(instance.getCompatibleInheritanceModes(), equalTo(Set.of(ModeOfInheritance.AUTOSOMAL_DOMINANT)));
assertThat(instance.getCompatibleGeneScores(), equalTo(List.of(adGeneScore)));
}

@Test
public void testGetCompatibleGeneScoresNoCompatibleMoi() throws Exception {
Gene instance = TestFactory.newGeneFGFR2();
// Hmm... this is a bit of a WFT - why does this need to be set rather than computed from the variants?
// ... because it gets set once by the InheritanceModeAnalyser after all the variants have been filtered
// instance.setCompatibleInheritanceModes(EnumSet.of(ModeOfInheritance.AUTOSOMAL_DOMINANT));
assertThat(instance.getCompatibleGeneScores().isEmpty(), is(true));

GeneScore anyGeneScore = GeneScore.builder()
.geneIdentifier(instance.getGeneIdentifier())
.modeOfInheritance(ModeOfInheritance.ANY)
.phenotypeScore(0.5d)
.variantScore(0.5d)
.combinedScore(0.5d)
.pValue(0.0000001)
.build();

instance.addGeneScore(anyGeneScore);

assertThat(instance.getCompatibleInheritanceModes().isEmpty(), is(true));
assertThat(instance.getCompatibleGeneScores(), equalTo(List.of(anyGeneScore)));
}
}

0 comments on commit d31cf8f

Please sign in to comment.