Skip to content

Commit

Permalink
Fix for issues #410, #412 application fails to start due to NoUniqueB…
Browse files Browse the repository at this point in the history
…eanDefinitionException when only hg38 data sources are defined
  • Loading branch information
julesjacobsen committed Nov 23, 2021
1 parent ea9942a commit 1192984
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The Exomiser - A tool to annotate and prioritize genomic variants
*
* Copyright (c) 2016-2020 Queen Mary University of London.
* Copyright (c) 2016-2021 Queen Mary University of London.
* Copyright (c) 2012-2016 Charité Universitätsmedizin Berlin and Genome Research Ltd.
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -24,6 +24,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

import java.util.Locale;

Expand All @@ -33,7 +34,7 @@
*
* @author Jules Jacobsen <j.jacobsen@qmul.ac.uk>
*/
@SpringBootApplication
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class Main {

private static final Logger logger = LoggerFactory.getLogger(Main.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public abstract class AbstractGenomeProperties implements GenomeProperties {
// datastore
private String testPathogenicityScorePath = "";

protected AbstractGenomeProperties(GenomeAssembly assembly) {
this.assembly = assembly;
}

@Override
public Path getDataDirectory() {
return dataDirectory;
Expand All @@ -61,10 +65,6 @@ public void setDataDirectory(String dataDirectory) {
this.dataDirectory = Paths.get(dataDirectory);
}

public AbstractGenomeProperties(GenomeAssembly assembly) {
this.assembly = assembly;
}

public GenomeAssembly getAssembly() {
return assembly;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
* @author Jules Jacobsen <j.jacobsen@qmul.ac.uk>
Expand All @@ -44,17 +43,20 @@ public Hg19GenomeProperties() {
// the default configuration is contained in the application.properties shipped in the jar's classpath
// this can be overridden by the user in their own application.properties.

@Primary
@Bean
@ConfigurationProperties("exomiser.hg19.genome.datasource")
public DataSourceProperties hg19genomeDataSourceProperties() {
return new DataSourceProperties();
}

@Primary
@Bean(name = "hg19genomeDataSource")
@Bean
@ConfigurationProperties("exomiser.hg19.genome.datasource.hikari")
public HikariDataSource hg19genomeDataSource(DataSourceProperties hg19genomeDataSourceProperties) {
return hg19genomeDataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
}

@Override
public HikariDataSource genomeDataSource() {
return hg19genomeDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
return hg19genomeDataSource(hg19genomeDataSourceProperties());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ public DataSourceProperties hg38genomeDataSourceProperties() {
return new DataSourceProperties();
}

@Bean(name = "hg38genomeDataSource")
@Bean
@ConfigurationProperties("exomiser.hg38.genome.datasource.hikari")
public HikariDataSource genomeDataSource() {
return hg38genomeDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
public HikariDataSource hg38genomeDataSource(DataSourceProperties hg38genomeDataSourceProperties) {
return hg38genomeDataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
}

@Override
public HikariDataSource genomeDataSource() {
return hg38genomeDataSource(hg38genomeDataSourceProperties());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The Exomiser - A tool to annotate and prioritize genomic variants
*
* Copyright (c) 2016-2019 Queen Mary University of London.
* Copyright (c) 2016-2021 Queen Mary University of London.
* Copyright (c) 2012-2016 Charité Universitätsmedizin Berlin and Genome Research Ltd.
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -48,10 +48,10 @@ public DataSourceProperties phenotypeDataSourceProperties() {
return new DataSourceProperties();
}

@Bean(name = "phenotypeDataSource")
@Bean
@ConfigurationProperties("exomiser.phenotype.datasource.hikari")
public HikariDataSource phenotypeDataSource() {
return phenotypeDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
public HikariDataSource phenotypeDataSource(DataSourceProperties phenotypeDataSourceProperties) {
return phenotypeDataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
}

//Random walk matrix for hiPhive and exomeWalker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

package org.monarchinitiative.exomiser.autoconfigure;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.monarchinitiative.exomiser.core.Exomiser;
import org.monarchinitiative.exomiser.core.genome.GenomeAnalysisServiceProvider;
Expand All @@ -43,7 +42,6 @@ public class ExomiserAutoConfigurationTest extends AbstractAutoConfigurationTest

// n.b there are issues with the @PreDestroy shutdown hooks for classes in the GenomeAnalysisServiceConfigurer using the MVStore
// so all the relevant beans are being tested in one go
@Disabled("File lock exception when run as part of full test suite")
@Test
public void testAutoConfiguration() {
load(EmptyConfiguration.class, TEST_DATA_ENV, "exomiser.hg19.data-version=1710", "exomiser.hg38.data-version=1710", "exomiser.phenotype.data-version=1710");
Expand All @@ -59,6 +57,36 @@ public void testAutoConfiguration() {
assertThat(phenotypeMatchService, instanceOf(PhenotypeMatchService.class));
}

@Test
public void testHg19OnlyAutoConfiguration() {
load(EmptyConfiguration.class, TEST_DATA_ENV, "exomiser.hg19.data-version=1710", "exomiser.phenotype.data-version=1710");
Exomiser exomiser = (Exomiser) context.getBean("exomiser");
assertThat(exomiser, instanceOf(Exomiser.class));

GenomeAnalysisServiceProvider genomeAnalysisServiceProvider = (GenomeAnalysisServiceProvider) context.getBean("genomeAnalysisServiceProvider");
assertThat(genomeAnalysisServiceProvider, instanceOf(GenomeAnalysisServiceProvider.class));
assertThat(genomeAnalysisServiceProvider.hasServiceFor(GenomeAssembly.HG19), is(true));
assertThat(genomeAnalysisServiceProvider.hasServiceFor(GenomeAssembly.HG38), is(false));

PhenotypeMatchService phenotypeMatchService = (PhenotypeMatchService) context.getBean("phenotypeMatchService");
assertThat(phenotypeMatchService, instanceOf(PhenotypeMatchService.class));
}

@Test
public void testHg38OnlyAutoConfiguration() {
load(EmptyConfiguration.class, TEST_DATA_ENV, "exomiser.hg38.data-version=1710", "exomiser.phenotype.data-version=1710");
Exomiser exomiser = (Exomiser) context.getBean("exomiser");
assertThat(exomiser, instanceOf(Exomiser.class));

GenomeAnalysisServiceProvider genomeAnalysisServiceProvider = (GenomeAnalysisServiceProvider) context.getBean("genomeAnalysisServiceProvider");
assertThat(genomeAnalysisServiceProvider, instanceOf(GenomeAnalysisServiceProvider.class));
assertThat(genomeAnalysisServiceProvider.hasServiceFor(GenomeAssembly.HG19), is(false));
assertThat(genomeAnalysisServiceProvider.hasServiceFor(GenomeAssembly.HG38), is(true));

PhenotypeMatchService phenotypeMatchService = (PhenotypeMatchService) context.getBean("phenotypeMatchService");
assertThat(phenotypeMatchService, instanceOf(PhenotypeMatchService.class));
}

@Configuration
@ImportAutoConfiguration(value = ExomiserAutoConfiguration.class)
protected static class EmptyConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
public class Hg19GenomeAnalysisServiceAutoConfigurationTest extends AbstractAutoConfigurationTest {

@Test
public synchronized void genomeAnalysisService() throws Exception {
public void genomeAnalysisService() throws Exception {

load(EmptyConfiguration.class, TEST_DATA_ENV, "exomiser.hg19.data-version=1710", "exomiser.hg19.local-frequency-path=../local/local_freq.tsv.gz");
load(EmptyConfiguration.class, TEST_DATA_ENV, "exomiser.hg19.data-version=1710");

GenomeAnalysisService genomeAnalysisService = (GenomeAnalysisService) this.context.getBean("hg19genomeAnalysisService");
GenomeAnalysisService genomeAnalysisService = (GenomeAnalysisService) context.getBean("hg19genomeAnalysisService");
assertThat(genomeAnalysisService.getGenomeAssembly(), equalTo(GenomeAssembly.HG19));

assertThat(context.getBean("hg19jannovarData"), instanceOf(JannovarData.class));
Expand All @@ -60,7 +60,7 @@ public synchronized void genomeAnalysisService() throws Exception {
}

@Test
public synchronized void genomeAnalysisServiceWithOptionalTestPathDao() throws Exception {
public void genomeAnalysisServiceWithOptionalTestPathDao() throws Exception {

String testPathogenicitySourcePath = TEST_DATA.resolve("remm/remmData.tsv.gz").toAbsolutePath().toString();
load(EmptyConfiguration.class, TEST_DATA_ENV, "exomiser.hg19.data-version=1710", "exomiser.hg19.test-pathogenicity-score-path=" + testPathogenicitySourcePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void genomeAnalysisService() throws Exception {

load(EmptyConfiguration.class, TEST_DATA_ENV, "exomiser.hg38.data-version=1710");

GenomeAnalysisService genomeAnalysisService = (GenomeAnalysisService) this.context.getBean("hg38genomeAnalysisService");
GenomeAnalysisService genomeAnalysisService = (GenomeAnalysisService) context.getBean("hg38genomeAnalysisService");
assertThat(genomeAnalysisService.getGenomeAssembly(), equalTo(GenomeAssembly.HG38));

assertThat(context.getBean("hg38jannovarData"), instanceOf(JannovarData.class));
Expand All @@ -61,6 +61,7 @@ public void genomeAnalysisService() throws Exception {

@Test
public void genomeAnalysisServiceWithOptionalTestPathDao() throws Exception {

String testPathogenicitySourcePath = TEST_DATA.resolve("remm/remmData.tsv.gz").toAbsolutePath().toString();
load(EmptyConfiguration.class, TEST_DATA_ENV, "exomiser.hg38.data-version=1710", "exomiser.hg38.test-pathogenicity-score-path=" + testPathogenicitySourcePath);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The Exomiser - A tool to annotate and prioritize genomic variants
*
* Copyright (c) 2016-2020 Queen Mary University of London.
* Copyright (c) 2016-2021 Queen Mary University of London.
* Copyright (c) 2012-2016 Charité Universitätsmedizin Berlin and Genome Research Ltd.
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -20,7 +20,6 @@

package org.monarchinitiative.exomiser.autoconfigure.phenotype;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.monarchinitiative.exomiser.autoconfigure.AbstractAutoConfigurationTest;
import org.monarchinitiative.exomiser.autoconfigure.DataDirectoryAutoConfiguration;
Expand Down Expand Up @@ -59,11 +58,9 @@ public void onlyLoadsWhenPhenotypeDataVersionIsPresent() {
assertThat(context.getBean("phenotypeDataDirectory"), not(nullValue()));
}

//this works in prod, but fails to autowire the phenotypeDataSource in test, despite being able to load the dataSource.
@Disabled
@Test
public void canDefinePhenotypeDataDirectory() {
Path definedDir = TEST_DATA.resolve("user-defined");
Path definedDir = TEST_DATA.resolve("1710_phenotype");
load(EmptyConfiguration.class, TEST_DATA_ENV, DATA_VERSION, "exomiser.phenotype.data-directory=" + definedDir);
Path phenotypeDataDirectory = (Path) this.context.getBean("phenotypeDataDirectory");
assertThat(phenotypeDataDirectory, equalTo(definedDir));
Expand Down

0 comments on commit 1192984

Please sign in to comment.