public void writeHeader(VCFHeader header) { mHeader = doNotWriteGenotypes ? new VCFHeader(header.getMetaData()) : header; try { // the file format field needs to be written first mWriter.write( VCFHeader.METADATA_INDICATOR + VCFHeaderVersion.VCF4_1.getFormatString() + "=" + VCFHeaderVersion.VCF4_1.getVersionString() + "\n"); for (VCFHeaderLine line : mHeader.getMetaData()) { if (VCFHeaderVersion.isFormatString(line.getKey())) continue; // are the records filtered (so we know what to put in the FILTER column of passing records) // ? if (line instanceof VCFFilterHeaderLine) filtersWereAppliedToContext = true; mWriter.write(VCFHeader.METADATA_INDICATOR); mWriter.write(line.toString()); mWriter.write("\n"); } // write out the column line mWriter.write(VCFHeader.HEADER_INDICATOR); for (VCFHeader.HEADER_FIELDS field : mHeader.getHeaderFields()) { mWriter.write(field.toString()); mWriter.write(VCFConstants.FIELD_SEPARATOR); } if (mHeader.hasGenotypingData()) { mWriter.write("FORMAT"); for (String sample : mHeader.getGenotypeSamples()) { mWriter.write(VCFConstants.FIELD_SEPARATOR); mWriter.write(sample); } } mWriter.write("\n"); mWriter.flush(); // necessary so that writing to an output stream will work } catch (IOException e) { throw new TribbleException("IOException writing the VCF header to " + locationString(), e); } }