starting on RODs for Reads: made RODRecordList implement list<RODatum> (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
This commit is contained in:
aaron 2010-02-24 22:11:53 +00:00
parent 9306041cf4
commit fef1154fc8
26 changed files with 264 additions and 365 deletions

View File

@ -31,11 +31,11 @@ public class RodLocusView extends LocusView implements ReferenceOrderedView {
/**
* The data sources along with their current states.
*/
private MergingIterator<ReferenceOrderedDatum> rodQueue = null;
private MergingIterator rodQueue = null;
RefMetaDataTracker tracker = null;
GenomeLoc lastLoc = null;
RODRecordList<ReferenceOrderedDatum> 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<RODRecordList<ReferenceOrderedDatum>> > iterators = new LinkedList< Iterator<RODRecordList<ReferenceOrderedDatum>> >();
List< Iterator<List<ReferenceOrderedDatum>> > iterators = new LinkedList< Iterator<List<ReferenceOrderedDatum>> >();
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<ReferenceOrderedDatum>)it.next();
interval = it.next();
} else {
iterators.add( it );
}
}
rodQueue = new MergingIterator<ReferenceOrderedDatum>(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<ReferenceOrderedDatum> 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<RODRecordList<ReferenceOrderedDatum>> allTracksHere = getSpanningTracks(datum);
Collection<RODRecordList> 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<RODRecordList<ReferenceOrderedDatum>> allTracksHere ) {
private RefMetaDataTracker createTracker( Collection<RODRecordList> allTracksHere ) {
RefMetaDataTracker t = new RefMetaDataTracker();
for ( RODRecordList<ReferenceOrderedDatum> 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<RODRecordList<ReferenceOrderedDatum>> getSpanningTracks(RODRecordList<ReferenceOrderedDatum> marker) {
private Collection<RODRecordList> getSpanningTracks(RODRecordList marker) {
return rodQueue.allElementsLTE(marker);
}

View File

@ -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<String,GenomeLoc> last_intervals = new HashMap<String,GenomeLoc>();
private static Map<String,ReferenceOrderedDatum> last_rods = new HashMap<String,ReferenceOrderedDatum>();
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<ReferenceOrderedDatum> 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;
}
}

View File

@ -13,72 +13,74 @@ import java.util.*;
* Time: 6:10:48 PM
* To change this template use File | Settings | File Templates.
*/
public class RODRecordList<ROD extends ReferenceOrderedDatum> implements Iterable<ROD>, Comparable<RODRecordList<ROD>>, Cloneable {
private List<ROD> records;
public class RODRecordList extends AbstractList<ReferenceOrderedDatum> implements Comparable<RODRecordList>, Cloneable {
private List<ReferenceOrderedDatum> 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<ROD>();
records = new ArrayList<ReferenceOrderedDatum>();
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<ROD> data, GenomeLoc loc) {
this.records = new ArrayList<ROD>(data==null?0:data.size());
public RODRecordList(String name, Collection<ReferenceOrderedDatum> data, GenomeLoc loc) {
this.records = new ArrayList<ReferenceOrderedDatum>(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<ROD> getRecords() { return records; }
public Iterator<ROD> iterator() { return records.iterator() ; }
public List<ReferenceOrderedDatum> getRecords() { return records; }
public Iterator<ReferenceOrderedDatum> 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<ROD> records ) { add( records, false ); }
public void add(RODRecordList records ) { add( records, false ); }
public void add(RODRecordList<ROD> 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<ROD extends ReferenceOrderedDatum> 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.
* <p/>
* <p>The implementor must ensure <tt>sgn(x.compareTo(y)) ==
* -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This
* implies that <tt>x.compareTo(y)</tt> must throw an exception iff
* <tt>y.compareTo(x)</tt> throws an exception.)
* <p/>
* <p>The implementor must also ensure that the relation is transitive:
* <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies
* <tt>x.compareTo(z)&gt;0</tt>.
* <p/>
* <p>Finally, the implementor must ensure that <tt>x.compareTo(y)==0</tt>
* implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for
* all <tt>z</tt>.
* <p/>
* <p>It is strongly recommended, but <i>not</i> strictly required that
* <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>. Generally speaking, any
* class that implements the <tt>Comparable</tt> 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."
* <p/>
* <p>In the foregoing description, the notation
* <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical
* <i>signum</i> function, which is defined to return one of <tt>-1</tt>,
* <tt>0</tt>, or <tt>1</tt> according to whether the value of
* <i>expression</i> 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<ROD extends ReferenceOrderedDatum> implements Iterabl
* @throws ClassCastException if the specified object's type prevents it
* from being compared to this object.
*/
public int compareTo(RODRecordList<ROD> 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.
}
}

View File

@ -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<String, RODRecordList<ReferenceOrderedDatum>> map = new HashMap<String, RODRecordList<ReferenceOrderedDatum>>();
final HashMap<String, RODRecordList> map = new HashMap<String, RODRecordList>();
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<ReferenceOrderedDatum> value = map.get(luName) ;
RODRecordList value = map.get(luName) ;
if ( value != null ) {
List<ReferenceOrderedDatum> 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<ReferenceOrderedDatum> 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<ReferenceOrderedDatum> trackData = null;
RODRecordList trackData = null;
if ( requireExactMatch ) {
if ( map.containsKey(luName) )
trackData = map.get(luName);
} else {
for ( Map.Entry<String, RODRecordList<ReferenceOrderedDatum>> datum : map.entrySet() ) {
for ( Map.Entry<String, RODRecordList> datum : map.entrySet() ) {
final String rodName = datum.getKey();
if ( rodName.startsWith(luName) ) {
if ( trackData == null ) trackData = new RODRecordList<ReferenceOrderedDatum>(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<ReferenceOrderedDatum>(defaultValue.getName(),
return new RODRecordList(defaultValue.getName(),
Collections.singletonList(defaultValue),
defaultValue.getLocation());
}
public RODRecordList<ReferenceOrderedDatum> 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<ReferenceOrderedDatum> getAllRods() {
List<ReferenceOrderedDatum> l = new ArrayList<ReferenceOrderedDatum>();
for ( RODRecordList<ReferenceOrderedDatum> 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<RODRecordList<ReferenceOrderedDatum>> getBoundRodTracks() {
LinkedList<RODRecordList<ReferenceOrderedDatum>> bound = new LinkedList<RODRecordList<ReferenceOrderedDatum>>();
public Collection<RODRecordList> getBoundRodTracks() {
LinkedList<RODRecordList> bound = new LinkedList<RODRecordList>();
for ( RODRecordList<ReferenceOrderedDatum> 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<ReferenceOrderedDatum> 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<ReferenceOrderedDatum> getBoundRodRecords() {
LinkedList<ReferenceOrderedDatum> bound = new LinkedList<ReferenceOrderedDatum>();
for ( RODRecordList<ReferenceOrderedDatum> 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<VariantContext> getAllVariantContexts(EnumSet<VariantContext.Type> allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) {
List<VariantContext> contexts = new ArrayList<VariantContext>();
for ( RODRecordList<ReferenceOrderedDatum> rodList : getBoundRodTracks() ) {
for ( RODRecordList rodList : getBoundRodTracks() ) {
addVariantContexts(contexts, rodList, allowedTypes, curLocation, requireStartHere, takeFirstOnly);
}
@ -254,7 +254,7 @@ public class RefMetaDataTracker {
Collection<VariantContext> contexts = new ArrayList<VariantContext>();
for ( String name : names ) {
RODRecordList<ReferenceOrderedDatum> 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<VariantContext> contexts, RODRecordList<ReferenceOrderedDatum> rodList, EnumSet<VariantContext.Type> allowedTypes, GenomeLoc curLocation, boolean requireStartHere, boolean takeFirstOnly ) {
private void addVariantContexts(Collection<VariantContext> contexts, RODRecordList rodList, EnumSet<VariantContext.Type> 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<ReferenceOrderedDatum> rod) {
public void bind(final String name, RODRecordList rod) {
//logger.debug(String.format("Binding %s to %s", name, rod));
map.put(canonicalName(name), rod);
}

View File

@ -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<ROD extends ReferenceOrderedDatum> implements Iterable<RODRecordList<ROD>> { // }, RMDTrackBuilder {
public class ReferenceOrderedData<ROD extends ReferenceOrderedDatum> implements Iterable<List<ReferenceOrderedDatum>> { // }, RMDTrackBuilder {
private String name;
private File file = null;
// private String fieldDelimiter;
@ -234,11 +235,11 @@ public class ReferenceOrderedData<ROD extends ReferenceOrderedDatum> implements
return this.name.equals(name) && type.isAssignableFrom(this.type);
}
public SeekableRODIterator<ROD> iterator() {
Iterator<ROD> it;
public SeekableRODIterator iterator() {
Iterator<ReferenceOrderedDatum> it;
try {
Method m = type.getDeclaredMethod("createIterator", String.class, java.io.File.class);
it = (Iterator<ROD>) m.invoke(null, name, file);
it = (Iterator<ReferenceOrderedDatum>) 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<ROD extends ReferenceOrderedDatum> implements
return new SeekableRODIterator(it);
}
// ----------------------------------------------------------------------
//
// Testing
//
// ----------------------------------------------------------------------
public void testMe() {
for (RODRecordList<ROD> 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<ROD extends ReferenceOrderedDatum> implements
// ----------------------------------------------------------------------
public ArrayList<ReferenceOrderedDatum> readAll() {
ArrayList<ReferenceOrderedDatum> elts = new ArrayList<ReferenceOrderedDatum>();
for ( RODRecordList<ROD> l : this ) {
for ( List<ReferenceOrderedDatum> l : this ) {
for (ReferenceOrderedDatum rec : l) {
elts.add(rec);
}
@ -306,7 +289,7 @@ public class ReferenceOrderedData<ROD extends ReferenceOrderedDatum> implements
public boolean validateFile() throws Exception {
ReferenceOrderedDatum last = null;
for ( RODRecordList<ROD> l : this ) {
for ( List<ReferenceOrderedDatum> l : this ) {
for (ReferenceOrderedDatum rec : l) {
if (last != null && last.compareTo(rec) > 1) {
// It's out of order

View File

@ -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<ROD extends ReferenceOrderedDatum> implements Iterator<RODRecordList<ROD> > {
private PushbackIterator<ROD> it;
List<ROD> records = null; // here we will keep a pile of records overlaping with current position; when we iterate
public class SeekableRODIterator implements Iterator<List<ReferenceOrderedDatum>> {
private PushbackIterator<ReferenceOrderedDatum> it;
List<ReferenceOrderedDatum> 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<ROD extends ReferenceOrderedDatum> 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<ROD> it) {
this.it = new PushbackIterator<ROD>(it);
records = new LinkedList<ROD>();
public SeekableRODIterator(Iterator<ReferenceOrderedDatum> it) {
this.it = new PushbackIterator<ReferenceOrderedDatum>(it);
records = new LinkedList<ReferenceOrderedDatum>();
// 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<ROD extends ReferenceOrderedDatum> 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<ROD extends ReferenceOrderedDatum> 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<ROD> 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<ROD extends ReferenceOrderedDatum> 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<ROD extends ReferenceOrderedDatum> 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<ROD extends ReferenceOrderedDatum> 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<ROD> 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<ROD extends ReferenceOrderedDatum> 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<ROD extends ReferenceOrderedDatum> implements I
}
if ( records.size() > 0 ) {
return new RODRecordList<ROD>(name,records,interval.clone());
return new RODRecordList(name,records,interval.clone());
} else {
return null;
}
@ -335,9 +335,9 @@ public class SeekableRODIterator<ROD extends ReferenceOrderedDatum> implements I
* curr_position <= max_position, as well as that we are still on the same contig.
*/
private void purgeOutOfScopeRecords() {
Iterator<ROD> i = records.iterator();
Iterator<ReferenceOrderedDatum> 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
}

View File

@ -280,7 +280,7 @@ public class rodDbSNP extends BasicReferenceOrderedDatum implements VariationRod
return getAlternateAlleleList().size() == 1;
}
public static rodDbSNP getFirstRealSNP(RODRecordList<ReferenceOrderedDatum> dbsnpList) {
public static rodDbSNP getFirstRealSNP(RODRecordList dbsnpList) {
if (dbsnpList == null)
return null;

View File

@ -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<rodRefSeq> 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<rodRefSeq> 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 <i>and</i> within a coding interval simultaneously.
* @return
*/
public static boolean isCodingExon(RODRecordList<rodRefSeq> 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;

View File

@ -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<GATKFeature> getIterator() {
return data.iterator();
return new SRIToIterator(data.iterator());
}
}
class SRIToIterator implements Iterator<GATKFeature> {
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");
}
}

View File

@ -52,7 +52,7 @@ public class FeatureToGATKFeatureIterator implements Iterator<GATKFeature> {
@Override
public GATKFeature next() {
return new TribbleGATKFeature(iterator.next(),name);
return new GATKFeature.TribbleGATKFeature(iterator.next(),name);
}
@Override

View File

@ -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();
}
}

View File

@ -185,7 +185,7 @@ public class VariantAnnotator extends LocusWalker<Integer, Integer> {
if ( tracker == null )
return 0;
RODRecordList<ReferenceOrderedDatum> 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;

View File

@ -26,7 +26,7 @@ public class PickSequenomProbes extends RefWalker<String, String> {
String project_id = null;
private byte [] maskFlags = new byte[401];
private SeekableRODIterator<TabularROD> snpMaskIterator=null;
private SeekableRODIterator snpMaskIterator=null;
public void initialize() {
if ( SNP_MASK != null ) {
@ -66,9 +66,9 @@ public class PickSequenomProbes extends RefWalker<String, String> {
// we have variant; let's load all the snps falling into the current window and prepare the mask array:
if ( snpMaskIterator != null ) {
RODRecordList<TabularROD> 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<TabularROD> snpsInWindow = snpList.iterator();
Iterator<ReferenceOrderedDatum> snpsInWindow = snpList.iterator();
int i = 0;
while ( snpsInWindow.hasNext() ) {
GenomeLoc snp = snpsInWindow.next().getLocation();

View File

@ -115,7 +115,7 @@ public class VariantFiltrationWalker extends RodWalker<Integer, Integer> {
if ( tracker == null )
return 0;
RODRecordList<ReferenceOrderedDatum> 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<Integer, Integer> {
StringBuilder filterString = new StringBuilder();
// test for SNP mask, if present
RODRecordList<ReferenceOrderedDatum> mask = context.first.getTrackData("mask", null);
RODRecordList mask = context.first.getTrackData("mask", null);
if ( mask != null && mask.getRecords().size() > 0 )
addFilter(filterString, MASK_NAME);

View File

@ -80,7 +80,7 @@ public class IndelGenotyperV2Walker extends ReadWalker<Integer,Integer> {
boolean outOfContigUserWarned = false;
private SeekableRODIterator<rodRefSeq> refseqIterator=null;
private SeekableRODIterator refseqIterator=null;
private Set<String> normalReadGroups; // we are going to remember which read groups are normals and which are tumors in order to be able
private Set<String> tumorReadGroups ; // to properly assign the reads coming from a merged stream
@ -329,7 +329,7 @@ public class IndelGenotyperV2Walker extends ReadWalker<Integer,Integer> {
location = GenomeLocParser.setStart(location,pos);
location = GenomeLocParser.setStop(location,pos); // retrieve annotation data
RODRecordList<rodRefSeq> 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<Integer,Integer> {
location = GenomeLocParser.setStart(location,pos);
location = GenomeLocParser.setStop(location,pos); // retrieve annotation data
RODRecordList<rodRefSeq> 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<Integer,Integer> {
return fullRecord.toString();
}
private String getAnnotationString(RODRecordList<rodRefSeq> ann) {
private String getAnnotationString(RODRecordList ann) {
if ( ann == null ) return annGenomic;
else {
StringBuilder b = new StringBuilder();

View File

@ -61,8 +61,8 @@ public class CountRodWalker extends RodWalker<CountRodWalker.Datum, Pair<Expandi
nRodsHere = -1; // don't update this
nTotalBases = context.getSkippedBases();
} else {
Collection<RODRecordList<ReferenceOrderedDatum>> rods = new LinkedList<RODRecordList<ReferenceOrderedDatum>>();
for ( RODRecordList<ReferenceOrderedDatum> rod : tracker.getBoundRodTracks() ) {
Collection<RODRecordList> rods = new LinkedList<RODRecordList>();
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<CountRodWalker.Datum, Pair<Expandi
if ( nRodsHere > 0 ) {
if ( verbose ) {
List<String> names = new ArrayList<String>();
for ( RODRecordList<ReferenceOrderedDatum> rod : rods ) {
for ( RODRecordList rod : rods ) {
names.add(rod.getName());
}

View File

@ -25,7 +25,7 @@ public class VCFValidator extends RodWalker<Integer, Integer> {
public Integer map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
if ( tracker != null ) {
RODRecordList<ReferenceOrderedDatum> 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()) )

View File

@ -78,7 +78,7 @@ public abstract class ChipConcordance extends BasicVariantAnalysis {
// get all of the chip rods at this locus
HashMap<String, Genotype> chips = new HashMap<String, Genotype>();
for ( String name : rodNames ) {
RODRecordList<ReferenceOrderedDatum> 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

View File

@ -58,7 +58,7 @@ public class VariantDBCoverage extends BasicVariantAnalysis implements GenotypeA
return nConcordant() / (1.0 * nSNPsAtdbSNPs());
}
public static Variation getFirstRealSNP(RODRecordList<ReferenceOrderedDatum> dbsnpList) {
public static Variation getFirstRealSNP(RODRecordList dbsnpList) {
if (dbsnpList == null)
return null;

View File

@ -359,7 +359,7 @@ public class VariantEvalWalker extends RodWalker<Integer, Integer> {
}
private ANALYSIS_TYPE getNovelAnalysisType(RefMetaDataTracker tracker) {
RODRecordList<ReferenceOrderedDatum> dbsnpList = tracker.getTrackData("dbsnp", null);
RODRecordList dbsnpList = tracker.getTrackData("dbsnp", null);
if (dbsnpList == null)
return ANALYSIS_TYPE.NOVEL_SNPS;

View File

@ -135,7 +135,7 @@ public class HapmapPoolAllelicInfoWalker extends LocusWalker<String, PrintWriter
private List<Pair<Genotype,Genotype>> getChips(String[] rodNames, RefMetaDataTracker tracker) {
List<Pair<Genotype, Genotype>> chips = new ArrayList <Pair<Genotype,Genotype>>(rodNames.length);
for ( String name : rodNames ) {
RODRecordList<ReferenceOrderedDatum> 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

View File

@ -37,7 +37,7 @@ public class SNPDensity extends RefWalker<Pair<VariantContext, GenomeLoc>, SNPDe
public Pair<VariantContext, GenomeLoc> map(RefMetaDataTracker tracker, ReferenceContext ref, AlignmentContext context) {
VariantContext vc = null;
RODRecordList<ReferenceOrderedDatum> vcfList = tracker.getTrackData("eval", null);
RODRecordList vcfList = tracker.getTrackData("eval", null);
if (vcfList != null) {
for (ReferenceOrderedDatum d : vcfList) {
RodVCF vcfRecord = (RodVCF)d;

View File

@ -56,7 +56,7 @@ public class HybSelPerformanceWalker extends LocusWalker<Integer, HybSelPerforma
doc="Name of RefSeq transcript annotation file. If specified, intervals will be specified with gene names", required=false)
String REFSEQ_FILE = null;
private SeekableRODIterator<rodRefSeq> refseqIterator=null;
private SeekableRODIterator refseqIterator=null;
public static class TargetInfo {
public int counts = 0;
@ -247,12 +247,12 @@ public class HybSelPerformanceWalker extends LocusWalker<Integer, HybSelPerforma
private String getGeneName(GenomeLoc target) {
if (refseqIterator == null) { return "UNKNOWN"; }
RODRecordList<rodRefSeq> 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();
}
}

View File

@ -79,7 +79,7 @@ public class VCFSelectWalker extends RodWalker<Integer, Integer> {
if ( tracker == null )
return 0;
RODRecordList<ReferenceOrderedDatum> 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;

View File

@ -8,7 +8,7 @@ import org.broadinstitute.sting.gatk.refdata.RODRecordList;
import java.util.*;
public class MergingIterator<ROD extends ReferenceOrderedDatum> implements Iterator<RODRecordList<ROD>>, Iterable<RODRecordList<ROD>> {
public class MergingIterator implements Iterator<RODRecordList>, Iterable<RODRecordList> {
PriorityQueue<Element> queue = new PriorityQueue<Element>();
private class Element implements Comparable<Element> {
@ -16,7 +16,7 @@ public class MergingIterator<ROD extends ReferenceOrderedDatum> implements Itera
//public E value = null;
public GenomeLoc nextLoc = null;
public Element(Iterator<RODRecordList<ROD>> it) {
public Element(Iterator<List<ReferenceOrderedDatum>> 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<ROD extends ReferenceOrderedDatum> implements Itera
return nextLoc.compareTo(other.nextLoc);
}
public RODRecordList<ROD> next() {
RODRecordList<ROD> value = it.next();
public RODRecordList next() {
RODRecordList value = it.next();
update();
return value;
}
}
public Iterator<RODRecordList<ROD>> iterator() {
public Iterator<RODRecordList> iterator() {
return this;
}
@ -57,12 +57,12 @@ public class MergingIterator<ROD extends ReferenceOrderedDatum> implements Itera
;
}
public MergingIterator(Iterator<RODRecordList<ROD>> it) {
public MergingIterator(Iterator<List<ReferenceOrderedDatum>> it) {
add(it);
}
public MergingIterator(Collection<Iterator<RODRecordList<ROD>>> its) {
for ( Iterator<RODRecordList<ROD>> it : its ) {
public MergingIterator(Collection<Iterator<List<ReferenceOrderedDatum>>> its) {
for ( Iterator<List<ReferenceOrderedDatum>> it : its ) {
add(it);
}
}
@ -71,7 +71,7 @@ public class MergingIterator<ROD extends ReferenceOrderedDatum> 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<RODRecordList<ROD>> it) {
public void add(Iterator<List<ReferenceOrderedDatum>> it) {
if ( it.hasNext() )
queue.add(new Element(it));
}
@ -80,9 +80,9 @@ public class MergingIterator<ROD extends ReferenceOrderedDatum> implements Itera
return ! queue.isEmpty();
}
public RODRecordList<ROD> next() {
public RODRecordList next() {
Element e = queue.poll();
RODRecordList<ROD> 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<ROD extends ReferenceOrderedDatum> implements Itera
return queue.peek().nextLoc;
}
public Collection<RODRecordList<ROD>> allElementsLTE(RODRecordList<ROD> elt) {
public Collection<RODRecordList> allElementsLTE(RODRecordList elt) {
return allElementsLTE(elt, true);
}
public Collection<RODRecordList<ROD>> allElementsLTE(RODRecordList<ROD> elt, boolean includeElt) {
LinkedList<RODRecordList<ROD>> all = new LinkedList<RODRecordList<ROD>>();
public Collection<RODRecordList> allElementsLTE(RODRecordList elt, boolean includeElt) {
LinkedList<RODRecordList> all = new LinkedList<RODRecordList>();
if ( includeElt ) all.add(elt);

View File

@ -26,7 +26,7 @@ import net.sf.picard.reference.ReferenceSequenceFile;
public class TabularRODTest extends BaseTest {
private static ReferenceSequenceFile seq;
private ReferenceOrderedData ROD;
private SeekableRODIterator<TabularROD> iter;
private SeekableRODIterator iter;
@BeforeClass
@ -48,8 +48,8 @@ public class TabularRODTest extends BaseTest {
@Test
public void test1() {
logger.warn("Executing test1");
RODRecordList<TabularROD> 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<TabularROD> oneList = iter.next();
RODRecordList<TabularROD> 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<TabularROD> oneList = iter.next();
RODRecordList<TabularROD> twoList = iter.next();
RODRecordList<TabularROD> 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<TabularROD> oneList = iter.next();
RODRecordList<TabularROD> twoList = iter.next();
RODRecordList<TabularROD> 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<TabularROD> 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<TabularROD> 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<TabularROD> iter_commas = ROD_commas.iterator();
SeekableRODIterator iter_commas = ROD_commas.iterator();
logger.warn("Executing testDelim1");
RODRecordList<TabularROD> 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<TabularROD> iter_commas = ROD_commas.iterator();
SeekableRODIterator iter_commas = ROD_commas.iterator();
logger.warn("Executing testDelim1");
RODRecordList<TabularROD> 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<TabularROD> iter_commas = ROD_commas.iterator();
SeekableRODIterator iter_commas = ROD_commas.iterator();
RODRecordList<TabularROD> 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<TabularROD> 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"));