AnalysisParser { public Analysis parseAnalysis(Path analysisScript) { Map settingsMap = loadMap(analysisScript); return constructAnalysisFromMap(settingsMap); } @Autowired  AnalysisParser(GenomeAnalysisServiceProvider genomeAnalysisServiceProvider, PriorityFactory prioritiserFactory, OntologyService ontologyService); Analysis parseAnalysis(Path analysisScript); Analysis parseAnalysis(String analysisDoc); OutputSettings parseOutputSettings(Path analysisScript); OutputSettings parseOutputSettings(String analysisDoc);  }
@Test public void testParseAnalysisStepsNoSteps() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("")); System.out.println(analysis); assertThat(analysis.getVcfPath(), equalTo(Paths.get("test.vcf"))); assertThat(analysis.getPedigree(), equalTo(Pedigree.empty())); assertThat(analysis.getProbandSampleName(), equalTo("")); assertThat(analysis.getInheritanceModeOptions(), equalTo(InheritanceModeOptions.defaults())); assertThat(analysis.getHpoIds(), equalTo(hpoIds)); assertThat(analysis.getAnalysisMode(), equalTo(AnalysisMode.PASS_ONLY)); assertThat(analysis.getFrequencySources(), equalTo(frequencySources)); assertThat(analysis.getPathogenicitySources(), equalTo(pathogenicitySources)); assertThat(analysis.getAnalysisSteps().isEmpty(), is(true)); }
@Test public void throwsExceptionWhenNoVcfIsSet() { assertThrows(AnalysisParserException.class, () -> instance.parseAnalysis( "analysis:\n" + " vcf: \n" )); }
@Test public void testParseAnalysisPedPathSpecified() { Analysis analysis = instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " ped: " + TestPedigrees.trioWithChildAffectedPedPath() +"\n" + " "); assertThat(analysis.getPedigree(), equalTo(TestPedigrees.trioChildAffected())); }
@Test public void testParseAnalysisPedPathEmpty() { Analysis analysis = instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " ped: ''\n" + " "); assertThat(analysis.getPedigree(), equalTo(Pedigree.empty())); }
@Test public void testParseAnalysisProbandSampleNameSpecified() { Analysis analysis = instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " proband: Bod \n" + " "); assertThat(analysis.getProbandSampleName(), equalTo("Bod")); }
@Test public void testParseAnalysisFullAnalysisMode() { Analysis analysis = instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " analysisMode: FULL \n" + " "); assertThat(analysis.getAnalysisMode(), equalTo(AnalysisMode.FULL)); }
@Test public void testParseAnalysisPassOnlyAnalysisMode() { Analysis analysis = instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " analysisMode: PASS_ONLY \n" + " "); assertThat(analysis.getAnalysisMode(), equalTo(AnalysisMode.PASS_ONLY)); }
@Test public void testParseAnalysisSparseAnalysisModeReturnsPassOnlyDefault() { Analysis analysis = instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " analysisMode: SPARSE \n" + " "); assertThat(analysis.getAnalysisMode(), equalTo(AnalysisMode.PASS_ONLY)); }
@Test public void testParseAnalysisNotSettingGenomeBuildReturnsDefault() { Analysis analysis = instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " "); assertThat(analysis.getGenomeAssembly(), equalTo(GenomeAssembly.defaultBuild())); }
@Test public void testParseAnalysisThrowsExceptionForUnsupportedGenomeBuild() { assertThrows(UnsupportedGenomeAssemblyException.class, () -> instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " genomeAssembly: hg38\n" + " ") ); }
@Test public void testParseAnalysisCanSetAlternativeGenomeAssemblyUsingUcscName() { AnalysisParser hg19And38SupportedParser = getHg19and38SupportedParser(); Analysis hg38Analysis = hg19And38SupportedParser.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " genomeAssembly: hg38\n" + " "); assertThat(hg38Analysis.getGenomeAssembly(), equalTo(GenomeAssembly.HG38)); Analysis hg19Analysis = hg19And38SupportedParser.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " genomeAssembly: hg19\n" + " "); assertThat(hg19Analysis.getGenomeAssembly(), equalTo(GenomeAssembly.HG19)); }
@Test public void testParseAnalysisCanSetGenomeBuildUsingGrcName() { Analysis analysis = instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " genomeAssembly: GRCh37\n" + " "); assertThat(analysis.getGenomeAssembly(), equalTo(GenomeAssembly.HG19)); }
@Test public void testParseAnalysisUnrecognisedGenomeBuild() { assertThrows(GenomeAssembly.InvalidGenomeAssemblyException.class, () -> instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " genomeAssembly: invalid\n" + " ") ); }
@Test public void testParseAnalysisModeOfInheritanceAutosomalDominant() { Analysis analysis = instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " inheritanceModes: {\n" + " AUTOSOMAL_DOMINANT: 0.1 \n" + "}\n" + " "); Map<SubModeOfInheritance, Float> options = ImmutableMap.of(SubModeOfInheritance.AUTOSOMAL_DOMINANT, 0.1f); assertThat(analysis.getInheritanceModeOptions(), equalTo(InheritanceModeOptions.of(options))); }
@Test public void testParseAnalysisModeOfInheritanceMultipleModes() { Analysis analysis = instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " inheritanceModes: {\n" + " AUTOSOMAL_DOMINANT: 0.1,\n" + " ANY: 0.1 \n" + "}\n" + " "); Map<SubModeOfInheritance, Float> options = ImmutableMap.of( SubModeOfInheritance.AUTOSOMAL_DOMINANT, 0.1f, SubModeOfInheritance.ANY, 0.1f ); assertThat(analysis.getInheritanceModeOptions(), equalTo(InheritanceModeOptions.of(options))); }
@Test public void testParseAnalysisOldModeOfInheritanceConvertsToInheritanceModes() { Analysis analysis = instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " modeOfInheritance: AUTOSOMAL_DOMINANT\n" + " "); assertThat(analysis.getInheritanceModeOptions(), equalTo(InheritanceModeOptions.defaultForModes(ModeOfInheritance.AUTOSOMAL_DOMINANT))); }
@Test public void testParseAnalysisModeOfInheritanceUserUsesWrongValue() { assertThrows(AnalysisParserException.class, () -> instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " modeOfInheritance: AD\n" ) ); }
@Test public void testParseAnalysisDeprecatedGeneScoreModeHasNoEffect() { Analysis analysis = instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " geneScoreMode: RAWSCORE\n" ); Analysis expected = Analysis.builder().vcfPath(Paths.get("test.vcf")).build(); assertThat(analysis, equalTo(expected)); }
@Test public void testParseAnalysisStepUnsupportedFilterAddsNothingToAnalysisSteps() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("wibbleFilter: {}")); assertThat(analysis.getAnalysisSteps().isEmpty(), is(true)); }
@Test public void testParseAnalysisStepFailedVariantFilter() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("failedVariantFilter: {}")); analysisSteps.add(new FailedVariantFilter()); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepRegulatoryFeatureFilter() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("regulatoryFeatureFilter: {}")); analysisSteps.add(new RegulatoryFeatureFilter()); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepIntervalFilterFromInterval() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("intervalFilter: {interval: 'chr10:122892600-122892700'}")); analysisSteps.add(new IntervalFilter(new GeneticInterval(10, 122892600, 122892700))); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepIntervalFilterFromList() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("intervalFilter: {intervals: ['chr10:122892600-122892700', 'chr10:122892900-122893000']}")); List<ChromosomalRegion> expectedIntervals = ImmutableList.of( new GeneticInterval(10, 122892600, 122892700), new GeneticInterval(10, 122892900, 122893000) ); analysisSteps.add(new IntervalFilter(expectedIntervals)); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepIntervalFilterFromBedFile() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("intervalFilter: {bed: src/test/resources/intervals.bed}")); List<ChromosomalRegion> expectedIntervals = new ArrayList<>(); expectedIntervals.add(new GeneticInterval(7, 127471197, 127472363)); expectedIntervals.add(new GeneticInterval(7, 127472364, 127473530)); expectedIntervals.add(new GeneticInterval(7, 127475865, 127477031)); expectedIntervals.add(new GeneticInterval(7, 127479366, 127480532)); expectedIntervals.add(new GeneticInterval(7, 127480533, 127481699)); analysisSteps.add(new IntervalFilter(expectedIntervals)); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testThrowsExceptionWithUnexpectedTokenForIntervalFilter() { assertThrows(AnalysisParserException.class, () -> instance.parseAnalysis(addStepToAnalysis("intervalFilter: {bod: src/test/resources/intervals.bed}")) ); }
@Test public void testParseAnalysisStepGeneIdFilter() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("genePanelFilter: {geneSymbols: [FGFR1, FGFR2]}")); analysisSteps.add(new GeneSymbolFilter(new LinkedHashSet<>(Arrays.asList("FGFR1", "FGFR2")))); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepQualityFilter() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("qualityFilter: {minQuality: 50.0}")); analysisSteps.add(new QualityFilter(50.0f)); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepVariantEffectFilter() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("variantEffectFilter: {remove: [SYNONYMOUS_VARIANT, INTERGENIC_VARIANT]}")); analysisSteps.add(new VariantEffectFilter(EnumSet.of(VariantEffect.SYNONYMOUS_VARIANT, VariantEffect.INTERGENIC_VARIANT))); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepVariantEffectFilterillegalVariantEffect() { assertThrows(AnalysisParserException.class, () -> instance.parseAnalysis(addStepToAnalysis("variantEffectFilter: {remove: [WIBBLE]}")) ); }
@Test public void testParseAnalysisStepKnownVariantFilterFilter() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("knownVariantFilter: {}")); analysisSteps.add(new KnownVariantFilter()); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepFrequencyFilterNoFrequencySourcesDefined() { String script = "analysis:\n" + " vcf: test.vcf\n" + " frequencySources: []\n" + " steps: [" + " frequencyFilter: {maxFrequency: 1.0}\n" + "]"; assertThrows(AnalysisParserException.class, () -> instance.parseAnalysis(script) ); }
@Test public void testParseAnalysisStepFrequencyFilter() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("frequencyFilter: {maxFrequency: 1.0}")); analysisSteps.add(new FrequencyFilter(1.0f)); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepFrequencyFilterNoMaxFreqDefined() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("frequencyFilter: {}")); analysisSteps.add(new FrequencyFilter(2.0f)); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepPathogenicityFilterNoPathSourcesDefined() { String script = "analysis:\n" + " vcf: test.vcf\n" + " pathogenicitySources: []\n" + " steps: [" + " pathogenicityFilter: {keepNonPathogenic: false}\n" + "]"; assertThrows(AnalysisParserException.class, () -> instance.parseAnalysis(script) ); }
@Test public void testParseAnalysisStepPathogenicityFilter() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("pathogenicityFilter: {keepNonPathogenic: false}")); analysisSteps.add(new PathogenicityFilter(false)); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepPriorityScoreFilter() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("priorityScoreFilter: {priorityType: HIPHIVE_PRIORITY, minPriorityScore: 0.65}")); analysisSteps.add(new PriorityScoreFilter(PriorityType.HIPHIVE_PRIORITY, 0.65f)); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepInheritanceFilterUndefinedMode() { Analysis analysis = instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " inheritanceModes: {}\n" + " hpoIds: []\n" + " analysisMode: PASS_ONLY \n" + " pathogenicitySources: []\n" + " frequencySources: []\n" + " steps: [" + " inheritanceFilter: {}\n" + "]" ); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepInheritanceFilterUnrecognisedValue() { assertThrows(AnalysisParserException.class, () -> instance.parseAnalysis( "analysis:\n" + " vcf: test.vcf\n" + " inheritanceModes: {WIBBLE: 0.0}\n" ) ); }
@Test public void testParseAnalysisStepInheritanceFilterDefinedMode() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("inheritanceFilter: {}")); analysisSteps.add(new InheritanceFilter(ModeOfInheritance.AUTOSOMAL_DOMINANT, ModeOfInheritance.AUTOSOMAL_RECESSIVE, ModeOfInheritance.X_DOMINANT, ModeOfInheritance.X_RECESSIVE, ModeOfInheritance.MITOCHONDRIAL)); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepOmimPrioritiser() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("omimPrioritiser: {}")); analysisSteps.add(priorityFactory.makeOmimPrioritiser()); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepHiPhivePrioritiserWithDefaultOptions() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("hiPhivePrioritiser: {}")); analysisSteps.add(priorityFactory.makeHiPhivePrioritiser(HiPhiveOptions.defaults())); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepHiPhivePrioritiserWithUserDefinedOptions() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("hiPhivePrioritiser: {diseaseId: 'OMIM:101600', candidateGeneSymbol: FGFR2, runParams: 'human,mouse,fish,ppi'}")); HiPhiveOptions hiPhiveOptions = HiPhiveOptions.builder().diseaseId("OMIM:101600").candidateGeneSymbol("FGFR2").runParams("human,mouse,fish,ppi").build(); analysisSteps.add(priorityFactory.makeHiPhivePrioritiser(hiPhiveOptions)); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepPhivePrioritiser() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("phivePrioritiser: {}")); analysisSteps.add(priorityFactory.makePhivePrioritiser()); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepPhenixPrioritiser() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("phenixPrioritiser: {}")); analysisSteps.add(priorityFactory.makePhenixPrioritiser()); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisStepWalkerPrioritiser() { Analysis analysis = instance.parseAnalysis(addStepToAnalysis("exomeWalkerPrioritiser: {seedGeneIds: [11111, 22222, 33333]}")); analysisSteps.add(priorityFactory.makeExomeWalkerPrioritiser(new ArrayList<>(Arrays.asList(11111, 22222, 33333)))); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisFileFromPath() { ModeOfInheritance modeOfInheritance = ModeOfInheritance.AUTOSOMAL_DOMINANT; Analysis analysis = instance.parseAnalysis(Paths.get("src/test/resources/analysisExample.yml")); System.out.println(analysis); assertThat(analysis.getVcfPath(), equalTo(Paths.get("test.vcf"))); assertThat(analysis.getPedigree(), equalTo(Pedigree.empty())); assertThat(analysis.getHpoIds(), equalTo(hpoIds)); assertThat(analysis.getInheritanceModeOptions(), equalTo(InheritanceModeOptions.defaultForModes(modeOfInheritance))); assertThat(analysis.getFrequencySources(), equalTo(frequencySources)); assertThat(analysis.getPathogenicitySources(), equalTo(pathogenicitySources)); analysisSteps.add(new IntervalFilter(new GeneticInterval(10, 123256200, 123256300))); analysisSteps.add(new GeneSymbolFilter(new LinkedHashSet<>(Arrays.asList("FGFR1", "FGFR2")))); analysisSteps.add(new QualityFilter(50.0f)); analysisSteps.add(new VariantEffectFilter(EnumSet.of(VariantEffect.SYNONYMOUS_VARIANT))); analysisSteps.add(new KnownVariantFilter()); analysisSteps.add(new FrequencyFilter(1.0f)); analysisSteps.add(new PathogenicityFilter(false)); analysisSteps.add(new InheritanceFilter(modeOfInheritance)); analysisSteps.add(priorityFactory.makeOmimPrioritiser()); analysisSteps.add(priorityFactory.makeHiPhivePrioritiser(HiPhiveOptions.defaults())); analysisSteps.add(priorityFactory.makeHiPhivePrioritiser(HiPhiveOptions.builder() .diseaseId("OMIM:101600") .candidateGeneSymbol("FGFR2") .build())); analysisSteps.add(new PriorityScoreFilter(PriorityType.HIPHIVE_PRIORITY, 0.7f)); assertThat(analysis.getAnalysisSteps(), equalTo(analysisSteps)); }
@Test public void testParseAnalysisNonExistentFile() { assertThrows(AnalysisFileNotFoundException.class, () -> instance.parseAnalysis(Paths.get("src/test/resources/wibble")) ); }