<commit_before>package org.broadinstitute.sting.utils.genotype.vcf;


import java.io.*;

/**
 * this class writers VCF files
 */
public class VCFWriter {

    public static final String VERSION = "VCRv3.2";

    // the VCF header we're storing
    private VCFHeader mHeader;

    // the print stream we're writting to
    BufferedWriter mWriter;
    private final String FIELD_SEPERATOR = "\t";

    /**
     * create a VCF writer, given a VCF header and a file to write to
     *
     * @param header   the VCF header
     * @param location the file location to write to
     */
    public VCFWriter(VCFHeader header, File location) {
        FileOutputStream output;
        try {
            output = new FileOutputStream(location);
        } catch (FileNotFoundException e) {
            throw new RuntimeException("Unable to create VCF file at location: " + location);
        }
        initialize(header, output);
    }


    /**
     * create a VCF writer, given a VCF header and a file to write to
     *
     * @param header   the VCF header
     * @param location the file location to write to
     */
    public VCFWriter(VCFHeader header, OutputStream location) {
        initialize(header, location);
    }

    private void initialize(VCFHeader header, OutputStream location) {
        this.mHeader = header;
        mWriter = new BufferedWriter(
                new OutputStreamWriter(location));
        try {
            // write the header meta-data out
            for (String metadata : header.getMetaData().keySet()) {
                mWriter.write(VCFHeader.METADATA_INDICATOR + metadata + "=" + header.getMetaData().get(metadata) + "\n");
            }
            // write out the column line
            StringBuilder b = new StringBuilder();
            b.append(VCFHeader.HEADER_INDICATOR);
            for (VCFHeader.HEADER_FIELDS field : header.getHeaderFields()) b.append(field + FIELD_SEPERATOR);
            if (header.hasGenotypingData()) {
                b.append("FORMAT" + FIELD_SEPERATOR);
                for (String field : header.getGenotypeSamples()) b.append(field + FIELD_SEPERATOR);
                mWriter.write(b.toString() + "\n");
            }
        }
        catch (IOException e) {
            throw new RuntimeException("IOException writing the VCF header", e);
        }
    }

    /**
     * output a record to the VCF file
     *
     * @param record the record to output
     */
    public void addRecord(VCFRecord record) {
        String vcfString = record.toStringEncoding(mHeader);
        try {
            mWriter.write(vcfString + "\n");<commit_msg>Always print out VCF header - not just when there is genotype data present.<commit_after>package org.broadinstitute.sting.utils.genotype.vcf;


import java.io.*;

/**
 * this class writers VCF files
 */
public class VCFWriter {

    public static final String VERSION = "VCRv3.2";

    // the VCF header we're storing
    private VCFHeader mHeader;

    // the print stream we're writting to
    BufferedWriter mWriter;
    private final String FIELD_SEPERATOR = "\t";

    /**
     * create a VCF writer, given a VCF header and a file to write to
     *
     * @param header   the VCF header
     * @param location the file location to write to
     */
    public VCFWriter(VCFHeader header, File location) {
        FileOutputStream output;
        try {
            output = new FileOutputStream(location);
        } catch (FileNotFoundException e) {
            throw new RuntimeException("Unable to create VCF file at location: " + location);
        }
        initialize(header, output);
    }


    /**
     * create a VCF writer, given a VCF header and a file to write to
     *
     * @param header   the VCF header
     * @param location the file location to write to
     */
    public VCFWriter(VCFHeader header, OutputStream location) {
        initialize(header, location);
    }

    private void initialize(VCFHeader header, OutputStream location) {
        this.mHeader = header;
        mWriter = new BufferedWriter(
                new OutputStreamWriter(location));
        try {
            // write the header meta-data out
            for (String metadata : header.getMetaData().keySet()) {
                mWriter.write(VCFHeader.METADATA_INDICATOR + metadata + "=" + header.getMetaData().get(metadata) + "\n");
            }
            // write out the column line
            StringBuilder b = new StringBuilder();
            b.append(VCFHeader.HEADER_INDICATOR);
            for (VCFHeader.HEADER_FIELDS field : header.getHeaderFields()) b.append(field + FIELD_SEPERATOR);
            if (header.hasGenotypingData()) {
                b.append("FORMAT" + FIELD_SEPERATOR);
                for (String field : header.getGenotypeSamples()) b.append(field + FIELD_SEPERATOR);
            }
            mWriter.write(b.toString() + "\n");
        }
        catch (IOException e) {
            throw new RuntimeException("IOException writing the VCF header", e);
        }
    }

    /**
     * output a record to the VCF file
     *
     * @param record the record to output
     */
    public void addRecord(VCFRecord record) {
        String vcfString = record.toStringEncoding(mHeader);
        try {
            mWriter.write(vcfString + "\n");
{'fraction_non_alphanumeric': 0.09266263237518911, 'fraction_numerical': 0.0007564296520423601, 'mean_word_length': 2.167065868263473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4154279', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1418, 'n_words': 441}