Skip to content

Commit

Permalink
Merge pull request #102 from molgenis/fix/categorical
Browse files Browse the repository at this point in the history
Fix: interpret CATEGORICAL metadata as string value
  • Loading branch information
dennishendriksen authored Nov 26, 2024
2 parents c905eb5 + cf88f6f commit 96f5268
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
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>5.1.0</version>
<version>5.1.1</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
Expand Up @@ -373,7 +373,7 @@ private Object getInfo(Field field) {
case FLOAT:
value = VcfUtils.getInfoAsDouble(variantContext, field);
break;
case CHARACTER, STRING:
case CHARACTER, STRING, CATEGORICAL:
value = VcfUtils.getInfoAsString(variantContext, field);
break;
default:
Expand All @@ -392,7 +392,7 @@ private List<?> getInfoList(Field field) {
case FLOAT:
listValues = VcfUtils.getInfoAsDoubleList(variantContext, field);
break;
case CHARACTER, STRING:
case CHARACTER, STRING, CATEGORICAL:
listValues = VcfUtils.getInfoAsStringList(variantContext, field);
break;
case FLAG:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private static void validateValueTypes(String nodeId, Object singleValue, ValueT
singleValue, singleValue.getClass().getSimpleName(), valueType, nodeId));
}
break;
case STRING:
case STRING, CATEGORICAL:
if (!(String.class.isAssignableFrom(singleValue.getClass()))) {
throw new ConfigDecisionTreeValidationException(
format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,19 @@ void getValueInfoFixedOneString() {
assertEquals("str0", vcfRecord.getValue(field, createAllele()));
}

@Test
void getValueInfoFixedOneCategorical() {
FieldImpl field =
FieldImpl.builder()
.id("my_field")
.fieldType(FieldType.INFO)
.valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build())
.valueType(ValueType.CATEGORICAL)
.build();
when(variantContext.getAttribute("my_field")).thenReturn("str0");
assertEquals("str0", vcfRecord.getValue(field, createAllele()));
}

@Test
void getValueFormatAD() {
FieldImpl field =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ private static Stream<Arguments> provideValidValues() {
ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)),
Arguments.of("123", new FieldImpl("id", FieldType.INFO, ValueType.STRING,
ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)),
Arguments.of("123", new FieldImpl("id", FieldType.INFO, ValueType.CATEGORICAL,
ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)),
Arguments.of(1, new FieldImpl("id", FieldType.INFO, ValueType.FLOAT,
ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)),
Arguments.of(true, new FieldImpl("id", FieldType.INFO, ValueType.FLAG,
Expand Down

0 comments on commit 96f5268

Please sign in to comment.