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

fix cnvpadding param. TEST FAILING #628

Open
wants to merge 2 commits into
base: release-5.2.x
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 @@ -32,6 +32,7 @@
import org.opencb.commons.datastore.core.QueryOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.opencb.biodata.models.variant.avro.VariantType;

import java.util.*;

Expand Down Expand Up @@ -73,7 +74,9 @@ protected void parseQueryParam(QueryOptions queryOptions) {
}

protected int getStart(int extraPadding) {
if (imprecise && variant.getSv() != null) {
if (imprecise && VariantType.CNV.equals(variant.getType())) {
return variant.getStart() - extraPadding;
} else if (imprecise && variant.getSv() != null) {
return variant.getSv().getCiStartLeft() != null ? variant.getSv().getCiStartLeft() - extraPadding
: variant.getStart();
} else {
Expand All @@ -83,7 +86,9 @@ protected int getStart(int extraPadding) {
}

protected int getEnd(int extraPadding) {
if (imprecise && variant.getSv() != null) {
if (imprecise && VariantType.CNV.equals(variant.getType())) {
return variant.getEnd() + extraPadding;
} else if (imprecise && variant.getSv() != null) {
return variant.getSv().getCiEndRight() != null ? variant.getSv().getCiEndRight() + extraPadding
: variant.getEnd();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.opencb.biodata.models.core.Gene;
import org.opencb.biodata.models.core.Transcript;
import org.opencb.biodata.models.variant.Variant;
import org.opencb.biodata.models.variant.avro.VariantType;
import org.opencb.biodata.models.variant.avro.ConsequenceType;
import org.opencb.biodata.models.variant.avro.ExonOverlap;
import org.opencb.cellbase.core.ParamConstants;
Expand All @@ -43,8 +44,9 @@ public List<ConsequenceType> run(Variant inputVariant, List<Gene> geneList, bool
parseQueryParam(queryOptions);
List<ConsequenceType> consequenceTypeList = new ArrayList<>();
variant = inputVariant;
variantEnd = getEnd(svExtraPadding);
variantStart = getStart(svExtraPadding);
int extraPadding = VariantType.CNV.equals(variant.getType()) ? cnvExtraPadding : svExtraPadding;
variantEnd = getEnd(extraPadding);
variantStart = getStart(extraPadding);
// isBigDeletion = ((variantEnd - variantStart) > BIG_VARIANT_SIZE_THRESHOLD);
boolean isIntergenic = true;
for (Gene currentGene : geneList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,8 @@ private List<VariantAnnotation> runAnnotationProcess(List<Variant> normalizedVar

if (annotatorSet.contains("consequenceType")) {
try {
List<ConsequenceType> consequenceTypeList = getConsequenceTypeList(variant, affectedGenes, true, QueryOptions.empty(),
dataRelease);
List<ConsequenceType> consequenceTypeList = getConsequenceTypeList(variant, affectedGenes, true,
new QueryOptions().append("imprecise", imprecise).append("cnvExtraPadding", cnvExtraPadding), dataRelease);
variantAnnotation.setConsequenceTypes(consequenceTypeList);
if (phased) {
checkAndAdjustPhasedConsequenceTypes(variant, variantBuffer, dataRelease);
Expand Down Expand Up @@ -1308,6 +1308,9 @@ private boolean[] getRegulatoryRegionOverlaps(Variant variant) throws QueryExcep
return getRegulatoryRegionOverlaps(variant.getChromosome(), variant.getStart());
} else if (VariantType.INDEL.equals(variant.getType()) && StringUtils.isBlank(variant.getReference())) {
return getRegulatoryRegionOverlaps(variant.getChromosome(), variant.getStart() - 1, variant.getEnd());
} else if (VariantType.CNV.equals(variant.getType())) {
return getRegulatoryRegionOverlaps(variant.getChromosome(), variant.getStart() - cnvExtraPadding,
variant.getEnd() + cnvExtraPadding);
// Short deletions and symbolic variants except breakends
} else if (!VariantType.BREAKEND.equals(variant.getType())) {
return getRegulatoryRegionOverlaps(variant.getChromosome(), variant.getStart(), variant.getEnd());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.opencb.cellbase.lib.GenericMongoDBAdaptorTest;
import org.opencb.cellbase.lib.variant.annotation.VariantAnnotationCalculator;
import org.opencb.commons.datastore.core.QueryOptions;
import org.opencb.commons.datastore.core.result.QueryResult;

import java.io.IOException;
import java.nio.file.Path;
Expand Down Expand Up @@ -1957,6 +1958,39 @@ public void testGetAllConsequenceTypesByVariant() throws IOException, QueryExcep
// }
}

@Test
// long variant should have same annotations as short variant + cnvPadding
public void testCNVExtraPadding() throws Exception {

// short variant
Variant shortVariant = new Variant("chr17:43087248-43087249:<CNV>");
// long variant
Variant longVariant = new Variant("chr17:43087248-43098506:<CNV>");

QueryOptions queryOptions = new QueryOptions("useCache", false);
queryOptions.put("include", "consequenceType, reference, alternate ,clinical");
queryOptions.put("normalize", true);
queryOptions.put("skipDecompose", false);
queryOptions.put("checkAminoAcidChange", true);
queryOptions.put("imprecise", true);
queryOptions.put("phased", false);

// long variant
CellBaseDataResult<ConsequenceType> consequenceTypeResult =
variantAnnotationCalculator.getAllConsequenceTypesByVariant(longVariant, queryOptions);
assertEquals(27, consequenceTypeResult.getNumResults());

// short variant
consequenceTypeResult = variantAnnotationCalculator.getAllConsequenceTypesByVariant(shortVariant, queryOptions);
assertEquals(27, consequenceTypeResult.getNumResults());

queryOptions.put("cnvExtraPadding", 10000);

// short variant with padding
consequenceTypeResult = variantAnnotationCalculator.getAllConsequenceTypesByVariant(shortVariant, queryOptions);
assertEquals(27, consequenceTypeResult.getNumResults());
}

private <T> void assertObjectListEquals(String expectedConsequenceTypeJson, List<T> actualList,
Class<T> clazz) throws IOException {
ObjectReader reader = jsonObjectMapper
Expand Down