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

import org.broadinstitute.sting.gatk.LocusContext;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.refdata.rodSAMPileup;
import org.broadinstitute.sting.utils.cmdLine.Argument;
import org.broadinstitute.sting.utils.Utils;
import org.broadinstitute.sting.utils.BasicPileup;
import org.broadinstitute.sting.utils.ReadBackedPileup;

/**
 * Created by IntelliJ IDEA.
 * User: mdepristo
 * Date: Feb 22, 2009
 * Time: 3:22:14 PM
 * To change this template use File | Settings | File Templates.
 */
public class ValidatingPileupWalker extends LocusWalker<Integer, ValidationStats> {
    @Argument(fullName="verbose",required=false,defaultValue="false")
    public boolean VERBOSE;

    public Integer map(RefMetaDataTracker tracker, char ref, LocusContext context) {
        ReadBackedPileup pileup = new ReadBackedPileup(ref, context);

        rodSAMPileup truePileup = (rodSAMPileup)tracker.lookup("pileup", null);
        if ( truePileup == null )
            Utils.scareUser(String.format("No pileup data available at %s given GATK's output of %s -- this walker requires samtools pileup data over all bases",
                    context.getLocation(), pileup.getBases()));

        String pileupDiff = BasicPileup.pileupDiff(pileup, truePileup);
        if ( pileupDiff != null ) {
            out.printf("%s vs. %s%n", pileup.getPileupString(), truePileup.getPileupString());
            throw new RuntimeException(String.format("Pileups aren't equal: %s", pileupDiff));
        }

        return pileup.size();
    }

    // Given result of map function
    public ValidationStats reduceInit() { return new ValidationStats(); }
    public ValidationStats reduce(Integer value, ValidationStats sum) {
        sum.nLoci++;
        sum.nBases += value;
        return sum;
    }
}

class ValidationStats {
    public long nLoci = 0;
    public long nBases = 0;

    public ValidationStats() {
    }

    public String toString() {
        return String.format("Validated %d sites covered by %d bases%n", nLoci, nBases);
    }
}<commit_msg>Support for -continue_after_errors flag in the validating pileup walker in case you want to see errors as they arise, rather than aborting greedily<commit_after>package org.broadinstitute.sting.gatk.walkers;

import org.broadinstitute.sting.gatk.LocusContext;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.refdata.rodSAMPileup;
import org.broadinstitute.sting.utils.cmdLine.Argument;
import org.broadinstitute.sting.utils.Utils;
import org.broadinstitute.sting.utils.Pileup;
import org.broadinstitute.sting.utils.BasicPileup;
import org.broadinstitute.sting.utils.ReadBackedPileup;

/**
 * Created by IntelliJ IDEA.
 * User: mdepristo
 * Date: Feb 22, 2009
 * Time: 3:22:14 PM
 * To change this template use File | Settings | File Templates.
 */
public class ValidatingPileupWalker extends LocusWalker<Integer, ValidationStats> {
    @Argument(fullName="continue_after_error",required=false,defaultValue="false")
    public boolean CONTINUE_AFTER_AN_ERROR;

    public Integer map(RefMetaDataTracker tracker, char ref, LocusContext context) {
        Pileup pileup = new ReadBackedPileup(ref, context);
        Pileup truePileup = (Pileup)tracker.lookup("pileup", null);
        
        if ( truePileup == null ) {
            System.out.printf("No truth pileup data available at %s%n", pileup.getPileupString());
            if ( ! CONTINUE_AFTER_AN_ERROR ) {
                Utils.scareUser(String.format("No pileup data available at %s given GATK's output of %s -- this walker requires samtools pileup data over all bases",
                                context.getLocation(), pileup.getBases()));
            }
        } else {
            String pileupDiff = BasicPileup.pileupDiff(pileup, truePileup);
            if ( pileupDiff != null ) {
                out.printf("%s vs. %s%n", pileup.getPileupString(), truePileup.getPileupString());
                if ( ! CONTINUE_AFTER_AN_ERROR ) {
                    throw new RuntimeException(String.format("Pileups aren't equal: %s", pileupDiff));
                }
            }
        }

        return pileup.size();
    }

    // Given result of map function
    public ValidationStats reduceInit() { return new ValidationStats(); }
    public ValidationStats reduce(Integer value, ValidationStats sum) {
        sum.nLoci++;
        sum.nBases += value;
        return sum;
    }
}

class ValidationStats {
    public long nLoci = 0;
    public long nBases = 0;

    public ValidationStats() {
    }

    public String toString() {
        return String.format("Validated %d sites covered by %d bases%n", nLoci, nBases);
    }
}
{'fraction_non_alphanumeric': 0.10083333333333333, 'fraction_numerical': 0.005416666666666667, 'mean_word_length': 3.244916003536693, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7592024', 'n_tokens_mistral': 1520, 'n_tokens_neox': 1450, 'n_words': 353}