<commit_before>package org.broadinstitute.sting.playground.gatk.walkers.varianteval;


import org.broadinstitute.sting.utils.genotype.Genotype;
import org.broadinstitute.sting.utils.genotype.Variation;
import org.broadinstitute.sting.utils.Pair;
import org.broadinstitute.sting.utils.Utils;

import java.util.*;

/**
 * The Broad Institute
 * SOFTWARE COPYRIGHT NOTICE AGREEMENT
 * This software and its documentation are copyright 2009 by the
 * Broad Institute/Massachusetts Institute of Technology. All rights are reserved.
 * <p/>
 * This software is supplied without any warranty or guaranteed support whatsoever. Neither
 * the Broad Institute nor MIT can be responsible for its use, misuse, or functionality.
 */
public class ConcordanceTruthTable {
    public static final int TRUE_POSITIVE = 0;
    public static final int TRUE_NEGATIVE = 1;
    public static final int FALSE_POSITIVE = 2;
    public static final int FALSE_NEGATIVE = 3;
    public static final int VARIANT = 1;
    private static final String[] POOL_HEADERS = {"TP","TN","FP","FN"};

    public static final int REF = 0;
    public static final int VAR_HET = 1;
    public static final int VAR_HOM = 2;
    public static final int UNKNOWN = 3;
    public static final int NO_CALL = 3;   // synonym
    private static final String[] TRUTH_NAMES = {"IS_REF", "IS_VAR_HET", "IS_VAR_HOM", "UNKNOWN"};
    private static final String[] CALL_NAMES = {"CALLED_REF", "CALLED_VAR_HET", "CALLED_VAR_HOM", "NO_CALL"};

    private String name = null;
    private boolean singleSampleMode;

    private int[][] table;
    private int[] truth_totals;
    private int[] calls_totals;


    public ConcordanceTruthTable(String name) {
        // there's a specific sample associated with this truth table
        this.name = name;
        singleSampleMode = true;

        table = new int[4][4];
        truth_totals = new int[4];
        calls_totals = new int[4];
        for (int i = 0; i < 4; i++) {
            truth_totals[i] = 0;
            calls_totals[i] = 0;
            for (int j = 0; j < 4; j++)
                table[i][j] = 0;
        }
    }

    public ConcordanceTruthTable(int nSamples) {
        // there's no specific sample associated with this truth table
        singleSampleMode = false;
        name = "pooled_concordance";
        truth_totals = new int[4];
        calls_totals = new int[4];
        for (int i = 0; i < 4; i++) {
            truth_totals[i] = 0;
            calls_totals[i] = 0;
        }

        initializeFrequencyTable(nSamples);
    }

    private void initializeFrequencyTable( int numChips ) {
        // System.out.println("Frequency Table for Pooled Concordance initialized with number of chips = "+numChips);
        table = new int[numChips*2][4];
        for (int i = 0; i < 4; i++) {
            for ( int freq = 0; freq < 2*numChips; freq ++ ) {
                table[freq][i] = 0;
            }
        }

        // System.out.println("Table Size: "+table.length+" by "+table[1].length);
    }

