<commit_before>/*
 * SNPLogging
 */
package net.maizegenetics.gbs.pipeline;

import java.io.BufferedWriter;
import java.io.File;
import net.maizegenetics.pal.alignment.Alignment;
import net.maizegenetics.util.Utils;

/**
 *
 * @author terry
 */
public class SNPLogging {

    private static final String HEADER = "Chr\tPosition\tAlleles\tTagLocusStart\tStrand\tPlugin\tTest\tStatus\tValue\tCuttoff\n";
    private static final String DELIMITER = "\t";
    private final BufferedWriter myWriter;

    public SNPLogging(String filename) {

        boolean exists = false;
        File file = new File(filename);
        if (file.exists()) {
            exists = true;
        }

        myWriter = Utils.getBufferedWriter(filename, true);
        if (!exists) {
            try {
                myWriter.append(HEADER);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    public void close() {
        try {
            myWriter.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public void writeEntry(Alignment a, int site, String tagLocusStart, String strand, Class plugin, String test, String status, String value, String cuttoff) {
        String alleles = a.getMajorAlleleAsString(site) + "/" + a.getMinorAlleleAsString(site);
        writeEntry(a.getLocusName(site), a.getPositionInLocus(site), alleles, tagLocusStart, strand, plugin, test, status, value, cuttoff);
    }

    public void writeEntry(String chr, int position, String alleles, String tagLocusStart, String strand, Class plugin, String test, String status, String value, String cuttoff) {
        try {
            myWriter.append(chr);
            myWriter.append(DELIMITER);
            myWriter.append(String.valueOf(position));
            myWriter.append(DELIMITER);
            myWriter.append(alleles);
            myWriter.append(DELIMITER);
            myWriter.append(tagLocusStart);
            myWriter.append(DELIMITER);
            myWriter.append(strand);
            myWriter.append(DELIMITER);
            myWriter.append(plugin.getSimpleName());
            myWriter.append(DELIMITER);
            myWriter.append(test);
            myWriter.append(DELIMITER);
            myWriter.append(status);
            myWriter.append(DELIMITER);
            myWriter.append(value);
            myWriter.append(DELIMITER);
            myWriter.append(cuttoff);
            myWriter.append("\n");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}<commit_msg>Updated to send log messages to console if no file defined.<commit_after>/*
 * SNPLogging
 */
package net.maizegenetics.gbs.pipeline;

import java.io.BufferedWriter;
import java.io.File;
import net.maizegenetics.pal.alignment.Alignment;
import net.maizegenetics.util.Utils;
import org.apache.log4j.Logger;

/**
 *
 * @author terry
 */
public class SNPLogging {

    private final Logger myLogger = Logger.getLogger(SNPLogging.class);
    private static final String HEADER = "Chr\tPosition\tAlleles\tTagLocusStart\tStrand\tPlugin\tTest\tStatus\tValue\tCuttoff\n";
    private static final String DELIMITER = "\t";
    private final BufferedWriter myWriter;

    public SNPLogging(String filename) {

        if ((filename == null) || (filename.length() == 0)) {
            myWriter = null;
        } else {
            boolean exists = false;
            File file = new File(filename);
            if (file.exists()) {
                exists = true;
            }

            myWriter = Utils.getBufferedWriter(filename, true);
            if (!exists) {
                try {
                    myWriter.append(HEADER);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

    }

    public void close() {
        try {
            myWriter.close();
        } catch (Exception e) {
            // do nothing;
        }
    }

    public void writeEntry(Alignment a, int site, String tagLocusStart, String strand, Class plugin, String test, String status, String value, String cuttoff) {
        String alleles = a.getMajorAlleleAsString(site) + "/" + a.getMinorAlleleAsString(site);
        writeEntry(a.getLocusName(site), a.getPositionInLocus(site), alleles, tagLocusStart, strand, plugin, test, status, value, cuttoff);
    }

    public void writeEntry(String chr, int position, String alleles, String tagLocusStart, String strand, Class plugin, String test, String status, String value, String cuttoff) {

        StringBuilder builder = new StringBuilder();
        builder.append(chr);
        builder.append(DELIMITER);
        builder.append(String.valueOf(position));
        builder.append(DELIMITER);
        builder.append(alleles);
        builder.append(DELIMITER);
        builder.append(tagLocusStart);
        builder.append(DELIMITER);
        builder.append(strand);
        builder.append(DELIMITER);
        builder.append(plugin.getSimpleName());
        builder.append(DELIMITER);
        builder.append(test);
        builder.append(DELIMITER);
        builder.append(status);
        builder.append(DELIMITER);
        builder.append(value);
        builder.append(DELIMITER);
        builder.append(cuttoff);
        builder.append("\n");

        if (myWriter == null) {
            myLogger.info(builder.toString());
        } else {
            try {
                myWriter.append(builder.toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }
}
{'fraction_non_alphanumeric': 0.10824834496332081, 'fraction_numerical': 0.0003578457684737878, 'mean_word_length': 2.2200460829493087, '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': '7481363', 'n_tokens_mistral': 1601, 'n_tokens_neox': 1553, 'n_words': 332}