From fef1154fc84aa6057cb3b8d745c4a1324a31a43c Mon Sep 17 00:00:00 2001 From: aaron Date: Wed, 24 Feb 2010 22:11:53 +0000 Subject: [PATCH] starting on RODs for Reads: made RODRecordList implement list (so we can sub in fake lists during testing), and removed unnecessary generic-ness. Removed BrokenRODSimulator, which isn't being used. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@2884 348d0f76-0448-11de-a6fe-93d51630548a --- .../datasources/providers/RodLocusView.java | 20 +-- .../gatk/refdata/BrokenRODSimulator.java | 90 ------------ .../sting/gatk/refdata/RODRecordList.java | 79 ++++------ .../gatk/refdata/RefMetaDataTracker.java | 36 ++--- .../gatk/refdata/ReferenceOrderedData.java | 31 +--- .../gatk/refdata/SeekableRODIterator.java | 32 ++-- .../sting/gatk/refdata/rodDbSNP.java | 2 +- .../sting/gatk/refdata/rodRefSeq.java | 18 +-- .../gatk/refdata/tracks/RODRMDTrack.java | 34 ++++- .../utils/FeatureToGATKFeatureIterator.java | 2 +- .../sting/gatk/refdata/utils/GATKFeature.java | 139 +++++++++--------- .../walkers/annotator/VariantAnnotator.java | 2 +- .../walkers/fasta/PickSequenomProbes.java | 6 +- .../filters/VariantFiltrationWalker.java | 4 +- .../indels/IndelGenotyperV2Walker.java | 8 +- .../sting/gatk/walkers/qc/CountRodWalker.java | 6 +- .../sting/gatk/walkers/qc/VCFValidator.java | 2 +- .../walkers/varianteval/ChipConcordance.java | 2 +- .../varianteval/VariantDBCoverage.java | 2 +- .../varianteval/VariantEvalWalker.java | 2 +- .../walkers/HapmapPoolAllelicInfoWalker.java | 2 +- .../gatk/walkers/diagnostics/SNPDensity.java | 2 +- .../HybSelPerformanceWalker.java | 10 +- .../walkers/vcftools/VCFSelectWalker.java | 2 +- .../sting/utils/MergingIterator.java | 28 ++-- .../sting/gatk/refdata/TabularRODTest.java | 68 ++++----- 26 files changed, 264 insertions(+), 365 deletions(-) delete mode 100644 java/src/org/broadinstitute/sting/gatk/refdata/BrokenRODSimulator.java diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/providers/RodLocusView.java b/java/src/org/broadinstitute/sting/gatk/datasources/providers/RodLocusView.java index ae6b04770..17db1ab4f 100644 --- a/java/src/org/broadinstitute/sting/gatk/datasources/providers/RodLocusView.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/providers/RodLocusView.java @@ -31,11 +31,11 @@ public class RodLocusView extends LocusView implements ReferenceOrderedView { /** * The data sources along with their current states. */ - private MergingIterator rodQueue = null; + private MergingIterator rodQueue = null; RefMetaDataTracker tracker = null; GenomeLoc lastLoc = null; - RODRecordList interval = null; + RODRecordList interval = null; /** * The data sources along with their current states. @@ -59,7 +59,7 @@ public class RodLocusView extends LocusView implements ReferenceOrderedView { GenomeLoc firstLoc = provider.getShard().getGenomeLocs().get(0); - List< Iterator> > iterators = new LinkedList< Iterator> >(); + List< Iterator> > iterators = new LinkedList< Iterator> >(); for( ReferenceOrderedDataSource dataSource: provider.getReferenceOrderedData() ) { if ( DEBUG ) System.out.printf("Shard is %s%n", provider.getShard().getGenomeLocs()); @@ -75,13 +75,13 @@ public class RodLocusView extends LocusView implements ReferenceOrderedView { if ( dataSource.getName().equals(INTERVAL_ROD_NAME) ) { if ( interval != null ) throw new RuntimeException("BUG: interval local variable already assigned " + interval); - interval = (RODRecordList)it.next(); + interval = it.next(); } else { iterators.add( it ); } } - rodQueue = new MergingIterator(iterators); + rodQueue = new MergingIterator(iterators); //throw new StingException("RodLocusView currently disabled"); } @@ -106,13 +106,13 @@ public class RodLocusView extends LocusView implements ReferenceOrderedView { */ public AlignmentContext next() { if ( DEBUG ) System.out.printf("In RodLocusView.next()...%n"); - RODRecordList datum = rodQueue.next(); + RODRecordList datum = rodQueue.next(); if ( DEBUG ) System.out.printf("In RodLocusView.next(); datum = %s...%n", datum.getLocation()); if ( DEBUG ) System.out.printf("In RodLocusView.next(): creating tracker...%n"); // Update the tracker here for use - Collection> allTracksHere = getSpanningTracks(datum); + Collection allTracksHere = getSpanningTracks(datum); tracker = createTracker(allTracksHere); GenomeLoc rodSite = datum.getLocation(); @@ -131,9 +131,9 @@ public class RodLocusView extends LocusView implements ReferenceOrderedView { return null; } - private RefMetaDataTracker createTracker( Collection> allTracksHere ) { + private RefMetaDataTracker createTracker( Collection allTracksHere ) { RefMetaDataTracker t = new RefMetaDataTracker(); - for ( RODRecordList track : allTracksHere ) { + for ( RODRecordList track : allTracksHere ) { if ( ! t.hasROD(track.getName()) ) t.bind(track.getName(), track); } @@ -144,7 +144,7 @@ public class RodLocusView extends LocusView implements ReferenceOrderedView { return t; } - private Collection> getSpanningTracks(RODRecordList marker) { + private Collection getSpanningTracks(RODRecordList marker) { return rodQueue.allElementsLTE(marker); } diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/BrokenRODSimulator.java b/java/src/org/broadinstitute/sting/gatk/refdata/BrokenRODSimulator.java deleted file mode 100644 index e9fef6baa..000000000 --- a/java/src/org/broadinstitute/sting/gatk/refdata/BrokenRODSimulator.java +++ /dev/null @@ -1,90 +0,0 @@ -package org.broadinstitute.sting.gatk.refdata; - -import org.broadinstitute.sting.utils.GenomeLoc; -import org.broadinstitute.sting.utils.GenomeLocParser; -import org.broadinstitute.sting.utils.StingException; - -import java.util.Map; -import java.util.HashMap; - -/** - * This is a temporary solution that keeps integration tests passing until they are fixed permanently. - * The new ROD iterator system fixes a few issues present in the previous version, and as the result applications - * see somewhat different sets of RODs (notably, in ubiquitous rodDbSNP). This class takes the results returned - * by the new ROD system and simulates the results that would be returned by the old one. Everytime this class is used, - * it's an indication of the urgent need to get rid of it and fix the integration test!!! - * - * - * Created by IntelliJ IDEA. - * User: asivache - * Date: Sep 21, 2009 - * Time: 11:15:34 AM - * To change this template use File | Settings | File Templates. - */ -public class BrokenRODSimulator { - // multiple instances can access the sam tracker (and thus underlying iterator) from different - // places in the code. By making the mapping static we simulate this paradigm of "accessing the same RODIterator" - // through the tracke objects passed around at will. - private static Map last_intervals = new HashMap(); - private static Map last_rods = new HashMap(); - - public BrokenRODSimulator() { -// last_interval = GenomeLocParser.createGenomeLoc(0,1,1); - } - - public static void attach(String name) { - if ( last_intervals.containsKey(name)) return; // this track is already monitored - last_intervals.put(name,GenomeLocParser.createGenomeLoc(0,1,1)); - last_rods.put(name,null); - } - - public static ReferenceOrderedDatum simulate_lookup(String track, GenomeLoc loc, RefMetaDataTracker tracker) { - - if ( ! last_intervals.containsKey(track)) throw new StingException("Track "+track+" is not monitored by BrokenRODSimulator"); - -// if ( loc.getStart() >= 10168704 && loc.getStop() <= 10168728) System.out.println("Request at "+loc); - - ReferenceOrderedDatum oldStyleRod = null; // we will be searching for a record among all the records at a site - - RODRecordList rods = tracker.getTrackData(track,null); // get all records at the site -// if ( loc.getStart() >= 10168704 && loc.getStop() <= 10168728) { -// System.out.println(" Rods:" ); -// for ( ReferenceOrderedDatum d : rods ) System.out.println(" "+d.getLocation()); -// System.out.println(" Last ROD is: "+last_intervals.get(track)); -// } - - if ( rods == null || rods.size() == 0 ) return oldStyleRod; // no data, nothing to do - - ReferenceOrderedDatum firstRod = rods.getRecords().get(0); - - // There were quite a few pecularities with the old rod system. First, if there was an "extended" rod - // (length > 1), and if we landed on it exactly at its start location, we would see that same rod at every - // reference position until we walk past that rod's stop position. Other rods within the span of that extended rod - // would be masked (never seen at all). However, if the first time we land inside an extended rod after its start position, we would not - // see it at all. - - if ( last_intervals.get(track).equals( firstRod.getLocation() ) ) { - // normally, we would see the first rod spanning current position (can be extended); - // here we are just making sure that we legitimately "grabbed" this first rod earlier, i.e. - // landed on its start position -// if ( loc.getStart() >= 10168704 && loc.getStop() <= 10168728) System.out.println("Returning last"); - return last_rods.get(track); - } - - // if we are here, the first rod we see at the current location is not the same as the last one we returned - // in this case we want to skip all extended rods that started before the current position (if any). - - for( ReferenceOrderedDatum d : rods.getRecords() ) { - - if ( d.getLocation().compareTo(loc) < 0 ) continue; // rod starts before current location, old RODIterator would not see it - oldStyleRod = d; - break; - } - if ( oldStyleRod != null ) { - last_rods.put(track, oldStyleRod); - last_intervals.put(track, oldStyleRod.getLocation()); // remember what we just read; note that we would remember an extended rod here only if stepped into it at its start position! - } - return oldStyleRod; - - } -} diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/RODRecordList.java b/java/src/org/broadinstitute/sting/gatk/refdata/RODRecordList.java index 907be2226..ab45d0825 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/RODRecordList.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/RODRecordList.java @@ -13,72 +13,74 @@ import java.util.*; * Time: 6:10:48 PM * To change this template use File | Settings | File Templates. */ -public class RODRecordList implements Iterable, Comparable>, Cloneable { - private List records; +public class RODRecordList extends AbstractList implements Comparable, Cloneable { + private List records; private GenomeLoc location = null; private String name = null; - private RODRecordList() {} // dummy constructor for internal use; does not initialize/allocate anything - public RODRecordList(String name) { - records = new ArrayList(); + records = new ArrayList(); this.name = name; } /** - * Fully qualified constructor: instantiates a new RODRecordList object with specified ROD track name, location on the - * reference, and list of associated RODs. This is a knee-deep COPY constructor: passed name, loc, and data element - * objects will be referenced from the created RODRecordList (so that changing them from outside will affect data + * Fully qualified constructor: instantiates a new ReferenceOrderedDatumRecordList object with specified ReferenceOrderedDatum track name, location on the + * reference, and list of associated ReferenceOrderedDatums. This is a knee-deep COPY constructor: passed name, loc, and data element + * objects will be referenced from the created ReferenceOrderedDatumRecordList (so that changing them from outside will affect data * in this object), however, the data elements will be copied into a newly * allocated list, so that the 'data' collection argument can be modified afterwards without affecting the state * of this record list. WARNING: this constructor is (semi-)validating: passed name and location - * are allowed to be nulls (although it maybe unsafe, use caution), but if they are not nulls, then passed non-null ROD data + * are allowed to be nulls (although it maybe unsafe, use caution), but if they are not nulls, then passed non-null ReferenceOrderedDatum data * elements must have same track name, and their locations must overlap with the passed 'location' argument. Null * data elements or null 'data' collection argument are allowed as well. * @param name * @param data * @param loc */ - public RODRecordList(String name, Collection data, GenomeLoc loc) { - this.records = new ArrayList(data==null?0:data.size()); + public RODRecordList(String name, Collection data, GenomeLoc loc) { + this.records = new ArrayList(data==null?0:data.size()); this.name = name; this.location = loc; if ( data == null || data.size() == 0 ) return; // empty dataset, nothing to do - for ( ROD r : data ) { + for ( ReferenceOrderedDatum r : data ) { records.add(r); if ( r == null ) continue; if ( ! this.name.equals(r.getName() ) ) { - throw new StingException("Attempt to add ROD with non-matching name "+r.getName()+" to the track "+name); + throw new StingException("Attempt to add ReferenceOrderedDatum with non-matching name "+r.getName()+" to the track "+name); } if ( location != null && ! location.overlapsP(r.getLocation()) ) { - throw new StingException("Attempt to add ROD that lies outside of specified interval "+location+"; offending ROD:\n"+r.toString()); + throw new StingException("Attempt to add ReferenceOrderedDatum that lies outside of specified interval "+location+"; offending ReferenceOrderedDatum:\n"+r.toString()); } } } public GenomeLoc getLocation() { return location; } - public void setLocation(GenomeLoc location) { this.location = location; } public String getName() { return name; } - public List getRecords() { return records; } - public Iterator iterator() { return records.iterator() ; } + public List getRecords() { return records; } + public Iterator iterator() { return records.iterator() ; } public void clear() { records.clear(); } public boolean isEmpty() { return records.isEmpty(); } - public void add(ROD record) { add(record, false); } + public boolean add(ReferenceOrderedDatum record) { add(record, false); return true;} - public void add(ROD record, boolean allowNameMismatch) { + @Override + public ReferenceOrderedDatum get(int i) { + return records.get(i); + } + + public void add(ReferenceOrderedDatum record, boolean allowNameMismatch) { if ( record != null ) { if ( ! allowNameMismatch && ! name.equals(record.getName() ) ) - throw new StingException("Attempt to add ROD with non-matching name "+record.getName()+" to the track "+name); + throw new StingException("Attempt to add ReferenceOrderedDatum with non-matching name "+record.getName()+" to the track "+name); } records.add(record); } - public void add(RODRecordList records ) { add( records, false ); } + public void add(RODRecordList records ) { add( records, false ); } - public void add(RODRecordList records, boolean allowNameMismatch) { - for ( ROD record : records ) + public void add(RODRecordList records, boolean allowNameMismatch) { + for ( ReferenceOrderedDatum record : records ) add(record, allowNameMismatch); } @@ -88,32 +90,6 @@ public class RODRecordList implements Iterabl * Compares this object with the specified object for order. Returns a * negative integer, zero, or a positive integer as this object is less * than, equal to, or greater than the specified object. - *

- *

The implementor must ensure sgn(x.compareTo(y)) == - * -sgn(y.compareTo(x)) for all x and y. (This - * implies that x.compareTo(y) must throw an exception iff - * y.compareTo(x) throws an exception.) - *

- *

The implementor must also ensure that the relation is transitive: - * (x.compareTo(y)>0 && y.compareTo(z)>0) implies - * x.compareTo(z)>0. - *

- *

Finally, the implementor must ensure that x.compareTo(y)==0 - * implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for - * all z. - *

- *

It is strongly recommended, but not strictly required that - * (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any - * class that implements the Comparable interface and violates - * this condition should clearly indicate this fact. The recommended - * language is "Note: this class has a natural ordering that is - * inconsistent with equals." - *

- *

In the foregoing description, the notation - * sgn(expression) designates the mathematical - * signum function, which is defined to return one of -1, - * 0, or 1 according to whether the value of - * expression is negative, zero or positive. * * @param that the object to be compared. * @return a negative integer, zero, or a positive integer as this object @@ -121,10 +97,7 @@ public class RODRecordList implements Iterabl * @throws ClassCastException if the specified object's type prevents it * from being compared to this object. */ - public int compareTo(RODRecordList that) { -// if ( this.getLocation() == null ) { - // if ( that.getLocation() == null ) - // } + public int compareTo(RODRecordList that) { return getLocation().compareTo(that.getLocation()); //To change body of implemented methods use File | Settings | File Templates. } } diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java b/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java index 07e3c8a7d..12219f2ad 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/RefMetaDataTracker.java @@ -24,7 +24,7 @@ Genotype * Traversal calls tracker.bind(name, rod) for each rod in rods * Time: 3:05:23 PM */ public class RefMetaDataTracker { - final HashMap> map = new HashMap>(); + final HashMap map = new HashMap(); protected static Logger logger = Logger.getLogger(RefMetaDataTracker.class); /** @@ -41,7 +41,7 @@ public class RefMetaDataTracker { //logger.debug(String.format("Lookup %s%n", name)); final String luName = canonicalName(name); if ( map.containsKey(luName) ) { - RODRecordList value = map.get(luName) ; + RODRecordList value = map.get(luName) ; if ( value != null ) { List l = value.getRecords(); if ( l != null & l.size() > 0 ) return value.getRecords().get(0); @@ -63,20 +63,20 @@ public class RefMetaDataTracker { * @param defaultValue * @return */ - public RODRecordList getTrackData(final String name, ReferenceOrderedDatum defaultValue, boolean requireExactMatch) { + public RODRecordList getTrackData(final String name, ReferenceOrderedDatum defaultValue, boolean requireExactMatch) { //logger.debug(String.format("Lookup %s%n", name)); final String luName = canonicalName(name); - RODRecordList trackData = null; + RODRecordList trackData = null; if ( requireExactMatch ) { if ( map.containsKey(luName) ) trackData = map.get(luName); } else { - for ( Map.Entry> datum : map.entrySet() ) { + for ( Map.Entry datum : map.entrySet() ) { final String rodName = datum.getKey(); if ( rodName.startsWith(luName) ) { - if ( trackData == null ) trackData = new RODRecordList(name); + if ( trackData == null ) trackData = new RODRecordList(name); //System.out.printf("Adding bindings from %s to %s at %s%n", rodName, name, datum.getValue().getLocation()); trackData.add(datum.getValue(), true); } @@ -88,12 +88,12 @@ public class RefMetaDataTracker { else if ( defaultValue == null ) return null; else - return new RODRecordList(defaultValue.getName(), + return new RODRecordList(defaultValue.getName(), Collections.singletonList(defaultValue), defaultValue.getLocation()); } - public RODRecordList getTrackData(final String name, ReferenceOrderedDatum defaultValue) { + public RODRecordList getTrackData(final String name, ReferenceOrderedDatum defaultValue) { return getTrackData(name, defaultValue, true); } @@ -142,7 +142,7 @@ public class RefMetaDataTracker { */ public Collection getAllRods() { List l = new ArrayList(); - for ( RODRecordList rl : map.values() ) { + for ( RODRecordList rl : map.values() ) { if ( rl == null ) continue; // how do we get null value stored for a track? shouldn't the track be missing from the map alltogether? l.addAll(rl.getRecords()); } @@ -156,10 +156,10 @@ public class RefMetaDataTracker { * * @return */ - public Collection> getBoundRodTracks() { - LinkedList> bound = new LinkedList>(); + public Collection getBoundRodTracks() { + LinkedList bound = new LinkedList(); - for ( RODRecordList value : map.values() ) { + for ( RODRecordList value : map.values() ) { if ( value != null && value.size() != 0 ) bound.add(value); } @@ -174,7 +174,7 @@ public class RefMetaDataTracker { final String exclude = excludeIn == null ? null : canonicalName(excludeIn); int n = 0; - for ( RODRecordList value : map.values() ) { + for ( RODRecordList value : map.values() ) { if ( value != null && ! value.isEmpty() ) { if ( exclude == null || ! value.getName().equals(exclude) ) n++; @@ -187,7 +187,7 @@ public class RefMetaDataTracker { public Collection getBoundRodRecords() { LinkedList bound = new LinkedList(); - for ( RODRecordList valueList : map.values() ) { + for ( RODRecordList valueList : map.values() ) { for ( ReferenceOrderedDatum value : valueList ) { if ( value != null ) bound.add(value); @@ -227,7 +227,7 @@ public class RefMetaDataTracker { public Collection getAllVariantContexts(EnumSet allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) { List contexts = new ArrayList(); - for ( RODRecordList rodList : getBoundRodTracks() ) { + for ( RODRecordList rodList : getBoundRodTracks() ) { addVariantContexts(contexts, rodList, allowedTypes, curLocation, requireStartHere, takeFirstOnly); } @@ -254,7 +254,7 @@ public class RefMetaDataTracker { Collection contexts = new ArrayList(); for ( String name : names ) { - RODRecordList rodList = getTrackData(name, null); + RODRecordList rodList = getTrackData(name, null); if ( rodList != null ) addVariantContexts(contexts, rodList, allowedTypes, curLocation, requireStartHere, takeFirstOnly ); @@ -284,7 +284,7 @@ public class RefMetaDataTracker { return contexts.iterator().next(); } - private void addVariantContexts(Collection contexts, RODRecordList rodList, EnumSet allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) { + private void addVariantContexts(Collection contexts, RODRecordList rodList, EnumSet allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) { for ( ReferenceOrderedDatum rec : rodList.getRecords() ) { if ( VariantContextAdaptors.canBeConvertedToVariantContext(rec) ) { // ok, we might actually be able to turn this record in a variant context @@ -316,7 +316,7 @@ public class RefMetaDataTracker { * @param name * @param rod */ - public void bind(final String name, RODRecordList rod) { + public void bind(final String name, RODRecordList rod) { //logger.debug(String.format("Binding %s to %s", name, rod)); map.put(canonicalName(name), rod); } diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/ReferenceOrderedData.java b/java/src/org/broadinstitute/sting/gatk/refdata/ReferenceOrderedData.java index b4bf4afb4..41a65d6f9 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/ReferenceOrderedData.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/ReferenceOrderedData.java @@ -4,6 +4,7 @@ import org.apache.log4j.Logger; import org.broadinstitute.sting.gatk.refdata.tracks.RMDTrack; import org.broadinstitute.sting.gatk.refdata.tracks.RMDTrackCreationException; import org.broadinstitute.sting.gatk.refdata.tracks.RODRMDTrack; +import org.broadinstitute.sting.gatk.refdata.tracks.builders.RMDTrackBuilder; import org.broadinstitute.sting.oneoffprojects.refdata.HapmapVCFROD; import org.broadinstitute.sting.utils.StingException; import org.broadinstitute.sting.utils.Utils; @@ -20,7 +21,7 @@ import java.util.*; * Time: 10:47:14 AM * To change this template use File | Settings | File Templates. */ -public class ReferenceOrderedData implements Iterable> { // }, RMDTrackBuilder { +public class ReferenceOrderedData implements Iterable> { // }, RMDTrackBuilder { private String name; private File file = null; // private String fieldDelimiter; @@ -234,11 +235,11 @@ public class ReferenceOrderedData implements return this.name.equals(name) && type.isAssignableFrom(this.type); } - public SeekableRODIterator iterator() { - Iterator it; + public SeekableRODIterator iterator() { + Iterator it; try { Method m = type.getDeclaredMethod("createIterator", String.class, java.io.File.class); - it = (Iterator) m.invoke(null, name, file); + it = (Iterator) m.invoke(null, name, file); } catch (java.lang.NoSuchMethodException e) { it = new RODRecordIterator(file,name,type); } catch (java.lang.NullPointerException e) { @@ -256,24 +257,6 @@ public class ReferenceOrderedData implements return new SeekableRODIterator(it); } - // ---------------------------------------------------------------------- - // - // Testing - // - // ---------------------------------------------------------------------- - public void testMe() { - for (RODRecordList rec : this) { - System.out.println(rec.getRecords().get(0).toString()); - - RodGenotypeChipAsGFF gff = (RodGenotypeChipAsGFF) rec.getRecords().get(0); - String[] keys = {"LENGTH", "ALT", "FOBARBAR"}; - for (String key : keys) { - System.out.printf(" -> %s is (%s)%n", key, gff.containsAttribute(key) ? gff.getAttribute(key) : "none"); - } - } - System.exit(1); - } - // ---------------------------------------------------------------------- // // Manipulations of all of the data @@ -281,7 +264,7 @@ public class ReferenceOrderedData implements // ---------------------------------------------------------------------- public ArrayList readAll() { ArrayList elts = new ArrayList(); - for ( RODRecordList l : this ) { + for ( List l : this ) { for (ReferenceOrderedDatum rec : l) { elts.add(rec); } @@ -306,7 +289,7 @@ public class ReferenceOrderedData implements public boolean validateFile() throws Exception { ReferenceOrderedDatum last = null; - for ( RODRecordList l : this ) { + for ( List l : this ) { for (ReferenceOrderedDatum rec : l) { if (last != null && last.compareTo(rec) > 1) { // It's out of order diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/SeekableRODIterator.java b/java/src/org/broadinstitute/sting/gatk/refdata/SeekableRODIterator.java index 6d15a0ba1..6d21f62be 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/SeekableRODIterator.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/SeekableRODIterator.java @@ -33,9 +33,9 @@ import java.util.LinkedList; * Time: 6:20:46 PM * To change this template use File | Settings | File Templates. */ -public class SeekableRODIterator implements Iterator > { - private PushbackIterator it; - List records = null; // here we will keep a pile of records overlaping with current position; when we iterate +public class SeekableRODIterator implements Iterator> { + private PushbackIterator it; + List records = null; // here we will keep a pile of records overlaping with current position; when we iterate // and step out of record's scope, we purge it from the list String name = null; // name of the ROD track wrapped by this iterator. Will be pulled from underlying iterator. @@ -76,15 +76,15 @@ public class SeekableRODIterator implements I // This implementation tracks the query history and makes next() illegal after a seekforward query of length > 1, // but re-enables next() again after a length-1 query. - public SeekableRODIterator(Iterator it) { - this.it = new PushbackIterator(it); - records = new LinkedList(); + public SeekableRODIterator(Iterator it) { + this.it = new PushbackIterator(it); + records = new LinkedList(); // the following is a trick: we would like the iterator to know the actual name assigned to // the ROD implementing object we are working with. But the only way to do that is to // get an instance of that ROD and query it for its name. Now, the only generic way we have at this point to instantiate // the ROD is to make the underlying stream iterator to do it for us. So we are reading (or rather peeking into) // the first line of the track data file just to get the ROD object created. - ROD r = null; + ReferenceOrderedDatum r = null; if (this.it.hasNext()) r = this.it.element(); name = (r==null?null:r.getName()); } @@ -113,7 +113,7 @@ public class SeekableRODIterator implements I // the location we will jump to upon next call to next() is the start of the next ROD record that we did // not read yet: if ( it.hasNext() ) { - ROD r = it.element(); // peek, do not load! + ReferenceOrderedDatum r = it.element(); // peek, do not load! return GenomeLocParser.createGenomeLoc(r.getLocation().getContigIndex(),r.getLocation().getStart()); } return null; // underlying iterator has no more records, there is no next location! @@ -125,7 +125,7 @@ public class SeekableRODIterator implements I * Note that next() is disabled (will throw an exception) after seekForward() operation with query length > 1. * @return list of all RODs overlapping with the next "covered" genomic position */ - public RODRecordList next() { + public RODRecordList next() { if ( ! next_is_allowed ) throw new StingException("Illegal use of iterator: Can not advance iterator with next() after seek-forward query of length > 1"); @@ -141,7 +141,7 @@ public class SeekableRODIterator implements I // ooops, we are past the end of all loaded records - kill them all at once, // load next record and reinitialize by fastforwarding current position to the start of next record records.clear(); - ROD r = it.next(); // if hasNext() previously returned true, we are guaranteed that this call to reader.next() is safe + ReferenceOrderedDatum r = it.next(); // if hasNext() previously returned true, we are guaranteed that this call to reader.next() is safe records.add( r ); curr_contig = r.getLocation().getContigIndex(); curr_position = r.getLocation().getStart(); @@ -154,7 +154,7 @@ public class SeekableRODIterator implements I // covered by new records, so we need to load them too: while ( it.hasNext() ) { - ROD r = it.element(); + ReferenceOrderedDatum r = it.element(); if ( r == null ) { it.next(); continue; @@ -263,7 +263,7 @@ public class SeekableRODIterator implements I * @param interval point-like genomic location to fastforward to. * @return ROD object at (or overlapping with) the specified position, or null if no such ROD exists. */ - public RODRecordList seekForward(GenomeLoc interval) { + public RODRecordList seekForward(GenomeLoc interval) { if ( interval.getContigIndex() < curr_contig ) throw new StingException("Out of order query: query contig "+interval.getContig()+" is located before "+ @@ -296,7 +296,7 @@ public class SeekableRODIterator implements I // curr_contig and curr_position are set to where we asked to scroll to while ( it.hasNext() ) { - ROD r = it.next(); + ReferenceOrderedDatum r = it.next(); if ( r == null ) continue; int that_contig = r.getLocation().getContigIndex(); @@ -322,7 +322,7 @@ public class SeekableRODIterator implements I } if ( records.size() > 0 ) { - return new RODRecordList(name,records,interval.clone()); + return new RODRecordList(name,records,interval.clone()); } else { return null; } @@ -335,9 +335,9 @@ public class SeekableRODIterator implements I * curr_position <= max_position, as well as that we are still on the same contig. */ private void purgeOutOfScopeRecords() { - Iterator i = records.iterator(); + Iterator i = records.iterator(); while ( i.hasNext() ) { - ROD r = i.next(); + ReferenceOrderedDatum r = i.next(); if ( r.getLocation().getStop() < curr_position ) { i.remove(); // we moved past the end of interval the record r is associated with, purge the record forever } diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/rodDbSNP.java b/java/src/org/broadinstitute/sting/gatk/refdata/rodDbSNP.java index 3b98a9d15..8f6ef29ee 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/rodDbSNP.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/rodDbSNP.java @@ -280,7 +280,7 @@ public class rodDbSNP extends BasicReferenceOrderedDatum implements VariationRod return getAlternateAlleleList().size() == 1; } - public static rodDbSNP getFirstRealSNP(RODRecordList dbsnpList) { + public static rodDbSNP getFirstRealSNP(RODRecordList dbsnpList) { if (dbsnpList == null) return null; diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/rodRefSeq.java b/java/src/org/broadinstitute/sting/gatk/refdata/rodRefSeq.java index 1d0944350..fec7106e2 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/rodRefSeq.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/rodRefSeq.java @@ -136,14 +136,14 @@ public class rodRefSeq extends BasicReferenceOrderedDatum implements Transcript * NOTE: position can be still within a UTR, see #isCoding * @return */ - public static boolean isExon(RODRecordList l) { + public static boolean isExon(RODRecordList l) { if ( l == null ) return false; GenomeLoc loc = l.getLocation(); - for ( rodRefSeq t : l ) { - if ( t.overlapsExonP(loc) ) return true; + for ( ReferenceOrderedDatum t : l ) { + if ( ((rodRefSeq)t).overlapsExonP(loc) ) return true; } return false; @@ -159,14 +159,14 @@ public class rodRefSeq extends BasicReferenceOrderedDatum implements Transcript * indeed within an exon but not in UTR, use #isCodingExon(). * @return */ - public static boolean isCoding(RODRecordList l) { + public static boolean isCoding(RODRecordList l) { if ( l == null ) return false; GenomeLoc loc = l.getLocation(); - for ( rodRefSeq t : l ) { - if ( t.overlapsCodingP(loc) ) return true; + for ( ReferenceOrderedDatum t : l ) { + if ( ((rodRefSeq)t).overlapsCodingP(loc) ) return true; } return false; @@ -179,14 +179,14 @@ public class rodRefSeq extends BasicReferenceOrderedDatum implements Transcript * for which the current position is within an exon and within a coding interval simultaneously. * @return */ - public static boolean isCodingExon(RODRecordList l) { + public static boolean isCodingExon(RODRecordList l) { if ( l == null ) return false; GenomeLoc loc = l.getLocation(); - for ( rodRefSeq t : l ) { - if ( t.overlapsCodingP(loc) && t.overlapsExonP(loc) ) return true; + for ( ReferenceOrderedDatum t : l ) { + if ( ((rodRefSeq)t).overlapsCodingP(loc) && ((rodRefSeq)t).overlapsExonP(loc) ) return true; } return false; diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/RODRMDTrack.java b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/RODRMDTrack.java index cd9f209c5..f4c348720 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/tracks/RODRMDTrack.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/tracks/RODRMDTrack.java @@ -23,7 +23,9 @@ package org.broadinstitute.sting.gatk.refdata.tracks; +import org.broadinstitute.sting.gatk.refdata.RODRecordList; import org.broadinstitute.sting.gatk.refdata.ReferenceOrderedData; +import org.broadinstitute.sting.gatk.refdata.SeekableRODIterator; import org.broadinstitute.sting.gatk.refdata.utils.GATKFeature; import java.io.File; @@ -64,6 +66,36 @@ public class RODRMDTrack extends RMDTrack { */ @Override public Iterator getIterator() { - return data.iterator(); + return new SRIToIterator(data.iterator()); } } + +class SRIToIterator implements Iterator { + private RODRecordList list = null; + private SeekableRODIterator iterator = null; + + SRIToIterator(SeekableRODIterator iter) { + iterator = iter; + } + + public boolean hasNext() { + if (this.list != null && list.size() > 0) return true; + return iterator.hasNext(); + } + + public GATKFeature next() { + if (this.list != null && list.size() > 0) { + GATKFeature f = new GATKFeature.RODGATKFeature(list.get(0)); + list.remove(0); + return f; + } + else { + list = iterator.next(); + return next(); + } + } + + public void remove() { + throw new UnsupportedOperationException("not supported"); + } +} \ No newline at end of file diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/utils/FeatureToGATKFeatureIterator.java b/java/src/org/broadinstitute/sting/gatk/refdata/utils/FeatureToGATKFeatureIterator.java index ec75adbc4..99a93f72c 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/utils/FeatureToGATKFeatureIterator.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/utils/FeatureToGATKFeatureIterator.java @@ -52,7 +52,7 @@ public class FeatureToGATKFeatureIterator implements Iterator { @Override public GATKFeature next() { - return new TribbleGATKFeature(iterator.next(),name); + return new GATKFeature.TribbleGATKFeature(iterator.next(),name); } @Override diff --git a/java/src/org/broadinstitute/sting/gatk/refdata/utils/GATKFeature.java b/java/src/org/broadinstitute/sting/gatk/refdata/utils/GATKFeature.java index 7c8b96559..ea3153dd6 100644 --- a/java/src/org/broadinstitute/sting/gatk/refdata/utils/GATKFeature.java +++ b/java/src/org/broadinstitute/sting/gatk/refdata/utils/GATKFeature.java @@ -57,83 +57,84 @@ public abstract class GATKFeature implements Feature { public abstract GenomeLoc getLocation(); public abstract Object getUnderlyingObject(); -} -/** - * wrapping a Tribble feature in a GATK friendly interface - */ -class TribbleGATKFeature extends GATKFeature { - private final Feature feature; + /** + * wrapping a Tribble feature in a GATK friendly interface + */ + public static class TribbleGATKFeature extends GATKFeature { + private final Feature feature; - public TribbleGATKFeature(Feature f, String name) { - super(name); - feature = f; - } - public GenomeLoc getLocation() { - return GenomeLocParser.createGenomeLoc(feature.getChr(), feature.getStart(), feature.getEnd()); - } + public TribbleGATKFeature(Feature f, String name) { + super(name); + feature = f; + } + public GenomeLoc getLocation() { + return GenomeLocParser.createGenomeLoc(feature.getChr(), feature.getStart(), feature.getEnd()); + } - /** Return the features reference sequence name, e.g chromosome or contig */ - @Override - public String getChr() { - return feature.getChr(); - } + /** Return the features reference sequence name, e.g chromosome or contig */ + @Override + public String getChr() { + return feature.getChr(); + } - /** Return the start position in 1-based coordinates (first base is 1) */ - @Override - public int getStart() { - return feature.getStart(); + /** Return the start position in 1-based coordinates (first base is 1) */ + @Override + public int getStart() { + return feature.getStart(); + } + + /** + * Return the end position following 1-based fully closed conventions. The length of a feature is + * end - start + 1; + */ + @Override + public int getEnd() { + return feature.getEnd(); + } + + public Object getUnderlyingObject() { + return feature; + } } /** - * Return the end position following 1-based fully closed conventions. The length of a feature is - * end - start + 1; + * wrapping a old style rod into the new GATK feature style */ - @Override - public int getEnd() { - return feature.getEnd(); + public static class RODGATKFeature extends GATKFeature { + + // our data + private ReferenceOrderedDatum datum; + + public RODGATKFeature(ReferenceOrderedDatum datum) { + super(datum.getName()); + this.datum = datum; + } + + @Override + public GenomeLoc getLocation() { + return datum.getLocation(); + } + + @Override + public Object getUnderlyingObject() { + return datum; + } + + @Override + public String getChr() { + return datum.getLocation().getContig(); + } + + @Override + public int getStart() { + return (int)datum.getLocation().getStart(); + } + + @Override + public int getEnd() { + return (int)datum.getLocation().getStop(); + } } - public Object getUnderlyingObject() { - return feature; - } } - -/** - * wrapping a old style rod into the new GATK feature style - */ -class RODGATKFeature extends GATKFeature { - - // our data - private ReferenceOrderedDatum datum; - - public RODGATKFeature(ReferenceOrderedDatum datum) { - super(datum.getName()); - this.datum = datum; - } - - @Override - public GenomeLoc getLocation() { - return datum.getLocation(); - } - - @Override - public Object getUnderlyingObject() { - return datum; - } - - @Override - public String getChr() { - return datum.getLocation().getContig(); - } - - @Override - public int getStart() { - return (int)datum.getLocation().getStart(); - } - - @Override - public int getEnd() { - return (int)datum.getLocation().getStop(); - } -} \ No newline at end of file diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java index 736b5f61c..7f4cb182c 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java @@ -185,7 +185,7 @@ public class VariantAnnotator extends LocusWalker { if ( tracker == null ) return 0; - RODRecordList rods = tracker.getTrackData("variant", null); + RODRecordList rods = tracker.getTrackData("variant", null); // ignore places where we don't have a variant if ( rods == null || rods.getRecords().size() == 0 ) return 0; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/fasta/PickSequenomProbes.java b/java/src/org/broadinstitute/sting/gatk/walkers/fasta/PickSequenomProbes.java index 85cedf520..8d93fe34e 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/fasta/PickSequenomProbes.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/fasta/PickSequenomProbes.java @@ -26,7 +26,7 @@ public class PickSequenomProbes extends RefWalker { String project_id = null; private byte [] maskFlags = new byte[401]; - private SeekableRODIterator snpMaskIterator=null; + private SeekableRODIterator snpMaskIterator=null; public void initialize() { if ( SNP_MASK != null ) { @@ -66,9 +66,9 @@ public class PickSequenomProbes extends RefWalker { // we have variant; let's load all the snps falling into the current window and prepare the mask array: if ( snpMaskIterator != null ) { - RODRecordList snpList = snpMaskIterator.seekForward(GenomeLocParser.createGenomeLoc(contig,offset-200,offset+200)); + RODRecordList snpList = snpMaskIterator.seekForward(GenomeLocParser.createGenomeLoc(contig,offset-200,offset+200)); if ( snpList != null && snpList.size() != 0 ) { - Iterator snpsInWindow = snpList.iterator(); + Iterator snpsInWindow = snpList.iterator(); int i = 0; while ( snpsInWindow.hasNext() ) { GenomeLoc snp = snpsInWindow.next().getLocation(); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java index e84fcddf1..97251a172 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java @@ -115,7 +115,7 @@ public class VariantFiltrationWalker extends RodWalker { if ( tracker == null ) return 0; - RODRecordList rods = tracker.getTrackData("variant", null); + RODRecordList rods = tracker.getTrackData("variant", null); // ignore places where we don't have a variant if ( rods == null || rods.getRecords().size() == 0 ) return 0; @@ -147,7 +147,7 @@ public class VariantFiltrationWalker extends RodWalker { StringBuilder filterString = new StringBuilder(); // test for SNP mask, if present - RODRecordList mask = context.first.getTrackData("mask", null); + RODRecordList mask = context.first.getTrackData("mask", null); if ( mask != null && mask.getRecords().size() > 0 ) addFilter(filterString, MASK_NAME); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelGenotyperV2Walker.java b/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelGenotyperV2Walker.java index a2516660d..b1ef8812c 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelGenotyperV2Walker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/indels/IndelGenotyperV2Walker.java @@ -80,7 +80,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { boolean outOfContigUserWarned = false; - private SeekableRODIterator refseqIterator=null; + private SeekableRODIterator refseqIterator=null; private Set normalReadGroups; // we are going to remember which read groups are normals and which are tumors in order to be able private Set tumorReadGroups ; // to properly assign the reads coming from a merged stream @@ -329,7 +329,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { location = GenomeLocParser.setStart(location,pos); location = GenomeLocParser.setStop(location,pos); // retrieve annotation data - RODRecordList annotationList = (refseqIterator == null ? null : refseqIterator.seekForward(location)); + RODRecordList annotationList = (refseqIterator == null ? null : refseqIterator.seekForward(location)); if ( normalCall.failsNQSMismatch() ) { String fullRecord = makeFullRecord(normalCall); @@ -487,7 +487,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { location = GenomeLocParser.setStart(location,pos); location = GenomeLocParser.setStop(location,pos); // retrieve annotation data - RODRecordList annotationList = (refseqIterator == null ? null : refseqIterator.seekForward(location)); + RODRecordList annotationList = (refseqIterator == null ? null : refseqIterator.seekForward(location)); if ( normalCall.failsNQSMismatch() ) { String fullRecord = makeFullRecord(normalCall,tumorCall); @@ -568,7 +568,7 @@ public class IndelGenotyperV2Walker extends ReadWalker { return fullRecord.toString(); } - private String getAnnotationString(RODRecordList ann) { + private String getAnnotationString(RODRecordList ann) { if ( ann == null ) return annGenomic; else { StringBuilder b = new StringBuilder(); diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/qc/CountRodWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/qc/CountRodWalker.java index 78913ce5d..b5974385b 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/qc/CountRodWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/qc/CountRodWalker.java @@ -61,8 +61,8 @@ public class CountRodWalker extends RodWalker> rods = new LinkedList>(); - for ( RODRecordList rod : tracker.getBoundRodTracks() ) { + Collection rods = new LinkedList(); + for ( RODRecordList rod : tracker.getBoundRodTracks() ) { //System.out.printf("Considering rod %s%n", rod); if ( rod.getLocation().getStart() == context.getLocation().getStart() && ! rod.getName().equals("interval") ) { // only consider the first element @@ -76,7 +76,7 @@ public class CountRodWalker extends RodWalker 0 ) { if ( verbose ) { List names = new ArrayList(); - for ( RODRecordList rod : rods ) { + for ( RODRecordList rod : rods ) { names.add(rod.getName()); } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/qc/VCFValidator.java b/java/src/org/broadinstitute/sting/gatk/walkers/qc/VCFValidator.java index 10936d1de..0ae947aae 100644 --- a/java/src/org/broadinstitute/sting/gatk/walkers/qc/VCFValidator.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/qc/VCFValidator.java @@ -25,7 +25,7 @@ public class VCFValidator extends RodWalker { public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { if ( tracker != null ) { - RODRecordList rodlist = tracker.getTrackData("vcf", null); + RODRecordList rodlist = tracker.getTrackData("vcf", null); if ( rodlist != null ) { RodVCF rod = (RodVCF)rodlist.getRecords().get(0); if ( (rod.isSNP() || rod.isReference()) && Character.toUpperCase(rod.getReference().charAt(0)) != Character.toUpperCase(ref.getBase()) ) diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/ChipConcordance.java b/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/ChipConcordance.java index 8c964cc62..84ba40a1f 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/ChipConcordance.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/ChipConcordance.java @@ -78,7 +78,7 @@ public abstract class ChipConcordance extends BasicVariantAnalysis { // get all of the chip rods at this locus HashMap chips = new HashMap(); for ( String name : rodNames ) { - RODRecordList rods = tracker.getTrackData(name, null); + RODRecordList rods = tracker.getTrackData(name, null); Variation chip = (rods == null ? null : (Variation)rods.getRecords().get(0)); if ( chip != null ) { // chips must be Genotypes diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantDBCoverage.java b/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantDBCoverage.java index a7bc3ef01..44296e64a 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantDBCoverage.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantDBCoverage.java @@ -58,7 +58,7 @@ public class VariantDBCoverage extends BasicVariantAnalysis implements GenotypeA return nConcordant() / (1.0 * nSNPsAtdbSNPs()); } - public static Variation getFirstRealSNP(RODRecordList dbsnpList) { + public static Variation getFirstRealSNP(RODRecordList dbsnpList) { if (dbsnpList == null) return null; diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantEvalWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantEvalWalker.java index 5db36821c..aae2bd684 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantEvalWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/varianteval/VariantEvalWalker.java @@ -359,7 +359,7 @@ public class VariantEvalWalker extends RodWalker { } private ANALYSIS_TYPE getNovelAnalysisType(RefMetaDataTracker tracker) { - RODRecordList dbsnpList = tracker.getTrackData("dbsnp", null); + RODRecordList dbsnpList = tracker.getTrackData("dbsnp", null); if (dbsnpList == null) return ANALYSIS_TYPE.NOVEL_SNPS; diff --git a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/HapmapPoolAllelicInfoWalker.java b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/HapmapPoolAllelicInfoWalker.java index 7547bbd0c..dc5acd7cb 100755 --- a/java/src/org/broadinstitute/sting/oneoffprojects/walkers/HapmapPoolAllelicInfoWalker.java +++ b/java/src/org/broadinstitute/sting/oneoffprojects/walkers/HapmapPoolAllelicInfoWalker.java @@ -135,7 +135,7 @@ public class HapmapPoolAllelicInfoWalker extends LocusWalker> getChips(String[] rodNames, RefMetaDataTracker tracker) { List> chips = new ArrayList >(rodNames.length); for ( String name : rodNames ) { - RODRecordList rods = tracker.getTrackData(name, null); + RODRecordList rods = tracker.getTrackData(name, null); Variation chip = (rods == null ? null : (Variation)rods.getRecords().get(0)); if ( chip != null ) { // chips must be Genotypes diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/SNPDensity.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/SNPDensity.java index b4321027c..68efeedaa 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/SNPDensity.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/diagnostics/SNPDensity.java @@ -37,7 +37,7 @@ public class SNPDensity extends RefWalker, SNPDe public Pair map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) { VariantContext vc = null; - RODRecordList vcfList = tracker.getTrackData("eval", null); + RODRecordList vcfList = tracker.getTrackData("eval", null); if (vcfList != null) { for (ReferenceOrderedDatum d : vcfList) { RodVCF vcfRecord = (RodVCF)d; diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/HybSelPerformanceWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/HybSelPerformanceWalker.java index fe6209f88..0c233bd4f 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/HybSelPerformanceWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/hybridselection/HybSelPerformanceWalker.java @@ -56,7 +56,7 @@ public class HybSelPerformanceWalker extends LocusWalker refseqIterator=null; + private SeekableRODIterator refseqIterator=null; public static class TargetInfo { public int counts = 0; @@ -247,12 +247,12 @@ public class HybSelPerformanceWalker extends LocusWalker annotationList = refseqIterator.seekForward(target); + RODRecordList annotationList = refseqIterator.seekForward(target); if (annotationList == null) { return "UNKNOWN"; } - for(rodRefSeq rec : annotationList) { - if ( rec.overlapsExonP(target) ) { - return rec.getGeneName(); + for(ReferenceOrderedDatum rec : annotationList) { + if ( ((rodRefSeq)rec).overlapsExonP(target) ) { + return ((rodRefSeq)rec).getGeneName(); } } diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/vcftools/VCFSelectWalker.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/vcftools/VCFSelectWalker.java index ac1bcfb28..aa0273ac4 100755 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/vcftools/VCFSelectWalker.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/vcftools/VCFSelectWalker.java @@ -79,7 +79,7 @@ public class VCFSelectWalker extends RodWalker { if ( tracker == null ) return 0; - RODRecordList rods = tracker.getTrackData("variant", null); + RODRecordList rods = tracker.getTrackData("variant", null); // ignore places where we don't have a variant if ( rods == null || rods.getRecords().size() == 0 ) return 0; diff --git a/java/src/org/broadinstitute/sting/utils/MergingIterator.java b/java/src/org/broadinstitute/sting/utils/MergingIterator.java index 2ccbc66a7..06942f182 100644 --- a/java/src/org/broadinstitute/sting/utils/MergingIterator.java +++ b/java/src/org/broadinstitute/sting/utils/MergingIterator.java @@ -8,7 +8,7 @@ import org.broadinstitute.sting.gatk.refdata.RODRecordList; import java.util.*; -public class MergingIterator implements Iterator>, Iterable> { +public class MergingIterator implements Iterator, Iterable { PriorityQueue queue = new PriorityQueue(); private class Element implements Comparable { @@ -16,7 +16,7 @@ public class MergingIterator implements Itera //public E value = null; public GenomeLoc nextLoc = null; - public Element(Iterator> it) { + public Element(Iterator> it) { if ( it instanceof SeekableRODIterator ) { this.it = (SeekableRODIterator)it; if ( ! it.hasNext() ) throw new StingException("Iterator is empty"); @@ -42,14 +42,14 @@ public class MergingIterator implements Itera return nextLoc.compareTo(other.nextLoc); } - public RODRecordList next() { - RODRecordList value = it.next(); + public RODRecordList next() { + RODRecordList value = it.next(); update(); return value; } } - public Iterator> iterator() { + public Iterator iterator() { return this; } @@ -57,12 +57,12 @@ public class MergingIterator implements Itera ; } - public MergingIterator(Iterator> it) { + public MergingIterator(Iterator> it) { add(it); } - public MergingIterator(Collection>> its) { - for ( Iterator> it : its ) { + public MergingIterator(Collection>> its) { + for ( Iterator> it : its ) { add(it); } } @@ -71,7 +71,7 @@ public class MergingIterator implements Itera * will be after a call to next() is peeked into and cached as queue's priority value. * @param it */ - public void add(Iterator> it) { + public void add(Iterator> it) { if ( it.hasNext() ) queue.add(new Element(it)); } @@ -80,9 +80,9 @@ public class MergingIterator implements Itera return ! queue.isEmpty(); } - public RODRecordList next() { + public RODRecordList next() { Element e = queue.poll(); - RODRecordList value = e.next(); // next() will also update next location cached by the Element + RODRecordList value = e.next(); // next() will also update next location cached by the Element if ( e.nextLoc != null ) // we have more data in the track queue.add(e); // add the element back to queue (note: its next location, on which priority is based, was updated @@ -99,12 +99,12 @@ public class MergingIterator implements Itera return queue.peek().nextLoc; } - public Collection> allElementsLTE(RODRecordList elt) { + public Collection allElementsLTE(RODRecordList elt) { return allElementsLTE(elt, true); } - public Collection> allElementsLTE(RODRecordList elt, boolean includeElt) { - LinkedList> all = new LinkedList>(); + public Collection allElementsLTE(RODRecordList elt, boolean includeElt) { + LinkedList all = new LinkedList(); if ( includeElt ) all.add(elt); diff --git a/java/test/org/broadinstitute/sting/gatk/refdata/TabularRODTest.java b/java/test/org/broadinstitute/sting/gatk/refdata/TabularRODTest.java index bd41876a4..0d5a8e4a9 100755 --- a/java/test/org/broadinstitute/sting/gatk/refdata/TabularRODTest.java +++ b/java/test/org/broadinstitute/sting/gatk/refdata/TabularRODTest.java @@ -26,7 +26,7 @@ import net.sf.picard.reference.ReferenceSequenceFile; public class TabularRODTest extends BaseTest { private static ReferenceSequenceFile seq; private ReferenceOrderedData ROD; - private SeekableRODIterator iter; + private SeekableRODIterator iter; @BeforeClass @@ -48,8 +48,8 @@ public class TabularRODTest extends BaseTest { @Test public void test1() { logger.warn("Executing test1"); - RODRecordList oneList = iter.next(); - TabularROD one = oneList.getRecords().get(0); + RODRecordList oneList = iter.next(); + TabularROD one = (TabularROD)oneList.getRecords().get(0); assertTrue(one.size() == 4); assertTrue(one.getLocation().equals(GenomeLocParser.createGenomeLoc("chrM", 10))); assertTrue(one.get("COL1").equals("A")); @@ -60,10 +60,10 @@ public class TabularRODTest extends BaseTest { @Test public void test2() { logger.warn("Executing test2"); - RODRecordList oneList = iter.next(); - RODRecordList twoList = iter.next(); - TabularROD one = oneList.getRecords().get(0); - TabularROD two = twoList.getRecords().get(0); + RODRecordList oneList = iter.next(); + RODRecordList twoList = iter.next(); + TabularROD one = (TabularROD)oneList.getRecords().get(0); + TabularROD two = (TabularROD)twoList.getRecords().get(0); assertTrue(two.size() == 4); assertTrue(two.getLocation().equals(GenomeLocParser.createGenomeLoc("chrM", 20))); assertTrue(two.get("COL1").equals("C")); @@ -74,12 +74,12 @@ public class TabularRODTest extends BaseTest { @Test public void test3() { logger.warn("Executing test3"); - RODRecordList oneList = iter.next(); - RODRecordList twoList = iter.next(); - RODRecordList threeList = iter.next(); - TabularROD one = oneList.getRecords().get(0); - TabularROD two = twoList.getRecords().get(0); - TabularROD three = threeList.getRecords().get(0); + RODRecordList oneList = iter.next(); + RODRecordList twoList = iter.next(); + RODRecordList threeList = iter.next(); + TabularROD one = (TabularROD)oneList.getRecords().get(0); + TabularROD two = (TabularROD)twoList.getRecords().get(0); + TabularROD three = (TabularROD)threeList.getRecords().get(0); assertTrue(three.size() == 4); assertTrue(three.getLocation().equals(GenomeLocParser.createGenomeLoc("chrM", 30))); assertTrue(three.get("COL1").equals("F")); @@ -90,20 +90,20 @@ public class TabularRODTest extends BaseTest { @Test public void testDone() { logger.warn("Executing testDone"); - RODRecordList oneList = iter.next(); - RODRecordList twoList = iter.next(); - RODRecordList threeList = iter.next(); - TabularROD one = oneList.getRecords().get(0); - TabularROD two = twoList.getRecords().get(0); - TabularROD three = threeList.getRecords().get(0); + RODRecordList oneList = iter.next(); + RODRecordList twoList = iter.next(); + RODRecordList threeList = iter.next(); + TabularROD one = (TabularROD)oneList.getRecords().get(0); + TabularROD two = (TabularROD)twoList.getRecords().get(0); + TabularROD three = (TabularROD)threeList.getRecords().get(0); assertTrue(!iter.hasNext()); } @Test public void testSeek() { logger.warn("Executing testSeek"); - RODRecordList twoList = iter.seekForward(GenomeLocParser.createGenomeLoc("chrM", 20)); - TabularROD two = twoList.getRecords().get(0); + RODRecordList twoList = iter.seekForward(GenomeLocParser.createGenomeLoc("chrM", 20)); + TabularROD two = (TabularROD)twoList.getRecords().get(0); assertTrue(two.size() == 4); assertTrue(two.getLocation().equals(GenomeLocParser.createGenomeLoc("chrM", 20))); assertTrue(two.get("COL1").equals("C")); @@ -114,8 +114,8 @@ public class TabularRODTest extends BaseTest { @Test public void testToString() { logger.warn("Executing testToString"); - RODRecordList oneList = iter.next(); - TabularROD one = oneList.getRecords().get(0); + RODRecordList oneList = iter.next(); + TabularROD one = (TabularROD)oneList.getRecords().get(0); assertTrue(one.toString().equals("chrM:10\tA\tB\tC")); } @@ -124,11 +124,11 @@ public class TabularRODTest extends BaseTest { public void testDelim1() { File file2 = new File(testDir + "TabularDataTest2.dat"); ReferenceOrderedData ROD_commas = new ReferenceOrderedData("tableTest", file2, TabularROD.class); - SeekableRODIterator iter_commas = ROD_commas.iterator(); + SeekableRODIterator iter_commas = ROD_commas.iterator(); logger.warn("Executing testDelim1"); - RODRecordList one2List = iter_commas.next(); - TabularROD one2 = one2List.getRecords().get(0); + RODRecordList one2List = iter_commas.next(); + TabularROD one2 = (TabularROD)one2List.getRecords().get(0); assertTrue(one2.size() == 5); assertTrue(one2.getLocation().equals(GenomeLocParser.createGenomeLoc("chrM", 10))); assertTrue(one2.get("COL1").equals("A")); @@ -142,11 +142,11 @@ public class TabularRODTest extends BaseTest { TabularROD.setDelimiter(",",","); File file2 = new File(testDir + "TabularDataTest2.dat"); ReferenceOrderedData ROD_commas = new ReferenceOrderedData("tableTest", file2, TabularROD.class); - SeekableRODIterator iter_commas = ROD_commas.iterator(); + SeekableRODIterator iter_commas = ROD_commas.iterator(); logger.warn("Executing testDelim1"); - RODRecordList one2List = iter_commas.next(); - TabularROD one2 = one2List.getRecords().get(0); + RODRecordList one2List = iter_commas.next(); + TabularROD one2 = (TabularROD)one2List.getRecords().get(0); assertTrue(one2.size() == 5); assertTrue(one2.getLocation().equals(GenomeLocParser.createGenomeLoc("chrM", 10))); assertTrue(one2.get("COL1").equals("A")); @@ -187,18 +187,18 @@ public class TabularRODTest extends BaseTest { out.println(row.toString()); ReferenceOrderedData ROD_commas = new ReferenceOrderedData("tableTest", outputFile, TabularROD.class); - SeekableRODIterator iter_commas = ROD_commas.iterator(); + SeekableRODIterator iter_commas = ROD_commas.iterator(); - RODRecordList oneList = iter_commas.next(); - TabularROD one = oneList.getRecords().get(0); + RODRecordList oneList = iter_commas.next(); + TabularROD one = (TabularROD)oneList.getRecords().get(0); assertTrue(one.size() == 4); assertTrue(one.getLocation().equals(GenomeLocParser.createGenomeLoc("chrM", 1))); assertTrue(one.get("col1").equals("1")); assertTrue(one.get("col2").equals("2")); assertTrue(one.get("col3").equals("3")); - RODRecordList twoList = iter_commas.next(); - TabularROD two = twoList.getRecords().get(0); + RODRecordList twoList = iter_commas.next(); + TabularROD two = (TabularROD)twoList.getRecords().get(0); assertTrue(two.size() == 4); assertTrue(two.getLocation().equals(GenomeLocParser.createGenomeLoc("chrM", 2))); assertTrue(two.get("col1").equals("3"));