Skip to content

Commit

Permalink
Resolve conflicts, #TASK-4641
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarraga committed Sep 7, 2023
2 parents 76c5791 + 348cb0d commit e18342b
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 45 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class PharmaChemicalQuery extends AbstractQuery {
@QueryParameter(id = "variants.haplotypes", alias = {"haplotype"})
private List<String> hapolotypes;

@QueryParameter(id = "variants.geneNames", alias = {"geneName"})
@QueryParameter(id = "geneName")
private List<String> geneNames;

@QueryParameter(id = "variants.phenotypes", alias = {"phenotype"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ public void updateParams(Map<String, String> uriParams) {
annotations = getAnnotations();

try {
validateParams(uriParams, classAttributesToType, annotations);
// Skip this validation because some CellBase endpoint URL parameters are not included
// in the query (such as GeneQuery, VariantQuery,...)
//validateParams(uriParams, classAttributesToType, annotations);

Map<String, Object> objectHashMap = new HashMap<>();
for (Map.Entry<String, Class<?>> entry : classAttributesToType.entrySet()) {
Expand Down Expand Up @@ -175,7 +177,7 @@ public void updateParams(Map<String, String> uriParams) {
}
}
objectMapper.updateValue(this, objectHashMap);
} catch (JsonProcessingException | QueryException e) {
} catch (JsonProcessingException e) { // | QueryException e) {
throw new IllegalArgumentException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
package org.opencb.cellbase.lib.impl.core;

import com.mongodb.client.model.Filters;
import org.apache.commons.collections4.CollectionUtils;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.opencb.biodata.models.pharma.PharmaChemical;
import org.opencb.cellbase.core.api.PharmaChemicalQuery;
import org.opencb.cellbase.core.api.query.LogicalList;
import org.opencb.cellbase.core.api.query.ProjectionQueryOptions;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.core.result.CellBaseDataResult;
Expand Down Expand Up @@ -108,7 +110,6 @@ public CellBaseDataResult<PharmaChemical> groupBy(PharmaChemicalQuery query) thr

public Bson parseQuery(PharmaChemicalQuery pharmaQuery) {
List<Bson> andBsonList = new ArrayList<>();
boolean visited = false;
try {
for (Map.Entry<String, Object> entry : pharmaQuery.toObjectMap().entrySet()) {
String dotNotationName = entry.getKey();
Expand All @@ -119,6 +120,12 @@ public Bson parseQuery(PharmaChemicalQuery pharmaQuery) {
case "dataRelease":
// do nothing
break;
case "geneName":
List<Bson> orBsonList = new ArrayList<>();
orBsonList.add(getLogicalListFilter(new LogicalList<String>((List) value), "variants.geneNames"));
orBsonList.add(getLogicalListFilter(new LogicalList<String>((List) value), "genes.xrefs.id"));
andBsonList.add(Filters.or(orBsonList));
break;
default:
createAndOrQuery(value, dotNotationName, QueryParam.Type.STRING, andBsonList);
break;
Expand All @@ -127,8 +134,8 @@ public Bson parseQuery(PharmaChemicalQuery pharmaQuery) {
} catch (IllegalAccessException e) {
e.printStackTrace();
}
logger.debug("pharmacogenomics parsed query: " + andBsonList);
if (andBsonList.size() > 0) {
logger.debug("Pharmacogenomics parsed query: {}", andBsonList);
if (CollectionUtils.isNotEmpty(andBsonList)) {
return Filters.and(andBsonList);
} else {
return new Document();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.opencb.cellbase.core.config.CellBaseConfiguration;
import org.opencb.cellbase.core.exception.CellBaseException;
import org.opencb.cellbase.core.models.DataRelease;
import org.opencb.cellbase.lib.EtlCommons;
import org.opencb.cellbase.lib.managers.DataReleaseManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -100,7 +101,9 @@ public void load(Path filePath, String data, int dataRelease, String field, Stri
// protein_functional_prediction documents are extremely big. Increasing the batch size will probably
// lead to an OutOfMemory error for this collection. Batch size can be much higher for the rest of
// collections though
if (data.equals(PROTEIN_FUNCTIONAL_PREDICTION)) {
if (data.equals(PROTEIN_FUNCTIONAL_PREDICTION)
|| data.equals(EtlCommons.PHARMACOGENOMICS_DATA)
|| data.equals(EtlCommons.PUBMED_DATA)) {
batchSize = 50;
} else {
batchSize = 200;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
import java.util.List;
import java.util.concurrent.ExecutionException;

import static org.opencb.cellbase.lib.EtlCommons.PHARMACOGENOMICS_DATA;
import static org.opencb.cellbase.lib.EtlCommons.PUBMED_DATA;
import static org.opencb.cellbase.lib.db.MongoDBManager.DBNAME_SEPARATOR;

/**
* Created by fjlopez on 18/09/15.
*/
Expand All @@ -55,7 +59,7 @@ public class GenericMongoDBAdaptorTest {

protected String cellBaseName;

private static final String DATASET_BASENAME = "cellbase-v5.6-dr4";
private static final String DATASET_BASENAME = "cellbase-v5.7-dr6";
private static final String DATASET_EXTENSION = ".tar.gz";
private static final String DATASET_URL = "http://reports.test.zettagenomics.com/cellbase/test-data/";
private static final String DATASET_TMP_DIR = "/tmp/cb";
Expand Down Expand Up @@ -124,7 +128,9 @@ private void downloadAndPopulate() throws IOException, ExecutionException, Class
Path tmpPath = Paths.get(DATASET_TMP_DIR);
tmpPath.toFile().mkdirs();

logger.info("Downloading " + url + " into " + tmpPath);
URLUtils.download(url, tmpPath);

Path tmpFile = tmpPath.resolve(DATASET_BASENAME + DATASET_EXTENSION);
String commandline = "tar -xvzf " + tmpFile.toAbsolutePath() + " -C " + tmpPath;
logger.info("Running: " + commandline);
Expand Down Expand Up @@ -195,6 +201,12 @@ private void downloadAndPopulate() throws IOException, ExecutionException, Class
// clinical_variants.full.json.gz
loadData("clinical_variants", "clinical_variants", baseDir.resolve("clinical_variants.full.json.gz"));

// pharmacogenomics.json.gz
loadData(PHARMACOGENOMICS_DATA, PHARMACOGENOMICS_DATA, baseDir.resolve("pharmacogenomics/pharmacogenomics.json.gz"));

// pubmed.json.gz
loadData(PUBMED_DATA, PUBMED_DATA, baseDir.resolve("pubmed/pubmed.json.gz"));

// Clean temporary dir
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2015-2020 OpenCB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.opencb.cellbase.lib.impl.core;

import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.models.core.Gene;
import org.opencb.biodata.models.pharma.PharmaChemical;
import org.opencb.biodata.models.variant.avro.Constraint;
import org.opencb.biodata.models.variant.avro.Expression;
import org.opencb.biodata.models.variant.avro.ExpressionCall;
import org.opencb.cellbase.core.api.GeneQuery;
import org.opencb.cellbase.core.api.PharmaChemicalQuery;
import org.opencb.cellbase.core.api.query.AbstractQuery;
import org.opencb.cellbase.core.api.query.LogicalList;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.lib.GenericMongoDBAdaptorTest;
import org.opencb.cellbase.lib.managers.GeneManager;
import org.opencb.cellbase.lib.managers.PharmacogenomicsManager;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.opencb.cellbase.core.ParamConstants.DATA_RELEASE_PARAM;

/**
* Created by jtarraga on 08/21/23.
*/
public class PharmacogenomicsMongoDBAdaptorTest extends GenericMongoDBAdaptorTest {

public PharmacogenomicsMongoDBAdaptorTest() throws IOException {
super();
}

@Test
public void testQueryName() throws Exception {
PharmacogenomicsManager pharmacogenomicsManager = cellBaseManagerFactory.getPharmacogenomicsManager(SPECIES, ASSEMBLY);

Map<String, String> paramMap = new HashMap<>();
paramMap.put("name", "galantamine");
paramMap.put("include", "id,name");
paramMap.put(DATA_RELEASE_PARAM, String.valueOf(dataRelease));

PharmaChemicalQuery chemicalQuery = new PharmaChemicalQuery(paramMap);
chemicalQuery.setCount(Boolean.TRUE);

CellBaseDataResult<PharmaChemical> cellBaseDataResult = pharmacogenomicsManager.search(chemicalQuery);

assertEquals(1, cellBaseDataResult.getNumMatches());
assertEquals("PA449726", cellBaseDataResult.first().getId());
}

@Test
public void testQuery() throws Exception {
PharmacogenomicsManager pharmacogenomicsManager = cellBaseManagerFactory.getPharmacogenomicsManager(SPECIES, ASSEMBLY);

PharmaChemicalQuery chemicalQuery = new PharmaChemicalQuery();
chemicalQuery.setGeneNames(Collections.singletonList("PRKCE"));
chemicalQuery.setDataRelease(dataRelease);
chemicalQuery.setCount(Boolean.TRUE);

CellBaseDataResult<PharmaChemical> cellBaseDataResult = pharmacogenomicsManager.search(chemicalQuery);

assertEquals(6, cellBaseDataResult.getNumMatches());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public PharmacogenomicsWSServer(@PathParam("apiVersion") @ApiParam(name = "apiVe
+ "please, call the endpoint endpoint pharmacogenomics/distinct?field=variants.haplotypes", dataType = "java.util.List",
paramType = "query"),
@ApiImplicitParam(name = "geneName", value = "List of gene names, e.g.: NT5C2,VKORC1. In order to get the list of gene names,"
+ "please, call the endpoint endpoint pharmacogenomics/distinct?field=variants.geneNames", dataType = "java.util.List",
+ "please, call the endpoint endpoints pharmacogenomics/distinct?field=variants.geneNames and "
+ " pharmacogenomics/distinct?field=genes.xrefs.id", dataType = "java.util.List",
paramType = "query"),
@ApiImplicitParam(name = "location", value = "List of chromosomic coordinates in the format: chromosome:position, e.g.:"
+ " 10:103109774", dataType = "java.util.List", paramType = "query"),
Expand Down Expand Up @@ -125,6 +126,7 @@ public PharmacogenomicsWSServer(@PathParam("apiVersion") @ApiParam(name = "apiVe
public Response getAll() {
try {
PharmaChemicalQuery query = new PharmaChemicalQuery(uriParams);
query.setDataRelease(getDataRelease());
CellBaseDataResult<PharmaChemical> queryResults = pharmacogenomicsManager.search(query);

return createOkResponse(queryResults);
Expand Down Expand Up @@ -170,6 +172,7 @@ public Response getUniqueValues(@QueryParam("field") @ApiParam(name = "field", r
try {
copyToFacet("field", field);
PharmaChemicalQuery query = new PharmaChemicalQuery(uriParams);
query.setDataRelease(getDataRelease());
CellBaseDataResult<String> queryResults = pharmacogenomicsManager.distinct(query);
return createOkResponse(queryResults);
} catch (Exception e) {
Expand Down

0 comments on commit e18342b

Please sign in to comment.