<commit_before>package org.broadinstitute.hellbender.tools.spark.pipelines;

import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.broadinstitute.barclay.argparser.Argument;
import org.broadinstitute.barclay.argparser.BetaFeature;
import org.broadinstitute.barclay.argparser.CommandLineProgramProperties;
import org.broadinstitute.barclay.help.DocumentedFeature;
import org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions;
import org.broadinstitute.hellbender.cmdline.programgroups.CoverageAnalysisProgramGroup;
import org.broadinstitute.hellbender.engine.spark.GATKSparkTool;
import org.broadinstitute.hellbender.utils.gcs.BucketUtils;
import org.broadinstitute.hellbender.utils.read.GATKRead;

import java.io.PrintStream;

/**
 * Calculate the overall number of reads in a SAM/BAM file
 *
 * <h3>Input</h3>
 * <ul>
 *     <li>A single BAM file</li>
 * </ul>
 *
 * <h3>Output</h3>
 * <ul>
 *     <li>A text file containing number of reads</li>
 * </ul>
 *
 * <h3>Example</h3>
 *
 * <h4>Output number of reads to file</h4>
 * <pre>
 *   gatk CountReadsSpark \
 *     -I input_reads.bam \
 *     -O read_count.txt
 * </pre>
 *
 * <h4>Print read count</h4>
 * <pre>
 *   gatk CountReadsSpark \
 *     -I input_reads.bam
 * </pre>
 */
@DocumentedFeature
@BetaFeature
@CommandLineProgramProperties(
        summary = "Counts reads in the input SAM/BAM",
        oneLineSummary = "Counts reads in the input SAM/BAM",
        programGroup = CoverageAnalysisProgramGroup.class
)
public final class CountReadsSpark extends GATKSparkTool {

    private static final long serialVersionUID = 1L;

    @Override
    public boolean requiresReads() { return true; }

    @Argument(
            doc = "uri for the output file: a local file path",
            shortName = StandardArgumentDefinitions.OUTPUT_SHORT_NAME,
            fullName = StandardArgumentDefinitions.OUTPUT_LONG_NAME,
            optional = true
    )
    public String out;

    @Override
    protected void runTool(final JavaSparkContext ctx) {
        final JavaRDD<GATKRead> reads = getReads();

        final long count = reads.count();
        System.out.println(count);

        if(out != null) {
            try (final PrintStream ps = new PrintStream(BucketUtils.createFile(out))) {
                ps.print(count);
            }
        }
    }
}
<commit_msg>Removing WellformedReadFilter from CountReadsSpark (#5329)<commit_after>package org.broadinstitute.hellbender.tools.spark.pipelines;

import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.broadinstitute.barclay.argparser.Argument;
import org.broadinstitute.barclay.argparser.BetaFeature;
import org.broadinstitute.barclay.argparser.CommandLineProgramProperties;
import org.broadinstitute.barclay.help.DocumentedFeature;
import org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions;
import org.broadinstitute.hellbender.cmdline.programgroups.CoverageAnalysisProgramGroup;
import org.broadinstitute.hellbender.engine.filters.ReadFilter;
import org.broadinstitute.hellbender.engine.filters.ReadFilterLibrary;
import org.broadinstitute.hellbender.engine.spark.GATKSparkTool;
import org.broadinstitute.hellbender.utils.gcs.BucketUtils;
import org.broadinstitute.hellbender.utils.read.GATKRead;

import java.io.PrintStream;
import java.util.Collections;
import java.util.List;

/**
 * Calculate the overall number of reads in a SAM/BAM file
 *
 * <h3>Input</h3>
 * <ul>
 *     <li>A single BAM file</li>
 * </ul>
 *
 * <h3>Output</h3>
 * <ul>
 *     <li>A text file containing number of reads</li>
 * </ul>
 *
 * <h3>Example</h3>
 *
 * <h4>Output number of reads to file</h4>
 * <pre>
 *   gatk CountReadsSpark \
 *     -I input_reads.bam \
 *     -O read_count.txt
 * </pre>
 *
 * <h4>Print read count</h4>
 * <pre>
 *   gatk CountReadsSpark \
 *     -I input_reads.bam
 * </pre>
 */
@DocumentedFeature
@BetaFeature
@CommandLineProgramProperties(
        summary = "Counts reads in the input SAM/BAM",
        oneLineSummary = "Counts reads in the input SAM/BAM",
        programGroup = CoverageAnalysisProgramGroup.class
)
public final class CountReadsSpark extends GATKSparkTool {

    private static final long serialVersionUID = 1L;

    @Override
    public boolean requiresReads() { return true; }

    @Argument(
            doc = "uri for the output file: a local file path",
            shortName = StandardArgumentDefinitions.OUTPUT_SHORT_NAME,
            fullName = StandardArgumentDefinitions.OUTPUT_LONG_NAME,
            optional = true
    )
    public String out;

    @Override
    public List<ReadFilter> getDefaultReadFilters() {
        return Collections.singletonList(ReadFilterLibrary.ALLOW_ALL_READS);
    }

    @Override
    protected void runTool(final JavaSparkContext ctx) {
        final JavaRDD<GATKRead> reads = getReads();

        final long count = reads.count();
        System.out.println(count);

        if(out != null) {
            try (final PrintStream ps = new PrintStream(BucketUtils.createFile(out))) {
                ps.print(count);
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.1044776119402985, 'fraction_numerical': 0.005039736383019965, 'mean_word_length': 3.4482758620689653, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 50, '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': '3960887', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1616, 'n_words': 334}