Skip to content

Commit

Permalink
lib: fix annotation test, #TASK-4791, #TASK-4641
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarraga committed Aug 31, 2023
1 parent a553982 commit 46fd4f5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class AbstractManager implements AutoCloseable {
protected MongoDataStore mongoDatastore;
protected MongoDBAdaptorFactory dbAdaptorFactory;

protected ApiKeyManager tokenManager;
protected ApiKeyManager apiKeyManager;

protected Logger logger;

Expand All @@ -58,7 +58,7 @@ public AbstractManager(String databaseName, CellBaseConfiguration configuration)
mongoDatastore = mongoDBManager.createMongoDBDatastore(databaseName);
dbAdaptorFactory = new MongoDBAdaptorFactory(mongoDatastore);

tokenManager = new ApiKeyManager(configuration.getSecretKey());
apiKeyManager = new ApiKeyManager(configuration.getSecretKey());
}

public AbstractManager(String species, String assembly, CellBaseConfiguration configuration)
Expand All @@ -79,7 +79,7 @@ public AbstractManager(String species, String assembly, CellBaseConfiguration co
mongoDatastore = mongoDBManager.createMongoDBDatastore(species, assembly);
dbAdaptorFactory = new MongoDBAdaptorFactory(mongoDatastore);

tokenManager = new ApiKeyManager(configuration.getSecretKey());
apiKeyManager = new ApiKeyManager(configuration.getSecretKey());
}

