diff --git a/public/java/src/org/broadinstitute/sting/commandline/VariantContextRodBinding.java b/public/java/src/org/broadinstitute/sting/commandline/VariantContextRodBinding.java index a01149cb0..a1bc05ef6 100644 --- a/public/java/src/org/broadinstitute/sting/commandline/VariantContextRodBinding.java +++ b/public/java/src/org/broadinstitute/sting/commandline/VariantContextRodBinding.java @@ -1,82 +1,78 @@ -///* -// * Copyright (c) 2011, The Broad Institute -// * -// * Permission is hereby granted, free of charge, to any person -// * obtaining a copy of this software and associated documentation -// * files (the "Software"), to deal in the Software without -// * restriction, including without limitation the rights to use, -// * copy, modify, merge, publish, distribute, sublicense, and/or sell -// * copies of the Software, and to permit persons to whom the -// * Software is furnished to do so, subject to the following -// * conditions: -// * -// * The above copyright notice and this permission notice shall be -// * included in all copies or substantial portions of the Software. -// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -// * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -// * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -// * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -// * OTHER DEALINGS IN THE SOFTWARE. -// */ -// -//package org.broadinstitute.sting.commandline; -// -//import org.broadinstitute.sting.gatk.contexts.ReferenceContext; -//import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; -//import org.broadinstitute.sting.utils.GenomeLoc; -//import org.broadinstitute.sting.utils.variantcontext.VariantContext; -// -//import java.util.Collection; -// -///** -// * A RodBinding representing a walker argument that gets bound to a ROD track containing VariantContexts -// */ -//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) { -// super(variableName, sourceFile, parser); -// } -// -// /** -// * Forwarding method to identical tracker method -// */ -// public Collection getVariantContexts(final RefMetaDataTracker tracker, -// final ReferenceContext ref, -// final GenomeLoc curLocation, -// final boolean requireStartHere, -// final boolean takeFirstOnly ) { -// return tracker.getVariantContexts(ref, variableName, curLocation, requireStartHere, takeFirstOnly); -// } -// -// /** -// * Forwarding method to identical tracker method -// * @param tracker -// * @param ref -// * @param curLocation -// * @param requireStartHere -// * @return -// */ -// public VariantContext getVariantContext(final RefMetaDataTracker tracker, -// final ReferenceContext ref, -// final GenomeLoc curLocation, -// final boolean requireStartHere ) { -// return tracker.getVariantContext(ref, variableName, curLocation, requireStartHere); -// } -// -// /** -// * Forwarding method to identical tracker method -// */ -// public VariantContext getVariantContext(final RefMetaDataTracker tracker, -// final ReferenceContext ref, -// final GenomeLoc curLocation) { -// return tracker.getVariantContext(ref, variableName, curLocation); -// } -//} +/* +* Copyright (c) 2011, The Broad Institute +* +* Permission is hereby granted, free of charge, to any person +* obtaining a copy of this software and associated documentation +* files (the "Software"), to deal in the Software without +* restriction, including without limitation the rights to use, +* copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following +* conditions: +* +* The above copyright notice and this permission notice shall be +* included in all copies or substantial portions of the Software. +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +* OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.broadinstitute.sting.commandline; + +import org.broadinstitute.sting.gatk.contexts.ReferenceContext; +import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; +import org.broadinstitute.sting.utils.GenomeLoc; +import org.broadinstitute.sting.utils.variantcontext.VariantContext; + +import java.util.Collection; + +/** +* A RodBinding representing a walker argument that gets bound to a ROD track containing VariantContexts +*/ +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) { + super(VariantContext.class, variableName, sourceFile, parser); + } + + /** + * Forwarding method to identical tracker method + */ + public Collection getVariantContexts(final RefMetaDataTracker tracker, + final GenomeLoc curLocation, + final boolean requireStartHere, + final boolean takeFirstOnly ) { + return tracker.getVariantContexts(variableName, curLocation, requireStartHere, takeFirstOnly); + } + + /** + * Forwarding method to identical tracker method + * @param tracker + * @param curLocation + * @param requireStartHere + * @return + */ + public VariantContext getVariantContext(final RefMetaDataTracker tracker, + final GenomeLoc curLocation, + final boolean requireStartHere ) { + return tracker.getVariantContext(variableName, curLocation, requireStartHere); + } + + /** + * Forwarding method to identical tracker method + */ + public VariantContext getVariantContext(final RefMetaDataTracker tracker, + final GenomeLoc curLocation) { + return tracker.getVariantContext(variableName, curLocation); + } +} diff --git a/public/java/src/org/broadinstitute/sting/gatk/datasources/providers/ManagingReferenceOrderedView.java b/public/java/src/org/broadinstitute/sting/gatk/datasources/providers/ManagingReferenceOrderedView.java index 223659a46..f75f358e1 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/datasources/providers/ManagingReferenceOrderedView.java +++ b/public/java/src/org/broadinstitute/sting/gatk/datasources/providers/ManagingReferenceOrderedView.java @@ -1,5 +1,6 @@ package org.broadinstitute.sting.gatk.datasources.providers; +import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.datasources.rmd.ReferenceOrderedDataSource; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.refdata.utils.LocationAwareSeekableRODIterator; @@ -49,8 +50,8 @@ public class ManagingReferenceOrderedView implements ReferenceOrderedView { * @param loc Locus at which to track. * @return A tracker containing information about this locus. */ - public RefMetaDataTracker getReferenceOrderedDataAtLocus( GenomeLoc loc ) { - RefMetaDataTracker tracks = new RefMetaDataTracker(states.size()); + public RefMetaDataTracker getReferenceOrderedDataAtLocus( GenomeLoc loc, ReferenceContext referenceContext ) { + RefMetaDataTracker tracks = new RefMetaDataTracker(states.size(), referenceContext); for ( ReferenceOrderedDataState state: states ) tracks.bind( state.dataSource.getName(), state.iterator.seekForward(loc) ); return tracks; diff --git a/public/java/src/org/broadinstitute/sting/gatk/datasources/providers/ReferenceOrderedView.java b/public/java/src/org/broadinstitute/sting/gatk/datasources/providers/ReferenceOrderedView.java index 2d46a85ac..939cbfe35 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/datasources/providers/ReferenceOrderedView.java +++ b/public/java/src/org/broadinstitute/sting/gatk/datasources/providers/ReferenceOrderedView.java @@ -1,8 +1,9 @@ package org.broadinstitute.sting.gatk.datasources.providers; +import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.utils.GenomeLoc; public interface ReferenceOrderedView extends View { - RefMetaDataTracker getReferenceOrderedDataAtLocus( GenomeLoc loc ); + RefMetaDataTracker getReferenceOrderedDataAtLocus( GenomeLoc loc, ReferenceContext refContext ); } diff --git a/public/java/src/org/broadinstitute/sting/gatk/datasources/providers/RodLocusView.java b/public/java/src/org/broadinstitute/sting/gatk/datasources/providers/RodLocusView.java index 50c10c26e..3db5bd19a 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/datasources/providers/RodLocusView.java +++ b/public/java/src/org/broadinstitute/sting/gatk/datasources/providers/RodLocusView.java @@ -26,6 +26,7 @@ package org.broadinstitute.sting.gatk.datasources.providers; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; +import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.datasources.rmd.ReferenceOrderedDataSource; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.refdata.utils.LocationAwareSeekableRODIterator; @@ -45,7 +46,8 @@ public class RodLocusView extends LocusView implements ReferenceOrderedView { */ private RODMergingIterator rodQueue = null; - RefMetaDataTracker tracker = null; + Collection allTracksHere; + GenomeLoc lastLoc = null; RODRecordList interval = null; @@ -98,8 +100,17 @@ public class RodLocusView extends LocusView implements ReferenceOrderedView { //throw new StingException("RodLocusView currently disabled"); } - public RefMetaDataTracker getReferenceOrderedDataAtLocus( GenomeLoc loc ) { - return tracker; + public RefMetaDataTracker getReferenceOrderedDataAtLocus( GenomeLoc loc, ReferenceContext referenceContext ) { + RefMetaDataTracker t = new RefMetaDataTracker(allTracksHere.size(), referenceContext); + for ( RODRecordList track : allTracksHere ) { + if ( ! t.hasValues(track.getName()) ) + t.bind(track.getName(), track); + } + + // special case the interval again -- add it into the ROD + if ( interval != null ) { t.bind(interval.getName(), interval); } + + return t; } public boolean hasNext() { @@ -122,10 +133,7 @@ public class RodLocusView extends LocusView implements ReferenceOrderedView { if ( DEBUG ) System.out.printf("In RodLocusView.next(): creating tracker...%n"); - // Update the tracker here for use - Collection allTracksHere = getSpanningTracks(datum); - tracker = createTracker(allTracksHere); - + allTracksHere = getSpanningTracks(datum); GenomeLoc rodSite = datum.getLocation(); GenomeLoc site = genomeLocParser.createGenomeLoc( rodSite.getContig(), rodSite.getStart(), rodSite.getStart()); @@ -137,19 +145,6 @@ public class RodLocusView extends LocusView implements ReferenceOrderedView { return new AlignmentContext(site, new ReadBackedPileupImpl(site), skippedBases); } - private RefMetaDataTracker createTracker( Collection allTracksHere ) { - RefMetaDataTracker t = new RefMetaDataTracker(allTracksHere.size()); - for ( RODRecordList track : allTracksHere ) { - if ( ! t.hasValues(track.getName()) ) - t.bind(track.getName(), track); - } - - // special case the interval again -- add it into the ROD - if ( interval != null ) { t.bind(interval.getName(), interval); } - - return t; - } - private Collection getSpanningTracks(RODRecordList marker) { return rodQueue.allElementsLTE(marker); } @@ -197,10 +192,6 @@ public class RodLocusView extends LocusView implements ReferenceOrderedView { return getSkippedBases(getLocOneBeyondShard()); } - public RefMetaDataTracker getTracker() { - return tracker; - } - /** * Closes the current view. */ @@ -209,6 +200,6 @@ public class RodLocusView extends LocusView implements ReferenceOrderedView { state.dataSource.close( state.iterator ); rodQueue = null; - tracker = null; + allTracksHere = null; } } \ No newline at end of file diff --git a/public/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java b/public/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java index 40cf4cbd4..808ad5430 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java @@ -4,6 +4,7 @@ import org.apache.log4j.Logger; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature; import org.broadinstitute.sting.gatk.refdata.utils.RODRecordList; +import org.broadinstitute.sting.gatk.walkers.Reference; import org.broadinstitute.sting.utils.GenomeLoc; import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; import org.broadinstitute.sting.utils.exceptions.UserException; @@ -18,7 +19,7 @@ import java.util.*; * The standard interaction model is: * * Traversal system arrives at a site, which has a bunch of RMDs covering it -Genotype * Traversal calls tracker.bind(name, RMD) for each RMDs in RMDs + Genotype * Traversal calls tracker.bind(name, RMD) for each RMDs in RMDs * Traversal passes tracker to the walker * walker calls lookup(name, default) to obtain the RMDs values at this site, or default if none was * bound at this site. @@ -29,15 +30,83 @@ Genotype * Traversal calls tracker.bind(name, RMD) for each RMDs in RMDs */ public class RefMetaDataTracker { final Map map; + final ReferenceContext ref; protected static Logger logger = Logger.getLogger(RefMetaDataTracker.class); - public RefMetaDataTracker(int nBindings) { + public RefMetaDataTracker(int nBindings, ReferenceContext ref) { + this.ref = ref; if ( nBindings == 0 ) map = Collections.emptyMap(); else map = new HashMap(nBindings); } + + // ------------------------------------------------------------------------------------------ + // + // + // Special ENGINE interaction functions + // + // + // ------------------------------------------------------------------------------------------ + + /** + * 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. + * + * DO NOT USE THIS FUNCTION UNLESS YOU ARE THE GATK ENGINE + * + * @param name the name of the track + * @param rod the collection of RMD data + */ + public void bind(final String name, RODRecordList rod) { + //logger.debug(String.format("Binding %s to %s", name, rod)); + map.put(canonicalName(name), maybeConvertToVariantContext(rod)); + } + + /** + * A private converter that transforms a RODRecordList of objects of type X into + * a list of VariantContexts, if possible. + * + * TODO: should be removed when Features like dbsnp and hapmap produce VCs directly + * + * @param bindings + * @return + */ + private final RODRecordList maybeConvertToVariantContext(RODRecordList bindings) { + List values = new ArrayList(bindings.size()); + + for ( GATKFeature rec : bindings ) { + if ( VariantContextAdaptors.canBeConvertedToVariantContext(rec.getUnderlyingObject()) ) { + final VariantContext vc = VariantContextAdaptors.toVariantContext(bindings.getName(), rec.getUnderlyingObject(), ref); + if ( vc != null ) // it's possible that the conversion failed, but we continue along anyway + values.add(new GATKFeature.TribbleGATKFeature(ref.getGenomeLocParser(), vc, rec.getName())); + } + } + + return new RODRecordListImpl(bindings.getName(), values, bindings.getLocation()); + } + +// /** +// * Temporary setting for putting a reference context into the system. +// * +// * DO NOT USE THIS FUNCTION UNLESS YOU ARE THE GATK ENGINE +// * +// * @param ref +// */ +// public void setRef(final ReferenceContext ref) { +// this.ref = ref; +// } + + + // ------------------------------------------------------------------------------------------ + // + // + // Generic accessors + // + // + // ------------------------------------------------------------------------------------------ + /** * No-assumption version of getValues(name, class). Returns Objects. */ @@ -60,18 +129,11 @@ public class RefMetaDataTracker { if (list == null) return Collections.emptyList(); else { - List objects = new ArrayList(); - for (GATKFeature feature : list) { - final Object obj = feature.getUnderlyingObject(); - if (!(clazz.isAssignableFrom(obj.getClass()))) - throw new UserException.CommandLineException("Unable to case track named " + name + " to type of " + clazz.toString() - + " it's of type " + obj.getClass()); - objects.add((T)obj); - } - return objects; + return addValues(name, clazz, new ArrayList(), list, list.getLocation(), false, false); } } + /** * get a singleton record, given the name and a type. This function will return the first record at the * current position seen. The object is cast into a type clazz, or thoses an error if this isn't possible. @@ -79,7 +141,7 @@ public class RefMetaDataTracker { * * 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 * picked may change from time to time! BE WARNED! - * + * * @param name the name of the track * @param clazz the underlying type to return * @param the type to parameterize on, matching the clazz argument @@ -116,7 +178,7 @@ public class RefMetaDataTracker { * * @return collection of all rods */ - public Collection getAllValuesAsGATKFeatures() { + public List getAllValuesAsGATKFeatures() { List l = new ArrayList(); for ( RODRecordList rl : map.values() ) { if ( rl != null ) @@ -125,7 +187,7 @@ public class RefMetaDataTracker { return l; } - /** + /** * get all the GATK features associated with a specific track name * @param name the name of the track we're looking for * @return a list of GATKFeatures for the target rmd @@ -141,9 +203,9 @@ public class RefMetaDataTracker { * Get all of the RMD tracks at the current site. Each track is returned as a single compound * object (RODRecordList) that may contain multiple RMD records associated with the current site. * - * @return collection of all tracks + * @return List of all tracks */ - public Collection getBoundRodTracks() { + public List getBoundRodTracks() { LinkedList bound = new LinkedList(); for ( RODRecordList value : map.values() ) { @@ -167,21 +229,6 @@ public class RefMetaDataTracker { return n; } - - /** - * 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. - * - * DO NOT USE THIS FUNCTION UNLESS YOU ARE THE GATK ENGINE - * - * @param name the name of the track - * @param rod the collection of RMD data - */ - public void bind(final String name, RODRecordList rod) { - //logger.debug(String.format("Binding %s to %s", name, rod)); - map.put(canonicalName(name), rod); - } - // ------------------------------------------------------------------------------------------ // // @@ -195,22 +242,20 @@ public class RefMetaDataTracker { * of entries per ROD. * The name of each VariantContext corresponds to the ROD name. * - * @param ref reference context * @return variant context */ - public Collection getAllVariantContexts(final ReferenceContext ref) { - return getAllVariantContexts(ref, null, false, false); + public List getAllVariantContexts() { + return getAllVariantContexts(null, false, false); } /** * Returns all of the variant contexts that start at the current location - * @param ref + * * @param curLocation * @return */ - public Collection getAllVariantContexts(final ReferenceContext ref, - final GenomeLoc curLocation) { - return getAllVariantContexts(ref, curLocation, true, false); + public List getAllVariantContexts(final GenomeLoc curLocation) { + return getAllVariantContexts(curLocation, true, false); } /** @@ -224,20 +269,19 @@ public class RefMetaDataTracker { * * The name of each VariantContext corresponds to the ROD name. * - * @param ref reference context + * * @param curLocation location * @param requireStartHere do we require the rod to start at this location? * @param takeFirstOnly do we take the first rod only? * @return variant context */ - public Collection getAllVariantContexts(final ReferenceContext ref, - final GenomeLoc curLocation, - final boolean requireStartHere, - final boolean takeFirstOnly ) { + public List getAllVariantContexts(final GenomeLoc curLocation, + final boolean requireStartHere, + final boolean takeFirstOnly) { List contexts = new ArrayList(); for ( RODRecordList rodList : getBoundRodTracks() ) { - addVariantContexts(contexts, rodList, ref, curLocation, requireStartHere, takeFirstOnly); + addVariantContexts(contexts, rodList, curLocation, requireStartHere, takeFirstOnly); } return contexts; @@ -248,33 +292,31 @@ public class RefMetaDataTracker { * * see getVariantContexts for more information. * - * @param ref ReferenceContext to enable conversion to variant context + * * @param name name * @param curLocation location * @param requireStartHere do we require the rod to start at this location? * @param takeFirstOnly do we take the first rod only? * @return variant context */ - public Collection getVariantContexts(final ReferenceContext ref, - final String name, - final GenomeLoc curLocation, - final boolean requireStartHere, - final boolean takeFirstOnly ) { - return getVariantContexts(ref, Arrays.asList(name), curLocation, requireStartHere, takeFirstOnly); + public List getVariantContexts(final String name, + final GenomeLoc curLocation, + final boolean requireStartHere, + final boolean takeFirstOnly) { + return getVariantContexts(Arrays.asList(name), curLocation, requireStartHere, takeFirstOnly); } - public Collection getVariantContexts(final ReferenceContext ref, - final Collection names, - final GenomeLoc curLocation, - final boolean requireStartHere, - final boolean takeFirstOnly ) { - Collection contexts = new ArrayList(); + public List getVariantContexts(final Collection names, + final GenomeLoc curLocation, + final boolean requireStartHere, + final boolean takeFirstOnly) { + List contexts = new ArrayList(); for ( String name : names ) { RODRecordList rodList = getTrackDataByName(name); // require that the name is an exact match if ( rodList != null ) - addVariantContexts(contexts, rodList, ref, curLocation, requireStartHere, takeFirstOnly ); + addVariantContexts(contexts, rodList, curLocation, requireStartHere, takeFirstOnly ); } return contexts; @@ -284,16 +326,16 @@ public class RefMetaDataTracker { * Gets the variant context associated with name, and assumes the system only has a single bound track at this location. Throws an exception if not. * see getVariantContexts for more information. * + * * @param name name * @param curLocation location * @param requireStartHere do we require the rod to start at this location? * @return variant context */ - public VariantContext getVariantContext(final ReferenceContext ref, - final String name, + public VariantContext getVariantContext(final String name, final GenomeLoc curLocation, - final boolean requireStartHere ) { - Collection contexts = getVariantContexts(ref, name, curLocation, requireStartHere, false ); + final boolean requireStartHere) { + List contexts = getVariantContexts(name, curLocation, requireStartHere, false ); if ( contexts.size() > 1 ) throw new ReviewedStingException("Requested a single VariantContext object for track " + name + " but multiple variants were present at position " + curLocation); @@ -306,46 +348,53 @@ public class RefMetaDataTracker { /** * Very simple accessor that gets the first (and only!) VC associated with name at the current location, or * null if there's no binding here. - * - * @param ref + * + * * @param name * @param curLocation * @return */ - public VariantContext getVariantContext(final ReferenceContext ref, - final String name, + public VariantContext getVariantContext(final String name, final GenomeLoc curLocation) { - return getVariantContext(ref, name, curLocation, true); + return getVariantContext(name, curLocation, true); } - private void addVariantContexts(final Collection contexts, + private void addVariantContexts(final List contexts, final RODRecordList rodList, - final ReferenceContext ref, final GenomeLoc curLocation, final boolean requireStartHere, final boolean takeFirstOnly ) { + addValues("xxx", VariantContext.class, contexts, rodList, curLocation, requireStartHere, takeFirstOnly); + } + + private static List addValues(final String name, + final Class type, + final List values, + final RODRecordList rodList, + final GenomeLoc curLocation, + final boolean requireStartHere, + final boolean takeFirstOnly ) { for ( GATKFeature rec : rodList ) { - if ( VariantContextAdaptors.canBeConvertedToVariantContext(rec.getUnderlyingObject()) ) { - // ok, we might actually be able to turn this record in a variant context - final VariantContext vc = VariantContextAdaptors.toVariantContext(rodList.getName(), rec.getUnderlyingObject(), ref); + if ( ! requireStartHere || rec.getLocation().getStart() == curLocation.getStart() ) { // ok, we are going to keep this thing + Object obj = rec.getUnderlyingObject(); + if (!(type.isAssignableFrom(obj.getClass()))) + throw new UserException.CommandLineException("Unable to cast track named " + name + " to type of " + type.toString() + + " it's of type " + obj.getClass()); - if ( vc == null ) // sometimes the track has odd stuff in it that can't be converted - continue; + values.add((T)obj); - if ( ! requireStartHere || rec.getLocation().getStart() == curLocation.getStart() ) { // ok, we are going to keep this thing - contexts.add(vc); - - if ( takeFirstOnly ) - // we only want the first passing instance, so break the loop over records in rodList - break; - } + if ( takeFirstOnly ) + // we only want the first passing instance, so break the loop over records in rodList + break; } } + + return values; } /** * Finds the reference metadata track named 'name' and returns all ROD records from that track associated - * with the current site as a RODRecordList collection object. If no data track with specified name is available, + * with the current site as a RODRecordList List object. If no data track with specified name is available, * returns defaultValue wrapped as RODRecordList object. NOTE: if defaultValue is null, it will be wrapped up * with track name set to 'name' and location set to null; otherwise the wrapper object will have name and * location set to defaultValue.getName() and defaultValue.getLocation(), respectively (use caution, diff --git a/public/java/src/org/broadinstitute/sting/gatk/traversals/TraverseLoci.java b/public/java/src/org/broadinstitute/sting/gatk/traversals/TraverseLoci.java index 232989fb0..08eb8f1d4 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/traversals/TraverseLoci.java +++ b/public/java/src/org/broadinstitute/sting/gatk/traversals/TraverseLoci.java @@ -65,13 +65,13 @@ public class TraverseLoci extends TraversalEngine,Locu referenceView.expandBoundsToAccomodateLoc(location); } - // Iterate forward to get all reference ordered data covering this location - final RefMetaDataTracker tracker = referenceOrderedDataView.getReferenceOrderedDataAtLocus(locus.getLocation()); - // create reference context. Note that if we have a pileup of "extended events", the context will // hold the (longest) stretch of deleted reference bases (if deletions are present in the pileup). ReferenceContext refContext = referenceView.getReferenceContext(location); + // Iterate forward to get all reference ordered data covering this location + final RefMetaDataTracker tracker = referenceOrderedDataView.getReferenceOrderedDataAtLocus(locus.getLocation(), refContext); + final boolean keepMeP = walker.filter(tracker, refContext, locus); if (keepMeP) { M x = walker.map(tracker, refContext, locus); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java index 207c4118d..932317700 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java @@ -202,7 +202,7 @@ public class VariantAnnotator extends RodWalker { if ( tracker == null ) return 0; - Collection VCs = tracker.getVariantContexts(ref, "variant", context.getLocation(), true, false); + Collection VCs = tracker.getVariantContexts("variant", context.getLocation(), true, false); if ( VCs.size() == 0 ) return 0; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java index 73249d343..9dc0bbfe6 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotatorEngine.java @@ -203,7 +203,7 @@ public class VariantAnnotatorEngine { infoAnnotations.put(VariantContext.ID_KEY, rsID); } else { boolean overlapsComp = false; - for ( VariantContext comp : tracker.getVariantContexts(ref, dbSet.getKey(), ref.getLocus(), false, false) ) { + for ( VariantContext comp : tracker.getVariantContexts(dbSet.getKey(), ref.getLocus(), false, false) ) { if ( !comp.isFiltered() ) { overlapsComp = true; break; @@ -216,7 +216,7 @@ public class VariantAnnotatorEngine { private void annotateExpressions(RefMetaDataTracker tracker, ReferenceContext ref, Map infoAnnotations) { for ( VAExpression expression : requestedExpressions ) { - Collection VCs = tracker.getVariantContexts(ref, expression.bindingName, ref.getLocus(), false, true); + Collection VCs = tracker.getVariantContexts(expression.bindingName, ref.getLocus(), false, true); if ( VCs.size() == 0 ) continue; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/GenomicAnnotator.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/GenomicAnnotator.java index 82d2af283..78057849c 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/GenomicAnnotator.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/annotator/genomicannotator/GenomicAnnotator.java @@ -244,7 +244,7 @@ public class GenomicAnnotator extends RodWalker implements Tre return 0; Set results = new LinkedHashSet(); - for (VariantContext vc : tracker.getVariantContexts(ref, "variant", context.getLocation(), true, false)) { + for (VariantContext vc : tracker.getVariantContexts("variant", context.getLocation(), true, false)) { if ( (vc.isFiltered() && IGNORE_FILTERED_SITES) || (vc.isVariant() && !vc.isBiallelic()) ) { results.add(vc); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/BeagleOutputToVCFWalker.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/BeagleOutputToVCFWalker.java index 5499c99b0..19eafc872 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/BeagleOutputToVCFWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/BeagleOutputToVCFWalker.java @@ -119,9 +119,9 @@ public class BeagleOutputToVCFWalker extends RodWalker { return 0; GenomeLoc loc = context.getLocation(); - VariantContext vc_input = tracker.getVariantContext(ref,INPUT_ROD_NAME, loc, true); + VariantContext vc_input = tracker.getVariantContext(INPUT_ROD_NAME, loc, true); - VariantContext vc_comp = tracker.getVariantContext(ref,COMP_ROD_NAME, loc, true); + VariantContext vc_comp = tracker.getVariantContext(COMP_ROD_NAME, loc, true); if ( vc_input == null ) return 0; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/ProduceBeagleInputWalker.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/ProduceBeagleInputWalker.java index b20b44cd6..353ebb82a 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/ProduceBeagleInputWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/ProduceBeagleInputWalker.java @@ -121,8 +121,8 @@ public class ProduceBeagleInputWalker extends RodWalker { public Integer map( RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context ) { if( tracker != null ) { GenomeLoc loc = context.getLocation(); - VariantContext variant_eval = tracker.getVariantContext(ref, ROD_NAME, loc, true); - VariantContext validation_eval = tracker.getVariantContext(ref,VALIDATION_ROD_NAME, loc, true); + VariantContext variant_eval = tracker.getVariantContext(ROD_NAME, loc, true); + VariantContext validation_eval = tracker.getVariantContext(VALIDATION_ROD_NAME, loc, true); if ( goodSite(variant_eval,validation_eval) ) { if ( useValidation(validation_eval, ref) ) { diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/VariantsToBeagleUnphasedWalker.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/VariantsToBeagleUnphasedWalker.java index 41b35321e..ee3dfb1df 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/VariantsToBeagleUnphasedWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/beagle/VariantsToBeagleUnphasedWalker.java @@ -102,7 +102,7 @@ public class VariantsToBeagleUnphasedWalker extends RodWalker public Integer map( RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context ) { if( tracker != null ) { GenomeLoc loc = context.getLocation(); - VariantContext vc = tracker.getVariantContext(ref, ROD_NAME, loc, true); + VariantContext vc = tracker.getVariantContext(ROD_NAME, loc, true); if ( ProduceBeagleInputWalker.canBeOutputToBeagle(vc) ) { // do we want to hold back this site? diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/fasta/FastaAlternateReferenceWalker.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/fasta/FastaAlternateReferenceWalker.java index efc101618..665ac539c 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/fasta/FastaAlternateReferenceWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/fasta/FastaAlternateReferenceWalker.java @@ -57,7 +57,7 @@ public class FastaAlternateReferenceWalker extends FastaReferenceWalker { String refBase = String.valueOf((char)ref.getBase()); - Collection vcs = tracker.getAllVariantContexts(ref); + Collection vcs = tracker.getAllVariantContexts(); // Check to see if we have a called snp for ( VariantContext vc : vcs ) { diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java index 2e96fc172..61991db2d 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java @@ -149,7 +149,7 @@ public class VariantFiltrationWalker extends RodWalker { if ( tracker == null ) return 0; - Collection VCs = tracker.getVariantContexts(ref, INPUT_VARIANT_ROD_BINDING_NAME, context.getLocation(), true, false); + Collection VCs = tracker.getVariantContexts(INPUT_VARIANT_ROD_BINDING_NAME, context.getLocation(), true, false); // is there a SNP mask present? boolean hasMask = tracker.getValues("mask").size() > 0; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/IndelGenotypeLikelihoodsCalculationModel.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/IndelGenotypeLikelihoodsCalculationModel.java index c76fea34f..54bb888c8 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/IndelGenotypeLikelihoodsCalculationModel.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/IndelGenotypeLikelihoodsCalculationModel.java @@ -321,7 +321,7 @@ public class IndelGenotypeLikelihoodsCalculationModel extends GenotypeLikelihood haplotypeMap.clear(); if (getAlleleListFromVCF) { - for( final VariantContext vc_input : tracker.getVariantContexts(ref, "alleles", ref.getLocus(), false, false) ) { + for( final VariantContext vc_input : tracker.getVariantContexts("alleles", ref.getLocus(), false, false) ) { if( vc_input != null && allowableTypes.contains(vc_input.getType()) && ref.getLocus().getStart() == vc_input.getStart()) { diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/SNPGenotypeLikelihoodsCalculationModel.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/SNPGenotypeLikelihoodsCalculationModel.java index 30a86249d..4f784d37a 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/SNPGenotypeLikelihoodsCalculationModel.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/SNPGenotypeLikelihoodsCalculationModel.java @@ -63,7 +63,7 @@ public class SNPGenotypeLikelihoodsCalculationModel extends GenotypeLikelihoodsC VariantContext vc = null; // search for usable record - for( final VariantContext vc_input : tracker.getVariantContexts(ref, "alleles", ref.getLocus(), true, false) ) { + for( final VariantContext vc_input : tracker.getVariantContexts("alleles", ref.getLocus(), true, false) ) { if ( vc_input != null && ! vc_input.isFiltered() && (! requireSNP || vc_input.isSNP() )) { if ( vc == null ) { vc = vc_input; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UGCallVariants.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UGCallVariants.java index 6e03088e7..1c5d55225 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UGCallVariants.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UGCallVariants.java @@ -96,7 +96,7 @@ public class UGCallVariants extends RodWalker { List VCs = new ArrayList(); for ( String name : trackNames ) { - Collection vc = tracker.getVariantContexts(ref, name, context.getLocation(), true, true); + Collection vc = tracker.getVariantContexts(name, context.getLocation(), true, true); VCs.addAll(vc); } diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java index 488e37f26..38a1dcb8d 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/indels/RealignerTargetCreator.java @@ -110,7 +110,7 @@ public class RealignerTargetCreator extends RodWalker { @Argument(fullName = "emitOnlyMNPs", shortName = "emitOnlyMNPs", doc = "Only output MNP records; [default:false]", required = false) protected boolean emitOnlyMNPs = false; - private LinkedList rodNames = null; + private String rodName = "variant"; private GenomeLocParser locParser = null; private TreeMap> MNPstartToStops = null; // Must be TreeMap sorted by START sites! @@ -105,9 +105,6 @@ public class AnnotateMNPsWalker extends RodWalker { protected final static String REFSEQ_HAS_MULT_AA_CHANGES = "alleleHasMultAAchanges"; public void initialize() { - rodNames = new LinkedList(); - rodNames.add(VARIANT_ROD_NAME); - locParser = getToolkit().getGenomeLocParser(); MNPstartToStops = new TreeMap>(); // sorted by start sites @@ -125,8 +122,8 @@ public class AnnotateMNPsWalker extends RodWalker { hInfo.addAll(VCFUtils.getHeaderFields(getToolkit())); hInfo.add(new VCFHeaderLine("reference", getToolkit().getArguments().referenceFile.getName())); - Map rodNameToHeader = getVCFHeadersFromRods(getToolkit(), rodNames); - writer.writeHeader(new VCFHeader(hInfo, new TreeSet(rodNameToHeader.get(rodNames.get(0)).getGenotypeSamples()))); + Map rodNameToHeader = getVCFHeadersFromRods(getToolkit(), Arrays.asList(rodName)); + writer.writeHeader(new VCFHeader(hInfo, new TreeSet(rodNameToHeader.get(rodName).getGenotypeSamples()))); } public boolean generateExtendedEvents() { @@ -155,7 +152,7 @@ public class AnnotateMNPsWalker extends RodWalker { boolean requireStartHere = false; // see EVERY site of the MNP boolean takeFirstOnly = false; // take as many entries as the VCF file has - for (VariantContext vc : tracker.getVariantContexts(ref, rodNames, context.getLocation(), requireStartHere, takeFirstOnly)) { + for (VariantContext vc : tracker.getVariantContexts(rodName, context.getLocation(), requireStartHere, takeFirstOnly)) { GenomeLoc vcLoc = VariantContextUtils.getLocation(locParser, vc); boolean atStartOfVc = curLocus.getStart() == vcLoc.getStart(); boolean atEndOfVc = curLocus.getStart() == vcLoc.getStop(); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/MergeAndMatchHaplotypes.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/MergeAndMatchHaplotypes.java index a4b49b8ff..ae7782434 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/MergeAndMatchHaplotypes.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/MergeAndMatchHaplotypes.java @@ -44,8 +44,8 @@ public class MergeAndMatchHaplotypes extends RodWalker { @Override public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { if (tracker != null) { - Collection pbts = tracker.getVariantContexts(ref, "pbt", ref.getLocus(), true, true); - Collection rbps = tracker.getVariantContexts(ref, "rbp", ref.getLocus(), true, true); + Collection pbts = tracker.getVariantContexts("pbt", ref.getLocus(), true, true); + Collection rbps = tracker.getVariantContexts("rbp", ref.getLocus(), true, true); VariantContext pbt = pbts.iterator().hasNext() ? pbts.iterator().next() : null; VariantContext rbp = rbps.iterator().hasNext() ? rbps.iterator().next() : null; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/MergeMNPsWalker.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/MergeMNPsWalker.java index d36da9835..6e328c07e 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/MergeMNPsWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/MergeMNPsWalker.java @@ -58,12 +58,9 @@ public class MergeMNPsWalker extends RodWalker { @Argument(fullName = "maxGenomicDistanceForMNP", shortName = "maxDistMNP", doc = "The maximum reference-genome distance between consecutive heterozygous sites to permit merging phased VCF records into a MNP record; [default:1]", required = false) protected int maxGenomicDistanceForMNP = 1; - private LinkedList rodNames = null; + private String rodName = "variant"; public void initialize() { - rodNames = new LinkedList(); - rodNames.add("variant"); - initializeVcfWriter(); } @@ -77,8 +74,8 @@ public class MergeMNPsWalker extends RodWalker { hInfo.addAll(VCFUtils.getHeaderFields(getToolkit())); hInfo.add(new VCFHeaderLine("reference", getToolkit().getArguments().referenceFile.getName())); - Map rodNameToHeader = getVCFHeadersFromRods(getToolkit(), rodNames); - vcMergerWriter.writeHeader(new VCFHeader(hInfo, new TreeSet(rodNameToHeader.get(rodNames.get(0)).getGenotypeSamples()))); + Map rodNameToHeader = getVCFHeadersFromRods(getToolkit(), Arrays.asList(rodName)); + vcMergerWriter.writeHeader(new VCFHeader(hInfo, new TreeSet(rodNameToHeader.get(rodName).getGenotypeSamples()))); } public boolean generateExtendedEvents() { @@ -103,7 +100,7 @@ public class MergeMNPsWalker extends RodWalker { boolean requireStartHere = true; // only see each VariantContext once boolean takeFirstOnly = false; // take as many entries as the VCF file has - for (VariantContext vc : tracker.getVariantContexts(ref, rodNames, context.getLocation(), requireStartHere, takeFirstOnly)) + for (VariantContext vc : tracker.getVariantContexts(rodName, context.getLocation(), requireStartHere, takeFirstOnly)) writeVCF(vc); return 0; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/MergeSegregatingAlternateAllelesWalker.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/MergeSegregatingAlternateAllelesWalker.java index 73d7fa529..c747e35d0 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/MergeSegregatingAlternateAllelesWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/MergeSegregatingAlternateAllelesWalker.java @@ -81,12 +81,9 @@ public class MergeSegregatingAlternateAllelesWalker extends RodWalker rodNames = null; + private String rodName = "variant"; public void initialize() { - rodNames = new LinkedList(); - rodNames.add("variant"); - initializeVcfWriter(); } @@ -114,8 +111,8 @@ public class MergeSegregatingAlternateAllelesWalker extends RodWalker rodNameToHeader = getVCFHeadersFromRods(getToolkit(), rodNames); - vcMergerWriter.writeHeader(new VCFHeader(hInfo, new TreeSet(rodNameToHeader.get(rodNames.get(0)).getGenotypeSamples()))); + Map rodNameToHeader = getVCFHeadersFromRods(getToolkit(), Arrays.asList(rodName)); + vcMergerWriter.writeHeader(new VCFHeader(hInfo, new TreeSet(rodNameToHeader.get(rodName).getGenotypeSamples()))); } public boolean generateExtendedEvents() { @@ -140,7 +137,7 @@ public class MergeSegregatingAlternateAllelesWalker extends RodWalker { @Override public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { if (tracker != null) { - Collection vcs = tracker.getVariantContexts(ref, ROD_NAME, context.getLocation(), true, true); + Collection vcs = tracker.getVariantContexts(ROD_NAME, context.getLocation(), true, true); for (VariantContext vc : vcs) { Map genotypeMap = vc.getGenotypes(); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/ReadBackedPhasingWalker.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/ReadBackedPhasingWalker.java index f96cec1b7..165cef477 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/ReadBackedPhasingWalker.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/phasing/ReadBackedPhasingWalker.java @@ -98,7 +98,7 @@ public class ReadBackedPhasingWalker extends RodWalker rodNames = null; + private String rodName = "variant"; public static final String PQ_KEY = "PQ"; @@ -123,9 +123,6 @@ public class ReadBackedPhasingWalker extends RodWalker(); - rodNames.add("variant"); - /* Since we cap each base quality (BQ) by its read's mapping quality (MQ) [in Read.updateBaseAndQuality()], then: if minBQ > minMQ, then we require that MQ be >= minBQ as well. @@ -175,8 +172,8 @@ public class ReadBackedPhasingWalker extends RodWalker rodNameToHeader = getVCFHeadersFromRods(getToolkit(), rodNames); - Set samples = new TreeSet(samplesToPhase == null ? rodNameToHeader.get(rodNames.get(0)).getGenotypeSamples() : samplesToPhase); + Map rodNameToHeader = getVCFHeadersFromRods(getToolkit(), Arrays.asList(rodName)); + Set samples = new TreeSet(samplesToPhase == null ? rodNameToHeader.get(rodName).getGenotypeSamples() : samplesToPhase); writer.writeHeader(new VCFHeader(hInfo, samples)); } @@ -209,7 +206,7 @@ public class ReadBackedPhasingWalker extends RodWalker { // if the argument was set, check for equivalence if (allRecordsVariantContextEquivalent && tracker != null) { - Collection col = tracker.getAllVariantContexts(ref); + Collection col = tracker.getAllVariantContexts(); VariantContext con = null; for (VariantContext contextInList : col) if (con == null) con = contextInList; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/validation/ValidationAmplicons.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/validation/ValidationAmplicons.java index 403401192..3d09ef785 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/validation/ValidationAmplicons.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/validation/ValidationAmplicons.java @@ -138,8 +138,8 @@ public class ValidationAmplicons extends RodWalker { // step 3 (or 1 if not new): // build up the sequence - VariantContext mask = tracker.getVariantContext(ref,"MaskAlleles",ref.getLocus()); - VariantContext validate = tracker.getVariantContext(ref,"ValidateAlleles",ref.getLocus()); + VariantContext mask = tracker.getVariantContext("MaskAlleles",ref.getLocus()); + VariantContext validate = tracker.getVariantContext("ValidateAlleles",ref.getLocus()); if ( mask == null && validate == null ) { if ( indelCounter > 0 ) { diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/stratifications/Novelty.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/stratifications/Novelty.java index 5bdec837e..5e98350ed 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/stratifications/Novelty.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/stratifications/Novelty.java @@ -25,7 +25,7 @@ public class Novelty extends VariantStratifier implements StandardStratification public ArrayList getRelevantStates(ReferenceContext ref, RefMetaDataTracker tracker, VariantContext comp, String compName, VariantContext eval, String evalName, String sampleName) { if (tracker != null && eval != null) { for (final String knownName : knownNames) { - final Collection knownComps = tracker.getVariantContexts(ref, knownName, ref.getLocus(), true, false); + final Collection knownComps = tracker.getVariantContexts(knownName, ref.getLocus(), true, false); for ( final VariantContext c : knownComps ) { // loop over sites, looking for something that matches the type eval if ( eval.getType() == c.getType() ) { diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/util/VariantEvalUtils.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/util/VariantEvalUtils.java index 7beb94593..285e75ed8 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/util/VariantEvalUtils.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/util/VariantEvalUtils.java @@ -336,7 +336,7 @@ public class VariantEvalUtils { for (String trackName : trackNames) { HashMap vcs = new HashMap(); - Collection contexts = tracker == null ? null : tracker.getVariantContexts(ref, trackName, ref.getLocus(), true, true); + Collection contexts = tracker == null ? null : tracker.getVariantContexts(trackName, ref.getLocus(), true, true); VariantContext vc = contexts != null && contexts.size() == 1 ? contexts.iterator().next() : null; // First, filter the VariantContext to represent only the samples for evaluation diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/ApplyRecalibration.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/ApplyRecalibration.java index 5fb738944..b195256d8 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/ApplyRecalibration.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/ApplyRecalibration.java @@ -168,7 +168,7 @@ public class ApplyRecalibration extends RodWalker { return 1; } - for( VariantContext vc : tracker.getVariantContexts(ref, inputNames, context.getLocation(), true, false) ) { + for( VariantContext vc : tracker.getVariantContexts(inputNames, context.getLocation(), true, false) ) { if( vc != null ) { if( VariantRecalibrator.checkRecalibrationMode( vc, MODE ) && (vc.isNotFiltered() || ignoreInputFilterSet.containsAll(vc.getFilters())) ) { String filterString = null; diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantDataManager.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantDataManager.java index c76efc2dd..7f32882f4 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantDataManager.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantDataManager.java @@ -258,7 +258,7 @@ public class VariantDataManager { datum.consensusCount = 0; for( final TrainingSet trainingSet : trainingSets ) { - for( final VariantContext trainVC : tracker.getVariantContexts( ref, trainingSet.name, context.getLocation(), false, false ) ) { + for( final VariantContext trainVC : tracker.getVariantContexts(trainingSet.name, context.getLocation(), false, false ) ) { if( trainVC != null && trainVC.isNotFiltered() && trainVC.isVariant() && ((evalVC.isSNP() && trainVC.isSNP()) || ((evalVC.isIndel()||evalVC.isMixed()) && (trainVC.isIndel()||trainVC.isMixed()))) && (TRUST_ALL_POLYMORPHIC || !trainVC.hasGenotypes() || trainVC.isPolymorphic()) ) { diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantRecalibrator.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantRecalibrator.java index 7e1d931c9..497a02baf 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantRecalibrator.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantrecalibration/VariantRecalibrator.java @@ -163,7 +163,7 @@ public class VariantRecalibrator extends RodWalker { // get all of the vcf rods at this locus // Need to provide reference bases to simpleMerge starting at current locus - Collection vcs = tracker.getAllVariantContexts(ref, context.getLocation(), true, false); + Collection vcs = tracker.getAllVariantContexts(context.getLocation(), true, false); if ( sitesOnlyVCF ) { vcs = VariantContextUtils.sitesOnlyVariantContexts(vcs); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/FilterLiftedVariants.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/FilterLiftedVariants.java index 97cb9a6e3..a55a53ff0 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/FilterLiftedVariants.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/FilterLiftedVariants.java @@ -85,7 +85,7 @@ public class FilterLiftedVariants extends RodWalker { if ( tracker == null ) return 0; - Collection VCs = tracker.getVariantContexts(ref, "variant", context.getLocation(), true, false); + Collection VCs = tracker.getVariantContexts("variant", context.getLocation(), true, false); for ( VariantContext vc : VCs ) filterAndWrite(ref.getBases(), vc); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignVariants.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignVariants.java index 566333d3f..01c7ddc91 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignVariants.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LeftAlignVariants.java @@ -68,7 +68,7 @@ public class LeftAlignVariants extends RodWalker { if ( tracker == null ) return 0; - Collection VCs = tracker.getVariantContexts(ref, "variant", context.getLocation(), true, false); + Collection VCs = tracker.getVariantContexts("variant", context.getLocation(), true, false); int changedSites = 0; for ( VariantContext vc : VCs ) diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LiftoverVariants.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LiftoverVariants.java index 061c3b256..38ac1e013 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LiftoverVariants.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/LiftoverVariants.java @@ -143,7 +143,7 @@ public class LiftoverVariants extends RodWalker { if ( tracker == null ) return 0; - Collection VCs = tracker.getVariantContexts(ref, "variant", context.getLocation(), true, false); + Collection VCs = tracker.getVariantContexts("variant", context.getLocation(), true, false); for ( VariantContext vc : VCs ) convertAndWrite(vc, ref); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/RandomlySplitVariants.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/RandomlySplitVariants.java index 99e12c836..de194e93f 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/RandomlySplitVariants.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/RandomlySplitVariants.java @@ -97,7 +97,7 @@ public class RandomlySplitVariants extends RodWalker { if ( tracker == null ) return 0; - Collection vcs = tracker.getVariantContexts(ref, INPUT_VARIANT_ROD_BINDING_NAME, context.getLocation(), true, false); + Collection vcs = tracker.getVariantContexts(INPUT_VARIANT_ROD_BINDING_NAME, context.getLocation(), true, false); for ( VariantContext vc : vcs ) { int random = GenomeAnalysisEngine.getRandomGenerator().nextInt(1000); if ( random < iFraction ) diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariants.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariants.java index 0efed393a..3bc598e2d 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariants.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariants.java @@ -25,38 +25,29 @@ package org.broadinstitute.sting.gatk.walkers.variantutils; import org.broadinstitute.sting.commandline.Hidden; -import org.broadinstitute.sting.commandline.Input; import org.broadinstitute.sting.utils.MathUtils; import org.broadinstitute.sting.utils.codecs.vcf.*; import org.broadinstitute.sting.utils.exceptions.UserException; import org.broadinstitute.sting.utils.text.XReadLines; -import org.broadinstitute.sting.utils.variantcontext.*; import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; import org.broadinstitute.sting.utils.MendelianViolation; import org.broadinstitute.sting.utils.variantcontext.VariantContext; import org.broadinstitute.sting.commandline.Argument; -import org.broadinstitute.sting.commandline.Hidden; import org.broadinstitute.sting.commandline.Output; -import org.broadinstitute.sting.gatk.GenomeAnalysisEngine; import org.broadinstitute.sting.gatk.contexts.AlignmentContext; import org.broadinstitute.sting.gatk.contexts.ReferenceContext; import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker; import org.broadinstitute.sting.gatk.walkers.RMD; import org.broadinstitute.sting.gatk.walkers.Requires; import org.broadinstitute.sting.gatk.walkers.RodWalker; -import org.broadinstitute.sting.utils.MathUtils; -import org.broadinstitute.sting.utils.MendelianViolation; import org.broadinstitute.sting.utils.SampleUtils; -import org.broadinstitute.sting.utils.codecs.vcf.*; import org.broadinstitute.sting.utils.variantcontext.Allele; import org.broadinstitute.sting.utils.variantcontext.Genotype; -import org.broadinstitute.sting.utils.variantcontext.VariantContext; import org.broadinstitute.sting.utils.variantcontext.VariantContextUtils; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; -import java.lang.annotation.AnnotationFormatError; import java.util.*; /** @@ -317,7 +308,7 @@ public class SelectVariants extends RodWalker { if ( tracker == null ) return 0; - Collection vcs = tracker.getVariantContexts(ref, variantRodName, context.getLocation(), true, false); + Collection vcs = tracker.getVariantContexts(variantRodName, context.getLocation(), true, false); if ( vcs == null || vcs.size() == 0) { return 0; @@ -345,12 +336,12 @@ public class SelectVariants extends RodWalker { break; } if (DISCORDANCE_ONLY) { - Collection compVCs = tracker.getVariantContexts(ref, discordanceRodName, context.getLocation(), true, false); + Collection compVCs = tracker.getVariantContexts(discordanceRodName, context.getLocation(), true, false); if (!isDiscordant(vc, compVCs)) return 0; } if (CONCORDANCE_ONLY) { - Collection compVCs = tracker.getVariantContexts(ref, concordanceRodName, context.getLocation(), true, false); + Collection compVCs = tracker.getVariantContexts(concordanceRodName, context.getLocation(), true, false); if (!isConcordant(vc, compVCs)) return 0; } diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/ValidateVariants.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/ValidateVariants.java index 756a00731..3bf8bd9e9 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/ValidateVariants.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/ValidateVariants.java @@ -86,7 +86,7 @@ public class ValidateVariants extends RodWalker { if ( tracker == null ) return 0; - Collection VCs = tracker.getVariantContexts(ref, "variant", context.getLocation(), true, false); + Collection VCs = tracker.getVariantContexts("variant", context.getLocation(), true, false); for ( VariantContext vc : VCs ) validate(vc, tracker, ref); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantValidationAssessor.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantValidationAssessor.java index 86bb3b0e8..e8a012e99 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantValidationAssessor.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantValidationAssessor.java @@ -93,7 +93,7 @@ public class VariantValidationAssessor extends RodWalker { return 0; if ( ++nRecords < MAX_RECORDS || MAX_RECORDS == -1 ) { - Collection vcs = tracker.getAllVariantContexts(ref, context.getLocation()); + Collection vcs = tracker.getAllVariantContexts(context.getLocation()); for ( VariantContext vc : vcs) { if ( (keepMultiAllelic || vc.isBiallelic()) && ( showFiltered || vc.isNotFiltered() ) ) { List vals = extractFields(vc, fieldsToTake, ALLOW_MISSING_DATA); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToTableNewRodStyle.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToTableNewRodStyle.java index 1b913e895..f5db48f0d 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToTableNewRodStyle.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToTableNewRodStyle.java @@ -138,7 +138,7 @@ public class VariantsToTableNewRodStyle extends RodWalker { System.out.printf("VariantList binding %s tags=%s%n", binding, getToolkit().getTags(binding).getPositionalTags()); if ( ++nRecords < MAX_RECORDS || MAX_RECORDS == -1 ) { - VariantContext vc = variants.getVariantContext(tracker, ref, context.getLocation()); + VariantContext vc = variants.getVariantContext(tracker, context.getLocation()); if ( (keepMultiAllelic || vc.isBiallelic()) && ( showFiltered || vc.isNotFiltered() ) ) { List vals = extractFields(vc, fieldsToTake, ALLOW_MISSING_DATA); out.println(Utils.join("\t", vals)); diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToVCF.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToVCF.java index 8f0fdd907..170daf6cc 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToVCF.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToVCF.java @@ -162,7 +162,7 @@ public class VariantsToVCF extends RodWalker { } // for everything else, we can just convert to VariantContext - return tracker.getVariantContexts(ref, INPUT_ROD_NAME, ref.getLocus(), true, false); + return tracker.getVariantContexts(INPUT_ROD_NAME, ref.getLocus(), true, false); } private DbSNPFeature getDbsnpFeature(String rsID) { diff --git a/public/java/test/org/broadinstitute/sting/gatk/datasources/providers/ReferenceOrderedViewUnitTest.java b/public/java/test/org/broadinstitute/sting/gatk/datasources/providers/ReferenceOrderedViewUnitTest.java index 21be24a85..52d8fd4d0 100755 --- a/public/java/test/org/broadinstitute/sting/gatk/datasources/providers/ReferenceOrderedViewUnitTest.java +++ b/public/java/test/org/broadinstitute/sting/gatk/datasources/providers/ReferenceOrderedViewUnitTest.java @@ -69,7 +69,7 @@ public class ReferenceOrderedViewUnitTest extends BaseTest { LocusShardDataProvider provider = new LocusShardDataProvider(shard, null, genomeLocParser, shard.getGenomeLocs().get(0), null, seq, Collections.emptyList()); ReferenceOrderedView view = new ManagingReferenceOrderedView( provider ); - RefMetaDataTracker tracker = view.getReferenceOrderedDataAtLocus(genomeLocParser.createGenomeLoc("chrM",10)); + RefMetaDataTracker tracker = view.getReferenceOrderedDataAtLocus(genomeLocParser.createGenomeLoc("chrM",10), null); Assert.assertEquals(tracker.getAllValuesAsGATKFeatures().size(), 0, "The tracker should not have produced any data"); } @@ -87,7 +87,7 @@ public class ReferenceOrderedViewUnitTest extends BaseTest { LocusShardDataProvider provider = new LocusShardDataProvider(shard, null, genomeLocParser, shard.getGenomeLocs().get(0), null, seq, Collections.singletonList(dataSource)); ReferenceOrderedView view = new ManagingReferenceOrderedView( provider ); - RefMetaDataTracker tracker = view.getReferenceOrderedDataAtLocus(genomeLocParser.createGenomeLoc("chrM",20)); + RefMetaDataTracker tracker = view.getReferenceOrderedDataAtLocus(genomeLocParser.createGenomeLoc("chrM",20), null); TableFeature datum = tracker.getFirstValue("tableTest", TableFeature.class); Assert.assertEquals(datum.get("COL1"),"C","datum parameter for COL1 is incorrect"); @@ -113,7 +113,7 @@ public class ReferenceOrderedViewUnitTest extends BaseTest { LocusShardDataProvider provider = new LocusShardDataProvider(shard, null, genomeLocParser, shard.getGenomeLocs().get(0), null, seq, Arrays.asList(dataSource1,dataSource2)); ReferenceOrderedView view = new ManagingReferenceOrderedView( provider ); - RefMetaDataTracker tracker = view.getReferenceOrderedDataAtLocus(genomeLocParser.createGenomeLoc("chrM",20)); + RefMetaDataTracker tracker = view.getReferenceOrderedDataAtLocus(genomeLocParser.createGenomeLoc("chrM",20), null); TableFeature datum1 = tracker.getFirstValue("tableTest1", TableFeature.class); Assert.assertEquals(datum1.get("COL1"),"C","datum1 parameter for COL1 is incorrect");