Skip to content

Commit

Permalink
core: add new default constructor, now default database is taken from…
Browse files Browse the repository at this point in the history
… the databases array in the configuration. refactor the initislisation of objects
  • Loading branch information
imedina committed Mar 12, 2018
1 parent 70362c6 commit fcbc82b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opencb.bionetdb.core;

import htsjdk.variant.variantcontext.VariantContext;
import org.apache.commons.lang3.StringUtils;
import org.opencb.biodata.models.variant.Variant;
import org.opencb.biodata.tools.variant.converters.avro.VariantContextToVariantConverter;
import org.opencb.bionetdb.core.api.NetworkDBAdaptor;
Expand Down Expand Up @@ -39,8 +40,8 @@
public class BioNetDBManager {

private String database;
private BioNetDBConfiguration bioNetDBConfiguration;
private ClientConfiguration clientConfiguration;
private BioNetDBConfiguration configuration;
private ClientConfiguration cellbaseClientConfiguration;
private CellBaseClient cellBaseClient;

private NetworkDBAdaptor networkDBAdaptor;
Expand All @@ -51,19 +52,43 @@ public class BioNetDBManager {
private static final int VARIANT_BATCH_SIZE = 10000;
private static final int QUERY_MAX_RESULTS = 50000;

public BioNetDBManager(String database, BioNetDBConfiguration bioNetDBConfiguration) throws BioNetDBException {
this.database = database;
this.bioNetDBConfiguration = bioNetDBConfiguration;
networkDBAdaptor = new Neo4JNetworkDBAdaptor(database, bioNetDBConfiguration, true);

clientConfiguration = new ClientConfiguration();
clientConfiguration.setVersion("v4");
clientConfiguration.setRest(new RestConfig(Collections.singletonList("http://bioinfo.hpc.cam.ac.uk/cellbase"), 30000));
cellBaseClient = new CellBaseClient("hsapiens", clientConfiguration);
public BioNetDBManager(BioNetDBConfiguration configuration) throws BioNetDBException {
init(null, configuration);
}

idToUidMap = new HashMap<>();
public BioNetDBManager(String database, BioNetDBConfiguration configuration) throws BioNetDBException {
init(database, configuration);
}

private void init(String database, BioNetDBConfiguration configuration) throws BioNetDBException {
// We first create te logger to debug next actions
logger = LoggerFactory.getLogger(BioNetDBManager.class);

// We check that the configuration exists and the databases are not empty
if (configuration == null || configuration.getDatabases() == null || configuration.getDatabases().size() == 0) {
logger.error("BioNetDB configuration is null or databases are empty");
throw new BioNetDBException("BioNetDBConfiguration is null or databases are empty");
}
this.configuration = configuration;

// If database parameter is empty then we use take the first database
if (StringUtils.isNotEmpty(database)) {
this.database = database;
} else {
logger.debug("Empty database parameter: {}, using the first instance of 'databases'", database);
this.database = this.configuration.getDatabases().get(0).getId();
}

// We can now create the default NetworkDBAdaptor
networkDBAdaptor = new Neo4JNetworkDBAdaptor(database, this.configuration, true);

// We create CellBase client
cellbaseClientConfiguration = new ClientConfiguration();
cellbaseClientConfiguration.setVersion("v4");
cellbaseClientConfiguration.setRest(new RestConfig(Collections.singletonList("http://bioinfo.hpc.cam.ac.uk/cellbase"), 30000));
cellBaseClient = new CellBaseClient("hsapiens", cellbaseClientConfiguration);

idToUidMap = new HashMap<>();
}

public void loadBioPax(java.nio.file.Path path) throws IOException, BioNetDBException {
Expand Down
19 changes: 8 additions & 11 deletions bionetdb-core/src/main/resources/configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
defaultDatabase: "scerevisiae"
logLevel: null
logFile: null

## You can define more than one database, you can pass the database id to BioNetDBManager.
## If not passed the default database will always be the first one.
databases:
- id: "${BIONETDB.DATABASE}"
host: "${BIONETDB.CATALOG.DB.HOST}"
port: "${BIONETDB.CATALOG.DB.PORT}"
user: "${BIONETDB.CATALOG.DB.USER}"
password: "${BIONETDB.CATALOG.DB.PASSWORD}"
options: null
- id: "hsapiens"
host: "localhost"
port: "7688"
user: "neo4j"
password: "neo4j;"
- id: "${BIONETDB.DB.DATABASE}"
host: "${BIONETDB.DB.HOST}"
port: "${BIONETDB.DB.PORT}"
user: "${BIONETDB.DB.USER}"
password: "${BIONETDB.DB.PASSWORD}"
options: null
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<BIONETDB.DATABASE>scerevisiae</BIONETDB.DATABASE>
<BIONETDB.CATALOG.DB.HOST>localhost</BIONETDB.CATALOG.DB.HOST>
<BIONETDB.CATALOG.DB.PORT>7687</BIONETDB.CATALOG.DB.PORT>
<BIONETDB.CATALOG.DB.USER>neo4j</BIONETDB.CATALOG.DB.USER>
<BIONETDB.CATALOG.DB.PASSWORD>neo4j;</BIONETDB.CATALOG.DB.PASSWORD>
<BIONETDB.DB.DATABASE>scerevisiae</BIONETDB.DB.DATABASE>
<BIONETDB.DB.HOST>localhost</BIONETDB.DB.HOST>
<BIONETDB.DB.PORT>7687</BIONETDB.DB.PORT>
<BIONETDB.DB.USER>neo4j</BIONETDB.DB.USER>
<BIONETDB.DB.PASSWORD>neo4j</BIONETDB.DB.PASSWORD>
</properties>
</profile>

Expand Down

0 comments on commit fcbc82b

Please sign in to comment.