2010-02-05 22:18:26 +08:00
package org.broadinstitute.sting.oneoffprojects.walkers ;
2010-01-28 01:19:37 +08:00
import org.broadinstitute.sting.gatk.contexts.AlignmentContext ;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext ;
2010-02-05 23:42:54 +08:00
import org.broadinstitute.sting.gatk.contexts.variantcontext.VariantContext ;
2010-01-28 12:10:16 +08:00
import org.broadinstitute.sting.gatk.refdata.* ;
2010-01-28 01:19:37 +08:00
import org.broadinstitute.sting.gatk.walkers.RodWalker ;
import org.broadinstitute.sting.utils.* ;
2010-02-05 23:42:54 +08:00
import org.broadinstitute.sting.utils.cmdLine.Argument ;
import java.util.EnumSet ;
2010-01-28 01:19:37 +08:00
/ * *
* Test routine for new VariantContext object
* /
public class TestVariantContextWalker extends RodWalker < Integer , Integer > {
2010-02-05 23:42:54 +08:00
@Argument ( fullName = "takeFirstOnly" , doc = "Only take the first second at a locus, as opposed to all" , required = false )
boolean takeFirstOnly = false ;
@Argument ( fullName = "onlyContextsOfType" , doc = "Only take variant contexts of this type" , required = false )
VariantContext . Type onlyOfThisType = null ;
@Argument ( fullName = "onlyContextsStartinAtCurrentPosition" , doc = "Only take variant contexts at actually start at the current position, excluding those at span to the current location but start earlier" , required = false )
boolean onlyContextsStartinAtCurrentPosition = false ;
@Argument ( fullName = "printPerLocus" , doc = "If true, we'll print the variant contexts, in addition to counts" , required = false )
boolean printContexts = false ;
2010-01-28 01:19:37 +08:00
public Integer map ( RefMetaDataTracker tracker , ReferenceContext ref , AlignmentContext context ) {
if ( ref = = null )
return 0 ;
else {
2010-02-05 23:42:54 +08:00
EnumSet < VariantContext . Type > allowedTypes = onlyOfThisType = = null ? null : EnumSet . of ( onlyOfThisType ) ;
2010-01-28 12:10:16 +08:00
2010-02-05 23:42:54 +08:00
int n = 0 ;
for ( VariantContext vc : tracker . getAllVariantContexts ( context . getLocation ( ) , allowedTypes , onlyContextsStartinAtCurrentPosition , takeFirstOnly ) ) {
n + + ;
if ( printContexts ) out . printf ( " %s%n" , vc ) ;
}
if ( n > 0 & & printContexts ) {
out . printf ( "%s => had %d variant context objects%n" , context . getLocation ( ) , n ) ;
out . printf ( "---------------------------------------------%n" ) ;
}
return n ;
2010-01-28 01:19:37 +08:00
}
}
public Integer reduceInit ( ) {
return 0 ;
}
public Integer reduce ( Integer point , Integer sum ) {
return point + sum ;
}
}