Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include API-KEY for CADD scores #699

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void execute() throws CellBaseException {
case EtlCommons.VARIATION_FUNCTIONAL_SCORE_DATA: {
// Export data
VariantManager variantManager = managerFactory.getVariantManager(species, assembly);
CellBaseDataResult<GenomicScoreRegion> results = variantManager.getFunctionalScoreRegion(regions, null,
CellBaseDataResult<GenomicScoreRegion> results = variantManager.getFunctionalScoreRegion(regions, null, apiKey,
dataRelease);
counter = writeExportedData(results.getResults(), "cadd", output);
counterMsg = counter + " CADD items";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public final class ApiKeyLicensedDataUtils {
public static final Set<String> LICENSED_CLINICAL_DATA = new HashSet<>(Arrays.asList("cosmic", "hgmd"));
public static final Set<String> UNLICENSED_CLINICAL_DATA = new HashSet<>(Collections.singletonList("clinvar"));

public static final int NUM_VARIANT_FUNCTIONAL_SCORE_SOURCES = 1;
public static final Set<String> LICENSED_VARIANT_FUNCTIONAL_SCORE_SOURCES = new HashSet<>(Collections.singletonList("cadd"));


private ApiKeyLicensedDataUtils() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.opencb.cellbase.core.models.DataRelease;
import org.opencb.cellbase.core.result.CellBaseDataResult;
import org.opencb.cellbase.core.variant.AnnotationBasedPhasedQueryManager;
import org.opencb.cellbase.lib.EtlCommons;
import org.opencb.cellbase.lib.impl.core.CellBaseCoreDBAdaptor;
import org.opencb.cellbase.lib.impl.core.SpliceScoreMongoDBAdaptor;
import org.opencb.cellbase.lib.impl.core.VariantMongoDBAdaptor;
Expand All @@ -43,6 +44,7 @@
import org.opencb.cellbase.lib.variant.annotation.CellBaseNormalizerSequenceAdaptor;
import org.opencb.cellbase.lib.variant.annotation.VariantAnnotationCalculator;
import org.opencb.cellbase.lib.variant.hgvs.HgvsCalculator;
import org.opencb.commons.datastore.core.Event;
import org.opencb.commons.datastore.core.Query;
import org.opencb.commons.datastore.core.QueryOptions;

Expand Down Expand Up @@ -288,17 +290,24 @@ public List<CellBaseDataResult> getByRegion(Query query, QueryOptions queryOptio
return queryResults;
}

public CellBaseDataResult<Score> getFunctionalScoreVariant(Variant variant, QueryOptions queryOptions, int dataRelease)
public CellBaseDataResult<Score> getFunctionalScoreVariant(Variant variant, QueryOptions queryOptions, String apiKey, int dataRelease)
throws CellBaseException {
return variantDBAdaptor.getFunctionalScoreVariant(variant, queryOptions, dataRelease);
Set<String> validSources = apiKeyManager.getValidSources(apiKey, null);
if (validSources.contains(EtlCommons.CADD_DATA)) {
return variantDBAdaptor.getFunctionalScoreVariant(variant, queryOptions, dataRelease);
} else {
return new CellBaseDataResult<>(variant.toStringSimple(), 0, Collections.singletonList(new Event(Event.Type.WARNING,
"Your current API key does not grant access to CADD data")), 0);
}
}

public List<CellBaseDataResult<Score>> getFunctionalScoreVariant(List<Variant> variants, QueryOptions options, int dataRelease)
public List<CellBaseDataResult<Score>> getFunctionalScoreVariant(List<Variant> variants, QueryOptions options, String apiKey,
int dataRelease)
throws CellBaseException {
List<CellBaseDataResult<Score>> cellBaseDataResults = new ArrayList<>(variants.size());
for (Variant variant: variants) {
if (variant.getType() == VariantType.SNV) {
cellBaseDataResults.add(getFunctionalScoreVariant(variant, options, dataRelease));
cellBaseDataResults.add(getFunctionalScoreVariant(variant, options, apiKey, dataRelease));
} else {
cellBaseDataResults.add(new CellBaseDataResult<>(variant.toString(), 0, Collections.emptyList(), 0));
}
Expand Down Expand Up @@ -344,13 +353,19 @@ public List<CellBaseDataResult<SpliceScore>> getSpliceScoreVariant(List<Variant>
}

public CellBaseDataResult<GenomicScoreRegion> getFunctionalScoreRegion(List<Region> regions, CellBaseQueryOptions options,
int dataRelease)
String apiKey, int dataRelease)
throws CellBaseException {
Set<String> chunkIdSet = new HashSet<>();
for (Region region : regions) {
chunkIdSet.addAll(variantDBAdaptor.getFunctionalScoreChunkIds(region));
}

return variantDBAdaptor.getFunctionalScoreRegion(new ArrayList<>(chunkIdSet), options, dataRelease);
Set<String> validSources = apiKeyManager.getValidSources(apiKey, null);
if (validSources.contains(EtlCommons.CADD_DATA)) {
for (Region region : regions) {
chunkIdSet.addAll(variantDBAdaptor.getFunctionalScoreChunkIds(region));
}
return variantDBAdaptor.getFunctionalScoreRegion(new ArrayList<>(chunkIdSet), options, dataRelease);
} else {
return new CellBaseDataResult<>("", 0, Collections.singletonList(new Event(Event.Type.WARNING, "Your current API key does not"
+ " grant access to CADD data.")), 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ public List<CellBaseDataResult<Score>> call() throws Exception {
long startTime = System.currentTimeMillis();
logger.debug("Query variant functional score");
List<CellBaseDataResult<Score>> variantFunctionalScoreCellBaseDataResultList =
variantManager.getFunctionalScoreVariant(variantList, queryOptions, dataRelease);
variantManager.getFunctionalScoreVariant(variantList, queryOptions, apiKey, dataRelease);
logger.debug("VariantFunctionalScore query performance is {}ms for {} variants",
System.currentTimeMillis() - startTime, variantList.size());
return variantFunctionalScoreCellBaseDataResultList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class GenericMongoDBAdaptorTest {
protected String HGMD_COSMIC_ACCESS_API_KEY = "eyJhbGciOiJIUzI1NiJ9.eyJzb3VyY2VzIjp7ImNvc21pYyI6OTIyMzM3MjAzNjg1NDc3NTgwNywiaGdtZCI6OTIyMzM3MjAzNjg1NDc3NTgwN30sIm1heE51bVF1ZXJpZXMiOjEwMDAwMDAwLCJ2ZXJzaW9uIjoiMS4wIiwic3ViIjoiVEVTVCIsImlhdCI6MTY4OTgzNzQ5OX0.ZsTxFaSzsLwyQMLwNIODerfaOTLywoRwkxvpsnjVTSE";
protected String HGMD_SPLICEAI_ACCESS_API_KEY = "eyJhbGciOiJIUzI1NiJ9.eyJzb3VyY2VzIjp7ImhnbWQiOjkyMjMzNzIwMzY4NTQ3NzU4MDcsInNwbGljZWFpIjo5MjIzMzcyMDM2ODU0Nzc1ODA3fSwibWF4TnVtUXVlcmllcyI6MTAwMDAwMDAsInZlcnNpb24iOiIxLjAiLCJzdWIiOiJURVNUIiwiaWF0IjoxNjg5ODM3NTE4fQ.rDH2BR2EkUgs3fz7hAuCbmAHgE0rHmp9JhD-5gFZmfI";
protected String COSMIC_SPLICEAI_ACCESS_API_KEY = "eyJhbGciOiJIUzI1NiJ9.eyJzb3VyY2VzIjp7ImNvc21pYyI6OTIyMzM3MjAzNjg1NDc3NTgwNywic3BsaWNlYWkiOjkyMjMzNzIwMzY4NTQ3NzU4MDd9LCJtYXhOdW1RdWVyaWVzIjoxMDAwMDAwMCwidmVyc2lvbiI6IjEuMCIsInN1YiI6IlRFU1QiLCJpYXQiOjE2ODk4Mzc1MzZ9.CkXvpNg0NWAXL3N06R2gCqe0kF4ptBk0MPvaAdDSEpQ";
protected String HGMD_CADD_ACCESS_API_KEY = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJaRVRUQS1URVNUSU5HIiwidmVyc2lvbiI6IjEuMCIsImlhdCI6MTcyMTMxNTg4MCwic291cmNlcyI6eyJjYWRkIjozMTQ5NDc4NDY5MDgwMDAwMCwiaGdtZCI6MzE0OTQ3ODQ2OTA4MDAwMDB9LCJxdW90YSI6eyJtYXhOdW1RdWVyaWVzIjoxMDAwMDAwMH19.kMCyzs6lMo44e-rlDTlZ1lucK1jEKVS0bl5MBOh6Ekg";

protected LoadRunner loadRunner = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2129,6 +2129,33 @@ public void testLicensedDataCosmicSpliceApiKeyAnnotation() throws Exception {
}
}

@Test
public void testCaddApiKeyAnnotation() throws Exception {
QueryOptions queryOptions = new QueryOptions("useCache", false);
queryOptions.put("exclude", "pharmacogenomics");
queryOptions.put("normalize", true);

variantAnnotationCalculator.setApiKey(HGMD_CADD_ACCESS_API_KEY);

Variant variant = Variant.parseVariant("X:32896535:A:T");
CellBaseDataResult<VariantAnnotation> cellBaseDataResult = variantAnnotationCalculator.getAnnotationByVariant(variant, queryOptions);
VariantAnnotation variantAnnotation = cellBaseDataResult.first();
assertTrue(variantAnnotation.getFunctionalScore().size() > 0);
}

@Test
public void testNoCaddApiKeyAnnotation() throws Exception {
QueryOptions queryOptions = new QueryOptions("useCache", false);
queryOptions.put("exclude", "pharmacogenomics");
queryOptions.put("normalize", true);

variantAnnotationCalculator.setApiKey(SPLICEAI_ACCESS_API_KEY);

Variant variant = Variant.parseVariant("X:32896535:A:T");
CellBaseDataResult<VariantAnnotation> cellBaseDataResult = variantAnnotationCalculator.getAnnotationByVariant(variant, queryOptions);
VariantAnnotation variantAnnotation = cellBaseDataResult.first();
assertTrue(CollectionUtils.isEmpty(variantAnnotation.getFunctionalScore()));
}

private boolean containTraitAssociation(VariantAnnotation variantAnnotation, String source) {
if (variantAnnotation == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.opencb.biodata.models.variant.VariantBuilder;
import org.opencb.biodata.models.variant.avro.PopulationFrequency;
import org.opencb.biodata.models.variant.avro.SampleEntry;
import org.opencb.biodata.models.variant.avro.Score;
import org.opencb.cellbase.core.ParamConstants;
import org.opencb.cellbase.core.api.VariantQuery;
import org.opencb.cellbase.core.api.query.LogicalList;
Expand All @@ -37,6 +38,7 @@
import java.util.Collections;
import java.util.List;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

Expand All @@ -54,15 +56,44 @@ public VariantMongoDBAdaptorTest() throws Exception {
variantManager = cellBaseManagerFactory.getVariantManager(SPECIES, ASSEMBLY);
}

// TODO: to be finished - properly implemented
@Disabled
@Test
public void testGetFunctionalScoreVariant() throws Exception {
// VariantMongoDBAdaptor variationDBAdaptor = dbAdaptorFactory.getVariationDBAdaptor("hsapiens", "GRCh37");
CellBaseDataResult functionalScoreVariant = variantManager.getFunctionalScoreVariant(Variant.parseVariant("10:130862563:A:G"),
new QueryOptions(), dataRelease.getRelease());
public void testGetFunctionalScoreVariantValidApiKey() throws Exception {
Variant variant = Variant.parseVariant("X:32896535:A:T");
CellBaseDataResult functionalScoreVariant = variantManager.getFunctionalScoreVariant(variant, new QueryOptions(),
HGMD_CADD_ACCESS_API_KEY, dataRelease.getRelease());

assertEquals(2, functionalScoreVariant.getNumResults());
}

@Test
public void testGetFunctionalScoreVariantInvalidApiKey() throws Exception {
Variant variant = Variant.parseVariant("X:32896535:A:T");
CellBaseDataResult functionalScoreVariant = variantManager.getFunctionalScoreVariant(variant, new QueryOptions(),
SPLICEAI_ACCESS_API_KEY, dataRelease.getRelease());

assertEquals(0, functionalScoreVariant.getNumResults());
System.out.println("functionalScoreVariant.getEvents() = " + functionalScoreVariant.getEvents());
}

System.out.println("Num. of results: " + functionalScoreVariant.getNumResults());
@Test
public void testGetFunctionalScoreVariantListValidApiKey() throws Exception {
List<Variant> variants = Arrays.asList(Variant.parseVariant("X:32896417:T:G"), Variant.parseVariant("X:32896535:A:T"));
List<CellBaseDataResult<Score>> functionalScoreVariantList = variantManager.getFunctionalScoreVariant(variants, new QueryOptions(),
HGMD_CADD_ACCESS_API_KEY, dataRelease.getRelease());
for (CellBaseDataResult<Score> functionalScoreVariant : functionalScoreVariantList) {
assertTrue(functionalScoreVariant.getNumResults() > 0);
}
}

@Test
public void testGetFunctionalScoreVariantListInvalidApiKey() throws Exception {
List<Variant> variants = Arrays.asList(Variant.parseVariant("X:32896417:T:G"), Variant.parseVariant("X:32896535:A:T"));
List<CellBaseDataResult<Score>> functionalScoreVariantList = variantManager.getFunctionalScoreVariant(variants, new QueryOptions(),
HGMD_SPLICEAI_ACCESS_API_KEY, dataRelease.getRelease());
for (CellBaseDataResult<Score> functionalScoreVariant : functionalScoreVariantList) {
assertEquals(0, functionalScoreVariant.getNumResults());
System.out.println("functionalScoreVariant.getEvents() = " + functionalScoreVariant.getEvents());
}
}

@Test
Expand Down