2009-03-18 07:22:37 +08:00
|
|
|
package org.broadinstitute.sting.gatk.walkers;
|
|
|
|
|
|
2009-03-27 23:03:32 +08:00
|
|
|
import java.io.PrintStream;
|
2009-04-25 05:39:44 +08:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.List;
|
2009-03-27 23:03:32 +08:00
|
|
|
|
2009-03-27 04:45:27 +08:00
|
|
|
import org.broadinstitute.sting.gatk.GenomeAnalysisTK;
|
2009-04-25 05:39:44 +08:00
|
|
|
import org.broadinstitute.sting.utils.GenomeLoc;
|
|
|
|
|
import org.broadinstitute.sting.utils.Pair;
|
2009-03-27 04:45:27 +08:00
|
|
|
|
2009-03-18 07:22:37 +08:00
|
|
|
/**
|
|
|
|
|
* Created by IntelliJ IDEA.
|
|
|
|
|
* User: hanna
|
|
|
|
|
* Date: Mar 17, 2009
|
|
|
|
|
* Time: 1:53:31 PM
|
|
|
|
|
* To change this template use File | Settings | File Templates.
|
|
|
|
|
*/
|
2009-03-27 23:40:45 +08:00
|
|
|
public abstract class Walker<MapType, ReduceType> {
|
2009-03-18 07:22:37 +08:00
|
|
|
// TODO: Can a walker be templatized so that map and reduce live here?
|
2009-03-27 04:45:27 +08:00
|
|
|
|
2009-03-27 23:03:32 +08:00
|
|
|
/**
|
|
|
|
|
* A stream for writing normal (non-error) output. System.out by default.
|
|
|
|
|
*/
|
|
|
|
|
protected PrintStream out = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A stream for writing error output. System.err by default.
|
|
|
|
|
*/
|
|
|
|
|
protected PrintStream err = null;
|
|
|
|
|
|
2009-03-27 04:45:27 +08:00
|
|
|
protected Walker() {
|
2009-03-29 09:50:27 +08:00
|
|
|
if( GenomeAnalysisTK.Instance != null ) {
|
|
|
|
|
GenomeAnalysisTK.Instance.loadArgumentsIntoObject(this);
|
|
|
|
|
out = GenomeAnalysisTK.Instance.out;
|
|
|
|
|
err = GenomeAnalysisTK.Instance.err;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
out = System.out;
|
|
|
|
|
err = System.err;
|
|
|
|
|
}
|
2009-03-27 04:45:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve the toolkit, for peering into internal structures that can't
|
|
|
|
|
* otherwise be read. Use sparingly, and discuss uses with software engineering
|
|
|
|
|
* team.
|
|
|
|
|
* @return The genome analysis toolkit.
|
|
|
|
|
*/
|
|
|
|
|
protected GenomeAnalysisTK getToolkit() {
|
|
|
|
|
return GenomeAnalysisTK.Instance;
|
2009-03-27 00:22:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initialize() { }
|
2009-04-25 05:39:44 +08:00
|
|
|
|
2009-03-27 21:44:46 +08:00
|
|
|
public void onTraversalDone(ReduceType result) {
|
2009-04-02 03:50:31 +08:00
|
|
|
out.println("[REDUCE RESULT] Traversal result is: " + result);
|
2009-03-27 21:44:46 +08:00
|
|
|
}
|
2009-04-25 05:39:44 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* General interval reduce routine called after all of the traversals are done
|
|
|
|
|
* @param results
|
|
|
|
|
*/
|
|
|
|
|
public void onTraversalDone(List<Pair<GenomeLoc, ReduceType>> results) {
|
|
|
|
|
for ( Pair<GenomeLoc, ReduceType> result : results ) {
|
|
|
|
|
out.printf("[INTERVAL REDUCE RESULT] at %s ", result.getFirst());
|
|
|
|
|
this.onTraversalDone(result.getSecond());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return true if your walker wants to reduce each interval separately. Default is false.
|
|
|
|
|
*
|
|
|
|
|
* If you set this flag, several things will happen.
|
|
|
|
|
*
|
|
|
|
|
* The system will invoke reduceInit() once for each interval being processed, starting a fresh reduce
|
|
|
|
|
* Reduce will accumulate normally at each map unit in the interval
|
|
|
|
|
* However, onTraversalDone(reduce) will be called after each interval is processed.
|
|
|
|
|
* The system will call onTraversalDone( GenomeLoc -> reduce ), after all reductions are done,
|
|
|
|
|
* which is overloaded here to call onTraversalDone(reduce) for each location
|
|
|
|
|
*/
|
2009-04-25 05:44:48 +08:00
|
|
|
public boolean isReduceByInterval() {
|
2009-04-25 05:39:44 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
2009-03-18 07:22:37 +08:00
|
|
|
}
|