2009-03-16 06:42:24 +08:00
|
|
|
package org.broadinstitute.sting.gatk.walkers;
|
|
|
|
|
|
2009-04-04 03:54:54 +08:00
|
|
|
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
|
2009-08-05 05:01:37 +08:00
|
|
|
import org.broadinstitute.sting.gatk.contexts.AlignmentContext;
|
|
|
|
|
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
|
2010-05-27 06:12:25 +08:00
|
|
|
import org.broadinstitute.sting.gatk.traversals.TraversalStatistics;
|
|
|
|
|
import org.broadinstitute.sting.gatk.filters.UnmappedReadFilter;
|
|
|
|
|
import org.broadinstitute.sting.gatk.filters.NotPrimaryAlignmentReadFilter;
|
|
|
|
|
import org.broadinstitute.sting.gatk.filters.DuplicateReadFilter;
|
|
|
|
|
import net.sf.picard.filter.SamRecordFilter;
|
|
|
|
|
import net.sf.samtools.SAMRecord;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Arrays;
|
2009-03-16 06:42:24 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Created by IntelliJ IDEA.
|
|
|
|
|
* User: mdepristo
|
|
|
|
|
* Date: Feb 22, 2009
|
|
|
|
|
* Time: 2:52:28 PM
|
|
|
|
|
* To change this template use File | Settings | File Templates.
|
|
|
|
|
*/
|
2009-05-16 05:02:12 +08:00
|
|
|
@By(DataSource.READS)
|
2009-06-19 05:03:57 +08:00
|
|
|
@Requires({DataSource.READS,DataSource.REFERENCE, DataSource.REFERENCE_BASES})
|
2009-03-27 23:40:45 +08:00
|
|
|
public abstract class LocusWalker<MapType, ReduceType> extends Walker<MapType, ReduceType> {
|
2009-03-16 06:42:24 +08:00
|
|
|
// Do we actually want to operate on the context?
|
2009-08-05 05:01:37 +08:00
|
|
|
public boolean filter(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
|
2009-03-27 00:22:35 +08:00
|
|
|
return true; // We are keeping all the reads
|
|
|
|
|
}
|
2009-03-16 06:42:24 +08:00
|
|
|
|
2009-08-05 05:01:37 +08:00
|
|
|
// Map over the org.broadinstitute.sting.gatk.contexts.AlignmentContext
|
|
|
|
|
public abstract MapType map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context);
|
2010-05-27 06:12:25 +08:00
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// mandatory read filters
|
|
|
|
|
//
|
|
|
|
|
// --------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
public List<SamRecordFilter> getMandatoryReadFilters() {
|
|
|
|
|
// if ( false ) {
|
|
|
|
|
// SamRecordFilter filter = new LocusStreamFilterFunc();
|
|
|
|
|
// return Arrays.asList(filter);
|
|
|
|
|
// } else {
|
|
|
|
|
SamRecordFilter filter1 = new UnmappedReadFilter();
|
|
|
|
|
SamRecordFilter filter2 = new NotPrimaryAlignmentReadFilter();
|
|
|
|
|
SamRecordFilter filter3 = new DuplicateReadFilter();
|
|
|
|
|
List<SamRecordFilter> x = super.getMandatoryReadFilters();
|
|
|
|
|
x.addAll(Arrays.asList(filter3, filter2, filter1));
|
|
|
|
|
// }
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class to filter out un-handle-able reads from the stream. We currently are skipping
|
|
|
|
|
* unmapped reads, non-primary reads, unaligned reads, and duplicate reads.
|
|
|
|
|
*/
|
|
|
|
|
private static class LocusStreamFilterFunc implements SamRecordFilter {
|
|
|
|
|
SAMRecord lastRead = null;
|
|
|
|
|
public boolean filterOut(SAMRecord rec) {
|
|
|
|
|
boolean result = false;
|
|
|
|
|
if (rec.getReadUnmappedFlag()) {
|
|
|
|
|
TraversalStatistics.nUnmappedReads++;
|
|
|
|
|
result = true;
|
|
|
|
|
//why = "Unmapped";
|
|
|
|
|
} else if (rec.getNotPrimaryAlignmentFlag()) {
|
|
|
|
|
TraversalStatistics.nNotPrimary++;
|
|
|
|
|
result = true;
|
|
|
|
|
// why = "Not Primary";
|
|
|
|
|
} else if (rec.getAlignmentStart() == SAMRecord.NO_ALIGNMENT_START) {
|
|
|
|
|
TraversalStatistics.nBadAlignments++;
|
|
|
|
|
result = true;
|
|
|
|
|
// why = "No alignment start";
|
|
|
|
|
} else if (rec.getDuplicateReadFlag()) {
|
|
|
|
|
TraversalStatistics.nDuplicates++;
|
|
|
|
|
result = true;
|
|
|
|
|
// why = "Duplicate reads";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
result = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
TraversalStatistics.nSkippedReads++;
|
|
|
|
|
//System.out.printf(" [filter] %s => %b %s", rec.getReadName(), result, why);
|
|
|
|
|
} else {
|
|
|
|
|
TraversalStatistics.nReads++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-16 06:42:24 +08:00
|
|
|
}
|