70 lines
2.2 KiB
Java
70 lines
2.2 KiB
Java
|
|
package org.broadinstitute.sting.gatk.walkers;
|
||
|
|
|
||
|
|
import org.broadinstitute.sting.gatk.LocusContext;
|
||
|
|
import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedDatum;
|
||
|
|
import org.broadinstitute.sting.gatk.refdata.rodDbSNP;
|
||
|
|
import net.sf.samtools.SAMRecord;
|
||
|
|
|
||
|
|
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 class PileupWalker extends BasicLociWalker<Integer, Integer> {
|
||
|
|
public void initialize() {
|
||
|
|
}
|
||
|
|
|
||
|
|
public String walkerType() { return "ByLocus"; }
|
||
|
|
|
||
|
|
// 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
|
||
|
|
}
|
||
|
|
|
||
|
|
// Map over the org.broadinstitute.sting.gatk.LocusContext
|
||
|
|
public Integer map(List<ReferenceOrderedDatum> rodData, char ref, LocusContext context) {
|
||
|
|
List<SAMRecord> reads = context.getReads();
|
||
|
|
List<Integer> offsets = context.getOffsets();
|
||
|
|
String bases = "";
|
||
|
|
String quals = "";
|
||
|
|
for ( int i = 0; i < reads.size(); i++ ) {
|
||
|
|
SAMRecord read = reads.get(i);
|
||
|
|
int offset = offsets.get(i);
|
||
|
|
|
||
|
|
bases += read.getReadString().charAt(offset);
|
||
|
|
quals += read.getBaseQualityString().charAt(offset);
|
||
|
|
}
|
||
|
|
|
||
|
|
String rodString = "";
|
||
|
|
for ( ReferenceOrderedDatum datum : rodData ) {
|
||
|
|
if ( datum != null ) {
|
||
|
|
if ( datum instanceof rodDbSNP) {
|
||
|
|
rodDbSNP dbsnp = (rodDbSNP)datum;
|
||
|
|
rodString += dbsnp.toMediumString();
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
rodString += datum.toSimpleString();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if ( rodString != "" )
|
||
|
|
rodString = "[ROD: " + rodString + "]";
|
||
|
|
|
||
|
|
if ( context.getLocation().getStart() % 1 == 0 ) {
|
||
|
|
System.out.printf("%s: %s %s %s %s%n", context.getLocation(), ref, bases, quals, rodString);
|
||
|
|
}
|
||
|
|
|
||
|
|
return 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Given result of map function
|
||
|
|
public Integer reduceInit() { return 0; }
|
||
|
|
public Integer reduce(Integer value, Integer sum) {
|
||
|
|
return value + sum;
|
||
|
|
}
|
||
|
|
}
|