diff --git a/exomiser-core/src/main/java/org/monarchinitiative/exomiser/core/model/Gene.java b/exomiser-core/src/main/java/org/monarchinitiative/exomiser/core/model/Gene.java index 36b2e9f82..b65f94c8c 100644 --- a/exomiser-core/src/main/java/org/monarchinitiative/exomiser/core/model/Gene.java +++ b/exomiser-core/src/main/java/org/monarchinitiative/exomiser/core/model/Gene.java @@ -359,12 +359,22 @@ public List getGeneScores() { * @return A list of {@link GeneScore} with a compatible mode of inheritance. */ public List 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 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() diff --git a/exomiser-core/src/main/java/org/monarchinitiative/exomiser/core/writers/AnalysisResultsWriter.java b/exomiser-core/src/main/java/org/monarchinitiative/exomiser/core/writers/AnalysisResultsWriter.java index 77ce448e4..71edc76fa 100644 --- a/exomiser-core/src/main/java/org/monarchinitiative/exomiser/core/writers/AnalysisResultsWriter.java +++ b/exomiser-core/src/main/java/org/monarchinitiative/exomiser/core/writers/AnalysisResultsWriter.java @@ -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} diff --git a/exomiser-core/src/test/java/org/monarchinitiative/exomiser/core/model/GeneTest.java b/exomiser-core/src/test/java/org/monarchinitiative/exomiser/core/model/GeneTest.java index 84e7254d1..d72804447 100644 --- a/exomiser-core/src/test/java/org/monarchinitiative/exomiser/core/model/GeneTest.java +++ b/exomiser-core/src/test/java/org/monarchinitiative/exomiser/core/model/GeneTest.java @@ -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))); + } }