-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server: update variant annotator to return the dbSNP IDs in the field…
… annotation.xrefs, #TASK-5821, #TASK-5789
- Loading branch information
Showing
4 changed files
with
232 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
.../src/main/java/org/opencb/cellbase/lib/variant/annotation/futures/FutureSnpAnnotator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* 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.variant.annotation.futures; | ||
|
||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.opencb.biodata.models.core.Snp; | ||
import org.opencb.biodata.models.variant.Variant; | ||
import org.opencb.biodata.models.variant.avro.VariantAnnotation; | ||
import org.opencb.biodata.models.variant.avro.Xref; | ||
import org.opencb.cellbase.core.api.SnpQuery; | ||
import org.opencb.cellbase.core.result.CellBaseDataResult; | ||
import org.opencb.cellbase.lib.managers.VariantManager; | ||
import org.slf4j.Logger; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.*; | ||
|
||
public class FutureSnpAnnotator implements Callable<List<CellBaseDataResult<Snp>>> { | ||
private VariantManager variantManager; | ||
|
||
private List<Variant> variantList; | ||
private int dataRelease; | ||
|
||
private Logger logger; | ||
|
||
public FutureSnpAnnotator(List<Variant> variantList, int dataRelease, VariantManager variantManager, Logger logger) { | ||
this.variantManager = variantManager; | ||
|
||
this.variantList = variantList; | ||
this.dataRelease = dataRelease; | ||
|
||
this.logger = logger; | ||
} | ||
|
||
@Override | ||
public List<CellBaseDataResult<Snp>> call() throws Exception { | ||
long startTime = System.currentTimeMillis(); | ||
|
||
List<CellBaseDataResult<Snp>> cellBaseDataResultList = new ArrayList<>(variantList.size()); | ||
|
||
logger.debug("SNP queries..."); | ||
// Want to return only one CellBaseDataResult object per Variant | ||
List<String> includes = new ArrayList<>(); | ||
includes.add("id"); | ||
includes.add("source"); | ||
String logMsg = StringUtils.join(includes, ","); | ||
logger.info("SNP annotation/search includes: {}", logMsg); | ||
for (Variant variant : variantList) { | ||
SnpQuery query = new SnpQuery(); | ||
query.setChromosome(variant.getChromosome()); | ||
query.setPosition(variant.getStart()); | ||
query.setReference(variant.getReference()); | ||
query.setDataRelease(dataRelease); | ||
query.setIncludes(includes); | ||
cellBaseDataResultList.add(variantManager.searchSnp(query)); | ||
} | ||
logger.info("SNP queries performance in {} ms for {} variants", System.currentTimeMillis() - startTime, variantList.size()); | ||
return cellBaseDataResultList; | ||
} | ||
|
||
public void processResults(Future<List<CellBaseDataResult<Snp>>> snpFuture, List<VariantAnnotation> variantAnnotationList) | ||
throws InterruptedException, ExecutionException { | ||
List<CellBaseDataResult<Snp>> snpCellBaseDataResults; | ||
try { | ||
snpCellBaseDataResults = snpFuture.get(30, TimeUnit.SECONDS); | ||
} catch (TimeoutException e) { | ||
snpFuture.cancel(true); | ||
throw new ExecutionException("Unable to finish SNP query on time", e); | ||
} | ||
|
||
if (CollectionUtils.isNotEmpty(snpCellBaseDataResults)) { | ||
for (int i = 0; i < variantAnnotationList.size(); i++) { | ||
CellBaseDataResult<Snp> snpResult = snpCellBaseDataResults.get(i); | ||
if (snpResult != null && CollectionUtils.isNotEmpty(snpResult.getResults())) { | ||
List<Xref> xrefs = new ArrayList<>(); | ||
for (Snp snp : snpResult.getResults()) { | ||
xrefs.add(new Xref(snp.getId(), snp.getSource())); | ||
} | ||
if (CollectionUtils.isNotEmpty(xrefs)) { | ||
if (variantAnnotationList.get(i).getXrefs() == null) { | ||
variantAnnotationList.get(i).setXrefs(new ArrayList<>()); | ||
} | ||
variantAnnotationList.get(i).getXrefs().addAll(xrefs); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
...n/java/org/opencb/cellbase/lib/variant/annotation/futures/FutureSpliceScoreAnnotator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* 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.variant.annotation.futures; | ||
|
||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.opencb.biodata.models.core.SpliceScore; | ||
import org.opencb.biodata.models.core.SpliceScoreAlternate; | ||
import org.opencb.biodata.models.variant.Variant; | ||
import org.opencb.biodata.models.variant.avro.ConsequenceType; | ||
import org.opencb.biodata.models.variant.avro.SpliceScores; | ||
import org.opencb.biodata.models.variant.avro.VariantAnnotation; | ||
import org.opencb.cellbase.core.result.CellBaseDataResult; | ||
import org.opencb.cellbase.lib.managers.VariantManager; | ||
import org.slf4j.Logger; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.*; | ||
|
||
public class FutureSpliceScoreAnnotator implements Callable<List<CellBaseDataResult<SpliceScore>>> { | ||
private List<Variant> variantList; | ||
private int dataRelease; | ||
private String apiKey; | ||
|
||
private VariantManager variantManager; | ||
|
||
private Logger logger; | ||
|
||
public FutureSpliceScoreAnnotator(List<Variant> variantList, int dataRelease, String apiKey, VariantManager variantManager, | ||
Logger logger) { | ||
this.variantList = variantList; | ||
this.dataRelease = dataRelease; | ||
this.apiKey = apiKey; | ||
|
||
this.variantManager = variantManager; | ||
|
||
this.logger = logger; | ||
} | ||
|
||
@Override | ||
public List<CellBaseDataResult<SpliceScore>> call() throws Exception { | ||
long startTime = System.currentTimeMillis(); | ||
|
||
List<CellBaseDataResult<SpliceScore>> cellBaseDataResultList = new ArrayList<>(variantList.size()); | ||
|
||
logger.debug("Query splice"); | ||
// Want to return only one CellBaseDataResult object per Variant | ||
for (Variant variant : variantList) { | ||
cellBaseDataResultList.add(variantManager.getSpliceScoreVariant(variant, apiKey, dataRelease)); | ||
} | ||
logger.debug("Splice score query performance is {}ms for {} variants", System.currentTimeMillis() - startTime, | ||
variantList.size()); | ||
return cellBaseDataResultList; | ||
} | ||
|
||
public void processResults(Future<List<CellBaseDataResult<SpliceScore>>> spliceFuture, List<VariantAnnotation> variantAnnotationList) | ||
throws InterruptedException, ExecutionException { | ||
List<CellBaseDataResult<SpliceScore>> spliceCellBaseDataResults; | ||
try { | ||
spliceCellBaseDataResults = spliceFuture.get(30, TimeUnit.SECONDS); | ||
} catch (TimeoutException e) { | ||
spliceFuture.cancel(true); | ||
throw new ExecutionException("Unable to finish splice score query on time", e); | ||
} | ||
|
||
if (CollectionUtils.isNotEmpty(spliceCellBaseDataResults)) { | ||
for (int i = 0; i < variantAnnotationList.size(); i++) { | ||
CellBaseDataResult<SpliceScore> spliceScoreResult = spliceCellBaseDataResults.get(i); | ||
if (spliceScoreResult != null && CollectionUtils.isNotEmpty(spliceScoreResult.getResults())) { | ||
for (SpliceScore spliceScore : spliceScoreResult.getResults()) { | ||
for (ConsequenceType ct : variantAnnotationList.get(i).getConsequenceTypes()) { | ||
for (SpliceScoreAlternate spliceScoreAlt : spliceScore.getAlternates()) { | ||
String alt = StringUtils.isEmpty(variantAnnotationList.get(i).getAlternate()) | ||
? "-" | ||
: variantAnnotationList.get(i).getAlternate(); | ||
if (alt.equals(spliceScoreAlt.getAltAllele())) { | ||
if (StringUtils.isEmpty(spliceScore.getTranscriptId()) | ||
|| StringUtils.isEmpty(ct.getTranscriptId()) | ||
|| spliceScore.getTranscriptId().equals(ct.getTranscriptId())) { | ||
SpliceScores scores = new SpliceScores(spliceScore.getSource(), spliceScoreAlt.getScores()); | ||
if (ct.getSpliceScores() == null) { | ||
ct.setSpliceScores(new ArrayList<>()); | ||
} | ||
ct.getSpliceScores().add(scores); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |