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

import org.broad.tribble.util.variantcontext.Genotype;
import org.broad.tribble.util.variantcontext.VariantContext;
import org.broadinstitute.sting.gatk.contexts.AlignmentContext;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.walkers.varianteval.tags.Analysis;
import org.broadinstitute.sting.gatk.walkers.varianteval.tags.DataPoint;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;

@Analysis(description = "Counts different classes of variants in the sample")
public class CountVariants extends VariantEvaluator implements StandardEval {

    // the following fields are in output order:

    // basic counts on various rates found
    @DataPoint(description = "Number of processed loci")
    public long nProcessedLoci = 0;
    @DataPoint(description = "Number of called loci")
    public long nCalledLoci = 0;
    @DataPoint(description = "Number of reference loci")
    public long nRefLoci = 0;
    @DataPoint(description = "Number of variant loci")
    public long nVariantLoci = 0;

    // the following two calculations get set in the finalizeEvaluation
    @DataPoint(description = "Variants per loci rate")
    public double variantRate = 0;
    @DataPoint(description = "Number of variants per base")
    public double variantRatePerBp = 0;


    @DataPoint(description = "Number of snp loci")
    public long nSNPs = 0;
    @DataPoint(description = "Number of insertions")
    public long nInsertions = 0;
    @DataPoint(description = "Number of deletions")
    public long nDeletions = 0;
    @DataPoint(description = "Number of complex loci")
    public long nComplex = 0;

    @DataPoint(description = "Number of no calls loci")
    public long nNoCalls = 0;
    @DataPoint(description = "Number of het loci")
    public long nHets = 0;
    @DataPoint(description = "Number of hom ref loci")
    public long nHomRef = 0;
    @DataPoint(description = "Number of hom var loci")
    public long nHomVar = 0;
    @DataPoint(description = "Number of singletons")
    public long nSingletons = 0;

    // calculations that get set in the finalizeEvaluation method
    @DataPoint(description = "heterozygosity per locus rate")
    public double heterozygosity = 0;
    @DataPoint(description = "heterozygosity per base pair")
    public double heterozygosityPerBp = 0;
    @DataPoint(description = "heterozygosity to homozygosity ratio")
    public double hetHomRatio = 0;
    @DataPoint(description = "indel rate (insertion count + deletion count)")
    public double indelRate = 0;
    @DataPoint(description = "indel rate per base pair")
    public double indelRatePerBp = 0;
    @DataPoint(description = "deletion to insertion ratio")
    public double deletionInsertionRatio = 0;
    
    private double perLocusRate(long n) {
        return rate(n, nProcessedLoci);
    }

    private long perLocusRInverseRate(long n) {
        return inverseRate(n, nProcessedLoci);
    }

    public boolean enabled() {
        return true;
    }

    public int getComparisonOrder() {
        return 1;   // we only need to see each eval track
    }

    public void update0(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
        nProcessedLoci += context.getSkippedBases() + (ref == null ? 0 : 1);
    }

    public String update1(VariantContext vc1, RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
        nCalledLoci++;

        if (vc1.isVariant()) nVariantLoci++;
        switch (vc1.getType()) {
            case NO_VARIATION:
                nRefLoci++;
                break;
            case SNP:
                nSNPs++;
                if (vc1.getAttributeAsBoolean("ISSINGLETON")) nSingletons++;
                break;
            case INDEL:
                if (vc1.isInsertion()) nInsertions++;
                else nDeletions++;
                break;
            case MIXED:
                nComplex++;
                break;
            default:
                throw new ReviewedStingException("Unexpected VariantContext type " + vc1.getType());
        }

        for (Genotype g : vc1.getGenotypes().values()) {
            switch (g.getType()) {
                case NO_CALL:
                    nNoCalls++;
                    break;
                case HOM_REF:
                    nHomRef++;
                    break;
                case HET:
                    nHets++;
                    break;
                case HOM_VAR:
                    nHomVar++;
                    break;
                default:<commit_msg>Added MNP to recognized and counted event types<commit_after>package org.broadinstitute.sting.gatk.walkers.varianteval.evaluators;

import org.broad.tribble.util.variantcontext.Genotype;
import org.broad.tribble.util.variantcontext.VariantContext;
import org.broadinstitute.sting.gatk.contexts.AlignmentContext;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.walkers.varianteval.tags.Analysis;
import org.broadinstitute.sting.gatk.walkers.varianteval.tags.DataPoint;
import org.broadinstitute.sting.utils.exceptions.ReviewedStingException;

@Analysis(description = "Counts different classes of variants in the sample")
public class CountVariants extends VariantEvaluator implements StandardEval {

    // the following fields are in output order:

    // basic counts on various rates found
    @DataPoint(description = "Number of processed loci")
    public long nProcessedLoci = 0;
    @DataPoint(description = "Number of called loci")
    public long nCalledLoci = 0;
    @DataPoint(description = "Number of reference loci")
    public long nRefLoci = 0;
    @DataPoint(description = "Number of variant loci")
    public long nVariantLoci = 0;

    // the following two calculations get set in the finalizeEvaluation
    @DataPoint(description = "Variants per loci rate")
    public double variantRate = 0;
    @DataPoint(description = "Number of variants per base")
    public double variantRatePerBp = 0;


    @DataPoint(description = "Number of snp loci")
    public long nSNPs = 0;
    @DataPoint(description = "Number of mnp loci")
    public long nMNPs = 0;
    @DataPoint(description = "Number of insertions")
    public long nInsertions = 0;
    @DataPoint(description = "Number of deletions")
    public long nDeletions = 0;
    @DataPoint(description = "Number of complex loci")
    public long nComplex = 0;


    @DataPoint(description = "Number of no calls loci")
    public long nNoCalls = 0;
    @DataPoint(description = "Number of het loci")
    public long nHets = 0;
    @DataPoint(description = "Number of hom ref loci")
    public long nHomRef = 0;
    @DataPoint(description = "Number of hom var loci")
    public long nHomVar = 0;
    @DataPoint(description = "Number of singletons")
    public long nSingletons = 0;

    // calculations that get set in the finalizeEvaluation method
    @DataPoint(description = "heterozygosity per locus rate")
    public double heterozygosity = 0;
    @DataPoint(description = "heterozygosity per base pair")
    public double heterozygosityPerBp = 0;
    @DataPoint(description = "heterozygosity to homozygosity ratio")
    public double hetHomRatio = 0;
    @DataPoint(description = "indel rate (insertion count + deletion count)")
    public double indelRate = 0;
    @DataPoint(description = "indel rate per base pair")
    public double indelRatePerBp = 0;
    @DataPoint(description = "deletion to insertion ratio")
    public double deletionInsertionRatio = 0;
    
    private double perLocusRate(long n) {
        return rate(n, nProcessedLoci);
    }

    private long perLocusRInverseRate(long n) {
        return inverseRate(n, nProcessedLoci);
    }

    public boolean enabled() {
        return true;
    }

    public int getComparisonOrder() {
        return 1;   // we only need to see each eval track
    }

    public void update0(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
        nProcessedLoci += context.getSkippedBases() + (ref == null ? 0 : 1);
    }

    public String update1(VariantContext vc1, RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
        nCalledLoci++;

        if (vc1.isVariant()) nVariantLoci++;
        switch (vc1.getType()) {
            case NO_VARIATION:
                nRefLoci++;
                break;
            case SNP:
                nSNPs++;
                if (vc1.getAttributeAsBoolean("ISSINGLETON")) nSingletons++;
                break;
            case MNP:
                nMNPs++;
                if (vc1.getAttributeAsBoolean("ISSINGLETON")) nSingletons++;
                break;
            case INDEL:
                if (vc1.isInsertion()) nInsertions++;
                else nDeletions++;
                break;
            case MIXED:
                nComplex++;
                break;
            default:
                throw new ReviewedStingException("Unexpected VariantContext type " + vc1.getType());
        }

        for (Genotype g : vc1.getGenotypes().values()) {
            switch (g.getType()) {
                case NO_CALL:
                    nNoCalls++;
                    break;
                case HOM_REF:
                    nHomRef++;
                    break;
                case HET:
                    nHets++;
                    break;
                case HOM_VAR:
                    nHomVar++;
                    break;
                default:
{'fraction_non_alphanumeric': 0.08547096244613174, 'fraction_numerical': 0.00697722142417402, 'mean_word_length': 2.5315217391304348, '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': '3441029', 'n_tokens_mistral': 2860, 'n_tokens_neox': 2645, 'n_words': 766}