Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix flag field behaviour #89

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,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() == Type.FIXED && field.getValueCount().getCount() <= 1;
}

public Map<String, Integer> getSampleNameToOffset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ private Object getInfoValue(Field field, Allele allele) {
value = getInfoList(field);
break;
case FIXED:
value = valueCount.getCount() == 1 ? getInfo(field) : getInfoList(field);
value = valueCount.getCount() <= 1 ? getInfo(field) : getInfoList(field);
break;
default:
throw new UnexpectedEnumException(valueCountType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ void getFieldInfoFlag() {
VCFInfoHeaderLine vcfInfoHeaderLine = mock(VCFInfoHeaderLine.class);
when(vcfInfoHeaderLine.getType()).thenReturn(VCFHeaderLineType.Flag);
when(vcfInfoHeaderLine.getCountType()).thenReturn(VCFHeaderLineCount.INTEGER);
when(vcfInfoHeaderLine.getCount()).thenReturn(1);
when(vcfInfoHeaderLine.getCount()).thenReturn(0);
when(vcfHeader.getInfoHeaderLine("my_field")).thenReturn(vcfInfoHeaderLine);
String fieldId = "INFO/my_field";
assertEquals(
FieldImpl.builder()
.id("my_field")
.fieldType(FieldType.INFO)
.valueType(ValueType.FLAG)
.valueCount(ValueCount.builder().type(Type.FIXED).count(1).build())
.valueCount(ValueCount.builder().type(Type.FIXED).count(0).build())
.build(),
vcfMetadata.getField(fieldId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.molgenis.vcf.utils.sample.model.Sex.MALE;
Expand Down Expand Up @@ -259,6 +256,18 @@ void getValueInfoVariable() {
assertEquals(asList(1, 2), vcfRecord.getValue(field, createAllele()));
}

@Test
void getValueInfoFlag() {
FieldImpl field =
FieldImpl.builder()
.id("my_field")
.fieldType(FieldType.INFO)
.valueCount(ValueCount.builder().type(Type.FIXED).count(0).build())
.valueType(ValueType.FLAG)
.build();
Allele allele = createAllele();
assertFalse((Boolean) vcfRecord.getValue(field, allele));
}
@Test
void getValueInfoVariableFlag() {
FieldImpl field =
Expand Down
6 changes: 4 additions & 2 deletions src/test/resources/example-classified.vcf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
##FORMAT=<ID=FORMAT2,Number=1,Type=String,Description="\"format2\"">
##INFO=<ID=CLINVAR,Number=.,Type=String,Description="\"Clinvar prediction\"">
##INFO=<ID=CSQ,Number=.,Type=String,Description="Consequence annotations from Ensembl VEP. Format: VKGL_CL|Allele|Consequence|IMPACT|SYMBOL|Gene|Feature_type|Feature|BIOTYPE|EXON|INTRON|HGVSc|HGVSp|cDNA_position|CDS_position|Protein_position|Amino_acids|Codons|Existing_variation|ALLELE_NUM|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|SpliceAI_pred_DS_AG|SpliceAI_pred_DS_AL|SpliceAI_pred_DS_DG|SpliceAI_pred_DS_DL|VIPC">
##INFO=<ID=FLAG1,Number=0,Type=Flag,Description="\"Flag field\"">
##INFO=<ID=TEST2,Number=1,Type=String,Description="\"Test\"">
##SnpEffCmd="SnpEff GRCh37.75 ../vip-decision-tree/src/CSQ/resources/test_annotated.vcf "
##SnpEffVersion="4.3t (build 2017-11-24 10:18), by Pablo Cingolani"
Expand Down Expand Up @@ -45,5 +46,6 @@
1 10042538 . C T . PASS CSQ=LP|T|missense_variant|MODERATE|NMNAT1|ENSG00000173614|Transcript|ENST00000377205|protein_coding|5/5||||763|619|207|R/W|Cgg/Tgg|rs142968179&CM127756|1||1||1|HGNC|17877|1|3.58e-05|0|2.891e-05|0|0|0|6.157e-05|0.0001629|0|pathogenic||1&1|26103963&22842229&22842230||0|0|0|0|LP,|T|NMD_transcript_variant|MODERATE|NMNAT1|ENSG00000173614|Transcript|ENST00000462686|nonsense_mediated_decay|5/6||||762|619|207|R/W|Cgg/Tgg|rs142968179&CM127756|1||1|||HGNC|17877|1|0.0001|0|0.0001|0|0|0|0.0001|0.0001629|0|pathogenic||1&1|26103963&22842229&22842230||0|0.43|0|0.41|LP
1 10042539 . C A,T . PASS CSQ=LP|A|missense_variant|MODERATE|NMNAT1|ENSG00000173614|Transcript|ENST00000377205|protein_coding|5/5||||763|619|207|R/W|Cgg/Tgg|rs142968179&CM127756|1||1||1|HGNC|17877|1|3.58e-05|0|2.891e-05|0|0|0|6.157e-05|0.0001629|0|pathogenic||1&1|26103963&22842229&22842230||0|0|0|0|LP,LB|T|missense_variant&NMD_transcript_variant|MODERATE|NMNAT1|ENSG00000173614|Transcript|ENST00000462686|nonsense_mediated_decay|5/6||||762|619|207|R/W|Cgg/Tgg|rs142968179&CM127756|2||2|||HGNC|17877|2|3.58e-05|0|2.891e-05|0|0|0|6.157e-05|0.0001629|0|pathogenic||1&1|26103963&22842229&22842230||0|0|0|0|LB
1 10042540 . C G . PASS CLINVAR=LP;CSQ=|||||||||||||||||||1||||||||||||||||||||||||||LP
1 10042541 . C G . PASS CSQ=|||||||||||||||||||1||||||||||||||||||||||||||VUS
1 10042542 . C G . . CSQ=|||||||||||||||||||1||||||||||||||||||||||||||VUS
1 10042541 . C G . PASS CSQ=|||||||||||||||||||1||||||||||||||||||||||||||LB
1 10042542 . C G . . CSQ=|||||||||||||||||||1||||||||||||||||||||||||||LB
1 10042543 . C G . PASS CSQ=|||||||||||||||||||1||||||||||||||||||||||||||LP;FLAG1
6 changes: 4 additions & 2 deletions src/test/resources/example-classified_paths-labels.vcf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
##FORMAT=<ID=FORMAT2,Number=1,Type=String,Description="\"format2\"">
##INFO=<ID=CLINVAR,Number=.,Type=String,Description="\"Clinvar prediction\"">
##INFO=<ID=CSQ,Number=.,Type=String,Description="Consequence annotations from Ensembl VEP. Format: VKGL_CL|Allele|Consequence|IMPACT|SYMBOL|Gene|Feature_type|Feature|BIOTYPE|EXON|INTRON|HGVSc|HGVSp|cDNA_position|CDS_position|Protein_position|Amino_acids|Codons|Existing_variation|ALLELE_NUM|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|SpliceAI_pred_DS_AG|SpliceAI_pred_DS_AL|SpliceAI_pred_DS_DG|SpliceAI_pred_DS_DL|VIPC|VIPP|VIPL">
##INFO=<ID=FLAG1,Number=0,Type=Flag,Description="\"Flag field\"">
##INFO=<ID=TEST2,Number=1,Type=String,Description="\"Test\"">
##SnpEffCmd="SnpEff GRCh37.75 ../vip-decision-tree/src/CSQ/resources/test_annotated.vcf "
##SnpEffVersion="4.3t (build 2017-11-24 10:18), by Pablo Cingolani"
Expand Down Expand Up @@ -47,5 +48,6 @@
1 10042538 . C T . PASS CSQ=LP|T|missense_variant|MODERATE|NMNAT1|ENSG00000173614|Transcript|ENST00000377205|protein_coding|5/5||||763|619|207|R/W|Cgg/Tgg|rs142968179&CM127756|1||1||1|HGNC|17877|1|3.58e-05|0|2.891e-05|0|0|0|6.157e-05|0.0001629|0|pathogenic||1&1|26103963&22842229&22842230||0|0|0|0|LP|filter&vkgl&exit_lp|,|T|NMD_transcript_variant|MODERATE|NMNAT1|ENSG00000173614|Transcript|ENST00000462686|nonsense_mediated_decay|5/6||||762|619|207|R/W|Cgg/Tgg|rs142968179&CM127756|1||1|||HGNC|17877|1|0.0001|0|0.0001|0|0|0|0.0001|0.0001629|0|pathogenic||1&1|26103963&22842229&22842230||0|0.43|0|0.41|LP|filter&vkgl&clinVar&gnomad&effect&spliceAI&exit_lp|
1 10042539 . C A,T . PASS CSQ=LP|A|missense_variant|MODERATE|NMNAT1|ENSG00000173614|Transcript|ENST00000377205|protein_coding|5/5||||763|619|207|R/W|Cgg/Tgg|rs142968179&CM127756|1||1||1|HGNC|17877|1|3.58e-05|0|2.891e-05|0|0|0|6.157e-05|0.0001629|0|pathogenic||1&1|26103963&22842229&22842230||0|0|0|0|LP|filter&vkgl&exit_lp|,LB|T|missense_variant&NMD_transcript_variant|MODERATE|NMNAT1|ENSG00000173614|Transcript|ENST00000462686|nonsense_mediated_decay|5/6||||762|619|207|R/W|Cgg/Tgg|rs142968179&CM127756|2||2|||HGNC|17877|2|3.58e-05|0|2.891e-05|0|0|0|6.157e-05|0.0001629|0|pathogenic||1&1|26103963&22842229&22842230||0|0|0|0|LB|filter&vkgl&exit_lb|
1 10042540 . C G . PASS CLINVAR=LP;CSQ=|||||||||||||||||||1||||||||||||||||||||||||||LP|filter&vkgl&clinVar&exit_lp|
1 10042541 . C G . PASS CSQ=|||||||||||||||||||1||||||||||||||||||||||||||VUS|filter&vkgl&clinVar&gnomad&effect&spliceAI&annotSV&impact&exit_vus|
1 10042542 . C G . . CSQ=|||||||||||||||||||1||||||||||||||||||||||||||VUS|filter&vkgl&clinVar&gnomad&effect&spliceAI&annotSV&impact&exit_vus|
1 10042541 . C G . PASS CSQ=|||||||||||||||||||1||||||||||||||||||||||||||LB|filter&vkgl&clinVar&gnomad&effect&spliceAI&annotSV&impact&flag&exit_lb|
1 10042542 . C G . . CSQ=|||||||||||||||||||1||||||||||||||||||||||||||LB|filter&vkgl&clinVar&gnomad&effect&spliceAI&annotSV&impact&flag&exit_lb|
1 10042543 . C G . PASS CSQ=|||||||||||||||||||1||||||||||||||||||||||||||LP|filter&vkgl&clinVar&gnomad&effect&spliceAI&annotSV&impact&flag&exit_lp|;FLAG1
18 changes: 18 additions & 0 deletions src/test/resources/example.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,24 @@
"nextNode": "exit_lp"
}
},
"outcomeMissing": {
"nextNode": "flag"
}
},
"flag": {
"type": "BOOL",
"description": "flag exists",
"query": {
"field": "INFO/FLAG1",
"operator": "==",
"value": true
},
"outcomeTrue": {
"nextNode": "exit_lp"
},
"outcomeFalse": {
"nextNode": "exit_lb"
},
"outcomeMissing": {
"nextNode": "exit_vus"
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/example.vcf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
##FILTER=<ID=PASS,Description="All filters passed">
##INFO=<ID=CLINVAR,Number=.,Type=String,Description="\"Clinvar prediction\"">
##INFO=<ID=TEST2,Number=1,Type=String,Description="\"Test\"">
##INFO=<ID=FLAG1,Number=0,Type=Flag,Description="\"Flag field\"">
##FORMAT=<ID=FORMAT1,Number=.,Type=String,Description="\"format1\"">
##FORMAT=<ID=FORMAT2,Number=1,Type=String,Description="\"format2\"">
##fileDate=20200320
Expand All @@ -44,3 +45,4 @@
1 10042540 . C G . PASS CLINVAR=LP
1 10042541 . C G . PASS .
1 10042542 . C G . . .
1 10042543 . C G . PASS FLAG1