Collapse the walker hierarchy, in preparation for in-walker output streams less hokey walker args.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@201 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
hanna 2009-03-26 16:22:35 +00:00
parent 7cad3acc61
commit 5f9010116a
20 changed files with 51 additions and 130 deletions

View File

@ -1,45 +0,0 @@
package org.broadinstitute.sting.gatk.walkers;
import org.broadinstitute.sting.gatk.walkers.LocusWalker;
import org.broadinstitute.sting.gatk.LocusContext;
import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedDatum;
import java.util.List;
/**
* 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 abstract class BasicLociWalker<MapType, ReduceType> implements LocusWalker<MapType, ReduceType> {
public String getName() {
// Return name of class, trimming 'Walker' from the end if present.
// TODO: Duplicate of BasicReadWalker.getName(). Eliminate duplication.
String className = getClass().getSimpleName();
if(className.endsWith(Walker.class.getSimpleName()))
return className.substring(0,className.lastIndexOf(Walker.class.getSimpleName()));
else
return className;
}
public void initialize() {
;
}
// Do we actually want to operate on the context?
public boolean filter(List<ReferenceOrderedDatum> rodData, char ref, LocusContext context) {
return true; // We are keeping all the reads
}
public void onTraversalDone() {
;
}
// These three capabilities must be overidden
public abstract MapType map(List<ReferenceOrderedDatum> rodData, char ref, LocusContext context);
public abstract ReduceType reduceInit();
public abstract ReduceType reduce(MapType value, ReduceType sum);
}

View File

@ -1,41 +0,0 @@
package org.broadinstitute.sting.gatk.walkers;
import net.sf.samtools.SAMRecord;
import org.broadinstitute.sting.gatk.LocusContext;
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
/**
* Created by IntelliJ IDEA.
* User: mdepristo
* Date: Feb 22, 2009
* Time: 2:52:28 PM
* To change this template use File | Settings | File Templates.
*/
public abstract class BasicReadWalker<MapType, ReduceType> implements ReadWalker<MapType, ReduceType> {
public String getName() {
// Return name of class, trimming 'Walker' from the end if present.
// TODO: Duplicate of BasicLociWalker.getName(). Eliminate duplication.
String className = getClass().getSimpleName();
if(className.endsWith(Walker.class.getSimpleName()))
return className.substring(0,className.lastIndexOf(Walker.class.getSimpleName()));
else
return className;
}
public void initialize() { }
public boolean requiresOrderedReads() { return false; }
public boolean filter(LocusContext context, SAMRecord read) {
// We are keeping all the reads
return true;
}
public void onTraversalDone() {
;
}
// Three basic abstract function that *must* be overridden
public abstract MapType map(LocusContext context, SAMRecord read);
public abstract ReduceType reduceInit();
public abstract ReduceType reduce(MapType value, ReduceType sum);
}

View File

