Cleaned up VariantContext accessors in RefMetaDataTracker

It's no longer possible to provided allowed types, as this was a very rarely used feature in the engine.  These get methods have been removed and local uses replaced with tests directly in their code.  This simplified the RefMetaDataTracker significantly
VariantContextRodBinding now forwards along all of the RefMetaDataTracker methods, so it is possible to create a full equivalent VariantContextRodBinding now as a walker field variable.
All walkers updated to the new RefMetaDataTracker function call style
This commit is contained in:
Mark DePristo 2011-07-28 00:16:34 -04:00
parent c83f9432eb
commit f7a126722b
32 changed files with 163 additions and 151 deletions

View File

@ -26,13 +26,13 @@ package org.broadinstitute.sting.commandline;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature; import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature;
import org.broadinstitute.sting.gatk.refdata.utils.RODRecordList;
import org.broadinstitute.sting.utils.exceptions.UserException;
import java.util.*; import java.util.List;
/** /**
* A RodBinding representing a walker argument that gets bound to a ROD track.
* *
* There is no constraint on the type of the ROD bound.
*/ */
public class RodBinding { public class RodBinding {
final String variableName; final String variableName;
@ -53,23 +53,23 @@ public class RodBinding {
return source; return source;
} }
public List<Object> getValues(RefMetaDataTracker tracker) { public List<Object> getValues(final RefMetaDataTracker tracker) {
return tracker.getValues(variableName); return tracker.getValues(variableName);
} }
public <T> List<T> getValues(RefMetaDataTracker tracker, Class<T> clazz) { public <T> List<T> getValues(final RefMetaDataTracker tracker, final Class<T> clazz) {
return tracker.getValues(variableName, clazz); return tracker.getValues(variableName, clazz);
} }
public <T> T getFirstValue(RefMetaDataTracker tracker, Class<T> clazz) { public <T> T getFirstValue(final RefMetaDataTracker tracker, final Class<T> clazz) {
return tracker.getFirstValue(variableName, clazz); return tracker.getFirstValue(variableName, clazz);
} }
public boolean hasValues(RefMetaDataTracker tracker) { public boolean hasValues(final RefMetaDataTracker tracker) {
return tracker.hasValues(variableName); return tracker.hasValues(variableName);
} }
public List<GATKFeature> getValuesAsGATKFeatures(RefMetaDataTracker tracker) { public List<GATKFeature> getValuesAsGATKFeatures(final RefMetaDataTracker tracker) {
return tracker.getValuesAsGATKFeatures(variableName); return tracker.getValuesAsGATKFeatures(variableName);
} }

View File

@ -29,42 +29,54 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.GenomeLoc;
import org.broadinstitute.sting.utils.variantcontext.VariantContext; import org.broadinstitute.sting.utils.variantcontext.VariantContext;
import java.io.File; import java.util.Collection;
import java.util.List;
/** /**
* * A RodBinding representing a walker argument that gets bound to a ROD track containing VariantContexts
*/ */
public class VariantContextRodBinding extends RodBinding { public class VariantContextRodBinding extends RodBinding {
/**
* Create a new RodBinding specialized to provide VariantContexts.
* @param variableName the name of the field in the walker that we will bind the ROD track too
* @param sourceFile the data source from which we will read the VCs
* @param parser the Engine parser used to obtain information about this argument, such as its underlying file type
*/
protected VariantContextRodBinding(final String variableName, final String sourceFile, final ParsingEngine parser) { protected VariantContextRodBinding(final String variableName, final String sourceFile, final ParsingEngine parser) {
super(variableName, sourceFile, parser); super(variableName, sourceFile, parser);
} }
public VariantContext getVariantContext(RefMetaDataTracker tracker, ReferenceContext ref, GenomeLoc loc) { /**
return tracker.getVariantContext(ref, variableName, loc); * Forwarding method to identical tracker method
*/
public Collection<VariantContext> getVariantContexts(final RefMetaDataTracker tracker,
final ReferenceContext ref,
final GenomeLoc curLocation,
final boolean requireStartHere,
final boolean takeFirstOnly ) {
return tracker.getVariantContexts(ref, variableName, curLocation, requireStartHere, takeFirstOnly);
} }
// public Collection<VariantContext> getAllVariantContexts(ReferenceContext ref) { /**
// } * Forwarding method to identical tracker method
// * @param tracker
// public Collection<VariantContext> getAllVariantContexts(ReferenceContext ref, GenomeLoc curLocation) { * @param ref
// } * @param curLocation
// * @param requireStartHere
// public Collection<VariantContext> getAllVariantContexts(ReferenceContext ref, EnumSet<VariantContext.Type> allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) { * @return
// } */
// public VariantContext getVariantContext(final RefMetaDataTracker tracker,
// public Collection<VariantContext> getVariantContexts(ReferenceContext ref, String name, EnumSet<VariantContext.Type> allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) { final ReferenceContext ref,
// } final GenomeLoc curLocation,
// final boolean requireStartHere ) {
// public Collection<VariantContext> getVariantContexts(ReferenceContext ref, Collection<String> names, EnumSet<VariantContext.Type> allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) { return tracker.getVariantContext(ref, variableName, curLocation, requireStartHere);
// } }
//
// public Collection<VariantContext> getVariantContextsByPrefix(ReferenceContext ref, Collection<String> names, EnumSet<VariantContext.Type> allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) { /**
// } * Forwarding method to identical tracker method
// */
// public VariantContext getVariantContext(ReferenceContext ref, String name, EnumSet<VariantContext.Type> allowedTypes, GenomeLoc curLocation, boolean requireStartHere ) { public VariantContext getVariantContext(final RefMetaDataTracker tracker,
// } final ReferenceContext ref,
// final GenomeLoc curLocation) {
// public VariantContext getVariantContext(ReferenceContext ref, String name, GenomeLoc curLocation) { return tracker.getVariantContext(ref, variableName, curLocation);
// } }
} }

View File

@ -54,7 +54,7 @@ public class RefMetaDataTracker {
* *
* Important: The list returned by this function is guaranteed not to be null, but may be empty! * Important: The list returned by this function is guaranteed not to be null, but may be empty!
*/ */
public <T> List<T> getValues(final String name, Class<T> clazz) { public <T> List<T> getValues(final String name, final Class<T> clazz) {
RODRecordList list = getTrackDataByName(name); RODRecordList list = getTrackDataByName(name);
if (list == null) if (list == null)
@ -73,10 +73,10 @@ public class RefMetaDataTracker {
} }
/** /**
* get a singleton record, given the name and a type. This function will return the first record at the current position seen, * get a singleton record, given the name and a type. This function will return the first record at the
* and emit a logger warning if there were more than one option. * current position seen. The object is cast into a type clazz, or thoses an error if this isn't possible.
* *
* WARNING: we now suppport more than one RMD at a single position for all tracks. If there are * * WARNING: we now suppport more than one RMD at a single position for all tracks. If there are
* are multiple RMD objects at this location, there is no contract for which object this method will pick, and which object gets * are multiple RMD objects at this location, there is no contract for which object this method will pick, and which object gets
* picked may change from time to time! BE WARNED! * picked may change from time to time! BE WARNED!
* *
@ -85,7 +85,7 @@ public class RefMetaDataTracker {
* @param <T> the type to parameterize on, matching the clazz argument * @param <T> the type to parameterize on, matching the clazz argument
* @return a record of type T, or null if no record is present. * @return a record of type T, or null if no record is present.
*/ */
public <T> T getFirstValue(final String name, Class<T> clazz) { public <T> T getFirstValue(final String name, final Class<T> clazz) {
RODRecordList objects = getTrackDataByName(name); RODRecordList objects = getTrackDataByName(name);
// if empty or null return null; // if empty or null return null;
@ -172,6 +172,8 @@ public class RefMetaDataTracker {
* Binds the list of reference ordered data records (RMDs) to track name at this site. Should be used only by the traversal * Binds the list of reference ordered data records (RMDs) to track name at this site. Should be used only by the traversal
* system to provide access to RMDs in a structured way to the walkers. * system to provide access to RMDs in a structured way to the walkers.
* *
* DO NOT USE THIS FUNCTION UNLESS YOU ARE THE GATK ENGINE
*
* @param name the name of the track * @param name the name of the track
* @param rod the collection of RMD data * @param rod the collection of RMD data
*/ */
@ -180,6 +182,13 @@ public class RefMetaDataTracker {
map.put(canonicalName(name), rod); map.put(canonicalName(name), rod);
} }
// ------------------------------------------------------------------------------------------
//
//
// VariantContext helpers
//
//
// ------------------------------------------------------------------------------------------
/** /**
* Converts all possible ROD tracks to VariantContexts objects, of all types, allowing any start and any number * Converts all possible ROD tracks to VariantContexts objects, of all types, allowing any start and any number
@ -189,8 +198,8 @@ public class RefMetaDataTracker {
* @param ref reference context * @param ref reference context
* @return variant context * @return variant context
*/ */
public Collection<VariantContext> getAllVariantContexts(ReferenceContext ref) { public Collection<VariantContext> getAllVariantContexts(final ReferenceContext ref) {
return getAllVariantContexts(ref, null, null, false, false); return getAllVariantContexts(ref, null, false, false);
} }
/** /**
@ -199,8 +208,9 @@ public class RefMetaDataTracker {
* @param curLocation * @param curLocation
* @return * @return
*/ */
public Collection<VariantContext> getAllVariantContexts(ReferenceContext ref, GenomeLoc curLocation) { public Collection<VariantContext> getAllVariantContexts(final ReferenceContext ref,
return getAllVariantContexts(ref, null, curLocation, true, false); final GenomeLoc curLocation) {
return getAllVariantContexts(ref, curLocation, true, false);
} }
/** /**
@ -215,17 +225,19 @@ public class RefMetaDataTracker {
* The name of each VariantContext corresponds to the ROD name. * The name of each VariantContext corresponds to the ROD name.
* *
* @param ref reference context * @param ref reference context
* @param allowedTypes allowed types
* @param curLocation location * @param curLocation location
* @param requireStartHere do we require the rod to start at this location? * @param requireStartHere do we require the rod to start at this location?
* @param takeFirstOnly do we take the first rod only? * @param takeFirstOnly do we take the first rod only?
* @return variant context * @return variant context
*/ */
public Collection<VariantContext> getAllVariantContexts(ReferenceContext ref, EnumSet<VariantContext.Type> allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) { public Collection<VariantContext> getAllVariantContexts(final ReferenceContext ref,
final GenomeLoc curLocation,
final boolean requireStartHere,
final boolean takeFirstOnly ) {
List<VariantContext> contexts = new ArrayList<VariantContext>(); List<VariantContext> contexts = new ArrayList<VariantContext>();
for ( RODRecordList rodList : getBoundRodTracks() ) { for ( RODRecordList rodList : getBoundRodTracks() ) {
addVariantContexts(contexts, rodList, ref, allowedTypes, curLocation, requireStartHere, takeFirstOnly); addVariantContexts(contexts, rodList, ref, curLocation, requireStartHere, takeFirstOnly);
} }
return contexts; return contexts;
@ -239,31 +251,30 @@ public class RefMetaDataTracker {
* @param ref ReferenceContext to enable conversion to variant context * @param ref ReferenceContext to enable conversion to variant context
* @param name name * @param name name
* @param curLocation location * @param curLocation location
* @param allowedTypes allowed types
* @param requireStartHere do we require the rod to start at this location? * @param requireStartHere do we require the rod to start at this location?
* @param takeFirstOnly do we take the first rod only? * @param takeFirstOnly do we take the first rod only?
* @return variant context * @return variant context
*/ */
// public Collection<VariantContext> getVariantContexts(String name, EnumSet<VariantContext.Type> allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) { public Collection<VariantContext> getVariantContexts(final ReferenceContext ref,
// return getVariantContexts(null, Arrays.asList(name), allowedTypes, curLocation, requireStartHere, takeFirstOnly); final String name,
// } final GenomeLoc curLocation,
final boolean requireStartHere,
public Collection<VariantContext> getVariantContexts(ReferenceContext ref, String name, EnumSet<VariantContext.Type> allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) { final boolean takeFirstOnly ) {
return getVariantContexts(ref, Arrays.asList(name), allowedTypes, curLocation, requireStartHere, takeFirstOnly); return getVariantContexts(ref, Arrays.asList(name), curLocation, requireStartHere, takeFirstOnly);
} }
// public Collection<VariantContext> getVariantContexts(Collection<String> names, EnumSet<VariantContext.Type> allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) { public Collection<VariantContext> getVariantContexts(final ReferenceContext ref,
// return getVariantContexts(null, names, allowedTypes, curLocation, requireStartHere, takeFirstOnly); final Collection<String> names,
// } final GenomeLoc curLocation,
final boolean requireStartHere,
public Collection<VariantContext> getVariantContexts(ReferenceContext ref, Collection<String> names, EnumSet<VariantContext.Type> allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) { final boolean takeFirstOnly ) {
Collection<VariantContext> contexts = new ArrayList<VariantContext>(); Collection<VariantContext> contexts = new ArrayList<VariantContext>();
for ( String name : names ) { for ( String name : names ) {
RODRecordList rodList = getTrackDataByName(name); // require that the name is an exact match RODRecordList rodList = getTrackDataByName(name); // require that the name is an exact match
if ( rodList != null ) if ( rodList != null )
addVariantContexts(contexts, rodList, ref, allowedTypes, curLocation, requireStartHere, takeFirstOnly ); addVariantContexts(contexts, rodList, ref, curLocation, requireStartHere, takeFirstOnly );
} }
return contexts; return contexts;
@ -275,12 +286,14 @@ public class RefMetaDataTracker {
* *
* @param name name * @param name name
* @param curLocation location * @param curLocation location
* @param allowedTypes allowed types
* @param requireStartHere do we require the rod to start at this location? * @param requireStartHere do we require the rod to start at this location?
* @return variant context * @return variant context
*/ */
public VariantContext getVariantContext(ReferenceContext ref, String name, EnumSet<VariantContext.Type> allowedTypes, GenomeLoc curLocation, boolean requireStartHere ) { public VariantContext getVariantContext(final ReferenceContext ref,
Collection<VariantContext> contexts = getVariantContexts(ref, name, allowedTypes, curLocation, requireStartHere, false ); final String name,
final GenomeLoc curLocation,
final boolean requireStartHere ) {
Collection<VariantContext> contexts = getVariantContexts(ref, name, curLocation, requireStartHere, false );
if ( contexts.size() > 1 ) if ( contexts.size() > 1 )
throw new ReviewedStingException("Requested a single VariantContext object for track " + name + " but multiple variants were present at position " + curLocation); throw new ReviewedStingException("Requested a single VariantContext object for track " + name + " but multiple variants were present at position " + curLocation);
@ -299,24 +312,27 @@ public class RefMetaDataTracker {
* @param curLocation * @param curLocation
* @return * @return
*/ */
public VariantContext getVariantContext(ReferenceContext ref, String name, GenomeLoc curLocation) { public VariantContext getVariantContext(final ReferenceContext ref,
return getVariantContext(ref, name, null, curLocation, true); final String name,
final GenomeLoc curLocation) {
return getVariantContext(ref, name, curLocation, true);
} }
private void addVariantContexts(Collection<VariantContext> contexts, RODRecordList rodList, ReferenceContext ref, EnumSet<VariantContext.Type> allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) { private void addVariantContexts(final Collection<VariantContext> contexts,
final RODRecordList rodList,
final ReferenceContext ref,
final GenomeLoc curLocation,
final boolean requireStartHere,
final boolean takeFirstOnly ) {
for ( GATKFeature rec : rodList ) { for ( GATKFeature rec : rodList ) {
if ( VariantContextAdaptors.canBeConvertedToVariantContext(rec.getUnderlyingObject()) ) { if ( VariantContextAdaptors.canBeConvertedToVariantContext(rec.getUnderlyingObject()) ) {
// ok, we might actually be able to turn this record in a variant context // ok, we might actually be able to turn this record in a variant context
VariantContext vc = VariantContextAdaptors.toVariantContext(rodList.getName(), rec.getUnderlyingObject(), ref); final VariantContext vc = VariantContextAdaptors.toVariantContext(rodList.getName(), rec.getUnderlyingObject(), ref);
if ( vc == null ) // sometimes the track has odd stuff in it that can't be converted if ( vc == null ) // sometimes the track has odd stuff in it that can't be converted
continue; continue;
// now, let's decide if we want to keep it if ( ! requireStartHere || rec.getLocation().getStart() == curLocation.getStart() ) { // ok, we are going to keep this thing
boolean goodType = allowedTypes == null || allowedTypes.contains(vc.getType());
boolean goodPos = ! requireStartHere || rec.getLocation().getStart() == curLocation.getStart();
if ( goodType && goodPos ) { // ok, we are going to keep this thing
contexts.add(vc); contexts.add(vc);
if ( takeFirstOnly ) if ( takeFirstOnly )

View File

@ -202,7 +202,7 @@ public class VariantAnnotator extends RodWalker<Integer, Integer> {
if ( tracker == null ) if ( tracker == null )
return 0; return 0;
Collection<VariantContext> VCs = tracker.getVariantContexts(ref, "variant", null, context.getLocation(), true, false); Collection<VariantContext> VCs = tracker.getVariantContexts(ref, "variant", context.getLocation(), true, false);
if ( VCs.size() == 0 ) if ( VCs.size() == 0 )
return 0; return 0;

View File

@ -203,7 +203,7 @@ public class VariantAnnotatorEngine {
infoAnnotations.put(VariantContext.ID_KEY, rsID); infoAnnotations.put(VariantContext.ID_KEY, rsID);
} else { } else {
boolean overlapsComp = false; boolean overlapsComp = false;
for ( VariantContext comp : tracker.getVariantContexts(ref, dbSet.getKey(), null, ref.getLocus(), false, false) ) { for ( VariantContext comp : tracker.getVariantContexts(ref, dbSet.getKey(), ref.getLocus(), false, false) ) {
if ( !comp.isFiltered() ) { if ( !comp.isFiltered() ) {
overlapsComp = true; overlapsComp = true;
break; break;
@ -216,7 +216,7 @@ public class VariantAnnotatorEngine {
private void annotateExpressions(RefMetaDataTracker tracker, ReferenceContext ref, Map<String, Object> infoAnnotations) { private void annotateExpressions(RefMetaDataTracker tracker, ReferenceContext ref, Map<String, Object> infoAnnotations) {
for ( VAExpression expression : requestedExpressions ) { for ( VAExpression expression : requestedExpressions ) {
Collection<VariantContext> VCs = tracker.getVariantContexts(ref, expression.bindingName, null, ref.getLocus(), false, true); Collection<VariantContext> VCs = tracker.getVariantContexts(ref, expression.bindingName, ref.getLocus(), false, true);
if ( VCs.size() == 0 ) if ( VCs.size() == 0 )
continue; continue;

View File

@ -244,7 +244,7 @@ public class GenomicAnnotator extends RodWalker<Integer, Integer> implements Tre
return 0; return 0;
Set<VariantContext> results = new LinkedHashSet<VariantContext>(); Set<VariantContext> results = new LinkedHashSet<VariantContext>();
for (VariantContext vc : tracker.getVariantContexts(ref, "variant", null, context.getLocation(), true, false)) { for (VariantContext vc : tracker.getVariantContexts(ref, "variant", context.getLocation(), true, false)) {
if ( (vc.isFiltered() && IGNORE_FILTERED_SITES) || if ( (vc.isFiltered() && IGNORE_FILTERED_SITES) ||
(vc.isVariant() && !vc.isBiallelic()) ) { (vc.isVariant() && !vc.isBiallelic()) ) {
results.add(vc); results.add(vc);

View File

@ -119,9 +119,9 @@ public class BeagleOutputToVCFWalker extends RodWalker<Integer, Integer> {
return 0; return 0;
GenomeLoc loc = context.getLocation(); GenomeLoc loc = context.getLocation();
VariantContext vc_input = tracker.getVariantContext(ref,INPUT_ROD_NAME, null, loc, true); VariantContext vc_input = tracker.getVariantContext(ref,INPUT_ROD_NAME, loc, true);
VariantContext vc_comp = tracker.getVariantContext(ref,COMP_ROD_NAME, null, loc, true); VariantContext vc_comp = tracker.getVariantContext(ref,COMP_ROD_NAME, loc, true);
if ( vc_input == null ) if ( vc_input == null )
return 0; return 0;

View File

@ -121,8 +121,8 @@ public class ProduceBeagleInputWalker extends RodWalker<Integer, Integer> {
public Integer map( RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context ) { public Integer map( RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context ) {
if( tracker != null ) { if( tracker != null ) {
GenomeLoc loc = context.getLocation(); GenomeLoc loc = context.getLocation();
VariantContext variant_eval = tracker.getVariantContext(ref, ROD_NAME, null, loc, true); VariantContext variant_eval = tracker.getVariantContext(ref, ROD_NAME, loc, true);
VariantContext validation_eval = tracker.getVariantContext(ref,VALIDATION_ROD_NAME,null,loc, true); VariantContext validation_eval = tracker.getVariantContext(ref,VALIDATION_ROD_NAME, loc, true);
if ( goodSite(variant_eval,validation_eval) ) { if ( goodSite(variant_eval,validation_eval) ) {
if ( useValidation(validation_eval, ref) ) { if ( useValidation(validation_eval, ref) ) {

View File

@ -102,7 +102,7 @@ public class VariantsToBeagleUnphasedWalker extends RodWalker<Integer, Integer>
public Integer map( RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context ) { public Integer map( RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context ) {
if( tracker != null ) { if( tracker != null ) {
GenomeLoc loc = context.getLocation(); GenomeLoc loc = context.getLocation();
VariantContext vc = tracker.getVariantContext(ref, ROD_NAME, null, loc, true); VariantContext vc = tracker.getVariantContext(ref, ROD_NAME, loc, true);
if ( ProduceBeagleInputWalker.canBeOutputToBeagle(vc) ) { if ( ProduceBeagleInputWalker.canBeOutputToBeagle(vc) ) {
// do we want to hold back this site? // do we want to hold back this site?

View File

@ -149,7 +149,7 @@ public class VariantFiltrationWalker extends RodWalker<Integer, Integer> {
if ( tracker == null ) if ( tracker == null )
return 0; return 0;
Collection<VariantContext> VCs = tracker.getVariantContexts(ref, INPUT_VARIANT_ROD_BINDING_NAME, null, context.getLocation(), true, false); Collection<VariantContext> VCs = tracker.getVariantContexts(ref, INPUT_VARIANT_ROD_BINDING_NAME, context.getLocation(), true, false);
// is there a SNP mask present? // is there a SNP mask present?
boolean hasMask = tracker.getValues("mask").size() > 0; boolean hasMask = tracker.getValues("mask").size() > 0;

View File

@ -293,6 +293,9 @@ public class IndelGenotypeLikelihoodsCalculationModel extends GenotypeLikelihood
return aList; return aList;
} }
private final static EnumSet<VariantContext.Type> allowableTypes = EnumSet.of(VariantContext.Type.INDEL, VariantContext.Type.MIXED);
public Allele getLikelihoods(RefMetaDataTracker tracker, public Allele getLikelihoods(RefMetaDataTracker tracker,
ReferenceContext ref, ReferenceContext ref,
Map<String, AlignmentContext> contexts, Map<String, AlignmentContext> contexts,
@ -318,11 +321,10 @@ public class IndelGenotypeLikelihoodsCalculationModel extends GenotypeLikelihood
haplotypeMap.clear(); haplotypeMap.clear();
if (getAlleleListFromVCF) { if (getAlleleListFromVCF) {
EnumSet<VariantContext.Type> allowableTypes = EnumSet.of(VariantContext.Type.INDEL); for( final VariantContext vc_input : tracker.getVariantContexts(ref, "alleles", ref.getLocus(), false, false) ) {
allowableTypes.add(VariantContext.Type.MIXED); if( vc_input != null &&
for( final VariantContext vc_input : tracker.getVariantContexts(ref, "alleles", allowableTypes.contains(vc_input.getType()) &&
allowableTypes, ref.getLocus(), false, false) ) { ref.getLocus().getStart() == vc_input.getStart()) {
if( vc_input != null && ref.getLocus().getStart() == vc_input.getStart()) {
vc = vc_input; vc = vc_input;
break; break;
} }

View File

@ -63,7 +63,7 @@ public class SNPGenotypeLikelihoodsCalculationModel extends GenotypeLikelihoodsC
VariantContext vc = null; VariantContext vc = null;
// search for usable record // search for usable record
for( final VariantContext vc_input : tracker.getVariantContexts(ref, "alleles", null, ref.getLocus(), true, false) ) { for( final VariantContext vc_input : tracker.getVariantContexts(ref, "alleles", ref.getLocus(), true, false) ) {
if ( vc_input != null && ! vc_input.isFiltered() && (! requireSNP || vc_input.isSNP() )) { if ( vc_input != null && ! vc_input.isFiltered() && (! requireSNP || vc_input.isSNP() )) {
if ( vc == null ) { if ( vc == null ) {
vc = vc_input; vc = vc_input;

View File

@ -96,7 +96,7 @@ public class UGCallVariants extends RodWalker<VariantCallContext, Integer> {
List<VariantContext> VCs = new ArrayList<VariantContext>(); List<VariantContext> VCs = new ArrayList<VariantContext>();
for ( String name : trackNames ) { for ( String name : trackNames ) {
Collection<VariantContext> vc = tracker.getVariantContexts(ref, name, null, context.getLocation(), true, true); Collection<VariantContext> vc = tracker.getVariantContexts(ref, name, context.getLocation(), true, true);
VCs.addAll(vc); VCs.addAll(vc);
} }

View File

@ -155,7 +155,7 @@ public class AnnotateMNPsWalker extends RodWalker<Integer, Integer> {
boolean requireStartHere = false; // see EVERY site of the MNP boolean requireStartHere = false; // see EVERY site of the MNP
boolean takeFirstOnly = false; // take as many entries as the VCF file has boolean takeFirstOnly = false; // take as many entries as the VCF file has
for (VariantContext vc : tracker.getVariantContexts(ref, rodNames, null, context.getLocation(), requireStartHere, takeFirstOnly)) { for (VariantContext vc : tracker.getVariantContexts(ref, rodNames, context.getLocation(), requireStartHere, takeFirstOnly)) {
GenomeLoc vcLoc = VariantContextUtils.getLocation(locParser, vc); GenomeLoc vcLoc = VariantContextUtils.getLocation(locParser, vc);
boolean atStartOfVc = curLocus.getStart() == vcLoc.getStart(); boolean atStartOfVc = curLocus.getStart() == vcLoc.getStart();
boolean atEndOfVc = curLocus.getStart() == vcLoc.getStop(); boolean atEndOfVc = curLocus.getStart() == vcLoc.getStop();

View File

@ -44,8 +44,8 @@ public class MergeAndMatchHaplotypes extends RodWalker<Integer, Integer> {
@Override @Override
public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
if (tracker != null) { if (tracker != null) {
Collection<VariantContext> pbts = tracker.getVariantContexts(ref, "pbt", null, ref.getLocus(), true, true); Collection<VariantContext> pbts = tracker.getVariantContexts(ref, "pbt", ref.getLocus(), true, true);
Collection<VariantContext> rbps = tracker.getVariantContexts(ref, "rbp", null, ref.getLocus(), true, true); Collection<VariantContext> rbps = tracker.getVariantContexts(ref, "rbp", ref.getLocus(), true, true);
VariantContext pbt = pbts.iterator().hasNext() ? pbts.iterator().next() : null; VariantContext pbt = pbts.iterator().hasNext() ? pbts.iterator().next() : null;
VariantContext rbp = rbps.iterator().hasNext() ? rbps.iterator().next() : null; VariantContext rbp = rbps.iterator().hasNext() ? rbps.iterator().next() : null;

View File

@ -103,7 +103,7 @@ public class MergeMNPsWalker extends RodWalker<Integer, Integer> {
boolean requireStartHere = true; // only see each VariantContext once boolean requireStartHere = true; // only see each VariantContext once
boolean takeFirstOnly = false; // take as many entries as the VCF file has boolean takeFirstOnly = false; // take as many entries as the VCF file has
for (VariantContext vc : tracker.getVariantContexts(ref, rodNames, null, context.getLocation(), requireStartHere, takeFirstOnly)) for (VariantContext vc : tracker.getVariantContexts(ref, rodNames, context.getLocation(), requireStartHere, takeFirstOnly))
writeVCF(vc); writeVCF(vc);
return 0; return 0;

View File

@ -140,7 +140,7 @@ public class MergeSegregatingAlternateAllelesWalker extends RodWalker<Integer, I
boolean requireStartHere = true; // only see each VariantContext once boolean requireStartHere = true; // only see each VariantContext once
boolean takeFirstOnly = false; // take as many entries as the VCF file has boolean takeFirstOnly = false; // take as many entries as the VCF file has
for (VariantContext vc : tracker.getVariantContexts(ref, rodNames, null, context.getLocation(), requireStartHere, takeFirstOnly)) for (VariantContext vc : tracker.getVariantContexts(ref, rodNames, context.getLocation(), requireStartHere, takeFirstOnly))
writeVCF(vc); writeVCF(vc);
return 0; return 0;

View File

@ -289,7 +289,7 @@ public class PhaseByTransmission extends RodWalker<Integer, Integer> {
@Override @Override
public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
if (tracker != null) { if (tracker != null) {
Collection<VariantContext> vcs = tracker.getVariantContexts(ref, ROD_NAME, null, context.getLocation(), true, true); Collection<VariantContext> vcs = tracker.getVariantContexts(ref, ROD_NAME, context.getLocation(), true, true);
for (VariantContext vc : vcs) { for (VariantContext vc : vcs) {
Map<String, Genotype> genotypeMap = vc.getGenotypes(); Map<String, Genotype> genotypeMap = vc.getGenotypes();

View File

@ -209,7 +209,7 @@ public class ReadBackedPhasingWalker extends RodWalker<PhasingStatsAndOutput, Ph
boolean requireStartHere = true; // only see each VariantContext once boolean requireStartHere = true; // only see each VariantContext once
boolean takeFirstOnly = false; // take as many entries as the VCF file has boolean takeFirstOnly = false; // take as many entries as the VCF file has
for (VariantContext vc : tracker.getVariantContexts(ref, rodNames, null, context.getLocation(), requireStartHere, takeFirstOnly)) { for (VariantContext vc : tracker.getVariantContexts(ref, rodNames, context.getLocation(), requireStartHere, takeFirstOnly)) {
if (samplesToPhase != null) vc = reduceVCToSamples(vc, samplesToPhase); if (samplesToPhase != null) vc = reduceVCToSamples(vc, samplesToPhase);
if (ReadBackedPhasingWalker.processVariantInPhasing(vc)) { if (ReadBackedPhasingWalker.processVariantInPhasing(vc)) {

View File

@ -40,9 +40,12 @@ public class Novelty extends VariantStratifier implements StandardStratification
allowableTypes.add(eval.getType()); allowableTypes.add(eval.getType());
} }
Collection<VariantContext> knownComps = tracker.getVariantContexts(ref, knownName, allowableTypes, ref.getLocus(), true, true); Collection<VariantContext> knownComps = tracker.getVariantContexts(ref, knownName, ref.getLocus(), true, true);
for ( VariantContext c : knownComps )
isNovel = knownComps.size() == 0; if ( allowableTypes.contains(c.getType()) ) {
isNovel = false;
break;
}
break; break;
} }

View File

@ -270,30 +270,7 @@ public class VariantEvalUtils {
Set<String> compNames, Set<String> compNames,
Set<String> evalNames, Set<String> evalNames,
boolean dynamicSelectTypes ) { boolean dynamicSelectTypes ) {
if ( dynamicSelectTypes ) { // todo -- this code is really conceptually broken return EnumSet.allOf(VariantContext.Type.class);
EnumSet<VariantContext.Type> allowableTypes = EnumSet.of(VariantContext.Type.NO_VARIATION);
if (tracker != null) {
Collection<VariantContext> evalvcs = tracker.getVariantContexts(ref, evalNames, null, ref.getLocus(), true, false);
for (VariantContext vc : evalvcs) {
allowableTypes.add(vc.getType());
}
if (allowableTypes.size() == 1) {
// We didn't find any variation in the eval track, so now let's look at the comp track for allowable types
Collection<VariantContext> compvcs = tracker.getVariantContexts(ref, compNames, null, ref.getLocus(), true, false);
for (VariantContext vc : compvcs) {
allowableTypes.add(vc.getType());
}
}
}
return allowableTypes;
} else {
return EnumSet.allOf(VariantContext.Type.class);
}
} }
/** /**
@ -359,7 +336,7 @@ public class VariantEvalUtils {
for (String trackName : trackNames) { for (String trackName : trackNames) {
HashMap<String, VariantContext> vcs = new HashMap<String, VariantContext>(); HashMap<String, VariantContext> vcs = new HashMap<String, VariantContext>();
Collection<VariantContext> contexts = tracker == null ? null : tracker.getVariantContexts(ref, trackName, allowableTypes, ref.getLocus(), true, true); Collection<VariantContext> contexts = tracker == null ? null : tracker.getVariantContexts(ref, trackName, ref.getLocus(), true, true);
VariantContext vc = contexts != null && contexts.size() == 1 ? contexts.iterator().next() : null; VariantContext vc = contexts != null && contexts.size() == 1 ? contexts.iterator().next() : null;
// First, filter the VariantContext to represent only the samples for evaluation // First, filter the VariantContext to represent only the samples for evaluation

View File

@ -168,7 +168,7 @@ public class ApplyRecalibration extends RodWalker<Integer, Integer> {
return 1; return 1;
} }
for( VariantContext vc : tracker.getVariantContexts(ref, inputNames, null, context.getLocation(), true, false) ) { for( VariantContext vc : tracker.getVariantContexts(ref, inputNames, context.getLocation(), true, false) ) {
if( vc != null ) { if( vc != null ) {
if( VariantRecalibrator.checkRecalibrationMode( vc, MODE ) && (vc.isNotFiltered() || ignoreInputFilterSet.containsAll(vc.getFilters())) ) { if( VariantRecalibrator.checkRecalibrationMode( vc, MODE ) && (vc.isNotFiltered() || ignoreInputFilterSet.containsAll(vc.getFilters())) ) {
String filterString = null; String filterString = null;

View File

@ -258,7 +258,7 @@ public class VariantDataManager {
datum.consensusCount = 0; datum.consensusCount = 0;
for( final TrainingSet trainingSet : trainingSets ) { for( final TrainingSet trainingSet : trainingSets ) {
for( final VariantContext trainVC : tracker.getVariantContexts( ref, trainingSet.name, null, context.getLocation(), false, false ) ) { for( final VariantContext trainVC : tracker.getVariantContexts( ref, trainingSet.name, context.getLocation(), false, false ) ) {
if( trainVC != null && trainVC.isNotFiltered() && trainVC.isVariant() && if( trainVC != null && trainVC.isNotFiltered() && trainVC.isVariant() &&
((evalVC.isSNP() && trainVC.isSNP()) || ((evalVC.isIndel()||evalVC.isMixed()) && (trainVC.isIndel()||trainVC.isMixed()))) && ((evalVC.isSNP() && trainVC.isSNP()) || ((evalVC.isIndel()||evalVC.isMixed()) && (trainVC.isIndel()||trainVC.isMixed()))) &&
(TRUST_ALL_POLYMORPHIC || !trainVC.hasGenotypes() || trainVC.isPolymorphic()) ) { (TRUST_ALL_POLYMORPHIC || !trainVC.hasGenotypes() || trainVC.isPolymorphic()) ) {

View File

@ -163,7 +163,7 @@ public class VariantRecalibrator extends RodWalker<ExpandingArrayList<VariantDat
return mapList; return mapList;
} }
for( final VariantContext vc : tracker.getVariantContexts(ref, inputNames, null, context.getLocation(), true, false) ) { for( final VariantContext vc : tracker.getVariantContexts(ref, inputNames, context.getLocation(), true, false) ) {
if( vc != null && ( vc.isNotFiltered() || ignoreInputFilterSet.containsAll(vc.getFilters()) ) ) { if( vc != null && ( vc.isNotFiltered() || ignoreInputFilterSet.containsAll(vc.getFilters()) ) ) {
if( checkRecalibrationMode( vc, VRAC.MODE ) ) { if( checkRecalibrationMode( vc, VRAC.MODE ) ) {
final VariantDatum datum = new VariantDatum(); final VariantDatum datum = new VariantDatum();

View File

@ -150,7 +150,7 @@ public class CombineVariants extends RodWalker<Integer, Integer> {
// get all of the vcf rods at this locus // get all of the vcf rods at this locus
// Need to provide reference bases to simpleMerge starting at current locus // Need to provide reference bases to simpleMerge starting at current locus
Collection<VariantContext> vcs = tracker.getAllVariantContexts(ref, null, context.getLocation(), true, false); Collection<VariantContext> vcs = tracker.getAllVariantContexts(ref, context.getLocation(), true, false);
if ( sitesOnlyVCF ) { if ( sitesOnlyVCF ) {
vcs = VariantContextUtils.sitesOnlyVariantContexts(vcs); vcs = VariantContextUtils.sitesOnlyVariantContexts(vcs);

View File

@ -85,7 +85,7 @@ public class FilterLiftedVariants extends RodWalker<Integer, Integer> {
if ( tracker == null ) if ( tracker == null )
return 0; return 0;
Collection<VariantContext> VCs = tracker.getVariantContexts(ref, "variant", null, context.getLocation(), true, false); Collection<VariantContext> VCs = tracker.getVariantContexts(ref, "variant", context.getLocation(), true, false);
for ( VariantContext vc : VCs ) for ( VariantContext vc : VCs )
filterAndWrite(ref.getBases(), vc); filterAndWrite(ref.getBases(), vc);

View File

@ -68,7 +68,7 @@ public class LeftAlignVariants extends RodWalker<Integer, Integer> {
if ( tracker == null ) if ( tracker == null )
return 0; return 0;
Collection<VariantContext> VCs = tracker.getVariantContexts(ref, "variant", null, context.getLocation(), true, false); Collection<VariantContext> VCs = tracker.getVariantContexts(ref, "variant", context.getLocation(), true, false);
int changedSites = 0; int changedSites = 0;
for ( VariantContext vc : VCs ) for ( VariantContext vc : VCs )

View File

@ -143,7 +143,7 @@ public class LiftoverVariants extends RodWalker<Integer, Integer> {
if ( tracker == null ) if ( tracker == null )
return 0; return 0;
Collection<VariantContext> VCs = tracker.getVariantContexts(ref, "variant", null, context.getLocation(), true, false); Collection<VariantContext> VCs = tracker.getVariantContexts(ref, "variant", context.getLocation(), true, false);
for ( VariantContext vc : VCs ) for ( VariantContext vc : VCs )
convertAndWrite(vc, ref); convertAndWrite(vc, ref);

View File

@ -97,7 +97,7 @@ public class RandomlySplitVariants extends RodWalker<Integer, Integer> {
if ( tracker == null ) if ( tracker == null )
return 0; return 0;
Collection<VariantContext> vcs = tracker.getVariantContexts(ref, INPUT_VARIANT_ROD_BINDING_NAME, null, context.getLocation(), true, false); Collection<VariantContext> vcs = tracker.getVariantContexts(ref, INPUT_VARIANT_ROD_BINDING_NAME, context.getLocation(), true, false);
for ( VariantContext vc : vcs ) { for ( VariantContext vc : vcs ) {
int random = GenomeAnalysisEngine.getRandomGenerator().nextInt(1000); int random = GenomeAnalysisEngine.getRandomGenerator().nextInt(1000);
if ( random < iFraction ) if ( random < iFraction )

View File

@ -317,7 +317,7 @@ public class SelectVariants extends RodWalker<Integer, Integer> {
if ( tracker == null ) if ( tracker == null )
return 0; return 0;
Collection<VariantContext> vcs = tracker.getVariantContexts(ref, variantRodName, null, context.getLocation(), true, false); Collection<VariantContext> vcs = tracker.getVariantContexts(ref, variantRodName, context.getLocation(), true, false);
if ( vcs == null || vcs.size() == 0) { if ( vcs == null || vcs.size() == 0) {
return 0; return 0;
@ -345,12 +345,12 @@ public class SelectVariants extends RodWalker<Integer, Integer> {
break; break;
} }
if (DISCORDANCE_ONLY) { if (DISCORDANCE_ONLY) {
Collection<VariantContext> compVCs = tracker.getVariantContexts(ref, discordanceRodName, null, context.getLocation(), true, false); Collection<VariantContext> compVCs = tracker.getVariantContexts(ref, discordanceRodName, context.getLocation(), true, false);
if (!isDiscordant(vc, compVCs)) if (!isDiscordant(vc, compVCs))
return 0; return 0;
} }
if (CONCORDANCE_ONLY) { if (CONCORDANCE_ONLY) {
Collection<VariantContext> compVCs = tracker.getVariantContexts(ref, concordanceRodName, null, context.getLocation(), true, false); Collection<VariantContext> compVCs = tracker.getVariantContexts(ref, concordanceRodName, context.getLocation(), true, false);
if (!isConcordant(vc, compVCs)) if (!isConcordant(vc, compVCs))
return 0; return 0;
} }

View File

@ -86,7 +86,7 @@ public class ValidateVariants extends RodWalker<Integer, Integer> {
if ( tracker == null ) if ( tracker == null )
return 0; return 0;
Collection<VariantContext> VCs = tracker.getVariantContexts(ref, "variant", null, context.getLocation(), true, false); Collection<VariantContext> VCs = tracker.getVariantContexts(ref, "variant", context.getLocation(), true, false);
for ( VariantContext vc : VCs ) for ( VariantContext vc : VCs )
validate(vc, tracker, ref); validate(vc, tracker, ref);

View File

@ -90,21 +90,23 @@ public class VariantsToVCF extends RodWalker<Integer, Integer> {
Collection<VariantContext> contexts = getVariantContexts(tracker, ref); Collection<VariantContext> contexts = getVariantContexts(tracker, ref);
for ( VariantContext vc : contexts ) { for ( VariantContext vc : contexts ) {
Map<String, Object> attrs = new HashMap<String, Object>(vc.getAttributes()); if ( ALLOWED_VARIANT_CONTEXT_TYPES.contains(vc.getType()) ) {
if ( rsID != null && !vc.hasID() ) { Map<String, Object> attrs = new HashMap<String, Object>(vc.getAttributes());
attrs.put(VariantContext.ID_KEY, rsID); if ( rsID != null && !vc.hasID() ) {
vc = VariantContext.modifyAttributes(vc, attrs); attrs.put(VariantContext.ID_KEY, rsID);
} vc = VariantContext.modifyAttributes(vc, attrs);
}
// set the appropriate sample name if necessary // set the appropriate sample name if necessary
if ( sampleName != null && vc.hasGenotypes() && vc.hasGenotype(INPUT_ROD_NAME) ) { if ( sampleName != null && vc.hasGenotypes() && vc.hasGenotype(INPUT_ROD_NAME) ) {
Genotype g = Genotype.modifyName(vc.getGenotype(INPUT_ROD_NAME), sampleName); Genotype g = Genotype.modifyName(vc.getGenotype(INPUT_ROD_NAME), sampleName);
Map<String, Genotype> genotypes = new HashMap<String, Genotype>(); Map<String, Genotype> genotypes = new HashMap<String, Genotype>();
genotypes.put(sampleName, g); genotypes.put(sampleName, g);
vc = VariantContext.modifyGenotypes(vc, genotypes); vc = VariantContext.modifyGenotypes(vc, genotypes);
} }
writeRecord(vc, tracker, ref.getBase()); writeRecord(vc, tracker, ref.getBase());
}
} }
return 1; return 1;
@ -160,7 +162,7 @@ public class VariantsToVCF extends RodWalker<Integer, Integer> {
} }
// for everything else, we can just convert to VariantContext // for everything else, we can just convert to VariantContext
return tracker.getVariantContexts(ref, INPUT_ROD_NAME, ALLOWED_VARIANT_CONTEXT_TYPES, ref.getLocus(), true, false); return tracker.getVariantContexts(ref, INPUT_ROD_NAME, ref.getLocus(), true, false);
} }
private DbSNPFeature getDbsnpFeature(String rsID) { private DbSNPFeature getDbsnpFeature(String rsID) {