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

import org.broadinstitute.sting.gatk.walkers.ReadWalker;
import org.broadinstitute.sting.gatk.walkers.WalkerName;
import org.broadinstitute.sting.utils.cmdLine.Argument;
import org.broadinstitute.sting.utils.GenomeLoc;
import net.sf.samtools.SAMRecord;
import net.sf.samtools.AlignmentBlock;

import java.util.List;

// A walker to determine intervals within which reads should be cleaned and realigned
// because they contain one or more indels (which possibly caused them not to align perfectly).
// Note that the reduce step assumes that reductions occur in order (i.e. no hierarchical reductions),
// although this can easily be changed if necessary.

@WalkerName("IndelIntervals")
public class IndelIntervalWalker extends ReadWalker<IndelIntervalWalker.Interval, IndelIntervalWalker.Interval> {
    @Argument(fullName="maxReadLength", shortName="maxRead", doc="max read length", required=false)
    public int maxReadLength = -1;
    @Argument(fullName="minIndelsPerInterval", shortName="minIndels", doc="min indels per interval", required=false)
    public int minIntervalIndelCount = 1;

    public void initialize() {}

    public boolean filter(char[] ref, SAMRecord read) {
        return ( !read.getReadUnmappedFlag() &&            // mapped
                 read.getReadLength() <= maxReadLength &&  // not too big
                 read.getAlignmentBlocks().size() > 1);    // indel
    }

    public Interval map(char[] ref, SAMRecord read) {
        List<AlignmentBlock> blocks = read.getAlignmentBlocks();
        long indelLeftEdge = read.getAlignmentStart() + blocks.get(0).getLength() - 1;
        long indelRightEdge = read.getAlignmentEnd() - blocks.get(blocks.size()-1).getLength() + 1;

        GenomeLoc indelLoc = new GenomeLoc(read.getReferenceIndex(), indelLeftEdge, indelRightEdge);
        GenomeLoc refLoc = new GenomeLoc(read);

        return new Interval(refLoc, indelLoc);
    }
<commit_msg>better filtering, plus deal with case where user doesn't input maxlength<commit_after>package org.broadinstitute.sting.playground.gatk.walkers.indels;

import org.broadinstitute.sting.gatk.walkers.ReadWalker;
import org.broadinstitute.sting.gatk.walkers.WalkerName;
import org.broadinstitute.sting.utils.cmdLine.Argument;
import org.broadinstitute.sting.utils.GenomeLoc;
import net.sf.samtools.SAMRecord;
import net.sf.samtools.AlignmentBlock;

import java.util.List;

// A walker to determine intervals within which reads should be cleaned and realigned
// because they contain one or more indels (which possibly caused them not to align perfectly).
// Note that the reduce step assumes that reductions occur in order (i.e. no hierarchical reductions),
// although this can easily be changed if necessary.

@WalkerName("IndelIntervals")
public class IndelIntervalWalker extends ReadWalker<IndelIntervalWalker.Interval, IndelIntervalWalker.Interval> {
    @Argument(fullName="maxReadLength", shortName="maxRead", doc="max read length", required=false)
    public int maxReadLength = -1;
    @Argument(fullName="minIndelsPerInterval", shortName="minIndels", doc="min indels per interval", required=false)
    public int minIntervalIndelCount = 1;

    public void initialize() {}

    public boolean filter(char[] ref, SAMRecord read) {
        return ( !read.getReadUnmappedFlag() &&            // mapped
                 (maxReadLength < 0 || read.getReadLength() <= maxReadLength) &&  // not too big
                 read.getMappingQuality() != 0 &&          // positive mapping quality
                 read.getAlignmentBlocks().size() > 1);    // indel
    }

    public Interval map(char[] ref, SAMRecord read) {
        List<AlignmentBlock> blocks = read.getAlignmentBlocks();
        long indelLeftEdge = read.getAlignmentStart() + blocks.get(0).getLength() - 1;
        long indelRightEdge = read.getAlignmentEnd() - blocks.get(blocks.size()-1).getLength() + 1;

        GenomeLoc indelLoc = new GenomeLoc(read.getReferenceIndex(), indelLeftEdge, indelRightEdge);
        GenomeLoc refLoc = new GenomeLoc(read);

        return new Interval(refLoc, indelLoc);
    }

{'fraction_non_alphanumeric': 0.10433117970806413, 'fraction_numerical': 0.00382866714525006, 'mean_word_length': 3.940898345153664, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 9, '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': '5048217', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1163, 'n_words': 313}