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: interpret CATEGORICAL metadata as string value #102

Merged
merged 1 commit into from
Nov 26, 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>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