    public String addEntry(List<Pair<Genotype, Genotype>> chipEvals, Variation eval, char ref) {
        String violation = null;

        // if the table represents a single sample, then we can calculate genotype stats
        if ( singleSampleMode ) {
            for ( Pair<Genotype, Genotype> chipEval : chipEvals ) {

                Genotype chipG = chipEval.first;
                Genotype evalG = chipEval.second;

                if (chipG == null && evalG == null)
                    continue;

                int truthType = getGenotype(chipG, ref);
                int callType = getGenotype(evalG, ref);

                //System.out.printf("TEST: %d/%d %s vs. %s%n", truthIndex, callIndex, chip, eval);
                addGenotypeEntry(truthType, callType);
            }<commit_msg>Better printing support for false positives and false negatives in concordance tables<commit_after>package org.broadinstitute.sting.playground.gatk.walkers.varianteval;


import org.broadinstitute.sting.utils.genotype.Genotype;
import org.broadinstitute.sting.utils.genotype.Variation;
import org.broadinstitute.sting.utils.Pair;
import org.broadinstitute.sting.utils.Utils;

import java.util.*;

/**
 * The Broad Institute
 * SOFTWARE COPYRIGHT NOTICE AGREEMENT
 * This software and its documentation are copyright 2009 by the
 * Broad Institute/Massachusetts Institute of Technology. All rights are reserved.
 * <p/>
 * This software is supplied without any warranty or guaranteed support whatsoever. Neither
 * the Broad Institute nor MIT can be responsible for its use, misuse, or functionality.
 */
public class ConcordanceTruthTable {
    public static final int TRUE_POSITIVE = 0;
    public static final int TRUE_NEGATIVE = 1;
    public static final int FALSE_POSITIVE = 2;
    public static final int FALSE_NEGATIVE = 3;
    public static final int VARIANT = 1;
    private static final String[] POOL_HEADERS = {"TP","TN","FP","FN"};

    public static final int REF = 0;
    public static final int VAR_HET = 1;
    public static final int VAR_HOM = 2;
    public static final int UNKNOWN = 3;
    public static final int NO_CALL = 3;   // synonym
    private static final String[] TRUTH_NAMES = {"IS_REF", "IS_VAR_HET", "IS_VAR_HOM", "UNKNOWN"};
    private static final String[] CALL_NAMES = {"CALLED_REF", "CALLED_VAR_HET", "CALLED_VAR_HOM", "NO_CALL"};

    private String name = null;
    private boolean singleSampleMode;

    private int[][] table;
    private int[] truth_totals;
    private int[] calls_totals;


    public ConcordanceTruthTable(String name) {
        // there's a specific sample associated with this truth table
        this.name = name;
        singleSampleMode = true;

        table = new int[4][4];
        truth_totals = new int[4];
        calls_totals = new int[4];
        for (int i = 0; i < 4; i++) {
            truth_totals[i] = 0;
            calls_totals[i] = 0;
            for (int j = 0; j < 4; j++)
                table[i][j] = 0;
        }
    }

    public ConcordanceTruthTable(int nSamples) {
        // there's no specific sample associated with this truth table
        singleSampleMode = false;
        name = "pooled_concordance";
        truth_totals = new int[4];
        calls_totals = new int[4];
        for (int i = 0; i < 4; i++) {
            truth_totals[i] = 0;
            calls_totals[i] = 0;
        }

        initializeFrequencyTable(nSamples);
    }

    private void initializeFrequencyTable( int numChips ) {
        // System.out.println("Frequency Table for Pooled Concordance initialized with number of chips = "+numChips);
        table = new int[numChips*2][4];
        for (int i = 0; i < 4; i++) {
            for ( int freq = 0; freq < 2*numChips; freq ++ ) {
                table[freq][i] = 0;
            }
        }

        // System.out.println("Table Size: "+table.length+" by "+table[1].length);
    }

    public String addEntry(List<Pair<Genotype, Genotype>> chipEvals, Variation eval, char ref) {
        String violation = null;

        // if the table represents a single sample, then we can calculate genotype stats
        if ( singleSampleMode ) {
            for ( Pair<Genotype, Genotype> chipEval : chipEvals ) {

                Genotype chipG = chipEval.first;
                Genotype evalG = chipEval.second;

                if (chipG == null && evalG == null)
                    continue;

                int truthType = getGenotype(chipG, ref);
                int callType = getGenotype(evalG, ref);

                //System.out.printf("TEST: %d/%d %s vs. %s%n", truthIndex, callIndex, chip, eval);
                if ( truthType == VARIANT && callType != VARIANT ) {
                    violation = String.format("False negative: ref=%c chip=%s call=%s", ref, chipG, evalG);
                } else if ( truthType == REF && callType == VARIANT ) {
                    violation = String.format("False positive: chip=%s call=%s", chipG, evalG);
                }

                addGenotypeEntry(truthType, callType);
            }
{'fraction_non_alphanumeric': 0.10294846382556987, 'fraction_numerical': 0.009663032705649157, 'mean_word_length': 2.45, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 11, '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': '6445237', 'n_tokens_mistral': 2480, 'n_tokens_neox': 2313, 'n_words': 740}