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 allowed operators for "file" values and improve exception messages. #88

Merged
merged 2 commits into from
Apr 25, 2024
Merged
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<groupId>org.molgenis</groupId>
<artifactId>vip-decision-tree</artifactId>
<version>4.0.0</version>
<version>4.1.0</version>

<name>vip-decision-tree</name>
<description>Decision tree module for filtering and labelling VCF files</description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.molgenis.vcf.decisiontree.runner;

import static org.molgenis.vcf.decisiontree.loader.model.ConfigOperator.IN;
import static org.molgenis.vcf.decisiontree.loader.model.ConfigOperator.NOT_IN;

import java.util.Collection;
import java.util.Set;
import org.molgenis.vcf.decisiontree.filter.model.BoolNode;
Expand All @@ -16,10 +13,12 @@
import org.molgenis.vcf.utils.UnexpectedEnumException;
import org.springframework.stereotype.Component;

import static org.molgenis.vcf.decisiontree.loader.model.ConfigOperator.*;

@Component
public class QueryValidatorImpl implements QueryValidator {

public static final Set<ConfigOperator> ALLOWED_FILE_OPERATORS = Set.of(IN, NOT_IN);
public static final Set<ConfigOperator> ALLOWED_FILE_OPERATORS = Set.of(IN, NOT_IN, CONTAINS, NOT_CONTAINS, CONTAINS_ALL, CONTAINS_ANY, CONTAINS_NONE);

@Override
public void validateBooleanNode(ConfigBoolQuery configBoolQuery, Field field) {
Expand Down Expand Up @@ -57,7 +56,7 @@ private void validateLesserGreater(Field field, ConfigBoolQuery query) {
if (field.getValueType() != ValueType.FLOAT && field.getValueType() != ValueType.INTEGER) {
throw new UnsupportedValueTypeException(field, DecisionType.BOOL);
}
validateSingleOrPerAlleleCount(field, DecisionType.BOOL);
validateSingleOrPerAlleleCount(field, DecisionType.BOOL, IN);
}

private void validateEquals(Field field, ConfigBoolQuery configBoolQuery) {
Expand All @@ -72,7 +71,7 @@ private void validateIn(Field field) {
if (field.getValueType() == ValueType.FLAG || field.getValueType() == ValueType.FLOAT) {
throw new UnsupportedValueTypeException(field, DecisionType.BOOL);
} else {
validateSingleOrPerAlleleCount(field, DecisionType.BOOL);
validateSingleOrPerAlleleCount(field, DecisionType.BOOL, IN);
}
}

Expand All @@ -82,17 +81,17 @@ private void validateContains(Field field, ConfigBoolQuery configBoolQuery) {
throw new UnsupportedValueTypeException(field, DecisionType.BOOL);
} else if (field.getValueCount().getType() == Type.FIXED
&& field.getValueCount().getCount() == 1) {
throw new UnsupportedValueCountException(field, DecisionType.BOOL);
throw new UnsupportedValueCountException(field, DecisionType.BOOL, CONTAINS);
}
}

private void validateSingleOrPerAlleleCount(Field field, DecisionType decisionType) {
private void validateSingleOrPerAlleleCount(Field field, DecisionType decisionType, ConfigOperator configOperator) {
if (field.getValueCount().getType() == Type.G ||
field.getValueCount().getType() == Type.VARIABLE) {
throw new UnsupportedValueCountTypeException(field, decisionType);
throw new UnsupportedValueCountTypeException(field, decisionType, configOperator);
} else if (field.getValueCount().getType() == Type.FIXED
&& field.getValueCount().getCount() != 1) {
throw new UnsupportedValueCountException(field, decisionType);
throw new UnsupportedValueCountException(field, decisionType, configOperator);
}
}

Expand All @@ -102,7 +101,7 @@ public void validateCategoricalNode(Field field) {
if (field.getValueType() == ValueType.FLAG || field.getValueType() == ValueType.FLOAT) {
throw new UnsupportedValueTypeException(field, DecisionType.CATEGORICAL);
}
validateSingleOrPerAlleleCount(field, DecisionType.CATEGORICAL);
validateSingleOrPerAlleleCount(field, DecisionType.CATEGORICAL, IN);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

import org.molgenis.vcf.decisiontree.filter.model.DecisionType;
import org.molgenis.vcf.decisiontree.filter.model.Field;
import org.molgenis.vcf.decisiontree.loader.model.ConfigOperator;

import java.io.Serial;

public class UnsupportedValueCountException extends RuntimeException {
@Serial
private static final long serialVersionUID = 1L;
public UnsupportedValueCountException(Field field, DecisionType decisionType) {
public UnsupportedValueCountException(Field field, DecisionType decisionType, ConfigOperator configOperator) {
super(
format(
"Unsupported number of values (%d) for field '%s' for decision type '%s'.", field.getValueCount().getCount(), field.getId(), decisionType));
"Unsupported number of values (%d) for field '%s' for combination of decision type '%s' and operator of type '%s'.", field.getValueCount().getCount(), field.getId(), decisionType, configOperator));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@

import org.molgenis.vcf.decisiontree.filter.model.DecisionType;
import org.molgenis.vcf.decisiontree.filter.model.Field;
import org.molgenis.vcf.decisiontree.loader.model.ConfigOperator;

import java.io.Serial;

public class UnsupportedValueCountTypeException extends RuntimeException {
@Serial
private static final long serialVersionUID = 1L;
public UnsupportedValueCountTypeException(Field field, DecisionType decisionType) {
public UnsupportedValueCountTypeException(Field field, DecisionType decisionType, ConfigOperator configOperator) {
super(
format(
"Unsupported value count type '%s' of field '%s' for decision type '%s'.",
field.getValueCount().getType(), field.getId(), decisionType));
"Unsupported value count type '%s' of field '%s' for combination of decision type '%s' and operator of type '%s'.",
field.getValueCount().getType(), field.getId(), decisionType, configOperator.toString()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
import org.molgenis.vcf.decisiontree.filter.model.ValueCount;
import org.molgenis.vcf.decisiontree.filter.model.ValueCount.Type;
import org.molgenis.vcf.decisiontree.filter.model.ValueType;
import org.molgenis.vcf.decisiontree.loader.model.ConfigOperator;

class UnsupportedValueCountExceptionTest {
@Test
void getMessage() {
assertEquals(
"Unsupported number of values (3) for field 'test' for decision type 'CATEGORICAL'.",
"Unsupported number of values (3) for field 'test' for combination of decision type 'CATEGORICAL' and operator of type 'CONTAINS'.",
new UnsupportedValueCountException(
FieldImpl.builder().id("test").fieldType(FieldType.INFO).valueType(ValueType.FLOAT)
.valueCount(
ValueCount.builder().type(Type.FIXED).count(3).build()).build(), DecisionType.CATEGORICAL).getMessage());
ValueCount.builder().type(Type.FIXED).count(3).build()).build(), DecisionType.CATEGORICAL, ConfigOperator.CONTAINS).getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
import org.molgenis.vcf.decisiontree.filter.model.ValueCount;
import org.molgenis.vcf.decisiontree.filter.model.ValueCount.Type;
import org.molgenis.vcf.decisiontree.filter.model.ValueType;
import org.molgenis.vcf.decisiontree.loader.model.ConfigOperator;

class UnsupportedValueCountTypeExceptionTest {
@Test
void getMessage() {
assertEquals(
"Unsupported value count type 'G' of field 'test' for decision type 'CATEGORICAL'.",
"Unsupported value count type 'G' of field 'test' for combination of decision type 'CATEGORICAL' and operator of type 'IN'.",
new UnsupportedValueCountTypeException(
FieldImpl.builder().id("test").fieldType(FieldType.INFO).valueType(ValueType.FLOAT)
.valueCount(
ValueCount.builder().type(Type.G).build()).build(), DecisionType.CATEGORICAL).getMessage());
ValueCount.builder().type(Type.G).build()).build(), DecisionType.CATEGORICAL, ConfigOperator.IN).getMessage());
}
}
3 changes: 3 additions & 0 deletions src/test/resources/clinvar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
conflicting_interpretations_of_pathogenicity
conflicting_data_from_submitters
uncertain_significance
11 changes: 6 additions & 5 deletions src/test/resources/example.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"files": {
"clinvar" : {
"path" : "src/test/resources/clinvar.txt"
}
},
"rootNode": "filter",
"nodes": {
"filter": {
Expand Down Expand Up @@ -163,11 +168,7 @@
{
"field": "INFO/CLINVAR",
"operator": "contains_any",
"value": [
"conflicting_interpretations_of_pathogenicity",
"conflicting_data_from_submitters",
"uncertain_significance"
]
"value": "file:clinvar"
}
],
"outcomeTrue": {
Expand Down