Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to vip utils 3.0.0 #101

Merged
merged 3 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<commons.cli.version>1.9.0</commons.cli.version>
<samtools.htsjdk.version>4.1.1</samtools.htsjdk.version>
<jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>
<vip.utils.version>2.0.2</vip.utils.version>
<vip.utils.version>3.0.0</vip.utils.version>
</properties>

<profiles>
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/org/molgenis/vcf/decisiontree/filter/VcfMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -72,15 +71,15 @@ private static Field toSampleField(List<String> 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);
}
Expand Down Expand Up @@ -127,19 +126,19 @@ private FieldImpl toCommonField(List<String> 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);
}
Expand Down Expand Up @@ -179,12 +178,12 @@ private Field toCompoundField(List<String> 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);
}

Expand Down Expand Up @@ -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<String, Integer> getSampleNameToOffset() {
Expand Down
26 changes: 21 additions & 5 deletions src/main/java/org/molgenis/vcf/decisiontree/filter/VcfReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,56 @@
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).
*/
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<VcfRecord> stream() {
return StreamSupport.stream(vcfFileReader.spliterator(), false).map(VcfRecord::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NestedField> {

final int index;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading