diff --git a/cellbase-client/src/test/java/org/opencb/cellbase/client/rest/VariantClientTest.java b/cellbase-client/src/test/java/org/opencb/cellbase/client/rest/VariantClientTest.java index 1ae1e6d27..9b3923953 100644 --- a/cellbase-client/src/test/java/org/opencb/cellbase/client/rest/VariantClientTest.java +++ b/cellbase-client/src/test/java/org/opencb/cellbase/client/rest/VariantClientTest.java @@ -18,6 +18,7 @@ import org.apache.avro.specific.SpecificRecordBase; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Assumptions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -31,9 +32,12 @@ import org.opencb.cellbase.client.config.ClientConfiguration; import org.opencb.cellbase.client.config.RestConfig; import org.opencb.cellbase.core.common.GitRepositoryState; +import org.opencb.cellbase.core.models.DataRelease; import org.opencb.cellbase.core.result.CellBaseDataResponse; +import org.opencb.commons.datastore.core.ObjectMap; import org.opencb.commons.datastore.core.Query; import org.opencb.commons.datastore.core.QueryOptions; +import org.opencb.commons.utils.VersionUtils; import java.util.*; import java.util.stream.Collectors; @@ -147,8 +151,7 @@ public void getAllConsequenceTypes(CellBaseClient cellBaseClient) throws Excepti @Test public void testSearchSnpBydbSnpId() throws Exception { - Assumptions.assumeTrue(GitRepositoryState.get().getBranch().equals("TASK-5789")); - + int dataRelease = 7; ClientConfiguration clientConfiguration = new ClientConfiguration() .setDefaultSpecies("hsapiens") .setVersion("v5.8.3-SNAPSHOT") @@ -156,9 +159,15 @@ public void testSearchSnpBydbSnpId() throws Exception { CellBaseClient client = new CellBaseClient(clientConfiguration); + // Assumptions before running the test + ObjectMap result = client.getMetaClient().about().firstResult(); + Assumptions.assumeTrue(VersionUtils.isMinVersion("5.8.3-SNAPSHOT", result.getString("Version"))); + CellBaseDataResponse dataReleaseResponse = client.getMetaClient().dataReleases(); + Assumptions.assumeTrue(dataReleaseResponse.getResponses().get(0).getResults().stream().map(DataRelease::getRelease).collect(Collectors.toList()).contains(dataRelease)); + Query query = new Query(); query.put("id", "rs1570391602,rs41278952"); - query.put("dataRelease", 7); + query.put("dataRelease", dataRelease); CellBaseDataResponse response = client.getVariantClient().searchSnp(query, new QueryOptions()); assertEquals(2, response.getResponses().get(0).getNumResults()); @@ -168,8 +177,7 @@ public void testSearchSnpBydbSnpId() throws Exception { @Test public void testSearchSnpByPosition() throws Exception { - Assumptions.assumeTrue(GitRepositoryState.get().getBranch().equals("TASK-5789")); - + int dataRelease = 7; ClientConfiguration clientConfiguration = new ClientConfiguration() .setDefaultSpecies("hsapiens") .setVersion("v5.8.3-SNAPSHOT") @@ -177,11 +185,17 @@ public void testSearchSnpByPosition() throws Exception { CellBaseClient client = new CellBaseClient(clientConfiguration); + // Assumptions before running the test + ObjectMap result = client.getMetaClient().about().firstResult(); + Assumptions.assumeTrue(VersionUtils.isMinVersion("5.8.3-SNAPSHOT", result.getString("Version"))); + CellBaseDataResponse dataReleaseResponse = client.getMetaClient().dataReleases(); + Assumptions.assumeTrue(dataReleaseResponse.getResponses().get(0).getResults().stream().map(DataRelease::getRelease).collect(Collectors.toList()).contains(dataRelease)); + Query query = new Query(); query.put("chromosome", "1"); query.put("position", "56948509"); query.put("reference", "T"); - query.put("dataRelease", 7); + query.put("dataRelease", dataRelease); CellBaseDataResponse response = client.getVariantClient().searchSnp(query, new QueryOptions()); assertEquals(1, response.getResponses().get(0).getNumResults()); @@ -194,8 +208,7 @@ public void testSearchSnpByPosition() throws Exception { @Test public void testStarsWithSnp() throws Exception { - Assumptions.assumeTrue(GitRepositoryState.get().getBranch().equals("TASK-5789")); - + int dataRelease = 7; ClientConfiguration clientConfiguration = new ClientConfiguration() .setDefaultSpecies("hsapiens") .setVersion("v5.8.3-SNAPSHOT") @@ -203,9 +216,15 @@ public void testStarsWithSnp() throws Exception { CellBaseClient client = new CellBaseClient(clientConfiguration); + // Assumptions before running the test + ObjectMap result = client.getMetaClient().about().firstResult(); + Assumptions.assumeTrue(VersionUtils.isMinVersion("5.8.3-SNAPSHOT", result.getString("Version"))); + CellBaseDataResponse dataReleaseResponse = client.getMetaClient().dataReleases(); + Assumptions.assumeTrue(dataReleaseResponse.getResponses().get(0).getResults().stream().map(DataRelease::getRelease).collect(Collectors.toList()).contains(dataRelease)); + Query query = new Query(); query.put("id", "rs157039161"); - query.put("dataRelease", 7); + query.put("dataRelease", dataRelease); CellBaseDataResponse response = client.getVariantClient().startsWithSnp(query, new QueryOptions()); assertEquals(9, response.getResponses().get(0).getNumResults()); diff --git a/cellbase-lib/src/main/java/org/opencb/cellbase/lib/EtlCommons.java b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/EtlCommons.java index 8d5b4c55c..edf41c1e1 100644 --- a/cellbase-lib/src/main/java/org/opencb/cellbase/lib/EtlCommons.java +++ b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/EtlCommons.java @@ -35,6 +35,8 @@ */ public class EtlCommons { + public static final String HOMO_SAPIENS_NAME ="Homo sapiens"; + public static final String GENOME_DATA = "genome"; public static final String GENE_DATA = "gene"; public static final String REFSEQ_DATA = "refseq"; diff --git a/cellbase-lib/src/main/java/org/opencb/cellbase/lib/download/VariationDownloadManager.java b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/download/VariationDownloadManager.java index 7f317d5f7..7586505d2 100644 --- a/cellbase-lib/src/main/java/org/opencb/cellbase/lib/download/VariationDownloadManager.java +++ b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/download/VariationDownloadManager.java @@ -19,6 +19,7 @@ import org.opencb.cellbase.core.config.CellBaseConfiguration; import org.opencb.cellbase.core.config.DownloadProperties; import org.opencb.cellbase.core.exception.CellBaseException; +import org.opencb.cellbase.lib.EtlCommons; import java.io.IOException; import java.nio.file.Files; @@ -45,7 +46,7 @@ public DownloadFile downloadDbSnp() throws IOException, InterruptedException { if (!speciesHasInfoToDownload(speciesConfiguration, VARIATION_DATA)) { return null; } - if (speciesConfiguration.getScientificName().equals("Homo sapiens")) { + if (speciesConfiguration.getScientificName().equals(EtlCommons.HOMO_SAPIENS_NAME)) { logger.info("Downloading dbSNP information ..."); Path variation = downloadFolder.resolve(VARIATION_DATA); diff --git a/cellbase-lib/src/main/java/org/opencb/cellbase/lib/impl/core/SnpMongoDBAdaptor.java b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/impl/core/SnpMongoDBAdaptor.java index 56757d5ea..6b3d78ce8 100644 --- a/cellbase-lib/src/main/java/org/opencb/cellbase/lib/impl/core/SnpMongoDBAdaptor.java +++ b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/impl/core/SnpMongoDBAdaptor.java @@ -122,7 +122,7 @@ public CellBaseDataResult startsWith(String id, QueryOptions options, int d return new CellBaseDataResult<>(mongoDBCollection.find(regex, projection, CONVERTER, options)); } - public Bson parseQuery(SnpQuery query) { + public Bson parseQuery(SnpQuery query) throws CellBaseException { List andBsonList = new ArrayList<>(); try { for (Map.Entry entry : query.toObjectMap().entrySet()) { @@ -145,7 +145,7 @@ public Bson parseQuery(SnpQuery query) { } } } catch (IllegalAccessException e) { - e.printStackTrace(); + throw new CellBaseException("Error parsing SNP query: " + query, e); } logger.info("SnpMongoDBAdaptor parsed query: {}", andBsonList); diff --git a/cellbase-lib/src/main/java/org/opencb/cellbase/lib/impl/core/VariantMongoDBAdaptor.java b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/impl/core/VariantMongoDBAdaptor.java index 7be8cf75f..3c33266f7 100644 --- a/cellbase-lib/src/main/java/org/opencb/cellbase/lib/impl/core/VariantMongoDBAdaptor.java +++ b/cellbase-lib/src/main/java/org/opencb/cellbase/lib/impl/core/VariantMongoDBAdaptor.java @@ -305,7 +305,7 @@ public Bson parseQuery(VariantQuery query) throws CellBaseException { } } } catch (IllegalAccessException e) { - throw new CellBaseException(e.getMessage()); + throw new CellBaseException("Error parsing variant query: " + query, e); } logger.debug("variant parsed query: {}", andBsonList);