protected String getApiKey(QueryOptions queryOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public CellBaseDataResult<Variant> search(ClinicalVariantQuery query) throws Que
query.validate();
CellBaseDataResult<Variant> results = getDBAdaptor().query(query);

Set<String> validSources = tokenManager.getValidSources(query.getApiKey(), DataAccessTokenUtils.UNLICENSED_CLINICAL_DATA);
Set<String> validSources = apiKeyManager.getValidSources(query.getApiKey(), DataAccessTokenUtils.UNLICENSED_CLINICAL_DATA);

// Check if is necessary to use the token licensed variant iterator
if (DataAccessTokenUtils.needFiltering(validSources, DataAccessTokenUtils.LICENSED_CLINICAL_DATA)) {
Expand All @@ -93,7 +93,7 @@ public List<CellBaseDataResult<Variant>> info(List<String> ids, CellBaseQueryOpt
throws CellBaseException {
List<CellBaseDataResult<Variant>> results = getDBAdaptor().info(ids, queryOptions, dataRelease, token);

Set<String> validSources = tokenManager.getValidSources(token, DataAccessTokenUtils.UNLICENSED_CLINICAL_DATA);
Set<String> validSources = apiKeyManager.getValidSources(token, DataAccessTokenUtils.UNLICENSED_CLINICAL_DATA);

// Check if is necessary to use the token licensed variant iterator
if (DataAccessTokenUtils.needFiltering(validSources, DataAccessTokenUtils.LICENSED_CLINICAL_DATA)) {
Expand All @@ -105,7 +105,7 @@ public List<CellBaseDataResult<Variant>> info(List<String> ids, CellBaseQueryOpt

@Override
public CellBaseIterator<Variant> iterator(ClinicalVariantQuery query) throws CellBaseException {
Set<String> validSources = tokenManager.getValidSources(query.getApiKey(), DataAccessTokenUtils.UNLICENSED_CLINICAL_DATA);
Set<String> validSources = apiKeyManager.getValidSources(query.getApiKey(), DataAccessTokenUtils.UNLICENSED_CLINICAL_DATA);

// Check if is necessary to use the token licensed variant iterator
if (DataAccessTokenUtils.needFiltering(validSources, DataAccessTokenUtils.LICENSED_CLINICAL_DATA)) {
Expand All @@ -118,7 +118,7 @@ public CellBaseIterator<Variant> iterator(ClinicalVariantQuery query) throws Cel
public CellBaseDataResult<Variant> search(Query query, QueryOptions queryOptions) throws CellBaseException {
CellBaseDataResult<Variant> result = clinicalDBAdaptor.nativeGet(query, queryOptions);

Set<String> validSources = tokenManager.getValidSources(getApiKey(queryOptions), DataAccessTokenUtils.UNLICENSED_CLINICAL_DATA);
Set<String> validSources = apiKeyManager.getValidSources(getApiKey(queryOptions), DataAccessTokenUtils.UNLICENSED_CLINICAL_DATA);

List<String> includes = null;
if (queryOptions.containsKey(INCLUDE)) {
Expand Down Expand Up @@ -176,7 +176,7 @@ public List<CellBaseDataResult<Variant>> getByVariant(List<Variant> variants, Li
QueryOptions queryOptions, int dataRelease) throws CellBaseException {
List<CellBaseDataResult<Variant>> results = clinicalDBAdaptor.getByVariant(variants, geneList, queryOptions, dataRelease);

Set<String> validSources = tokenManager.getValidSources(getApiKey(queryOptions), DataAccessTokenUtils.UNLICENSED_CLINICAL_DATA);
Set<String> validSources = apiKeyManager.getValidSources(getApiKey(queryOptions), DataAccessTokenUtils.UNLICENSED_CLINICAL_DATA);

// TODO: take into account includes and excludes
List<String> includes = null;
Expand All @@ -188,7 +188,7 @@ public List<CellBaseDataResult<Variant>> getByVariant(List<Variant> variants, Li
includes = Arrays.asList(queryOptions.getString(EXCLUDE).split(","));
}

// Check if is necessary to use the token licensed variant iterator
// Check if is necessary to use the API key licensed variant iterator
if (DataAccessTokenUtils.needFiltering(validSources, DataAccessTokenUtils.LICENSED_CLINICAL_DATA)) {
return DataAccessTokenUtils.filterDataSources(results, validSources);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public List<CellBaseDataResult<Variant>> getPopulationFrequencyByVariant(List<Va
}

public CellBaseDataResult<SpliceScore> getSpliceScoreVariant(Variant variant, String token, int dataRelease) throws CellBaseException {
Set<String> validSources = tokenManager.getValidSources(token, DataAccessTokenUtils.UNLICENSED_SPLICE_SCORES_DATA);
Set<String> validSources = apiKeyManager.getValidSources(token, DataAccessTokenUtils.UNLICENSED_SPLICE_SCORES_DATA);

CellBaseDataResult<SpliceScore> result = spliceDBAdaptor.getScores(variant.getChromosome(), variant.getStart(),
variant.getReference(), variant.getAlternate(), dataRelease);
Expand All @@ -325,7 +325,7 @@ public CellBaseDataResult<SpliceScore> getSpliceScoreVariant(Variant variant, St

public List<CellBaseDataResult<SpliceScore>> getSpliceScoreVariant(List<Variant> variants, String token, int dataRelease)
throws CellBaseException {
Set<String> validSources = tokenManager.getValidSources(token, DataAccessTokenUtils.UNLICENSED_SPLICE_SCORES_DATA);
Set<String> validSources = apiKeyManager.getValidSources(token, DataAccessTokenUtils.UNLICENSED_SPLICE_SCORES_DATA);

List<CellBaseDataResult<SpliceScore>> cellBaseDataResults = new ArrayList<>(variants.size());
if (DataAccessTokenUtils.needFiltering(validSources, DataAccessTokenUtils.LICENSED_SPLICE_SCORES_DATA)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static org.opencb.cellbase.core.ParamConstants.API_KEY_PARAM;
import static org.opencb.cellbase.core.variant.PhasedQueryManager.*;

/**
Expand All @@ -72,7 +73,7 @@ public class VariantAnnotationCalculator {
private ProteinManager proteinManager;
private PharmacogenomicsManager pharmacogenomicsManager;
private int dataRelease;
private String token;
private String apiKey;
private Set<String> annotatorSet;
private List<String> includeGeneFields;

Expand All @@ -95,7 +96,7 @@ public class VariantAnnotationCalculator {
private static final ExecutorService CACHED_THREAD_POOL = Executors.newCachedThreadPool();
private static Logger logger = LoggerFactory.getLogger(VariantAnnotationCalculator.class);

public VariantAnnotationCalculator(String species, String assembly, int dataRelease, String token,
public VariantAnnotationCalculator(String species, String assembly, int dataRelease, String apiKey,
CellBaseManagerFactory cellbaseManagerFactory) throws CellBaseException {
this.genomeManager = cellbaseManagerFactory.getGenomeManager(species, assembly);
this.variantManager = cellbaseManagerFactory.getVariantManager(species, assembly);
Expand All @@ -109,7 +110,7 @@ public VariantAnnotationCalculator(String species, String assembly, int dataRele
// Check data release
this.dataRelease = cellbaseManagerFactory.getDataReleaseManager(species, assembly).checkDataRelease(dataRelease);
logger.info("Variant annotation calculator using data release {}", this.dataRelease);
this.token = token;
this.apiKey = apiKey;

// Initialises normaliser configuration with default values. HEADS UP: configuration might be updated
// at parseQueryParam
Expand Down Expand Up @@ -483,7 +484,7 @@ private List<VariantAnnotation> runAnnotationProcess(List<Variant> normalizedVar
QueryOptions queryOptions = new QueryOptions();
queryOptions.add(ParamConstants.QueryParams.PHASE.key(), phased);
queryOptions.add(ParamConstants.QueryParams.CHECK_AMINO_ACID_CHANGE.key(), checkAminoAcidChange);
queryOptions.add("token", token);
queryOptions.add(API_KEY_PARAM, apiKey);
futureClinicalAnnotator = new FutureClinicalAnnotator(normalizedVariantList, batchGeneList, queryOptions);
clinicalFuture = CACHED_THREAD_POOL.submit(futureClinicalAnnotator);
}
Expand Down Expand Up @@ -1922,7 +1923,7 @@ public List<CellBaseDataResult<SpliceScore>> call() throws Exception {
logger.debug("Query splice");
// Want to return only one CellBaseDataResult object per Variant
for (Variant variant : variantList) {
cellBaseDataResultList.add(variantManager.getSpliceScoreVariant(variant, token, dataRelease));
cellBaseDataResultList.add(variantManager.getSpliceScoreVariant(variant, apiKey, dataRelease));
}
logger.debug("Splice score query performance is {}ms for {} variants", System.currentTimeMillis() - startTime,
variantList.size());
Expand Down Expand Up @@ -1974,12 +1975,12 @@ public VariantNormalizer getNormalizer() {
return normalizer;
}

public String getToken() {
return token;
public String getApiKey() {
return apiKey;
}

public VariantAnnotationCalculator setToken(String token) {
this.token = token;
public VariantAnnotationCalculator setApiKey(String apiKey) {
this.apiKey = apiKey;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,7 @@ public void testLicensedDataUnisersalTokenAnnotation() throws Exception {
queryOptions.put("exclude", "pharmacogenomics");
queryOptions.put("normalize", true);

variantAnnotationCalculator.setToken(UNIVERSAL_ACCES_API_KEY);
variantAnnotationCalculator.setApiKey(UNIVERSAL_ACCES_API_KEY);

Variant variant = new Variant("10", 113588287, "G", "A");
CellBaseDataResult<VariantAnnotation> cellBaseDataResult = variantAnnotationCalculator
Expand All @@ -1973,7 +1973,7 @@ public void testLicensedDataHgmdTokenAnnotation() throws Exception {
queryOptions.put("exclude", "pharmacogenomics");
queryOptions.put("normalize", true);

variantAnnotationCalculator.setToken(HGMD_ACCESS_API_KEY);
variantAnnotationCalculator.setApiKey(HGMD_ACCESS_API_KEY);

Variant variant = new Variant("10", 113588287, "G", "A");
CellBaseDataResult<VariantAnnotation> cellBaseDataResult = variantAnnotationCalculator
Expand All @@ -2000,7 +2000,7 @@ public void testLicensedDataCosmicTokenAnnotation() throws Exception {
queryOptions.put("exclude", "pharmacogenomics");
queryOptions.put("normalize", true);

variantAnnotationCalculator.setToken(COSMIC_ACCESS_API_KEY);
variantAnnotationCalculator.setApiKey(COSMIC_ACCESS_API_KEY);

Variant variant = new Variant("10", 113588287, "G", "A");
CellBaseDataResult<VariantAnnotation> cellBaseDataResult = variantAnnotationCalculator
Expand All @@ -2027,7 +2027,7 @@ public void testLicensedDataSpliceTokenAnnotation() throws Exception {
queryOptions.put("exclude", "pharmacogenomics");
queryOptions.put("normalize", true);

variantAnnotationCalculator.setToken(SPLICEAI_ACCESS_API_KEY);
variantAnnotationCalculator.setApiKey(SPLICEAI_ACCESS_API_KEY);

Variant variant = new Variant("10", 113588287, "G", "A");
CellBaseDataResult<VariantAnnotation> cellBaseDataResult = variantAnnotationCalculator
Expand All @@ -2054,7 +2054,7 @@ public void testLicensedDataHgmdCosmicTokenAnnotation() throws Exception {
queryOptions.put("exclude", "pharmacogenomics");
queryOptions.put("normalize", true);

variantAnnotationCalculator.setToken(HGMD_COSMIC_ACCESS_API_KEY);
variantAnnotationCalculator.setApiKey(HGMD_COSMIC_ACCESS_API_KEY);

Variant variant = new Variant("10", 113588287, "G", "A");
CellBaseDataResult<VariantAnnotation> cellBaseDataResult = variantAnnotationCalculator
Expand All @@ -2081,7 +2081,7 @@ public void testLicensedDataHgmdSpliceAiTokenAnnotation() throws Exception {
queryOptions.put("exclude", "pharmacogenomics");
queryOptions.put("normalize", true);

variantAnnotationCalculator.setToken(HGMD_SPLICEAI_ACCESS_API_KEY);
variantAnnotationCalculator.setApiKey(HGMD_SPLICEAI_ACCESS_API_KEY);

Variant variant = new Variant("10", 113588287, "G", "A");
CellBaseDataResult<VariantAnnotation> cellBaseDataResult = variantAnnotationCalculator
Expand All @@ -2108,7 +2108,7 @@ public void testLicensedDataCosmicSpliceTokenAnnotation() throws Exception {
queryOptions.put("exclude", "pharmacogenomics");
queryOptions.put("normalize", true);

variantAnnotationCalculator.setToken(COSMIC_SPLICEAI_ACCESS_API_KEY);
variantAnnotationCalculator.setApiKey(COSMIC_SPLICEAI_ACCESS_API_KEY);

Variant variant = new Variant("10", 113588287, "G", "A");
CellBaseDataResult<VariantAnnotation> cellBaseDataResult = variantAnnotationCalculator
Expand Down

0 comments on commit 46fd4f5

Please sign in to comment.