@ -12,7 +12,7 @@ import java.util.List;
* Time: 3:22:14 PM
* To change this template use File | Settings | File Templates.
*/
public class CountLociWalker extends BasicLociWalker<Integer, Integer> {
public class CountLociWalker extends LocusWalker<Integer, Integer> {
public Integer map(List<ReferenceOrderedDatum> rodData, char ref, LocusContext context) {
return 1;
}

View File

@ -3,7 +3,7 @@ package org.broadinstitute.sting.gatk.walkers;
import net.sf.samtools.SAMRecord;
import org.broadinstitute.sting.gatk.LocusContext;
public class CountReadsWalker extends BasicReadWalker<Integer, Integer> {
public class CountReadsWalker extends ReadWalker<Integer, Integer> {
public Integer map(LocusContext context, SAMRecord read) {
return 1;
}

View File

@ -12,7 +12,7 @@ import java.util.List;
* Time: 3:22:14 PM
* To change this template use File | Settings | File Templates.
*/
public class DepthOfCoverageWalker extends BasicLociWalker<Integer, Integer> {
public class DepthOfCoverageWalker extends LocusWalker<Integer, Integer> {
public Integer map(List<ReferenceOrderedDatum> rodData, char ref, LocusContext context) {
System.out.printf("%s: %d%n", context.getLocation(), context.getReads().size() );
return 1;

View File

@ -12,14 +12,16 @@ import java.util.List;
* Time: 2:52:28 PM
* To change this template use File | Settings | File Templates.
*/
public interface LocusWalker<MapType, ReduceType> extends Walker {
public abstract class LocusWalker<MapType, ReduceType> extends Walker {
// Do we actually want to operate on the context?
boolean filter(List<ReferenceOrderedDatum> rodData, char ref, LocusContext context);
public boolean filter(List<ReferenceOrderedDatum> rodData, char ref, LocusContext context) {
return true; // We are keeping all the reads
}
// Map over the org.broadinstitute.sting.gatk.LocusContext
MapType map(List<ReferenceOrderedDatum> rodData, char ref, LocusContext context);
public abstract MapType map(List<ReferenceOrderedDatum> rodData, char ref, LocusContext context);
// Given result of map function
ReduceType reduceInit();
ReduceType reduce(MapType value, ReduceType sum);
public abstract ReduceType reduceInit();
public abstract ReduceType reduce(MapType value, ReduceType sum);
}

View File

@ -9,11 +9,7 @@ import java.util.List;
// Null traversal. For ATK performance measuring.
// j.maguire 3-7-2009
public class NullWalker implements LocusWalker<Integer, Integer> {
public String getName() {
return "Null";
}
public class NullWalker extends LocusWalker<Integer, Integer> {
public void initialize() {
}

View File

@ -14,7 +14,7 @@ import java.util.List;
* Time: 3:22:14 PM
* To change this template use File | Settings | File Templates.
*/
public class PileupWalker extends BasicLociWalker<Integer, Integer> {
public class PileupWalker extends LocusWalker<Integer, Integer> {
public void initialize() {
}

View File

@ -3,7 +3,7 @@ package org.broadinstitute.sting.gatk.walkers;
import net.sf.samtools.SAMRecord;
import org.broadinstitute.sting.gatk.LocusContext;
public class PrintReadsWalker extends BasicReadWalker<Integer, Integer> {
public class PrintReadsWalker extends ReadWalker<Integer, Integer> {
public Integer map(LocusContext context, SAMRecord read) {
System.out.println(read.format());
return 1;

View File

@ -10,16 +10,19 @@ import org.broadinstitute.sting.gatk.LocusContext;
* Time: 2:52:28 PM
* To change this template use File | Settings | File Templates.
*/
public interface ReadWalker<MapType, ReduceType> extends Walker {
boolean requiresOrderedReads();
public abstract class ReadWalker<MapType, ReduceType> extends Walker {
public boolean requiresOrderedReads() { return false; }
// Do we actually want to operate on the context?
boolean filter(LocusContext context, SAMRecord read);
public boolean filter(LocusContext context, SAMRecord read) {
// We are keeping all the reads
return true;
}
// Map over the org.broadinstitute.sting.gatk.LocusContext
MapType map(LocusContext context, SAMRecord read);
public abstract MapType map(LocusContext context, SAMRecord read);
// Given result of map function
ReduceType reduceInit();
ReduceType reduce(MapType value, ReduceType sum);
public abstract ReduceType reduceInit();
public abstract ReduceType reduce(MapType value, ReduceType sum);
}

View File

@ -7,9 +7,17 @@ package org.broadinstitute.sting.gatk.walkers;
* Time: 1:53:31 PM
* To change this template use File | Settings | File Templates.
*/
public interface Walker {
public abstract class Walker {
// TODO: Can a walker be templatized so that map and reduce live here?
String getName();
void initialize();
void onTraversalDone();
public String getName() {
// Return name of class, trimming 'Walker' from the end if present.
String className = getClass().getSimpleName();
if(className.endsWith(Walker.class.getSimpleName()))
return className.substring(0,className.lastIndexOf(Walker.class.getSimpleName()));
else
return className;
}
public void initialize() { }
public void onTraversalDone() { }
}

View File

@ -1,7 +1,7 @@
package org.broadinstitute.sting.playground.gatk.walkers;
import net.sf.samtools.SAMRecord;
import org.broadinstitute.sting.gatk.walkers.BasicReadWalker;
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
import org.broadinstitute.sting.gatk.LocusContext;
/**
@ -11,7 +11,7 @@ import org.broadinstitute.sting.gatk.LocusContext;
* Time: 3:22:14 PM
* To change this template use File | Settings | File Templates.
*/
public class AlignedReadsHistoWalker extends BasicReadWalker<Integer, Integer> {
public class AlignedReadsHistoWalker extends ReadWalker<Integer, Integer> {
long[] alignCounts = new long[51];
public String getName() {

View File

@ -3,7 +3,7 @@ package org.broadinstitute.sting.playground.gatk.walkers;
import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedDatum;
import org.broadinstitute.sting.gatk.refdata.rodDbSNP;
import org.broadinstitute.sting.gatk.refdata.rodGFF;
import org.broadinstitute.sting.gatk.walkers.BasicLociWalker;
import org.broadinstitute.sting.gatk.walkers.LocusWalker;
import org.broadinstitute.sting.gatk.LocusContext;
import org.broadinstitute.sting.playground.gatk.walkers.AlleleFrequencyWalker;
import org.broadinstitute.sting.playground.utils.AlleleFrequencyEstimate;
@ -18,7 +18,7 @@ import java.util.List;
* To change this template use File | Settings | File Templates.
*/
public class AlleleFrequencyMetricsWalker extends BasicLociWalker<AlleleFrequencyEstimate, String>
public class AlleleFrequencyMetricsWalker extends LocusWalker<AlleleFrequencyEstimate, String>
{
long dbsnp_hits=0;

View File

@ -3,14 +3,14 @@ package org.broadinstitute.sting.playground.gatk.walkers;
import org.broadinstitute.sting.gatk.LocusContext;
import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedDatum;
import org.broadinstitute.sting.gatk.refdata.rodDbSNP;
import org.broadinstitute.sting.gatk.walkers.BasicLociWalker;
import org.broadinstitute.sting.gatk.walkers.LocusWalker;
import org.broadinstitute.sting.playground.utils.AlleleFrequencyEstimate;
import net.sf.samtools.SAMRecord;
import java.util.List;
import java.util.Arrays;
public class AlleleFrequencyWalker extends BasicLociWalker<AlleleFrequencyEstimate, Integer> {
public class AlleleFrequencyWalker extends LocusWalker<AlleleFrequencyEstimate, Integer> {
int N=2;

View File

@ -2,7 +2,7 @@ package org.broadinstitute.sting.playground.gatk.walkers;
import net.sf.samtools.SAMRecord;
import org.broadinstitute.sting.gatk.LocusContext;
import org.broadinstitute.sting.gatk.walkers.BasicReadWalker;
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
import org.broadinstitute.sting.utils.Utils;
import edu.mit.broad.picard.reference.ReferenceSequence;
@ -10,7 +10,7 @@ import java.util.Iterator;
import java.util.List;
import static java.lang.reflect.Array.*;
public class BaseQualityDumpWalker extends BasicReadWalker<Integer, Integer> {
public class BaseQualityDumpWalker extends ReadWalker<Integer, Integer> {
protected final int MIN_TARGET_EDIT_DISTANCE = 0; //5;
protected final int MAX_TARGET_EDIT_DISTANCE = 4; //10;

View File

@ -1,7 +1,7 @@
package org.broadinstitute.sting.playground.gatk.walkers;
import net.sf.samtools.SAMRecord;
import org.broadinstitute.sting.gatk.walkers.BasicReadWalker;
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
import org.broadinstitute.sting.gatk.LocusContext;
/**
@ -11,7 +11,7 @@ import org.broadinstitute.sting.gatk.LocusContext;
* Time: 3:22:14 PM
* To change this template use File | Settings | File Templates.
*/
public class BaseQualityHistoWalker extends BasicReadWalker<Integer, Integer> {
public class BaseQualityHistoWalker extends ReadWalker<Integer, Integer> {
long[] qualCounts = new long[100];
public String getName() {

View File

@ -2,7 +2,7 @@ package org.broadinstitute.sting.playground.gatk.walkers;
import net.sf.samtools.SAMRecord;
import org.broadinstitute.sting.gatk.LocusContext;
import org.broadinstitute.sting.gatk.walkers.BasicReadWalker;
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
import org.broadinstitute.sting.utils.Utils;
import edu.mit.broad.picard.reference.ReferenceSequence;
@ -10,7 +10,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class MismatchCounterWalker extends BasicReadWalker<Integer, Integer> {
public class MismatchCounterWalker extends ReadWalker<Integer, Integer> {
public String getName() {
return "CountMismatches";
}

View File

@ -2,7 +2,7 @@ package org.broadinstitute.sting.playground.gatk.walkers;
import net.sf.samtools.SAMRecord;
import org.broadinstitute.sting.gatk.LocusContext;
import org.broadinstitute.sting.gatk.walkers.BasicReadWalker;
import org.broadinstitute.sting.gatk.walkers.ReadWalker;
import org.broadinstitute.sting.utils.Utils;
import edu.mit.broad.picard.reference.ReferenceSequence;
@ -10,7 +10,7 @@ import java.util.Iterator;
import java.util.List;
import static java.lang.reflect.Array.*;
public class MismatchHistoWalker extends BasicReadWalker<Integer, Integer> {
public class MismatchHistoWalker extends ReadWalker<Integer, Integer> {
protected long[] mismatchCounts = new long[0];
protected final int MIN_TARGET_EDIT_DISTANCE = 5;

View File

@ -3,7 +3,7 @@ package org.broadinstitute.sting.playground.gatk.walkers;
import org.broadinstitute.sting.gatk.LocusContext;
import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedDatum;
import org.broadinstitute.sting.gatk.refdata.rodDbSNP;
import org.broadinstitute.sting.gatk.walkers.BasicLociWalker;
import org.broadinstitute.sting.gatk.walkers.LocusWalker;
import org.broadinstitute.sting.utils.Utils;
import net.sf.samtools.SAMRecord;
@ -12,7 +12,7 @@ import java.util.List;
// Draft single sample genotyper
// j.maguire 3-7-2009
public class SingleSampleGenotyper extends BasicLociWalker<Integer, Integer> {
public class SingleSampleGenotyper extends LocusWalker<Integer, Integer> {
public boolean filter(List<ReferenceOrderedDatum> rodData, char ref, LocusContext context) {
return true; // We are keeping all the reads
}

View File

@ -134,7 +134,6 @@ public class ArgumentParser {
*/
private void AddToOptionStorage( List<Pair<Option,Pair<Object,Field>>> options ) {
OptionGroup optionGroup = new OptionGroup();
boolean isRequired = true;
for( Pair<Option,Pair<Object,Field>> option: options ) {
if (m_options.hasOption(option.first.getOpt()) )
@ -142,10 +141,9 @@ public class ArgumentParser {
optionGroup.addOption(option.first);
m_storageLocations.put( option.first.getLongOpt(), option.second );
isRequired &= option.first.isRequired();
optionGroup.setRequired( optionGroup.isRequired() & option.first.isRequired() );
}
optionGroup.setRequired(isRequired);
m_options.addOptionGroup(optionGroup);
}