Bugfix for VCFWriter in the case where there are no genotypes in the VC but genotypes in the header
This commit is contained in:
parent
4846bf5c8e
commit
4bde24f020
|
|
@ -162,7 +162,7 @@ class BCF2Writer extends IndexingVariantContextWriter {
|
|||
// info fields
|
||||
final int nAlleles = vc.getNAlleles();
|
||||
final int nInfo = vc.getAttributes().size();
|
||||
final int nGenotypeFormatFields = VCFWriter.calcVCFGenotypeKeys(vc).size();
|
||||
final int nGenotypeFormatFields = VCFWriter.calcVCFGenotypeKeys(vc, header).size();
|
||||
final int nSamples = vc.getNSamples();
|
||||
|
||||
encoder.encodeRawInt((nAlleles << 16) | (nInfo & 0x00FF), BCF2Type.INT32);
|
||||
|
|
@ -207,7 +207,7 @@ class BCF2Writer extends IndexingVariantContextWriter {
|
|||
}
|
||||
|
||||
private byte[] buildSamplesData(final VariantContext vc) throws IOException {
|
||||
List<String> genotypeFields = VCFWriter.calcVCFGenotypeKeys(vc);
|
||||
List<String> genotypeFields = VCFWriter.calcVCFGenotypeKeys(vc, header);
|
||||
for ( final String field : genotypeFields ) {
|
||||
if ( field.equals(VCFConstants.GENOTYPE_KEY) ) {
|
||||
addGenotypes(vc);
|
||||
|
|
|
|||
|
|
@ -254,13 +254,10 @@ class VCFWriter extends IndexingVariantContextWriter {
|
|||
mWriter.write(VCFConstants.FIELD_SEPARATOR);
|
||||
mWriter.write(((LazyGenotypesContext)gc).getUnparsedGenotypeData().toString());
|
||||
} else {
|
||||
List<String> genotypeAttributeKeys = new ArrayList<String>();
|
||||
if ( vc.hasGenotypes() ) {
|
||||
genotypeAttributeKeys.addAll(calcVCFGenotypeKeys(vc));
|
||||
}
|
||||
List<String> genotypeAttributeKeys = calcVCFGenotypeKeys(vc, mHeader);
|
||||
if ( ! genotypeAttributeKeys.isEmpty() ) {
|
||||
final String genotypeFormatString = ParsingUtils.join(VCFConstants.GENOTYPE_FIELD_SEPARATOR, genotypeAttributeKeys);
|
||||
|
||||
if ( genotypeAttributeKeys.size() > 0 ) {
|
||||
String genotypeFormatString = ParsingUtils.join(VCFConstants.GENOTYPE_FIELD_SEPARATOR, genotypeAttributeKeys);
|
||||
mWriter.write(VCFConstants.FIELD_SEPARATOR);
|
||||
mWriter.write(genotypeFormatString);
|
||||
|
||||
|
|
@ -472,7 +469,7 @@ class VCFWriter extends IndexingVariantContextWriter {
|
|||
* @param vc
|
||||
* @return an ordered list of genotype fields in use in VC. If vc has genotypes this will always include GT first
|
||||
*/
|
||||
public static List<String> calcVCFGenotypeKeys(VariantContext vc) {
|
||||
public static List<String> calcVCFGenotypeKeys(final VariantContext vc, final VCFHeader header) {
|
||||
Set<String> keys = new HashSet<String>();
|
||||
|
||||
boolean sawGoodGT = false;
|
||||
|
|
@ -504,7 +501,7 @@ class VCFWriter extends IndexingVariantContextWriter {
|
|||
sortedList = newList;
|
||||
}
|
||||
|
||||
if ( sortedList.isEmpty() && vc.hasGenotypes() ) {
|
||||
if ( sortedList.isEmpty() && header.hasGenotypingData() ) {
|
||||
// this needs to be done in case all samples are no-calls
|
||||
return Collections.singletonList(VCFConstants.GENOTYPE_KEY);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue