diff --git a/pom.xml b/pom.xml index 97f97bf9..abbbe263 100644 --- a/pom.xml +++ b/pom.xml @@ -43,7 +43,7 @@ 1.9.0 4.1.1 0.8.12 - 2.0.2 + 3.0.0 diff --git a/src/main/java/org/molgenis/vcf/decisiontree/filter/VcfMetadata.java b/src/main/java/org/molgenis/vcf/decisiontree/filter/VcfMetadata.java index 9b876109..ae9f6204 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/filter/VcfMetadata.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/filter/VcfMetadata.java @@ -18,12 +18,11 @@ import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; import org.molgenis.vcf.decisiontree.filter.model.FieldType; import org.molgenis.vcf.decisiontree.filter.model.MissingField; -import org.molgenis.vcf.decisiontree.filter.model.ValueCount; -import org.molgenis.vcf.decisiontree.filter.model.ValueCount.Type; -import org.molgenis.vcf.decisiontree.filter.model.ValueCount.ValueCountBuilder; -import org.molgenis.vcf.decisiontree.filter.model.ValueType; import org.molgenis.vcf.decisiontree.runner.info.NestedHeaderLine; import org.molgenis.vcf.utils.UnexpectedEnumException; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueCount.ValueCountBuilder; +import org.molgenis.vcf.utils.metadata.ValueType; /** * {@link VCFHeader} wrapper that works with nested metadata (e.g. CSQ INFO fields). @@ -72,15 +71,15 @@ private static Field toSampleField(List fieldTokens) { switch (field.toUpperCase()) { case "PROBAND" -> { valueType = ValueType.FLAG; - valueCount = ValueCount.builder().type(Type.FIXED).count(1).build(); + valueCount = ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(); } case "ID", "AFFECTED_STATUS", "SEX", "FATHER_ID", "MOTHER_ID", "FAMILY_ID" -> { valueType = ValueType.STRING; - valueCount = ValueCount.builder().type(Type.FIXED).count(1).build(); + valueCount = ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(); } case "PHENOTYPES" -> { valueType = ValueType.STRING; - valueCount = ValueCount.builder().type(Type.VARIABLE).nullable(true).build(); + valueCount = ValueCount.builder().type(ValueCount.Type.VARIABLE).nullable(true).build(); } default -> throw new UnsupportedFieldException(field); } @@ -127,19 +126,19 @@ private FieldImpl toCommonField(List fieldTokens) { switch (field) { case "#CHROM", "REF" -> { valueType = ValueType.STRING; - valueCount = ValueCount.builder().type(Type.FIXED).count(1).build(); + valueCount = ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(); } case "POS" -> { valueType = ValueType.INTEGER; - valueCount = ValueCount.builder().type(Type.FIXED).count(1).build(); + valueCount = ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(); } case "ID", "FILTER", "ALT" -> { valueType = ValueType.STRING; - valueCount = ValueCount.builder().type(Type.VARIABLE).nullable(true).build(); + valueCount = ValueCount.builder().type(ValueCount.Type.VARIABLE).nullable(true).build(); } case "QUAL" -> { valueType = ValueType.FLOAT; - valueCount = ValueCount.builder().type(Type.FIXED).count(1).nullable(true).build(); + valueCount = ValueCount.builder().type(ValueCount.Type.FIXED).count(1).nullable(true).build(); } default -> throw new UnsupportedFieldException(field); } @@ -179,12 +178,12 @@ private Field toCompoundField(List fieldTokens, FieldType fieldType) { switch (countType) { case INTEGER -> { int count = vcfCompoundHeaderLine.getCount(); - builder.type(Type.FIXED).count(count).nullable(valueType != ValueType.FLAG); + builder.type(ValueCount.Type.FIXED).count(count).nullable(valueType != ValueType.FLAG); } - case A -> builder.type(Type.A).nullable(true); - case R -> builder.type(Type.R).nullable(true); - case G -> builder.type(Type.G).nullable(true); - case UNBOUNDED -> builder.type(Type.VARIABLE).nullable(true); + case A -> builder.type(ValueCount.Type.A).nullable(true); + case R -> builder.type(ValueCount.Type.R).nullable(true); + case G -> builder.type(ValueCount.Type.G).nullable(true); + case UNBOUNDED -> builder.type(ValueCount.Type.VARIABLE).nullable(true); default -> throw new UnexpectedEnumException(countType); } @@ -217,7 +216,7 @@ private VCFCompoundHeaderLine getVcfCompoundHeaderLine(FieldType fieldType, Stri } public static boolean isSingleValueField(Field field) { - return field.getValueCount().getType() == Type.FIXED && field.getValueCount().getCount() <= 1; + return field.getValueCount().getType() == ValueCount.Type.FIXED && field.getValueCount().getCount() <= 1; } public Map getSampleNameToOffset() { diff --git a/src/main/java/org/molgenis/vcf/decisiontree/filter/VcfReader.java b/src/main/java/org/molgenis/vcf/decisiontree/filter/VcfReader.java index dfcf5b39..f48e47bd 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/filter/VcfReader.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/filter/VcfReader.java @@ -5,9 +5,12 @@ import htsjdk.variant.vcf.VCFFileReader; import java.util.stream.Stream; import java.util.stream.StreamSupport; + +import htsjdk.variant.vcf.VCFInfoHeaderLine; import org.molgenis.vcf.decisiontree.runner.info.GenotypeMetadataMapper; +import org.molgenis.vcf.decisiontree.runner.info.MissingVepException; import org.molgenis.vcf.decisiontree.runner.info.NestedHeaderLine; -import org.molgenis.vcf.decisiontree.runner.info.VepMetadataParser; +import org.molgenis.vcf.decisiontree.runner.info.VepMetadataMapper; /** * {@link VCFFileReader} wrapper that works with nested metadata and data (e.g. CSQ INFO fields). @@ -15,30 +18,43 @@ public class VcfReader implements AutoCloseable { private final VCFFileReader vcfFileReader; - private final VepMetadataParser vepMetadataParser; + private final VepMetadataMapper vepMetadataMapper; private final boolean strict; private final GenotypeMetadataMapper genotypeMetadataMapper; private boolean inited = false; private NestedHeaderLine vepNestedHeaderLine = null; private NestedHeaderLine gtNestedHeaderLine = null; - public VcfReader(VCFFileReader vcfFileReader, VepMetadataParser vepMetadataParser, + public VcfReader(VCFFileReader vcfFileReader, VepMetadataMapper vepMetadataMapper, GenotypeMetadataMapper genotypeMetadataMapper, boolean strict) { this.vcfFileReader = requireNonNull(vcfFileReader); - this.vepMetadataParser = requireNonNull(vepMetadataParser); + this.vepMetadataMapper = requireNonNull(vepMetadataMapper); this.genotypeMetadataMapper = requireNonNull(genotypeMetadataMapper); this.strict = strict; } private void initNestedMeta() { if (!inited) { - vepNestedHeaderLine = vepMetadataParser.map(vcfFileReader.getFileHeader()); + String vepID = getVepId(); + if(vepID == null) { + throw new MissingVepException(); + } + vepNestedHeaderLine = vepMetadataMapper.map(vepID, vcfFileReader.getFileHeader()); gtNestedHeaderLine = genotypeMetadataMapper.map(); inited = true; } } + private String getVepId() { + for(VCFInfoHeaderLine vcfInfoHeaderLine : vcfFileReader.getFileHeader().getInfoHeaderLines()){ + if(vepMetadataMapper.canMap(vcfInfoHeaderLine)){ + return vcfInfoHeaderLine.getID(); + } + } + return null; + } + public Stream stream() { return StreamSupport.stream(vcfFileReader.spliterator(), false).map(VcfRecord::new); } diff --git a/src/main/java/org/molgenis/vcf/decisiontree/filter/VcfRecord.java b/src/main/java/org/molgenis/vcf/decisiontree/filter/VcfRecord.java index 8c42c72a..d9b5aeb7 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/filter/VcfRecord.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/filter/VcfRecord.java @@ -21,11 +21,10 @@ import org.molgenis.vcf.decisiontree.filter.model.NestedField; import org.molgenis.vcf.decisiontree.filter.model.SampleContext; import org.molgenis.vcf.decisiontree.filter.model.SampleFieldType; -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.utils.VcfUtils; import org.molgenis.vcf.utils.UnexpectedEnumException; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; import org.springframework.lang.Nullable; /** @@ -240,7 +239,7 @@ private Object getExtendedAttributeValue(Field field, Genotype genotype) { } ValueCount valueCount = field.getValueCount(); - Type valueCountType = valueCount.getType(); + ValueCount.Type valueCountType = valueCount.getType(); switch (valueCountType) { case A, R, VARIABLE: typedValue = @@ -339,7 +338,7 @@ private Object getInfoValue(Field field, Allele allele) { Object value; ValueCount valueCount = field.getValueCount(); - Type valueCountType = valueCount.getType(); + ValueCount.Type valueCountType = valueCount.getType(); switch (valueCountType) { case A: List aInfoList = getInfoList(field); diff --git a/src/main/java/org/molgenis/vcf/decisiontree/filter/model/Field.java b/src/main/java/org/molgenis/vcf/decisiontree/filter/model/Field.java index cd3507ef..95ee9dc8 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/filter/model/Field.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/filter/model/Field.java @@ -1,5 +1,8 @@ package org.molgenis.vcf.decisiontree.filter.model; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; + public interface Field { String getId(); diff --git a/src/main/java/org/molgenis/vcf/decisiontree/filter/model/FieldImpl.java b/src/main/java/org/molgenis/vcf/decisiontree/filter/model/FieldImpl.java index a1e02315..499bd4c2 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/filter/model/FieldImpl.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/filter/model/FieldImpl.java @@ -1,21 +1,23 @@ package org.molgenis.vcf.decisiontree.filter.model; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.NonNull; -import lombok.Value; +import lombok.*; import lombok.experimental.NonFinal; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; @Value @Builder @NonFinal @AllArgsConstructor +@EqualsAndHashCode public class FieldImpl implements Field { @NonNull String id; @NonNull FieldType fieldType; - @NonNull ValueType valueType; - @NonNull ValueCount valueCount; + @NonNull + ValueType valueType; + @NonNull + ValueCount valueCount; /** * Returns count for FIXED value type, null otherwise */ diff --git a/src/main/java/org/molgenis/vcf/decisiontree/filter/model/GenotypeField.java b/src/main/java/org/molgenis/vcf/decisiontree/filter/model/GenotypeField.java index 161a4499..ac9fb886 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/filter/model/GenotypeField.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/filter/model/GenotypeField.java @@ -6,6 +6,8 @@ import lombok.NonNull; import lombok.Value; import lombok.experimental.NonFinal; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; @Value @NonFinal diff --git a/src/main/java/org/molgenis/vcf/decisiontree/filter/model/MissingField.java b/src/main/java/org/molgenis/vcf/decisiontree/filter/model/MissingField.java index 9f141fe1..ebb493f5 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/filter/model/MissingField.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/filter/model/MissingField.java @@ -5,6 +5,8 @@ import lombok.NonNull; import lombok.Value; import lombok.experimental.NonFinal; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; @Value @Builder diff --git a/src/main/java/org/molgenis/vcf/decisiontree/filter/model/NestedField.java b/src/main/java/org/molgenis/vcf/decisiontree/filter/model/NestedField.java index 86263d13..e4d53e7f 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/filter/model/NestedField.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/filter/model/NestedField.java @@ -3,12 +3,16 @@ import static java.util.Objects.requireNonNull; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.NonNull; import lombok.Value; import lombok.experimental.NonFinal; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; @Value @NonFinal +@EqualsAndHashCode(callSuper = false) public class NestedField extends FieldImpl implements Comparable { final int index; diff --git a/src/main/java/org/molgenis/vcf/decisiontree/filter/model/ValueCount.java b/src/main/java/org/molgenis/vcf/decisiontree/filter/model/ValueCount.java deleted file mode 100644 index d61c876a..00000000 --- a/src/main/java/org/molgenis/vcf/decisiontree/filter/model/ValueCount.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.molgenis.vcf.decisiontree.filter.model; - -import lombok.Builder; -import lombok.NonNull; -import lombok.Value; -import lombok.experimental.NonFinal; - -@Value -@Builder -@NonFinal -public class ValueCount { - - public enum Type { - A, - R, - G, - VARIABLE, - FIXED - } - - @NonNull - Type type; - /** - * Returns count for FIXED values, otherwise null - */ - Integer count; - /** - * True if null value (list item) is allowed - */ - boolean nullable; -} diff --git a/src/main/java/org/molgenis/vcf/decisiontree/filter/model/ValueType.java b/src/main/java/org/molgenis/vcf/decisiontree/filter/model/ValueType.java deleted file mode 100644 index dedfdccc..00000000 --- a/src/main/java/org/molgenis/vcf/decisiontree/filter/model/ValueType.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.molgenis.vcf.decisiontree.filter.model; - -public enum ValueType { - INTEGER, - FLOAT, - FLAG, - CHARACTER, - STRING -} diff --git a/src/main/java/org/molgenis/vcf/decisiontree/runner/QueryValidatorImpl.java b/src/main/java/org/molgenis/vcf/decisiontree/runner/QueryValidatorImpl.java index e2b0e3b0..58c2849b 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/runner/QueryValidatorImpl.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/runner/QueryValidatorImpl.java @@ -6,11 +6,11 @@ import org.molgenis.vcf.decisiontree.filter.model.DecisionType; import org.molgenis.vcf.decisiontree.filter.model.Field; import org.molgenis.vcf.decisiontree.filter.model.MissingField; -import org.molgenis.vcf.decisiontree.filter.model.ValueCount.Type; -import org.molgenis.vcf.decisiontree.filter.model.ValueType; import org.molgenis.vcf.decisiontree.loader.model.ConfigBoolQuery; import org.molgenis.vcf.decisiontree.loader.model.ConfigOperator; import org.molgenis.vcf.utils.UnexpectedEnumException; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; import org.springframework.stereotype.Component; import static org.molgenis.vcf.decisiontree.loader.model.ConfigOperator.*; @@ -79,17 +79,17 @@ private void validateContains(Field field, ConfigBoolQuery configBoolQuery) { validateFileValueAllowed(configBoolQuery, field); if (field.getValueType() == ValueType.FLAG || field.getValueType() == ValueType.FLOAT) { throw new UnsupportedValueTypeException(field, DecisionType.BOOL); - } else if (field.getValueCount().getType() == Type.FIXED + } else if (field.getValueCount().getType() == ValueCount.Type.FIXED && field.getValueCount().getCount() == 1) { throw new UnsupportedValueCountException(field, DecisionType.BOOL, CONTAINS); } } private void validateSingleOrPerAlleleCount(Field field, DecisionType decisionType, ConfigOperator configOperator) { - if (field.getValueCount().getType() == Type.G || - field.getValueCount().getType() == Type.VARIABLE) { + if (field.getValueCount().getType() == ValueCount.Type.G || + field.getValueCount().getType() == ValueCount.Type.VARIABLE) { throw new UnsupportedValueCountTypeException(field, decisionType, configOperator); - } else if (field.getValueCount().getType() == Type.FIXED + } else if (field.getValueCount().getType() == ValueCount.Type.FIXED && field.getValueCount().getCount() != 1) { throw new UnsupportedValueCountException(field, decisionType, configOperator); } diff --git a/src/main/java/org/molgenis/vcf/decisiontree/runner/ValueValidator.java b/src/main/java/org/molgenis/vcf/decisiontree/runner/ValueValidator.java index f3962456..2305c884 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/runner/ValueValidator.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/runner/ValueValidator.java @@ -19,7 +19,6 @@ import org.molgenis.vcf.decisiontree.filter.VcfMetadata; import org.molgenis.vcf.decisiontree.filter.model.Field; import org.molgenis.vcf.decisiontree.filter.model.MissingField; -import org.molgenis.vcf.decisiontree.filter.model.ValueType; import org.molgenis.vcf.decisiontree.loader.ConfigDecisionTreeValidationException; import org.molgenis.vcf.decisiontree.loader.model.ConfigBoolMultiNode; import org.molgenis.vcf.decisiontree.loader.model.ConfigBoolNode; @@ -28,6 +27,7 @@ import org.molgenis.vcf.decisiontree.loader.model.ConfigNode; import org.molgenis.vcf.decisiontree.loader.model.ConfigOperator; import org.molgenis.vcf.utils.UnexpectedEnumException; +import org.molgenis.vcf.utils.metadata.ValueType; import org.molgenis.vcf.utils.sample.model.AffectedStatus; import org.molgenis.vcf.utils.sample.model.Sex; diff --git a/src/main/java/org/molgenis/vcf/decisiontree/runner/VcfReaderFactoryImpl.java b/src/main/java/org/molgenis/vcf/decisiontree/runner/VcfReaderFactoryImpl.java index 7c743997..6d3704b7 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/runner/VcfReaderFactoryImpl.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/runner/VcfReaderFactoryImpl.java @@ -7,29 +7,29 @@ import org.molgenis.vcf.decisiontree.Settings; import org.molgenis.vcf.decisiontree.filter.VcfReader; import org.molgenis.vcf.decisiontree.runner.info.GenotypeMetadataMapper; -import org.molgenis.vcf.decisiontree.runner.info.VepMetadataParser; -import org.molgenis.vcf.decisiontree.runner.info.VepMetadataParserFactory; +import org.molgenis.vcf.decisiontree.runner.info.VepMetadataMapper; +import org.molgenis.vcf.decisiontree.runner.info.VepMetadataMapperFactory; import org.springframework.stereotype.Component; @Component class VcfReaderFactoryImpl implements VcfReaderFactory { - private final VepMetadataParserFactory vepMetadataParserFactory; private final GenotypeMetadataMapper genotypeMetadataMapper; + private final VepMetadataMapperFactory vepMetadataMapperFactory; - VcfReaderFactoryImpl(VepMetadataParserFactory vepMetadataParserFactory, + VcfReaderFactoryImpl(VepMetadataMapperFactory vepMetadataMapperFactory, GenotypeMetadataMapper genotypeMetadataMapper) { - this.vepMetadataParserFactory = requireNonNull(vepMetadataParserFactory); + this.vepMetadataMapperFactory = requireNonNull(vepMetadataMapperFactory); this.genotypeMetadataMapper = requireNonNull(genotypeMetadataMapper); } @Override public VcfReader create(Settings settings) { - VepMetadataParser vepMetadataParser = vepMetadataParserFactory.create(settings); + VepMetadataMapper vepMetadataMapper = vepMetadataMapperFactory.create(settings); Path inputVcfPath = settings.getInputVcfPath(); boolean strict = settings.isStrict(); - return new VcfReader(new VCFFileReader(inputVcfPath.toFile(), false), vepMetadataParser, + return new VcfReader(new VCFFileReader(inputVcfPath.toFile(), false), vepMetadataMapper, genotypeMetadataMapper, strict); } diff --git a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/GenotypeMetadataMapperImpl.java b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/GenotypeMetadataMapperImpl.java index ab43c8e3..4c6daafa 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/GenotypeMetadataMapperImpl.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/GenotypeMetadataMapperImpl.java @@ -1,8 +1,5 @@ package org.molgenis.vcf.decisiontree.runner.info; -import static org.molgenis.vcf.decisiontree.filter.model.ValueCount.Type.FIXED; -import static org.molgenis.vcf.decisiontree.filter.model.ValueCount.Type.VARIABLE; - import java.util.HashMap; import java.util.Map; import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; @@ -10,11 +7,14 @@ import org.molgenis.vcf.decisiontree.filter.model.GenotypeFieldType; import org.molgenis.vcf.decisiontree.filter.model.NestedField; import org.molgenis.vcf.decisiontree.filter.model.NestedField.NestedFieldBuilder; -import org.molgenis.vcf.decisiontree.filter.model.ValueCount; -import org.molgenis.vcf.decisiontree.filter.model.ValueType; import org.molgenis.vcf.utils.UnexpectedEnumException; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; import org.springframework.stereotype.Component; +import static org.molgenis.vcf.utils.metadata.ValueCount.Type.FIXED; +import static org.molgenis.vcf.utils.metadata.ValueCount.Type.VARIABLE; + @Component public class GenotypeMetadataMapperImpl implements GenotypeMetadataMapper { diff --git a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/MissingVepMetaException.java b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/MissingVepMetaException.java new file mode 100644 index 00000000..fff91707 --- /dev/null +++ b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/MissingVepMetaException.java @@ -0,0 +1,14 @@ +package org.molgenis.vcf.decisiontree.runner.info; + +import java.io.Serial; + +public class MissingVepMetaException extends + RuntimeException { + @Serial + private static final long serialVersionUID = 1L; + @Override + public String getMessage() { + return "Metadata json is missing required VEP annotation."; + } + +} diff --git a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/NestedHeaderLine.java b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/NestedHeaderLine.java index 47364dc3..9f9b43bc 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/NestedHeaderLine.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/NestedHeaderLine.java @@ -2,6 +2,7 @@ import java.util.Map; import lombok.Builder; +import lombok.EqualsAndHashCode; import lombok.NonNull; import lombok.Value; import org.molgenis.vcf.decisiontree.filter.model.Field; @@ -10,6 +11,7 @@ @Value @Builder +@EqualsAndHashCode public class NestedHeaderLine { @NonNull Field parentField; diff --git a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/NotParentFieldException.java b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/NotParentFieldException.java new file mode 100644 index 00000000..61dac69e --- /dev/null +++ b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/NotParentFieldException.java @@ -0,0 +1,19 @@ +package org.molgenis.vcf.decisiontree.runner.info; + +import org.springframework.lang.NonNull; +public class NotParentFieldException extends + RuntimeException { + private static final long serialVersionUID = 1L; + private static final String MESSAGE = "Field '%s' is not a parent field, it has no nested fields."; + private final String id; + + public NotParentFieldException(@NonNull String id) { + this.id = id; + } + + @Override + public String getMessage() { + return String.format(MESSAGE, id); + } + +} diff --git a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapper.java b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapper.java index eaef9f83..2fe33eff 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapper.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapper.java @@ -1,10 +1,11 @@ package org.molgenis.vcf.decisiontree.runner.info; +import htsjdk.variant.vcf.VCFHeader; import htsjdk.variant.vcf.VCFInfoHeaderLine; public interface VepMetadataMapper { boolean canMap(VCFInfoHeaderLine vcfInfoHeaderLine); - NestedHeaderLine map(VCFInfoHeaderLine vcfInfoHeaderLine); + NestedHeaderLine map(String id, VCFHeader vcfHeader); } diff --git a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapperFactoryImpl.java b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapperFactoryImpl.java index 0e21d843..d9bc36fd 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapperFactoryImpl.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapperFactoryImpl.java @@ -1,45 +1,15 @@ package org.molgenis.vcf.decisiontree.runner.info; -import htsjdk.variant.vcf.VCFInfoHeaderLine; import org.molgenis.vcf.decisiontree.Settings; import org.molgenis.vcf.utils.metadata.FieldMetadataService; -import org.molgenis.vcf.utils.metadata.AbstractFieldMetadataService; -import org.molgenis.vcf.utils.model.FieldMetadata; -import org.molgenis.vcf.utils.vep.VepMetadataService; +import org.molgenis.vcf.utils.metadata.FieldMetadataServiceImpl; import org.springframework.stereotype.Component; -import java.io.IOException; -import java.io.InputStream; -import java.io.UncheckedIOException; -import java.nio.file.Files; -import java.nio.file.Path; - -import static java.util.Objects.requireNonNull; - @Component public class VepMetadataMapperFactoryImpl implements VepMetadataMapperFactory { @Override public VepMetadataMapper create(Settings settings) { - Path metadataPath = settings.getMetadataPath(); - FieldMetadataService fieldMetadataService = new CustomFieldMetadataService(metadataPath); - VepMetadataService vepMetadataService = new VepMetadataService(fieldMetadataService); - return new VepMetadataMapperImpl(vepMetadataService); - } - - private static class CustomFieldMetadataService extends AbstractFieldMetadataService { - private final Path metadataPath; - - public CustomFieldMetadataService(Path metadataPath) { - this.metadataPath = requireNonNull(metadataPath); - } - - @Override - public FieldMetadata load(VCFInfoHeaderLine vcfInfoHeaderLine) { - try(InputStream inputStream = Files.newInputStream(metadataPath)) { - return this.load(inputStream, vcfInfoHeaderLine); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - } + FieldMetadataService fieldMetadataService = new FieldMetadataServiceImpl(settings.getMetadataPath().toFile()); + return new VepMetadataMapperImpl(fieldMetadataService); } } diff --git a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapperImpl.java b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapperImpl.java index 61681112..6f355b51 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapperImpl.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapperImpl.java @@ -1,25 +1,26 @@ package org.molgenis.vcf.decisiontree.runner.info; +import htsjdk.variant.vcf.VCFHeader; import htsjdk.variant.vcf.VCFInfoHeaderLine; import org.molgenis.vcf.decisiontree.filter.model.*; -import org.molgenis.vcf.decisiontree.filter.model.ValueCount.Type; -import org.molgenis.vcf.utils.UnexpectedEnumException; -import org.molgenis.vcf.utils.metadata.FieldMetadataService; -import org.molgenis.vcf.utils.model.FieldMetadata; -import org.molgenis.vcf.utils.model.NumberType; +import org.molgenis.vcf.utils.metadata.*; +import org.molgenis.vcf.utils.model.metadata.FieldMetadata; +import org.molgenis.vcf.utils.model.metadata.FieldMetadatas; +import org.molgenis.vcf.utils.model.metadata.NestedFieldMetadata; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import static java.util.Objects.requireNonNull; -import static org.molgenis.vcf.decisiontree.filter.model.ValueCount.Type.VARIABLE; +import static org.molgenis.vcf.decisiontree.filter.model.FieldType.INFO; +import static org.molgenis.vcf.decisiontree.filter.model.FieldType.INFO_VEP; +import static org.molgenis.vcf.utils.metadata.ValueCount.Type.VARIABLE; public class VepMetadataMapperImpl implements VepMetadataMapper { public static final String ALLELE_NUM = "ALLELE_NUM"; - private static final String INFO_DESCRIPTION_PREFIX = - "Consequence annotations from Ensembl VEP. Format: "; + private static final String INFO_DESCRIPTION_PREFIX = "Consequence annotations from Ensembl VEP. Format: "; private final FieldMetadataService fieldMetadataService; @@ -35,63 +36,37 @@ public boolean canMap(VCFInfoHeaderLine vcfInfoHeaderLine) { } @Override - public NestedHeaderLine map(VCFInfoHeaderLine vcfInfoHeaderLine) { - Map nestedFields = new HashMap<>(); + public NestedHeaderLine map(String csqId, VCFHeader vcfHeader) { + VCFInfoHeaderLine vcfInfoHeaderLine = vcfHeader.getInfoHeaderLine(csqId); FieldImpl vepField = FieldImpl.builder() .id(vcfInfoHeaderLine.getID()) - .fieldType(FieldType.INFO) + .fieldType(INFO) .valueType(ValueType.STRING) .valueCount(ValueCount.builder().type(VARIABLE).build()) .separator('|') .build(); - FieldMetadata nestedMetadata = fieldMetadataService.load(vcfInfoHeaderLine); - for (Entry entry : nestedMetadata.getNestedFields() - .entrySet()) { - NestedField nestedField = mapNested(entry.getKey(), entry.getValue(), vepField); - nestedFields.put(entry.getKey(), nestedField); + FieldMetadatas fieldMetadatas = fieldMetadataService.load(vcfHeader, Map.of(FieldIdentifier.builder().type(org.molgenis.vcf.utils.metadata.FieldType.INFO).name(csqId).build(), NestedAttributes.builder().prefix(INFO_DESCRIPTION_PREFIX).seperator("|").build())); + Map nestedFields = new HashMap<>(); + FieldMetadata csqField = fieldMetadatas.getInfo().get(csqId); + if(csqField == null){ + throw new MissingVepMetaException(); + } + Map nestedFieldsMeta = csqField.getNestedFields(); + if(nestedFieldsMeta == null){ + throw new NotParentFieldException(csqId); + } + for(Entry entry : nestedFieldsMeta.entrySet()){ + nestedFields.put(entry.getKey(), mapNestedFieldMetadata(entry.getKey(), entry.getValue(), vepField)); } return NestedHeaderLine.builder().parentField(vepField).nestedFields(nestedFields).build(); - - } - - private NestedField mapNested(String key, org.molgenis.vcf.utils.model.NestedField value, - Field parent) { - return NestedField.nestedBuilder().id(key).fieldType(FieldType.INFO_VEP) - .valueType(mapValueType(value.getType())) - .valueCount( - mapValueCount(value.getNumberType(), value.getNumberCount(), value.isRequired())) - .separator(value.getSeparator()).parent(parent).index(value.getIndex()).build(); - } - - private ValueType mapValueType(org.molgenis.vcf.utils.model.ValueType type) { - return switch (type) { - case INTEGER -> ValueType.INTEGER; - case FLOAT -> ValueType.FLOAT; - case FLAG -> ValueType.FLAG; - case CHARACTER -> ValueType.CHARACTER; - case STRING, CATEGORICAL -> ValueType.STRING; - //noinspection UnnecessaryDefault - default -> throw new UnexpectedEnumException(type); - }; - } - - private ValueCount mapValueCount(NumberType numberType, Integer numberCount, boolean required) { - return ValueCount.builder().type(mapNumberType(numberType)).count(numberCount) - .nullable(!required).build(); } - private Type mapNumberType(NumberType numberType) { - return switch (numberType) { - case NUMBER -> Type.FIXED; - case PER_ALT -> Type.A; - case PER_ALT_AND_REF -> Type.R; - case PER_GENOTYPE -> Type.G; - case OTHER -> VARIABLE; - //noinspection UnnecessaryDefault - default -> throw new UnexpectedEnumException(numberType); - }; + private NestedField mapNestedFieldMetadata(String id, NestedFieldMetadata nestedMeta, Field parent) { + return new NestedField(id, INFO_VEP, nestedMeta.getType(), + ValueCount.builder().count(nestedMeta.getNumberCount()).type(nestedMeta.getNumberType()).build(), + nestedMeta.getNumberCount(), nestedMeta.getSeparator(), nestedMeta.getIndex(), parent); } } diff --git a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParser.java b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParser.java deleted file mode 100644 index 4c901b95..00000000 --- a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParser.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.molgenis.vcf.decisiontree.runner.info; - -import htsjdk.variant.vcf.VCFHeader; - -public interface VepMetadataParser { - - NestedHeaderLine map(VCFHeader header); -} diff --git a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParserFactory.java b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParserFactory.java deleted file mode 100644 index 422cd109..00000000 --- a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParserFactory.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.molgenis.vcf.decisiontree.runner.info; - -import org.molgenis.vcf.decisiontree.Settings; - -public interface VepMetadataParserFactory { - VepMetadataParser create(Settings settings); -} diff --git a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParserFactoryImpl.java b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParserFactoryImpl.java deleted file mode 100644 index 4879451c..00000000 --- a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParserFactoryImpl.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.molgenis.vcf.decisiontree.runner.info; - -import org.molgenis.vcf.decisiontree.Settings; -import org.springframework.stereotype.Component; - -import static java.util.Objects.requireNonNull; - -@Component -public class VepMetadataParserFactoryImpl implements VepMetadataParserFactory { - private final VepMetadataMapperFactory vepMetadataMapperFactory; - - public VepMetadataParserFactoryImpl(VepMetadataMapperFactory vepMetadataMapperFactory) { - this.vepMetadataMapperFactory = requireNonNull(vepMetadataMapperFactory); - } - - @Override - public VepMetadataParser create(Settings settings) { - VepMetadataMapper vepMetadataMapper = vepMetadataMapperFactory.create(settings); - return new VepMetadataParserImpl(vepMetadataMapper); - } -} diff --git a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParserImpl.java b/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParserImpl.java deleted file mode 100644 index b4174132..00000000 --- a/src/main/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParserImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.molgenis.vcf.decisiontree.runner.info; - -import htsjdk.variant.vcf.VCFHeader; -import htsjdk.variant.vcf.VCFInfoHeaderLine; - -import static java.util.Objects.requireNonNull; - -public class VepMetadataParserImpl implements VepMetadataParser { - - private final VepMetadataMapper vepMetadataMapper; - - public VepMetadataParserImpl(VepMetadataMapper vepMetadataMapper) { - this.vepMetadataMapper = requireNonNull(vepMetadataMapper); - } - - @Override - public NestedHeaderLine map(VCFHeader header) { - for (VCFInfoHeaderLine headerLine : header.getInfoHeaderLines()) { - if (vepMetadataMapper.canMap(headerLine)) { - return vepMetadataMapper.map(headerLine); - } - } - throw new MissingVepException(); - } - -} diff --git a/src/main/java/org/molgenis/vcf/decisiontree/utils/VcfUtils.java b/src/main/java/org/molgenis/vcf/decisiontree/utils/VcfUtils.java index 452e13d2..7711b228 100644 --- a/src/main/java/org/molgenis/vcf/decisiontree/utils/VcfUtils.java +++ b/src/main/java/org/molgenis/vcf/decisiontree/utils/VcfUtils.java @@ -17,8 +17,8 @@ import org.molgenis.vcf.decisiontree.filter.UnsupportedFieldException; import org.molgenis.vcf.decisiontree.filter.model.Field; import org.molgenis.vcf.decisiontree.filter.model.FieldType; -import org.molgenis.vcf.decisiontree.filter.model.ValueType; import org.molgenis.vcf.utils.UnexpectedEnumException; +import org.molgenis.vcf.utils.metadata.ValueType; import org.springframework.lang.Nullable; public class VcfUtils { @@ -262,7 +262,7 @@ public static Object getTypedVcfValue(Field field, String stringValue) { case FLOAT: typedValue = VcfUtils.getVcfValueAsDouble(stringValue, missingValue); break; - case CHARACTER, STRING: + case CHARACTER, STRING, CATEGORICAL: typedValue = VcfUtils.getVcfValueAsString(stringValue, missingValue); break; default: diff --git a/src/test/java/org/molgenis/vcf/decisiontree/filter/BoolMultiNodeEvaluatorTest.java b/src/test/java/org/molgenis/vcf/decisiontree/filter/BoolMultiNodeEvaluatorTest.java index 79a042ef..77f680a5 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/filter/BoolMultiNodeEvaluatorTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/filter/BoolMultiNodeEvaluatorTest.java @@ -15,7 +15,7 @@ import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; import org.molgenis.vcf.decisiontree.filter.model.MissingField; import org.molgenis.vcf.decisiontree.filter.model.NodeOutcome; -import org.molgenis.vcf.decisiontree.filter.model.ValueType; +import org.molgenis.vcf.utils.metadata.ValueType; class BoolMultiNodeEvaluatorTest { diff --git a/src/test/java/org/molgenis/vcf/decisiontree/filter/BoolNodeEvaluatorTest.java b/src/test/java/org/molgenis/vcf/decisiontree/filter/BoolNodeEvaluatorTest.java index 52970858..1bf99c59 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/filter/BoolNodeEvaluatorTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/filter/BoolNodeEvaluatorTest.java @@ -16,9 +16,8 @@ import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; import org.molgenis.vcf.decisiontree.filter.model.MissingField; import org.molgenis.vcf.decisiontree.filter.model.NodeOutcome; -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.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; class BoolNodeEvaluatorTest { @@ -595,7 +594,7 @@ void evaluateMissingField() { void evaluateMissingValueCountVariable() { FieldImpl field = mock(FieldImpl.class); when(field.getValueType()).thenReturn(ValueType.STRING); - when(field.getValueCount()).thenReturn(ValueCount.builder().type(Type.VARIABLE).build()); + when(field.getValueCount()).thenReturn(ValueCount.builder().type(ValueCount.Type.VARIABLE).build()); Operator operator = Operator.EQUALS; List queryValue = List.of("PASS"); diff --git a/src/test/java/org/molgenis/vcf/decisiontree/filter/ClassifierImplTest.java b/src/test/java/org/molgenis/vcf/decisiontree/filter/ClassifierImplTest.java index d1d9fd10..36b2d48c 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/filter/ClassifierImplTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/filter/ClassifierImplTest.java @@ -19,11 +19,10 @@ import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; import org.molgenis.vcf.decisiontree.filter.model.FieldType; import org.molgenis.vcf.decisiontree.filter.model.NestedField; -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.runner.VepHelper; import org.molgenis.vcf.decisiontree.runner.info.NestedHeaderLine; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; @ExtendWith(MockitoExtension.class) class ClassifierImplTest { @@ -49,7 +48,7 @@ class ClassifierImplTest { @BeforeEach void setUp() { - ValueCount valueCount = ValueCount.builder().type(Type.VARIABLE).build(); + ValueCount valueCount = ValueCount.builder().type(ValueCount.Type.VARIABLE).build(); parent = FieldImpl.builder().id("VEP").fieldType(FieldType.INFO) .valueType(ValueType.STRING).valueCount(valueCount).separator('|').build(); NestedField nestedField1 = NestedField.nestedBuilder().id("ALLELE_NUM").parent(parent) diff --git a/src/test/java/org/molgenis/vcf/decisiontree/filter/ExistsNodeEvaluatorTest.java b/src/test/java/org/molgenis/vcf/decisiontree/filter/ExistsNodeEvaluatorTest.java index 1a1b88b5..a90c4b7d 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/filter/ExistsNodeEvaluatorTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/filter/ExistsNodeEvaluatorTest.java @@ -10,8 +10,7 @@ import org.molgenis.vcf.decisiontree.filter.model.ExistsNode; import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; import org.molgenis.vcf.decisiontree.filter.model.NodeOutcome; -import org.molgenis.vcf.decisiontree.filter.model.ValueCount; -import org.molgenis.vcf.decisiontree.filter.model.ValueCount.Type; +import org.molgenis.vcf.utils.metadata.ValueCount; class ExistsNodeEvaluatorTest { @@ -65,7 +64,7 @@ void evaluateExistsFalse() { @Test void evaluateExistsFalseValueCountVariable() { FieldImpl field = mock(FieldImpl.class); - when(field.getValueCount()).thenReturn(ValueCount.builder().type(Type.VARIABLE).build()); + when(field.getValueCount()).thenReturn(ValueCount.builder().type(ValueCount.Type.VARIABLE).build()); NodeOutcome outcomeTrue = mock(NodeOutcome.class); NodeOutcome outcomeFalse = mock(NodeOutcome.class); diff --git a/src/test/java/org/molgenis/vcf/decisiontree/filter/SampleClassifierImplTest.java b/src/test/java/org/molgenis/vcf/decisiontree/filter/SampleClassifierImplTest.java index 27e94d0f..4959ae80 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/filter/SampleClassifierImplTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/filter/SampleClassifierImplTest.java @@ -27,11 +27,10 @@ import org.molgenis.vcf.decisiontree.filter.model.NestedField; import org.molgenis.vcf.decisiontree.filter.model.SampleContext; import org.molgenis.vcf.decisiontree.filter.model.SamplesContext; -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.runner.VepHelper; import org.molgenis.vcf.decisiontree.runner.info.NestedHeaderLine; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; import org.molgenis.vcf.utils.sample.model.Sex; import org.molgenis.vcf.utils.sample.model.AffectedStatus; @@ -67,7 +66,7 @@ class SampleClassifierImplTest { @BeforeEach void setUp() { - ValueCount valueCount = ValueCount.builder().type(Type.VARIABLE).build(); + ValueCount valueCount = ValueCount.builder().type(ValueCount.Type.VARIABLE).build(); parent = FieldImpl.builder().id("VEP").fieldType(FieldType.INFO) .valueType(ValueType.STRING).valueCount(valueCount).separator('|').build(); NestedField nestedField1 = NestedField.nestedBuilder().id("ALLELE_NUM").parent(parent) diff --git a/src/test/java/org/molgenis/vcf/decisiontree/filter/VcfMetadataTest.java b/src/test/java/org/molgenis/vcf/decisiontree/filter/VcfMetadataTest.java index 2ce3663d..3153ad8c 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/filter/VcfMetadataTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/filter/VcfMetadataTest.java @@ -26,10 +26,9 @@ import org.molgenis.vcf.decisiontree.filter.model.FieldType; import org.molgenis.vcf.decisiontree.filter.model.MissingField; import org.molgenis.vcf.decisiontree.filter.model.NestedField; -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.runner.info.NestedHeaderLine; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; @ExtendWith(MockitoExtension.class) class VcfMetadataTest { @@ -47,7 +46,7 @@ void setUp() { vepNestedMetadata.put("consequence", createNestedField("consequence")); Field vepField = FieldImpl.builder().id("VEP").fieldType(FieldType.INFO) .valueType(ValueType.STRING).valueCount(ValueCount.builder() - .type(Type.VARIABLE).build()).build(); + .type(ValueCount.Type.VARIABLE).build()).build(); NestedHeaderLine nestedVepHeaderLine = NestedHeaderLine.builder() .nestedFields(vepNestedMetadata).parentField(vepField).build(); NestedHeaderLine nestedGtHeaderLine = NestedHeaderLine.builder() @@ -64,7 +63,7 @@ void getFieldCommonChrom() { .id(fieldId) .fieldType(FieldType.COMMON) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(), vcfMetadata.getField(fieldId)); } @@ -77,7 +76,7 @@ void getFieldCommonPos() { .id(fieldId) .fieldType(FieldType.COMMON) .valueType(ValueType.INTEGER) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(), vcfMetadata.getField(fieldId)); } @@ -91,7 +90,7 @@ void getFieldCommonId() { .id(fieldId) .fieldType(FieldType.COMMON) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.VARIABLE).nullable(true).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.VARIABLE).nullable(true).build()) .build(), vcfMetadata.getField(fieldId)); } @@ -104,7 +103,7 @@ void getFieldCommonRef() { .id(fieldId) .fieldType(FieldType.COMMON) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(), vcfMetadata.getField(fieldId)); } @@ -117,7 +116,7 @@ void getFieldCommonQual() { .id(fieldId) .fieldType(FieldType.COMMON) .valueType(ValueType.FLOAT) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).nullable(true).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).nullable(true).build()) .build(), vcfMetadata.getField(fieldId)); } @@ -139,7 +138,7 @@ void getFieldInfoInteger() { .id("my_field") .fieldType(FieldType.INFO) .valueType(ValueType.INTEGER) - .valueCount(ValueCount.builder().type(Type.G).nullable(true).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.G).nullable(true).build()) .build(), vcfMetadata.getField(fieldId)); } @@ -156,7 +155,7 @@ void getFieldInfoFloat() { .id("my_field") .fieldType(FieldType.INFO) .valueType(ValueType.FLOAT) - .valueCount(ValueCount.builder().type(Type.R).nullable(true).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.R).nullable(true).build()) .build(), vcfMetadata.getField(fieldId)); } @@ -173,7 +172,7 @@ void getFieldInfoString() { .id("my_field") .fieldType(FieldType.INFO) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.A).nullable(true).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.A).nullable(true).build()) .build(), vcfMetadata.getField(fieldId)); } @@ -190,7 +189,7 @@ void getFieldInfoStringUnbounded() { .id("my_field") .fieldType(FieldType.INFO) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.VARIABLE).nullable(true).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.VARIABLE).nullable(true).build()) .build(), vcfMetadata.getField(fieldId)); } @@ -207,7 +206,7 @@ void getFieldInfoCharacter() { .id("my_field") .fieldType(FieldType.INFO) .valueType(ValueType.CHARACTER) - .valueCount(ValueCount.builder().type(Type.R).nullable(true).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.R).nullable(true).build()) .build(), vcfMetadata.getField(fieldId)); } @@ -225,7 +224,7 @@ void getFieldInfoFlag() { .id("my_field") .fieldType(FieldType.INFO) .valueType(ValueType.FLAG) - .valueCount(ValueCount.builder().type(Type.FIXED).count(0).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(0).build()) .build(), vcfMetadata.getField(fieldId)); } @@ -247,7 +246,7 @@ void getFieldFormatInfo() { .id("my_field") .fieldType(FieldType.FORMAT) .valueType(ValueType.INTEGER) - .valueCount(ValueCount.builder().type(Type.G).nullable(true).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.G).nullable(true).build()) .build(), vcfMetadata.getField(fieldId)); } @@ -294,49 +293,49 @@ void getFieldFormatUnknownStrict() { @Test void getFieldSampleId() { - Field field = FieldImpl.builder().id("ID").fieldType(FieldType.SAMPLE).valueType(ValueType.STRING).valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()).build(); + Field field = FieldImpl.builder().id("ID").fieldType(FieldType.SAMPLE).valueType(ValueType.STRING).valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()).build(); assertEquals(field, vcfMetadata.getField("SAMPLE/ID")); } @Test void getFieldSampleProband() { - Field field = FieldImpl.builder().id("PROBAND").fieldType(FieldType.SAMPLE).valueType(ValueType.FLAG).valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()).build(); + Field field = FieldImpl.builder().id("PROBAND").fieldType(FieldType.SAMPLE).valueType(ValueType.FLAG).valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()).build(); assertEquals(field, vcfMetadata.getField("SAMPLE/PROBAND")); } @Test void getFieldSampleAffectedStatus() { - Field field = FieldImpl.builder().id("AFFECTED_STATUS").fieldType(FieldType.SAMPLE).valueType(ValueType.STRING).valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()).build(); + Field field = FieldImpl.builder().id("AFFECTED_STATUS").fieldType(FieldType.SAMPLE).valueType(ValueType.STRING).valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()).build(); assertEquals(field, vcfMetadata.getField("SAMPLE/AFFECTED_STATUS")); } @Test void getFieldSampleSex() { - Field field = FieldImpl.builder().id("SEX").fieldType(FieldType.SAMPLE).valueType(ValueType.STRING).valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()).build(); + Field field = FieldImpl.builder().id("SEX").fieldType(FieldType.SAMPLE).valueType(ValueType.STRING).valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()).build(); assertEquals(field, vcfMetadata.getField("SAMPLE/SEX")); } @Test void getFieldSampleFatherId() { - Field field = FieldImpl.builder().id("FATHER_ID").fieldType(FieldType.SAMPLE).valueType(ValueType.STRING).valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()).build(); + Field field = FieldImpl.builder().id("FATHER_ID").fieldType(FieldType.SAMPLE).valueType(ValueType.STRING).valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()).build(); assertEquals(field, vcfMetadata.getField("SAMPLE/FATHER_ID")); } @Test void getFieldSampleMotherId() { - Field field = FieldImpl.builder().id("MOTHER_ID").fieldType(FieldType.SAMPLE).valueType(ValueType.STRING).valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()).build(); + Field field = FieldImpl.builder().id("MOTHER_ID").fieldType(FieldType.SAMPLE).valueType(ValueType.STRING).valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()).build(); assertEquals(field, vcfMetadata.getField("SAMPLE/MOTHER_ID")); } @Test void getFieldSampleFamilyId() { - Field field = FieldImpl.builder().id("FAMILY_ID").fieldType(FieldType.SAMPLE).valueType(ValueType.STRING).valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()).build(); + Field field = FieldImpl.builder().id("FAMILY_ID").fieldType(FieldType.SAMPLE).valueType(ValueType.STRING).valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()).build(); assertEquals(field, vcfMetadata.getField("SAMPLE/FAMILY_ID")); } @Test void getFieldSamplePhenotypes() { - Field field = FieldImpl.builder().id("PHENOTYPES").fieldType(FieldType.SAMPLE).valueType(ValueType.STRING).valueCount(ValueCount.builder().type(Type.VARIABLE).nullable(true).build()).build(); + Field field = FieldImpl.builder().id("PHENOTYPES").fieldType(FieldType.SAMPLE).valueType(ValueType.STRING).valueCount(ValueCount.builder().type(ValueCount.Type.VARIABLE).nullable(true).build()).build(); assertEquals(field, vcfMetadata.getField("SAMPLE/PHENOTYPES")); } @@ -351,7 +350,7 @@ void unwrap() { } private NestedField createNestedField(String field) { - ValueCount valueCount = ValueCount.builder().type(Type.VARIABLE).build(); + ValueCount valueCount = ValueCount.builder().type(ValueCount.Type.VARIABLE).build(); FieldImpl parent = FieldImpl.builder().id("VEP").fieldType(FieldType.INFO) .valueType(ValueType.STRING).valueCount(valueCount).separator('|').build(); return NestedField.nestedBuilder().id(field).parent(parent).fieldType(FieldType.INFO_VEP) diff --git a/src/test/java/org/molgenis/vcf/decisiontree/filter/VcfRecordTest.java b/src/test/java/org/molgenis/vcf/decisiontree/filter/VcfRecordTest.java index 46a0dfdb..257c21b7 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/filter/VcfRecordTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/filter/VcfRecordTest.java @@ -27,9 +27,8 @@ import org.molgenis.vcf.decisiontree.filter.model.FieldType; import org.molgenis.vcf.decisiontree.filter.model.NestedField; import org.molgenis.vcf.decisiontree.filter.model.SampleContext; -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.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; import org.molgenis.vcf.utils.sample.model.AffectedStatus; @ExtendWith(MockitoExtension.class) @@ -193,7 +192,7 @@ void getValueInfoAltInteger() { FieldImpl.builder() .id("my_field") .fieldType(FieldType.INFO) - .valueCount(ValueCount.builder().type(Type.A).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.A).build()) .valueType(ValueType.INTEGER) .build(); int alleleIndex = 2; @@ -207,7 +206,7 @@ void getValueInfoAltFloat() { FieldImpl.builder() .id("my_field") .fieldType(FieldType.INFO) - .valueCount(ValueCount.builder().type(Type.A).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.A).build()) .valueType(ValueType.FLOAT) .build(); int alleleIndex = 2; @@ -221,7 +220,7 @@ void getValueInfoAltString() { FieldImpl.builder() .id("my_field") .fieldType(FieldType.INFO) - .valueCount(ValueCount.builder().type(Type.A).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.A).build()) .valueType(ValueType.STRING) .build(); int alleleIndex = 2; @@ -235,7 +234,7 @@ void getValueInfoRef() { FieldImpl.builder() .id("my_field") .fieldType(FieldType.INFO) - .valueCount(ValueCount.builder().type(Type.R).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.R).build()) .valueType(ValueType.INTEGER) .build(); int alleleIndex = 2; @@ -249,7 +248,7 @@ void getValueInfoVariable() { FieldImpl.builder() .id("my_field") .fieldType(FieldType.INFO) - .valueCount(ValueCount.builder().type(Type.VARIABLE).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.VARIABLE).build()) .valueType(ValueType.INTEGER) .build(); when(variantContext.getAttribute("my_field")).thenReturn(asList(1, 2)); @@ -262,7 +261,7 @@ void getValueInfoFlag() { FieldImpl.builder() .id("my_field") .fieldType(FieldType.INFO) - .valueCount(ValueCount.builder().type(Type.FIXED).count(0).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(0).build()) .valueType(ValueType.FLAG) .build(); Allele allele = createAllele(); @@ -274,7 +273,7 @@ void getValueInfoVariableFlag() { FieldImpl.builder() .id("my_field") .fieldType(FieldType.INFO) - .valueCount(ValueCount.builder().type(Type.VARIABLE).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.VARIABLE).build()) .valueType(ValueType.FLAG) .build(); Allele allele = createAllele(); @@ -287,7 +286,7 @@ void getValueInfoFixed() { FieldImpl.builder() .id("my_field") .fieldType(FieldType.INFO) - .valueCount(ValueCount.builder().type(Type.FIXED).count(2).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(2).build()) .valueType(ValueType.INTEGER) .build(); when(variantContext.getAttribute("my_field")).thenReturn(asList(1, 2)); @@ -300,7 +299,7 @@ void getValueInfoFixedOneInteger() { FieldImpl.builder() .id("my_field") .fieldType(FieldType.INFO) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .valueType(ValueType.INTEGER) .build(); when(variantContext.getAttribute("my_field")).thenReturn(1); @@ -313,7 +312,7 @@ void getValueInfoFixedOneFloat() { FieldImpl.builder() .id("my_field") .fieldType(FieldType.INFO) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .valueType(ValueType.FLOAT) .build(); when(variantContext.getAttribute("my_field")).thenReturn(1.2); @@ -326,7 +325,7 @@ void getValueInfoFixedOneFlag() { FieldImpl.builder() .id("my_field") .fieldType(FieldType.INFO) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .valueType(ValueType.FLAG) .build(); when(variantContext.getAttribute("my_field")).thenReturn(true); @@ -339,7 +338,7 @@ void getValueInfoFixedOneString() { FieldImpl.builder() .id("my_field") .fieldType(FieldType.INFO) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .valueType(ValueType.STRING) .build(); when(variantContext.getAttribute("my_field")).thenReturn("str0"); @@ -353,7 +352,7 @@ void getValueFormatAD() { .id("AD") .fieldType(FieldType.FORMAT) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getAD()).thenReturn(new int[]{10, 10}); @@ -370,7 +369,7 @@ void getValueFormatAdNull() { .id("AD") .fieldType(FieldType.FORMAT) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getAD()).thenReturn(null); @@ -386,7 +385,7 @@ void getValueFormatDP() { .id("DP") .fieldType(FieldType.FORMAT) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getDP()).thenReturn(10); @@ -402,7 +401,7 @@ void getValueFormatDPNull() { .id("DP") .fieldType(FieldType.FORMAT) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getDP()).thenReturn(-1); @@ -417,7 +416,7 @@ void getValueFormatGT() { .id("GT") .fieldType(FieldType.FORMAT) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getAlleles()).thenReturn(List.of(htsjdk.variant.variantcontext.Allele.ALT_T, @@ -437,7 +436,7 @@ void getValueFormatGtNoCall() { .id("GT") .fieldType(FieldType.FORMAT) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getAlleles()).thenReturn(List.of(htsjdk.variant.variantcontext.Allele.NO_CALL, @@ -457,7 +456,7 @@ void getValueFormatGQ() { .id("GQ") .fieldType(FieldType.FORMAT) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getGQ()).thenReturn(10); @@ -472,7 +471,7 @@ void getValueFormatGQMissing() { .id("GQ") .fieldType(FieldType.FORMAT) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getGQ()).thenReturn(-1); @@ -487,7 +486,7 @@ void getValueFormatPL() { .id("PL") .fieldType(FieldType.FORMAT) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getPL()).thenReturn(new int[]{10, 10}); @@ -503,7 +502,7 @@ void getValueFormatCustom() { .id("test") .fieldType(FieldType.FORMAT) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getExtendedAttribute("test")).thenReturn("testValue"); @@ -518,7 +517,7 @@ void getValueFormatCustomInt() { .id("test") .fieldType(FieldType.FORMAT) .valueType(ValueType.INTEGER) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getExtendedAttribute("test")).thenReturn("1"); @@ -533,7 +532,7 @@ void getValueFormatCustomException() { .id("test") .fieldType(FieldType.FORMAT) .valueType(ValueType.INTEGER) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getExtendedAttribute("test")).thenReturn(List.of(1, 2)); @@ -549,14 +548,14 @@ void getValueFormatGenotype() { .id("GENOTYPE") .fieldType(FieldType.GENOTYPE) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); NestedField field = NestedField.nestedBuilder() .parent(parent) .id("ALLELES") .fieldType(FieldType.GENOTYPE) .valueType(ValueType.INTEGER) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getAlleles()).thenReturn(List.of(htsjdk.variant.variantcontext.Allele.ALT_T, @@ -571,14 +570,14 @@ void getValueFormatGenotypeNum() { .id("GENOTYPE") .fieldType(FieldType.GENOTYPE) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); NestedField field = NestedField.nestedBuilder() .parent(parent) .id("ALLELE_NUM") .fieldType(FieldType.GENOTYPE) .valueType(ValueType.INTEGER) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getAlleles()).thenReturn(List.of(htsjdk.variant.variantcontext.Allele.ALT_T, @@ -597,14 +596,14 @@ void getValueFormatGenotypeType(String argument) { .id("GENOTYPE") .fieldType(FieldType.GENOTYPE) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); NestedField field = NestedField.nestedBuilder() .parent(parent) .id("TYPE") .fieldType(FieldType.GENOTYPE) .valueType(ValueType.INTEGER) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getType()).thenReturn(GenotypeType.valueOf(argument)); @@ -619,14 +618,14 @@ void getValueFormatGenotype(String fieldName, boolean expected) { .id("GENOTYPE") .fieldType(FieldType.GENOTYPE) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); NestedField field = NestedField.nestedBuilder() .parent(parent) .id(fieldName) .fieldType(FieldType.GENOTYPE) .valueType(ValueType.FLAG) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(variantContext.getGenotype(0)).thenReturn(gt); @@ -639,14 +638,14 @@ void getValueFormatGenotypePloidy() { .id("GENOTYPE") .fieldType(FieldType.GENOTYPE) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); NestedField field = NestedField.nestedBuilder() .parent(parent) .id("PLOIDY") .fieldType(FieldType.GENOTYPE) .valueType(ValueType.INTEGER) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getPloidy()).thenReturn(1); @@ -660,14 +659,14 @@ void getValueFormatGenotypePloidyNull() { .id("GENOTYPE") .fieldType(FieldType.GENOTYPE) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); NestedField field = NestedField.nestedBuilder() .parent(parent) .id("PLOIDY") .fieldType(FieldType.GENOTYPE) .valueType(ValueType.INTEGER) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); when(gt.getPloidy()).thenReturn(0); @@ -682,7 +681,7 @@ void getValueSampleId() { .id("ID") .fieldType(FieldType.SAMPLE) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); assertEquals("test", vcfRecord.getValue(field, createAllele(), sampleContext)); @@ -696,7 +695,7 @@ void getValueSample(String fieldName, String expected) { .id(fieldName) .fieldType(FieldType.SAMPLE) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.FIXED).count(1).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()) .build(); Genotype gt = mock(Genotype.class); assertEquals(expected, vcfRecord.getValue(field, createAllele(), sampleContext)); @@ -709,7 +708,7 @@ void getValueSamplePhenotypes() { .id("PHENOTYPES") .fieldType(FieldType.SAMPLE) .valueType(ValueType.STRING) - .valueCount(ValueCount.builder().type(Type.VARIABLE).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.VARIABLE).build()) .build(); Genotype gt = mock(Genotype.class); assertEquals(List.of("HP1", "HP2"), vcfRecord.getValue(field, createAllele(), sampleContext)); diff --git a/src/test/java/org/molgenis/vcf/decisiontree/runner/DecisionTreeFactoryImplTest.java b/src/test/java/org/molgenis/vcf/decisiontree/runner/DecisionTreeFactoryImplTest.java index b9ed71b2..eaf79e69 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/runner/DecisionTreeFactoryImplTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/runner/DecisionTreeFactoryImplTest.java @@ -25,9 +25,6 @@ import org.molgenis.vcf.decisiontree.filter.model.DecisionTree; import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; import org.molgenis.vcf.decisiontree.filter.model.Mode; -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.ConfigBoolNode; import org.molgenis.vcf.decisiontree.loader.model.ConfigBoolQuery; import org.molgenis.vcf.decisiontree.loader.model.ConfigDecisionTree; @@ -35,6 +32,8 @@ import org.molgenis.vcf.decisiontree.loader.model.ConfigNode; import org.molgenis.vcf.decisiontree.loader.model.ConfigNodeOutcome; import org.molgenis.vcf.decisiontree.loader.model.ConfigOperator; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; import org.springframework.util.ResourceUtils; @ExtendWith(MockitoExtension.class) @@ -74,7 +73,7 @@ void map(Operator expectedOperator, ConfigOperator configOperator) throws FileNo when(decisionTree.getRootNode()).thenReturn("test"); when(vcfMetadata.getField("INFO/testField")).thenReturn( FieldImpl.builder().id("testField").fieldType(INFO).valueType( - ValueType.STRING).valueCount(ValueCount.builder().type(Type.A).build()).build()); + ValueType.STRING).valueCount(ValueCount.builder().type(ValueCount.Type.A).build()).build()); Settings settings = Settings.builder().mode(Mode.VARIANT).configDecisionTree(decisionTree) .build(); DecisionTree decisionTree = decisionTreeFactory.map(vcfMetadata, settings); diff --git a/src/test/java/org/molgenis/vcf/decisiontree/runner/QueryValidatorImplTest.java b/src/test/java/org/molgenis/vcf/decisiontree/runner/QueryValidatorImplTest.java index 81109485..b9942891 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/runner/QueryValidatorImplTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/runner/QueryValidatorImplTest.java @@ -8,11 +8,10 @@ import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; import org.molgenis.vcf.decisiontree.filter.model.FieldType; import org.molgenis.vcf.decisiontree.filter.model.MissingField; -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.ConfigBoolQuery; import org.molgenis.vcf.decisiontree.loader.model.ConfigOperator; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; class QueryValidatorImplTest { @@ -22,7 +21,7 @@ class QueryValidatorImplTest { void validateBooleanNodeFlagPass() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.FLAG).valueCount( - ValueCount.builder().type(Type.FIXED).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).build()).build(); validateBooleanNode(field, ConfigOperator.EQUALS); } @@ -30,7 +29,7 @@ void validateBooleanNodeFlagPass() { void validateBooleanNodeFlag() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.FLAG).valueCount( - ValueCount.builder().type(Type.FIXED).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).build()).build(); assertThrows( UnsupportedValueTypeException.class, () -> validateBooleanNode(field, ConfigOperator.CONTAINS)); @@ -40,7 +39,7 @@ void validateBooleanNodeFlag() { void validateBooleanNodeEqualsOnCollection() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING).separator('&').valueCount( - ValueCount.builder().type(Type.FIXED).count(1).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()).build(); assertThrows( CountMismatchException.class, () -> validateBooleanNode(field, ConfigOperator.NOT_EQUALS)); @@ -50,7 +49,7 @@ void validateBooleanNodeEqualsOnCollection() { void validateBooleanNodeFloatPass() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.INTEGER).valueCount( - ValueCount.builder().type(Type.FIXED).count(1).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()).build(); validateBooleanNode(field, ConfigOperator.GREATER); } @@ -58,7 +57,7 @@ void validateBooleanNodeFloatPass() { void validateBooleanNodeStringGreater() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING).valueCount( - ValueCount.builder().type(Type.FIXED).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).build()).build(); assertThrows( UnsupportedValueTypeException.class, () -> validateBooleanNode(field, ConfigOperator.GREATER)); @@ -68,7 +67,7 @@ void validateBooleanNodeStringGreater() { void validateBooleanNodeFloatIn() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.FLOAT).valueCount( - ValueCount.builder().type(Type.FIXED).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).build()).build(); assertThrows( UnsupportedValueTypeException.class, () -> validateBooleanNode(field, IN)); @@ -79,7 +78,7 @@ void validateBooleanNodeContainsFixed1() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING) .valueCount( - ValueCount.builder().type(Type.FIXED).count(1).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()).build(); assertThrows( UnsupportedValueCountException.class, () -> validateBooleanNode(field, ConfigOperator.CONTAINS)); @@ -90,7 +89,7 @@ void validateBooleanNodeContainsMultiFixed1() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING) .valueCount( - ValueCount.builder().type(Type.FIXED).count(1).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()).build(); assertThrows( UnsupportedValueCountException.class, () -> validateBooleanNode(field, ConfigOperator.CONTAINS_ALL)); @@ -101,7 +100,7 @@ void validateBooleanNodeInFixed2() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING) .valueCount( - ValueCount.builder().type(Type.FIXED).count(2).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).count(2).build()).build(); assertThrows( UnsupportedValueCountException.class, () -> validateBooleanNode(field, IN)); @@ -111,7 +110,7 @@ void validateBooleanNodeInFixed2() { void validateBooleanNodeInA() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING).valueCount( - ValueCount.builder().type(Type.A).build()).build(); + ValueCount.builder().type(ValueCount.Type.A).build()).build(); validateBooleanNode(field, IN); } @@ -119,7 +118,7 @@ void validateBooleanNodeInA() { void validateBooleanNodeInGenotype() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING).valueCount( - ValueCount.builder().type(Type.G).count(2).build()).build(); + ValueCount.builder().type(ValueCount.Type.G).count(2).build()).build(); assertThrows( UnsupportedValueCountTypeException.class, () -> validateBooleanNode(field, IN)); @@ -130,7 +129,7 @@ void validateBooleanNodeInVariable() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING) .valueCount( - ValueCount.builder().type(Type.VARIABLE).count(2).build()).build(); + ValueCount.builder().type(ValueCount.Type.VARIABLE).count(2).build()).build(); assertThrows( UnsupportedValueCountTypeException.class, () -> validateBooleanNode(field, IN)); @@ -141,7 +140,7 @@ void validateBooleanNodeInFile() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING) .valueCount( - ValueCount.builder().type(Type.FIXED).count(1).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()).build(); queryValidator.validateBooleanNode(ConfigBoolQuery.builder().field("test").operator( IN).value("file:test").build(), field); } @@ -151,7 +150,7 @@ void validateBooleanNodeEqualsFile() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING) .valueCount( - ValueCount.builder().type(Type.FIXED).count(1).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()).build(); ConfigBoolQuery query = ConfigBoolQuery.builder().field("test").operator( ConfigOperator.EQUALS).value("file:test").build(); assertThrows( @@ -180,7 +179,7 @@ void validateCategoricalNodeFlag() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.FLAG) .valueCount( - ValueCount.builder().type(Type.FIXED).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).build()).build(); assertThrows( UnsupportedValueTypeException.class, () -> queryValidator.validateCategoricalNode(field)); @@ -190,7 +189,7 @@ void validateCategoricalNodeFlag() { void validateCategoricalCountVariable() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING).valueCount( - ValueCount.builder().type(Type.VARIABLE).build()).build(); + ValueCount.builder().type(ValueCount.Type.VARIABLE).build()).build(); assertThrows( UnsupportedValueCountTypeException.class, () -> queryValidator.validateCategoricalNode(field)); @@ -200,7 +199,7 @@ void validateCategoricalCountVariable() { void validateCategoricalCountGenotype() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING).valueCount( - ValueCount.builder().type(Type.G).build()).build(); + ValueCount.builder().type(ValueCount.Type.G).build()).build(); assertThrows( UnsupportedValueCountTypeException.class, () -> queryValidator.validateCategoricalNode(field)); @@ -210,7 +209,7 @@ void validateCategoricalCountGenotype() { void validateCategoricalNodeFloat() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.FLOAT).valueCount( - ValueCount.builder().type(Type.FIXED).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).build()).build(); assertThrows( UnsupportedValueTypeException.class, () -> queryValidator.validateCategoricalNode(field)); @@ -220,7 +219,7 @@ void validateCategoricalNodeFloat() { void validateCategoricalNumberGenotype() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING).valueCount( - ValueCount.builder().type(Type.G).build()).build(); + ValueCount.builder().type(ValueCount.Type.G).build()).build(); assertThrows( UnsupportedValueCountTypeException.class, () -> queryValidator.validateCategoricalNode(field)); @@ -230,7 +229,7 @@ void validateCategoricalNumberGenotype() { void validateCategoricalNumberVariable() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING).valueCount( - ValueCount.builder().type(Type.VARIABLE).build()).build(); + ValueCount.builder().type(ValueCount.Type.VARIABLE).build()).build(); assertThrows( UnsupportedValueCountTypeException.class, () -> queryValidator.validateCategoricalNode(field)); @@ -240,7 +239,7 @@ void validateCategoricalNumberVariable() { void validateCategoricalNumberFixedMoreThan1() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING).valueCount( - ValueCount.builder().type(Type.FIXED).count(2).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).count(2).build()).build(); assertThrows( UnsupportedValueCountException.class, () -> queryValidator.validateCategoricalNode(field)); @@ -251,7 +250,7 @@ void validateCategoricalNumberFixedMorePass() { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.STRING) .valueCount( - ValueCount.builder().type(Type.FIXED).count(1).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build()).build(); queryValidator.validateCategoricalNode(field); } diff --git a/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedOperatorExceptionTest.java b/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedOperatorExceptionTest.java index f70a95f6..3341f2e9 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedOperatorExceptionTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedOperatorExceptionTest.java @@ -6,16 +6,15 @@ import org.molgenis.vcf.decisiontree.filter.model.DecisionType; import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; import org.molgenis.vcf.decisiontree.filter.model.FieldType; -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; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; class UnsupportedOperatorExceptionTest { FieldImpl field = FieldImpl.builder().id("test").fieldType(FieldType.INFO) .valueType(ValueType.FLAG).valueCount( - ValueCount.builder().type(Type.FIXED).build()).build(); + ValueCount.builder().type(ValueCount.Type.FIXED).build()).build(); @Test void getMessage() { diff --git a/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedValueCountExceptionTest.java b/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedValueCountExceptionTest.java index a241f303..0d236ccf 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedValueCountExceptionTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedValueCountExceptionTest.java @@ -6,10 +6,9 @@ import org.molgenis.vcf.decisiontree.filter.model.DecisionType; import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; import org.molgenis.vcf.decisiontree.filter.model.FieldType; -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; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; class UnsupportedValueCountExceptionTest { @Test @@ -19,6 +18,6 @@ void getMessage() { new UnsupportedValueCountException( FieldImpl.builder().id("test").fieldType(FieldType.INFO).valueType(ValueType.FLOAT) .valueCount( - ValueCount.builder().type(Type.FIXED).count(3).build()).build(), DecisionType.CATEGORICAL, ConfigOperator.CONTAINS).getMessage()); + ValueCount.builder().type(ValueCount.Type.FIXED).count(3).build()).build(), DecisionType.CATEGORICAL, ConfigOperator.CONTAINS).getMessage()); } } \ No newline at end of file diff --git a/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedValueCountTypeExceptionTest.java b/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedValueCountTypeExceptionTest.java index 1f0956c6..bd5c4a06 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedValueCountTypeExceptionTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedValueCountTypeExceptionTest.java @@ -6,10 +6,9 @@ import org.molgenis.vcf.decisiontree.filter.model.DecisionType; import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; import org.molgenis.vcf.decisiontree.filter.model.FieldType; -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; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; class UnsupportedValueCountTypeExceptionTest { @Test @@ -19,6 +18,6 @@ void getMessage() { new UnsupportedValueCountTypeException( FieldImpl.builder().id("test").fieldType(FieldType.INFO).valueType(ValueType.FLOAT) .valueCount( - ValueCount.builder().type(Type.G).build()).build(), DecisionType.CATEGORICAL, ConfigOperator.IN).getMessage()); + ValueCount.builder().type(ValueCount.Type.G).build()).build(), DecisionType.CATEGORICAL, ConfigOperator.IN).getMessage()); } } \ No newline at end of file diff --git a/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedValueTypeExceptionTest.java b/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedValueTypeExceptionTest.java index 11b5f1de..6df8a0f1 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedValueTypeExceptionTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/runner/UnsupportedValueTypeExceptionTest.java @@ -1,14 +1,13 @@ package org.molgenis.vcf.decisiontree.runner; import static org.junit.jupiter.api.Assertions.*; +import static org.molgenis.vcf.utils.metadata.ValueType.*; import org.junit.jupiter.api.Test; import org.molgenis.vcf.decisiontree.filter.model.DecisionType; import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; import org.molgenis.vcf.decisiontree.filter.model.FieldType; -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.utils.metadata.ValueCount; class UnsupportedValueTypeExceptionTest { @Test @@ -16,9 +15,9 @@ void getMessage() { assertEquals( "Unsupported value type 'FLOAT' of field 'test' for decision type 'CATEGORICAL'.", new UnsupportedValueTypeException( - FieldImpl.builder().id("test").fieldType(FieldType.INFO).valueType(ValueType.FLOAT) + FieldImpl.builder().id("test").fieldType(FieldType.INFO).valueType(FLOAT) .valueCount( - ValueCount.builder().type(Type.A).build()).build(), DecisionType.CATEGORICAL) + ValueCount.builder().type(ValueCount.Type.A).build()).build(), DecisionType.CATEGORICAL) .getMessage()); } } \ No newline at end of file diff --git a/src/test/java/org/molgenis/vcf/decisiontree/runner/ValueValidatorTest.java b/src/test/java/org/molgenis/vcf/decisiontree/runner/ValueValidatorTest.java index f2d99c10..d0db3892 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/runner/ValueValidatorTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/runner/ValueValidatorTest.java @@ -17,15 +17,14 @@ import org.molgenis.vcf.decisiontree.filter.model.Field; import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; import org.molgenis.vcf.decisiontree.filter.model.FieldType; -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.ConfigDecisionTreeValidationException; import org.molgenis.vcf.decisiontree.loader.model.ConfigBoolNode; import org.molgenis.vcf.decisiontree.loader.model.ConfigBoolQuery; import org.molgenis.vcf.decisiontree.loader.model.ConfigDecisionTree; import org.molgenis.vcf.decisiontree.loader.model.ConfigNodeOutcome; import org.molgenis.vcf.decisiontree.loader.model.ConfigOperator; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; @ExtendWith(MockitoExtension.class) class ValueValidatorTest { @@ -60,106 +59,106 @@ void validateInvalid(Object value, Field field) { private static Stream provideValidValues() { return Stream.of( Arguments.of(1, new FieldImpl("id", FieldType.INFO, ValueType.INTEGER, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("123", new FieldImpl("id", FieldType.INFO, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(1, new FieldImpl("id", FieldType.INFO, ValueType.FLOAT, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(true, new FieldImpl("id", FieldType.INFO, ValueType.FLAG, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("1", new FieldImpl("id", FieldType.INFO, ValueType.CHARACTER, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(List.of(1, 2), new FieldImpl("id", FieldType.INFO, ValueType.INTEGER, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(List.of("123", "2"), new FieldImpl("id", FieldType.INFO, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(List.of(1, 2), new FieldImpl("id", FieldType.INFO, ValueType.FLOAT, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(List.of(true, false), new FieldImpl("id", FieldType.INFO, ValueType.FLAG, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(List.of("1", "2"), new FieldImpl("id", FieldType.INFO, ValueType.CHARACTER, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("MALE", new FieldImpl("SEX", FieldType.SAMPLE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("FEMALE", new FieldImpl("SEX", FieldType.SAMPLE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("UNKNOWN", new FieldImpl("SEX", FieldType.SAMPLE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("AFFECTED", new FieldImpl("AFFECTED_STATUS", FieldType.SAMPLE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("UNAFFECTED", new FieldImpl("AFFECTED_STATUS", FieldType.SAMPLE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("MISSING", new FieldImpl("AFFECTED_STATUS", FieldType.SAMPLE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("NO_CALL", new FieldImpl("TYPE", FieldType.GENOTYPE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("HOM_REF", new FieldImpl("TYPE", FieldType.GENOTYPE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("HET", new FieldImpl("TYPE", FieldType.GENOTYPE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("HOM_VAR", new FieldImpl("TYPE", FieldType.GENOTYPE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("UNAVAILABLE", new FieldImpl("TYPE", FieldType.GENOTYPE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("MIXED", new FieldImpl("TYPE", FieldType.GENOTYPE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(List.of(1, 2), new FieldImpl("id", FieldType.INFO, ValueType.INTEGER, - ValueCount.builder().type(Type.FIXED).count(2).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(2).build(), null, null)), Arguments.of(List.of("123", "2"), new FieldImpl("id", FieldType.INFO, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(2).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(2).build(), null, null)), Arguments.of(List.of(1, 2), new FieldImpl("id", FieldType.INFO, ValueType.FLOAT, - ValueCount.builder().type(Type.VARIABLE).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.VARIABLE).build(), null, null)), Arguments.of(List.of(true, false), new FieldImpl("id", FieldType.INFO, ValueType.FLAG, - ValueCount.builder().type(Type.A).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.A).build(), null, null)), Arguments.of(List.of("1", "2"), new FieldImpl("id", FieldType.INFO, ValueType.CHARACTER, - ValueCount.builder().type(Type.G).build(), null, null)) + ValueCount.builder().type(ValueCount.Type.G).build(), null, null)) ); } private static Stream provideInvalidValues() { return Stream.of( Arguments.of("TEST", new FieldImpl("SEX", FieldType.SAMPLE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("TEST", new FieldImpl("AFFECTED_STATUS", FieldType.SAMPLE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("TEST", new FieldImpl("TYPE", FieldType.GENOTYPE, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("1", new FieldImpl("id", FieldType.INFO, ValueType.INTEGER, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(1, new FieldImpl("id", FieldType.INFO, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("1", new FieldImpl("id", FieldType.INFO, ValueType.FLOAT, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of("true", new FieldImpl("id", FieldType.INFO, ValueType.FLAG, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(1, new FieldImpl("id", FieldType.INFO, ValueType.CHARACTER, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(List.of(1, "2"), new FieldImpl("id", FieldType.INFO, ValueType.INTEGER, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(List.of("123", 2), new FieldImpl("id", FieldType.INFO, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(List.of(1, "2"), new FieldImpl("id", FieldType.INFO, ValueType.FLOAT, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(List.of(true, "false"), new FieldImpl("id", FieldType.INFO, ValueType.FLAG, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(List.of("1", 2), new FieldImpl("id", FieldType.INFO, ValueType.CHARACTER, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(List.of("1", "12"), new FieldImpl("id", FieldType.INFO, ValueType.CHARACTER, - ValueCount.builder().type(Type.FIXED).count(1).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(1).build(), null, null)), Arguments.of(1, new FieldImpl("id", FieldType.INFO, ValueType.INTEGER, - ValueCount.builder().type(Type.FIXED).count(2).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(2).build(), null, null)), Arguments.of("123", new FieldImpl("id", FieldType.INFO, ValueType.STRING, - ValueCount.builder().type(Type.FIXED).count(2).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.FIXED).count(2).build(), null, null)), Arguments.of(1, new FieldImpl("id", FieldType.INFO, ValueType.FLOAT, - ValueCount.builder().type(Type.VARIABLE).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.VARIABLE).build(), null, null)), Arguments.of(true, new FieldImpl("id", FieldType.INFO, ValueType.FLAG, - ValueCount.builder().type(Type.A).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.A).build(), null, null)), Arguments.of("1", new FieldImpl("id", FieldType.INFO, ValueType.CHARACTER, - ValueCount.builder().type(Type.G).build(), null, null)), + ValueCount.builder().type(ValueCount.Type.G).build(), null, null)), Arguments.of("1", new FieldImpl("id", FieldType.INFO, ValueType.CHARACTER, - ValueCount.builder().type(Type.R).build(), null, null)) + ValueCount.builder().type(ValueCount.Type.R).build(), null, null)) ); } } \ No newline at end of file diff --git a/src/test/java/org/molgenis/vcf/decisiontree/runner/VepHelperTest.java b/src/test/java/org/molgenis/vcf/decisiontree/runner/VepHelperTest.java index 3c792eb4..7c80036f 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/runner/VepHelperTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/runner/VepHelperTest.java @@ -17,10 +17,9 @@ import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; import org.molgenis.vcf.decisiontree.filter.model.FieldType; import org.molgenis.vcf.decisiontree.filter.model.NestedField; -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.runner.info.NestedHeaderLine; +import org.molgenis.vcf.utils.metadata.ValueCount; +import org.molgenis.vcf.utils.metadata.ValueType; @ExtendWith(MockitoExtension.class) class VepHelperTest { @@ -31,7 +30,7 @@ class VepHelperTest { @BeforeEach void setUp() { vepHelper = new VepHelper(); - ValueCount valueCount = ValueCount.builder().type(Type.VARIABLE).build(); + ValueCount valueCount = ValueCount.builder().type(ValueCount.Type.VARIABLE).build(); FieldImpl parent = FieldImpl.builder().id("VEP").fieldType( FieldType.INFO) .valueType(ValueType.STRING).valueCount(valueCount).separator('|').build(); diff --git a/src/test/java/org/molgenis/vcf/decisiontree/runner/info/MissingVepMetaExceptionTest.java b/src/test/java/org/molgenis/vcf/decisiontree/runner/info/MissingVepMetaExceptionTest.java new file mode 100644 index 00000000..4384263c --- /dev/null +++ b/src/test/java/org/molgenis/vcf/decisiontree/runner/info/MissingVepMetaExceptionTest.java @@ -0,0 +1,15 @@ +package org.molgenis.vcf.decisiontree.runner.info; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class MissingVepMetaExceptionTest { + + @Test + void getMessage() { + assertEquals( + "Metadata json is missing required VEP annotation.", + new MissingVepMetaException().getMessage()); + } +} \ No newline at end of file diff --git a/src/test/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapperImplTest.java b/src/test/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapperImplTest.java index 7cb0cce3..86c1fd22 100644 --- a/src/test/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapperImplTest.java +++ b/src/test/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataMapperImplTest.java @@ -3,13 +3,16 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.molgenis.vcf.decisiontree.filter.model.ValueCount.Type.FIXED; -import static org.molgenis.vcf.decisiontree.filter.model.ValueCount.Type.VARIABLE; +import static org.molgenis.vcf.utils.metadata.ValueCount.Type.*; +import htsjdk.variant.vcf.VCFHeader; import htsjdk.variant.vcf.VCFInfoHeaderLine; + import java.util.HashMap; import java.util.Map; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -19,93 +22,77 @@ import org.molgenis.vcf.decisiontree.filter.model.FieldImpl; import org.molgenis.vcf.decisiontree.filter.model.FieldType; import org.molgenis.vcf.decisiontree.filter.model.NestedField; -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.utils.metadata.FieldMetadataService; -import org.molgenis.vcf.utils.model.FieldMetadata; -import org.molgenis.vcf.utils.model.NumberType; +import org.molgenis.vcf.utils.metadata.*; +import org.molgenis.vcf.utils.model.metadata.FieldMetadata; +import org.molgenis.vcf.utils.model.metadata.FieldMetadatas; +import org.molgenis.vcf.utils.model.metadata.NestedFieldMetadata; @ExtendWith(MockitoExtension.class) class VepMetadataMapperImplTest { - private VepMetadataMapperImpl vepMetadataMapperImpl; + private VepMetadataMapper vepMetadataMapper; @Mock - VCFInfoHeaderLine headerLine; + FieldMetadataService fieldMetadataService; + @Mock - FieldMetadataService metadataService; + VCFInfoHeaderLine headerLine; + + @BeforeEach - void setUp() { - vepMetadataMapperImpl = new VepMetadataMapperImpl(metadataService); + void setUp(){ + vepMetadataMapper = new VepMetadataMapperImpl(fieldMetadataService); } @Test void canMap() { when(headerLine.getDescription()).thenReturn( "Consequence annotations from Ensembl VEP. Format: Allele|Consequence|IMPACT|SYMBOL|Gene|Feature_type|Feature|BIOTYPE|EXON|INTRON|HGVSc|HGVSp|cDNA_position|CDS_position|Protein_position|Amino_acids|Codons|Existing_variation|DISTANCE|STRAND|FLAGS|PICK|SYMBOL_SOURCE|HGNC_ID|GENE_PHENO|gnomAD_AF|gnomAD_AFR_AF|gnomAD_AMR_AF|gnomAD_ASJ_AF|gnomAD_EAS_AF|gnomAD_FIN_AF|gnomAD_NFE_AF|gnomAD_OTH_AF|gnomAD_SAS_AF|CLIN_SIG|SOMATIC|PHENO|PUBMED|CHECK_REF"); - assertTrue(vepMetadataMapperImpl.canMap(headerLine)); + assertTrue(vepMetadataMapper.canMap(headerLine)); } @Test void cantMapDesc() { when(headerLine.getDescription()).thenReturn( "Other annotations not from Ensembl VEP. Format: Allele|Consequence|IMPACT|SYMBOL|Gene|Feature_type|Feature|BIOTYPE|EXON|INTRON|HGVSc|HGVSp|cDNA_position|CDS_position|Protein_position|Amino_acids|Codons|Existing_variation|DISTANCE|STRAND|FLAGS|PICK|SYMBOL_SOURCE|HGNC_ID|GENE_PHENO|gnomAD_AF|gnomAD_AFR_AF|gnomAD_AMR_AF|gnomAD_ASJ_AF|gnomAD_EAS_AF|gnomAD_FIN_AF|gnomAD_NFE_AF|gnomAD_OTH_AF|gnomAD_SAS_AF|CLIN_SIG|SOMATIC|PHENO|PUBMED|CHECK_REF"); - assertFalse(vepMetadataMapperImpl.canMap(headerLine)); + assertFalse(vepMetadataMapper.canMap(headerLine)); } @Test void map() { - when(headerLine.getID()).thenReturn( - "CSQ"); - HashMap vepMeta = new HashMap<>(); - vepMeta.put("Allele", org.molgenis.vcf.utils.model.NestedField.builder().index(4).numberCount(1) - .numberType(NumberType.NUMBER) - .type(org.molgenis.vcf.utils.model.ValueType.STRING).label("Allele").description("Allele") - .build()); - vepMeta.put("field2", org.molgenis.vcf.utils.model.NestedField.builder().index(3).numberCount(1) - .numberType(NumberType.PER_ALT) - .type(org.molgenis.vcf.utils.model.ValueType.INTEGER).label("Field2").description("Field2") - .build()); - vepMeta.put("field3", org.molgenis.vcf.utils.model.NestedField.builder().index(2).numberCount(1) - .numberType(NumberType.PER_GENOTYPE) - .type(org.molgenis.vcf.utils.model.ValueType.CHARACTER).label("Field3") - .description("Field3") - .build()); - vepMeta.put("field4", org.molgenis.vcf.utils.model.NestedField.builder().index(1).numberCount(1) - .numberType(NumberType.PER_ALT_AND_REF) - .type(org.molgenis.vcf.utils.model.ValueType.CATEGORICAL).label("Field4") - .description("Field4") - .build()); - when(metadataService.load(headerLine)).thenReturn( - FieldMetadata.builder().nestedFields(vepMeta).build()); - - NestedHeaderLine actual = vepMetadataMapperImpl - .map(headerLine); + VCFHeader vcfHeader = mock(VCFHeader.class); + VCFInfoHeaderLine csqInfoHeaderLine = mock(VCFInfoHeaderLine.class); + when(csqInfoHeaderLine.getID()).thenReturn("CSQ"); + when(vcfHeader.getInfoHeaderLine("CSQ")).thenReturn(csqInfoHeaderLine); + + NestedFieldMetadata nestedStrandMeta = NestedFieldMetadata.builder().index(0) + .label("STRAND").description("STRAND") + .type(ValueType.INTEGER).numberType(FIXED).numberCount(1).build(); + NestedFieldMetadata nestedTestMeta = NestedFieldMetadata.builder().index(1) + .label("TEST label").description("TEST desc").type(ValueType.INTEGER) + .numberType(ValueCount.Type.R).build(); + FieldMetadata csqMeta = FieldMetadata.builder().label("CSQ").description("Consequence annotations from Ensembl VEP. Format: STRAND|TEST").numberType(ValueCount.Type.VARIABLE).type(ValueType.STRING).numberType(ValueCount.Type.VARIABLE).nestedFields(Map.of("STRAND", nestedStrandMeta, "TEST", nestedTestMeta)).build(); + FieldMetadatas fieldMetadatas = FieldMetadatas.builder().info(Map.of("CSQ", csqMeta)).format(Map.of()).build(); + when(fieldMetadataService.load(vcfHeader, Map.of(FieldIdentifier.builder().name("CSQ").type(org.molgenis.vcf.utils.metadata.FieldType.INFO).build(), NestedAttributes.builder().seperator("|").prefix("Consequence annotations from Ensembl VEP. Format: ").build()))).thenReturn(fieldMetadatas); + + NestedHeaderLine actual = vepMetadataMapper + .map("CSQ", vcfHeader); Field vepField = FieldImpl.builder().id("CSQ").fieldType(FieldType.INFO) .valueType(ValueType.STRING).valueCount(ValueCount.builder() .type(VARIABLE).build()).separator('|').build(); Map expectedMap = new HashMap<>(); - expectedMap.put("Allele", NestedField.nestedBuilder().id("Allele").index(4).parent(vepField) + expectedMap.put("STRAND", NestedField.nestedBuilder().id("STRAND").index(0).parent(vepField) .fieldType(FieldType.INFO_VEP) .valueCount(ValueCount.builder().type(FIXED).count(1).build()) - .valueType(ValueType.STRING).build()); - expectedMap.put("field2", NestedField.nestedBuilder().id("field2").index(3).parent(vepField) - .fieldType(FieldType.INFO_VEP) - .valueCount(ValueCount.builder().type(Type.R).build()) .valueType(ValueType.INTEGER).build()); - expectedMap.put("field3", NestedField.nestedBuilder().id("field3").index(2).parent(vepField) - .fieldType(FieldType.INFO_VEP) - .valueCount(ValueCount.builder().type(Type.G).build()) - .valueType(ValueType.CHARACTER).build()); - expectedMap.put("field4", NestedField.nestedBuilder().id("field4").index(1).parent(vepField) + expectedMap.put("TEST", NestedField.nestedBuilder().id("TEST").index(1).parent(vepField) .fieldType(FieldType.INFO_VEP) - .valueCount(ValueCount.builder().type(Type.A).build()) + .valueCount(ValueCount.builder().type(ValueCount.Type.R).build()) .valueType(ValueType.STRING).build()); - assertEquals(NestedHeaderLine.builder().nestedFields(expectedMap).parentField(vepField).build(), - actual); + NestedHeaderLine expected = NestedHeaderLine.builder().nestedFields(expectedMap).parentField(vepField).build(); + assertEquals(expected, actual); } } \ No newline at end of file diff --git a/src/test/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParserImplTest.java b/src/test/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParserImplTest.java deleted file mode 100644 index 9ca4fb96..00000000 --- a/src/test/java/org/molgenis/vcf/decisiontree/runner/info/VepMetadataParserImplTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.molgenis.vcf.decisiontree.runner.info; - -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import htsjdk.variant.vcf.VCFHeader; -import htsjdk.variant.vcf.VCFInfoHeaderLine; -import java.util.Collections; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -class VepMetadataParserImplTest { - - @Mock - VepMetadataMapper mapper; - @Mock - VCFHeader vcfHeader; - @Mock - VCFInfoHeaderLine headerLine; - - private VepMetadataParserImpl nestedMetadataServiceImpl; - - @BeforeEach - void setUp() { - when(vcfHeader.getInfoHeaderLines()).thenReturn(Collections.singletonList(headerLine)); - - nestedMetadataServiceImpl = - new VepMetadataParserImpl(mapper); - } - - @Test - void mapMatchingHeader() { - when(mapper.canMap(headerLine)).thenReturn(true); - - nestedMetadataServiceImpl.map(vcfHeader); - - verify(mapper).map(headerLine); - } - - @Test - void mapNoMatchingHeader() { - when(mapper.canMap(headerLine)).thenReturn(false); - - assertThrows(MissingVepException.class, () -> { - nestedMetadataServiceImpl.map(vcfHeader); - }); - } -} \ No newline at end of file diff --git a/src/test/resources/field_metadata.json b/src/test/resources/field_metadata.json index 316f0a50..604a1772 100644 --- a/src/test/resources/field_metadata.json +++ b/src/test/resources/field_metadata.json @@ -6,16 +6,32 @@ "numberType": "OTHER", "separator": ",", "type": "CATEGORICAL", - "categories": [ - "AD", - "AD_IP", - "AR", - "AR_C", - "XLD", - "XLR", - "YL", - "MT" - ] + "categories": { + "AD": { + "label": "AD" + }, + "AD_IP": { + "label": "AD_IP" + }, + "AR": { + "label": "AR" + }, + "AR_C": { + "label": "AR_C" + }, + "XLD": { + "label": "XLD" + }, + "XLR": { + "label": "XLR" + }, + "YL": { + "label": "YL" + }, + "MT": { + "label": "MT" + } + } } }, "info": { @@ -41,13 +57,13 @@ "numberType": "NUMBER", "numberCount": 1, "type": "CATEGORICAL", - "categories": [ - "B", - "LB", - "VUS", - "LP", - "P" - ] + "categories": { + "B": {"label": "B"}, + "LB": {"label": "LB"}, + "VUS": {"label": "VUS"}, + "LP": {"label": "LP"}, + "P": {"label": "P", "description": "Description P"} + } }, "CAPICE_SC": { "label": "CAPICE", @@ -95,14 +111,26 @@ "numberType": "OTHER", "separator": "/", "type": "CATEGORICAL", - "categories": [ - "Benign", - "Likely_benign", - "Uncertain_significance", - "Likely_pathogenic", - "Pathogenic", - "Conflicting_interpretations_of_pathogenicity" - ] + "categories": { + "Benign": { + "label": "Benign" + }, + "Likely_benign": { + "label": "Likely_benign" + }, + "Uncertain_significance": { + "label": "Uncertain_significance" + }, + "Likely_pathogenic": { + "label": "Likely_pathogenic" + }, + "Pathogenic": { + "label": "Pathogenic" + }, + "Conflicting_interpretations_of_pathogenicity": { + "label": "Conflicting_interpretations_of_pathogenicity" + } + } }, "clinVar_CLNSIGINCL": { "label": "ClinVar variant combination", @@ -110,14 +138,26 @@ "numberType": "OTHER", "separator": "&", "type": "CATEGORICAL", - "categories": [ - "Benign", - "Likely_benign", - "Uncertain_significance", - "Likely_pathogenic", - "Pathogenic", - "Conflicting_interpretations_of_pathogenicity" - ] + "categories": { + "Benign": { + "label": "Benign" + }, + "Likely_benign": { + "label": "Likely_benign" + }, + "Uncertain_significance": { + "label": "Uncertain_significance" + }, + "Likely_pathogenic": { + "label": "Likely_pathogenic" + }, + "Pathogenic": { + "label": "Pathogenic" + }, + "Conflicting_interpretations_of_pathogenicity": { + "label": "Conflicting_interpretations_of_pathogenicity" + } + } }, "clinVar_CLNREVSTAT": { "label": "ClinVar status", @@ -125,17 +165,35 @@ "numberType": "OTHER", "separator": "&", "type": "CATEGORICAL", - "categories": [ - "practice_guideline", - "reviewed_by_expert_panel", - "criteria_provided", - "_multiple_submitters", - "_no_conflicts", - "_single_submitter", - "_conflicting_interpretations", - "no_assertion_criteria_provided", - "no_assertion_provided" - ] + "categories": { + "practice_guideline": { + "label": "practice_guideline" + }, + "reviewed_by_expert_panel": { + "label": "reviewed_by_expert_panel" + }, + "criteria_provided": { + "label": "criteria_provided" + }, + "_multiple_submitters": { + "label": "_multiple_submitters" + }, + "_no_conflicts": { + "label": "_no_conflicts" + }, + "_single_submitter": { + "label": "_single_submitter" + }, + "_conflicting_interpretations": { + "label": "_conflicting_interpretations" + }, + "no_assertion_criteria_provided": { + "label": "no_assertion_criteria_provided" + }, + "no_assertion_provided": { + "label": "no_assertion_provided" + } + } }, "Consequence": { "label": "Effect", @@ -157,11 +215,17 @@ "numberType": "NUMBER", "numberCount": 1, "type": "CATEGORICAL", - "categories": [ - "Transcript", - "RegulatoryFeature", - "MotifFeature" - ], + "categories": { + "Transcript": { + "label": "Transcript" + }, + "RegulatoryFeature": { + "label": "RegulatoryFeature" + }, + "MotifFeature": { + "label": "MotifFeature" + } + }, "required": true }, "FLAGS": { @@ -177,10 +241,14 @@ "numberType": "NUMBER", "numberCount": 1, "type": "CATEGORICAL", - "categories": [ - "LC", - "HC" - ] + "categories": { + "LC": { + "label": "LC" + }, + "HC": { + "label": "HC" + } + } }, "GADO_SC": { "label": "GADO_SC", @@ -230,11 +298,17 @@ "numberType": "NUMBER", "numberCount": 1, "type": "CATEGORICAL", - "categories": [ - "E", - "G", - "T" - ] + "categories": { + "E": { + "label": "E" + }, + "G": { + "label": "G" + }, + "T": { + "label": "T" + } + } }, "gnomAD_QC": { "label": "gnomAD QC", @@ -277,12 +351,20 @@ "numberType": "NUMBER", "numberCount": 1, "type": "CATEGORICAL", - "categories": [ - "LOW", - "MODERATE", - "HIGH", - "MODIFIER" - ], + "categories": { + "LOW": { + "label": "LOW" + }, + "MODERATE": { + "label": "MODERATE" + }, + "HIGH": { + "label": "HIGH" + }, + "MODIFIER": { + "label": "MODIFIER" + } + }, "required": true }, "IncompletePenetrance": { @@ -426,13 +508,13 @@ "numberType": "NUMBER", "numberCount": 1, "type": "CATEGORICAL", - "categories": [ - "B", - "LB", - "VUS", - "LP", - "P" - ] + "categories": { + "B": {"label": "B"}, + "LB": {"label": "LB"}, + "VUS": {"label": "VUS"}, + "LP": {"label": "LP"}, + "P": {"label": "P", "description": "Description P"} + } }, "VKGL_UMCG": { "label": "MVL", @@ -440,13 +522,13 @@ "numberType": "NUMBER", "numberCount": 1, "type": "CATEGORICAL", - "categories": [ - "B", - "LB", - "VUS", - "LP", - "P" - ] + "categories": { + "B": {"label": "B"}, + "LB": {"label": "LB"}, + "VUS": {"label": "VUS"}, + "LP": {"label": "LP"}, + "P": {"label": "P", "description": "Description P"} + } } } }