@@ -122,30 +122,35 @@ public enum FlagFieldLogic {
122
122
/**
123
123
* Comparators used for picking the representative genotype for a given sample
124
124
*/
125
+ // Priotize non-ref over ref
125
126
final Comparator <Genotype > genotypeIsNonRefComparator = (o1 , o2 ) -> {
126
127
final long count1 = Math .min (1 , o1 .getAlleles ().stream ().filter (Allele ::isNonReference ).filter (Allele ::isCalled ).count ());
127
128
final long count2 = Math .min (1 , o2 .getAlleles ().stream ().filter (Allele ::isNonReference ).filter (Allele ::isCalled ).count ());
128
129
return Long .compare (count1 , count2 );
129
130
};
130
131
132
+ // Priotize fewer ALT alleles over more. When applied after non-ref comparator, hom-ref genotypes will not be encountered.
131
133
final Comparator <Genotype > genotypeNonRefCountComparator = (o1 , o2 ) -> {
132
134
final long count1 = o1 .getAlleles ().stream ().filter (Allele ::isNonReference ).filter (Allele ::isCalled ).count ();
133
135
final long count2 = o2 .getAlleles ().stream ().filter (Allele ::isNonReference ).filter (Allele ::isCalled ).count ();
134
- return Long .compare (count1 , count2 );
136
+ return Long .compare (count2 , count1 );
135
137
};
136
138
139
+ // Priotize called genotypes
137
140
final Comparator <Genotype > genotypeCalledComparator = (o1 , o2 ) -> {
138
141
final long count1 = o1 .getAlleles ().stream ().filter (Allele ::isCalled ).count ();
139
142
final long count2 = o2 .getAlleles ().stream ().filter (Allele ::isCalled ).count ();
140
143
return Long .compare (count1 , count2 );
141
144
};
142
145
146
+ // Priotize higher quality
143
147
final Comparator <Genotype > genotypeQualityComparator = (o1 , o2 ) -> {
144
148
final int quality1 = VariantContextGetters .getAttributeAsInt (o1 , VCFConstants .GENOTYPE_QUALITY_KEY , 0 );
145
149
final int quality2 = VariantContextGetters .getAttributeAsInt (o2 , VCFConstants .GENOTYPE_QUALITY_KEY , 0 );
146
150
return Integer .compare (quality1 , quality2 );
147
151
};
148
152
153
+ // Priotize higher depth genotyping quality
149
154
final Comparator <Genotype > genotypeCopyNumberQualityComparator = new Comparator <Genotype >() {
150
155
@ Override
151
156
public int compare (Genotype o1 , Genotype o2 ) {
@@ -155,14 +160,33 @@ public int compare(Genotype o1, Genotype o2) {
155
160
}
156
161
};
157
162
163
+ // Priotize depth genotypes closer to reference
158
164
final Comparator <Genotype > genotypeCopyNumberComparator = new Comparator <Genotype >() {
159
165
@ Override
160
166
public int compare (Genotype o1 , Genotype o2 ) {
161
167
final int expectedQualityNumber1 = VariantContextGetters .getAttributeAsInt (o1 , GATKSVVCFConstants .EXPECTED_COPY_NUMBER_FORMAT , 0 );
162
168
final int copyNumber1 = VariantContextGetters .getAttributeAsInt (o1 , GATKSVVCFConstants .COPY_NUMBER_FORMAT , 0 );
163
169
final int expectedQualityNumber2 = VariantContextGetters .getAttributeAsInt (o2 , GATKSVVCFConstants .EXPECTED_COPY_NUMBER_FORMAT , 0 );
164
170
final int copyNumber2 = VariantContextGetters .getAttributeAsInt (o2 , GATKSVVCFConstants .COPY_NUMBER_FORMAT , 0 );
165
- return Double .compare (Math .abs (expectedQualityNumber1 - copyNumber1 ), Math .abs (expectedQualityNumber2 - copyNumber2 ));
171
+ return Double .compare (Math .abs (expectedQualityNumber2 - copyNumber2 ), Math .abs (expectedQualityNumber1 - copyNumber1 ));
172
+ }
173
+ };
174
+
175
+ // Priotize DEL over DUP as final tiebreaker
176
+ final Comparator <Genotype > genotypeDelOverDupComparator = new Comparator <Genotype >() {
177
+ @ Override
178
+ public int compare (Genotype o1 , Genotype o2 ) {
179
+ final int expectedCN1 = VariantContextGetters .getAttributeAsInt (o1 , GATKSVVCFConstants .EXPECTED_COPY_NUMBER_FORMAT , 0 );
180
+ final boolean isDel1 = VariantContextGetters .getAttributeAsInt (o1 , GATKSVVCFConstants .COPY_NUMBER_FORMAT , expectedCN1 ) < expectedCN1 ;
181
+ final int expectedCN2 = VariantContextGetters .getAttributeAsInt (o2 , GATKSVVCFConstants .EXPECTED_COPY_NUMBER_FORMAT , 0 );
182
+ final boolean isDel2 = VariantContextGetters .getAttributeAsInt (o2 , GATKSVVCFConstants .COPY_NUMBER_FORMAT , expectedCN2 ) < expectedCN2 ;
183
+ if (isDel1 && !isDel2 ) {
184
+ return 1 ;
185
+ } else if (isDel2 && !isDel1 ) {
186
+ return -1 ;
187
+ } else {
188
+ return 0 ;
189
+ }
166
190
}
167
191
};
168
192
@@ -461,7 +485,8 @@ protected Genotype getRepresentativeGenotype(final Collection<Genotype> genotype
461
485
.thenComparing (genotypeQualityComparator )
462
486
.thenComparing (genotypeNonRefCountComparator )
463
487
.thenComparing (genotypeCopyNumberQualityComparator )
464
- .thenComparing (genotypeCopyNumberComparator )).get ();
488
+ .thenComparing (genotypeCopyNumberComparator )
489
+ .thenComparing (genotypeDelOverDupComparator )).get ();
465
490
}
466
491
467
492
0 commit comments