2009-03-16 06:42:24 +08:00
|
|
|
package org.broadinstitute.sting.gatk.walkers;
|
|
|
|
|
|
|
|
|
|
import org.broadinstitute.sting.gatk.LocusContext;
|
|
|
|
|
import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedDatum;
|
2009-04-04 03:54:54 +08:00
|
|
|
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
|
2009-03-31 13:02:33 +08:00
|
|
|
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
|
|
|
|
import org.broadinstitute.sting.utils.Pair;
|
2009-03-16 06:42:24 +08:00
|
|
|
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.
|
|
|
|
|
*/
|
2009-03-31 13:02:33 +08:00
|
|
|
public class DepthOfCoverageWalker extends LocusWalker<Integer, Pair<Long, Long>> {
|
2009-03-31 23:14:00 +08:00
|
|
|
@Argument(fullName="suppressLocusPrinting",required=false,defaultValue="false")
|
|
|
|
|
public boolean suppressPrinting;
|
2009-03-31 13:02:33 +08:00
|
|
|
|
2009-04-04 03:54:54 +08:00
|
|
|
public Integer map(RefMetaDataTracker tracker, char ref, LocusContext context) {
|
2009-03-31 23:14:00 +08:00
|
|
|
if ( !suppressPrinting )
|
2009-03-31 13:02:33 +08:00
|
|
|
out.printf("%s: %d%n", context.getLocation(), context.getReads().size() );
|
|
|
|
|
return context.getReads().size();
|
2009-03-16 06:42:24 +08:00
|
|
|
}
|
|
|
|
|
|
2009-04-25 05:44:48 +08:00
|
|
|
public boolean isReduceByInterval() {
|
2009-04-25 05:39:44 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-31 23:51:59 +08:00
|
|
|
public Pair<Long, Long> reduceInit() { return new Pair(0l,0l); }
|
2009-03-31 13:02:33 +08:00
|
|
|
|
|
|
|
|
public Pair<Long, Long> reduce(Integer value, Pair<Long, Long> sum) {
|
2009-03-31 23:51:59 +08:00
|
|
|
long left = value.longValue() + sum.getFirst();
|
|
|
|
|
long right = sum.getSecond() + 1l;
|
|
|
|
|
return new Pair(left, right);
|
2009-03-31 13:02:33 +08:00
|
|
|
}
|
2009-03-16 06:42:24 +08:00
|
|
|
|
2009-03-31 13:02:33 +08:00
|
|
|
public void onTraversalDone(Pair<Long, Long> result) {
|
2009-04-25 05:39:44 +08:00
|
|
|
out.printf("Average depth of coverage is: %.2f in %d total coverage over %d sites\n",
|
|
|
|
|
((double)result.getFirst() / (double)result.getSecond()), result.getFirst(), result.getSecond());
|
2009-03-16 06:42:24 +08:00
|
|
|
}
|
|
|
|
|
}
|