2009-04-15 06:13:10 +08:00
|
|
|
package org.broadinstitute.sting.gatk.walkers;
|
|
|
|
|
|
|
|
|
|
import org.broadinstitute.sting.gatk.LocusContext;
|
|
|
|
|
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
|
|
|
|
|
import org.broadinstitute.sting.gatk.refdata.rodSAMPileup;
|
|
|
|
|
import org.broadinstitute.sting.utils.cmdLine.Argument;
|
|
|
|
|
import org.broadinstitute.sting.utils.Utils;
|
2009-04-17 11:13:11 +08:00
|
|
|
import org.broadinstitute.sting.utils.Pileup;
|
2009-04-15 06:13:10 +08:00
|
|
|
import org.broadinstitute.sting.utils.BasicPileup;
|
|
|
|
|
import org.broadinstitute.sting.utils.ReadBackedPileup;
|
2009-05-23 05:20:24 +08:00
|
|
|
import org.broadinstitute.sting.utils.StingException;
|
2009-04-15 06:13:10 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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-05-20 07:26:17 +08:00
|
|
|
@Requires(value={DataSource.READS,DataSource.REFERENCE},referenceMetaData=@RMD(name="pileup",type=rodSAMPileup.class))
|
2009-05-23 05:20:24 +08:00
|
|
|
public class ValidatingPileupWalker extends LocusWalker<Integer, ValidationStats> implements TreeReducible<ValidationStats> {
|
2009-05-07 09:22:01 +08:00
|
|
|
@Argument(fullName="continue_after_error",doc="Continue after an error",required=false)
|
|
|
|
|
public boolean CONTINUE_AFTER_AN_ERROR = false;
|
2009-04-15 06:13:10 +08:00
|
|
|
|
|
|
|
|
public Integer map(RefMetaDataTracker tracker, char ref, LocusContext context) {
|
2009-04-17 11:13:11 +08:00
|
|
|
Pileup pileup = new ReadBackedPileup(ref, context);
|
2009-05-24 04:50:28 +08:00
|
|
|
Pileup truePileup = getTruePileup( tracker );
|
2009-05-23 05:20:24 +08:00
|
|
|
|
2009-04-17 11:13:11 +08:00
|
|
|
if ( truePileup == null ) {
|
|
|
|
|
System.out.printf("No truth pileup data available at %s%n", pileup.getPileupString());
|
|
|
|
|
if ( ! CONTINUE_AFTER_AN_ERROR ) {
|
|
|
|
|
Utils.scareUser(String.format("No pileup data available at %s given GATK's output of %s -- this walker requires samtools pileup data over all bases",
|
|
|
|
|
context.getLocation(), pileup.getBases()));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
String pileupDiff = BasicPileup.pileupDiff(pileup, truePileup);
|
|
|
|
|
if ( pileupDiff != null ) {
|
|
|
|
|
out.printf("%s vs. %s%n", pileup.getPileupString(), truePileup.getPileupString());
|
|
|
|
|
if ( ! CONTINUE_AFTER_AN_ERROR ) {
|
|
|
|
|
throw new RuntimeException(String.format("Pileups aren't equal: %s", pileupDiff));
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-04-15 06:13:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pileup.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Given result of map function
|
|
|
|
|
public ValidationStats reduceInit() { return new ValidationStats(); }
|
|
|
|
|
public ValidationStats reduce(Integer value, ValidationStats sum) {
|
|
|
|
|
sum.nLoci++;
|
|
|
|
|
sum.nBases += value;
|
|
|
|
|
return sum;
|
|
|
|
|
}
|
2009-05-23 05:20:24 +08:00
|
|
|
|
|
|
|
|
public ValidationStats treeReduce( ValidationStats lhs, ValidationStats rhs ) {
|
|
|
|
|
ValidationStats combined = new ValidationStats();
|
|
|
|
|
combined.nLoci = lhs.nLoci + rhs.nLoci;
|
|
|
|
|
combined.nBases = lhs.nBases + rhs.nBases;
|
|
|
|
|
return combined;
|
|
|
|
|
}
|
2009-05-24 04:50:28 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Extracts the true pileup data from the given rodSAMPileup. Note that this implementation
|
|
|
|
|
* assumes that the genotype will only be point or indel.
|
|
|
|
|
* @param tracker ROD tracker from which to extract pileup data.
|
|
|
|
|
* @return True pileup data.
|
|
|
|
|
*/
|
|
|
|
|
private Pileup getTruePileup( RefMetaDataTracker tracker ) {
|
|
|
|
|
rodSAMPileup pileup = (rodSAMPileup)tracker.lookup("pileup", null);
|
|
|
|
|
if( pileup.hasPointGenotype() )
|
|
|
|
|
return (Pileup)pileup.getPointGenotype();
|
|
|
|
|
else if( pileup.hasIndelGenotype() )
|
|
|
|
|
return (Pileup)pileup.getIndelGenotype();
|
|
|
|
|
else
|
|
|
|
|
throw new StingException("Unsupported pileup type: " + pileup);
|
|
|
|
|
}
|
2009-04-15 06:13:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ValidationStats {
|
|
|
|
|
public long nLoci = 0;
|
|
|
|
|
public long nBases = 0;
|
|
|
|
|
|
|
|
|
|
public ValidationStats() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String toString() {
|
|
|
|
|
return String.format("Validated %d sites covered by %d bases%n", nLoci, nBases);
|
|
|
|
|
}
|
|
|
|
|
}
|