Fix for ROD in TraversalEngine
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@18 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
b19e4b502b
commit
63f8d82e36
|
|
@ -48,7 +48,6 @@ public class PrepareROD extends CommandLineProgram {
|
|||
final ReferenceSequenceFile refFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(REF_FILE_ARG);
|
||||
List<SAMSequenceRecord> refContigs = refFile.getSequenceDictionary();
|
||||
HashMap<String, Integer> refContigOrdering = new HashMap<String, Integer>();
|
||||
ReferenceOrderedDatum.setContigOrdering(refContigOrdering);
|
||||
|
||||
int i = 0;
|
||||
for ( SAMSequenceRecord contig : refContigs ) {
|
||||
|
|
@ -56,6 +55,7 @@ public class PrepareROD extends CommandLineProgram {
|
|||
refContigOrdering.put(contig.getSequenceName(), i);
|
||||
i++;
|
||||
}
|
||||
ReferenceOrderedDatum.setContigOrdering(refContigOrdering);
|
||||
|
||||
Class rodClass = Types.get(ROD_TYPE.toLowerCase());
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import edu.mit.broad.picard.reference.ReferenceSequenceFileFactory;
|
|||
import edu.mit.broad.sting.utils.ReferenceIterator;
|
||||
import edu.mit.broad.sting.utils.ReferenceOrderedData;
|
||||
import edu.mit.broad.sting.utils.ReferenceOrderedDatum;
|
||||
import edu.mit.broad.sting.utils.Utils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
|
@ -89,6 +90,7 @@ public class TraversalEngine {
|
|||
if ( refFileName!= null ) {
|
||||
this.refFile = ReferenceSequenceFileFactory.getReferenceSequenceFile(refFileName);
|
||||
this.refIter = new ReferenceIterator(this.refFile);
|
||||
Utils.setupRefContigOrdering(this.refFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ public class ReferenceOrderedData<ROD extends ReferenceOrderedDatum> implements
|
|||
while ( hasNext() ) {
|
||||
ROD current = next();
|
||||
//System.out.printf(" -> Seeking to %s %d AT %s %d%n", contigName, pos, current.getContig(), current.getStart());
|
||||
int strCmp = contigName.compareTo( prev.getContig() );
|
||||
int strCmp = ReferenceOrderedDatum.compareContigs( contigName, prev.getContig() );// contigName.compareTo( prev.getContig() );
|
||||
if ( strCmp == 0 ) {
|
||||
// The contigs are equal
|
||||
if ( current.getStart() > pos ) {
|
||||
|
|
@ -161,8 +161,9 @@ public class ReferenceOrderedData<ROD extends ReferenceOrderedDatum> implements
|
|||
}
|
||||
}
|
||||
else if ( strCmp < 0 ) {
|
||||
if ( DEBUG ) System.out.printf(" -> Jumping to contig %s%n", contigName);
|
||||
if ( DEBUG ) System.out.printf(" -> Jumped to contig %s%n", contigName);
|
||||
// We've gone past the desired contig, break
|
||||
it.pushback(current);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,40 +31,43 @@ public abstract class ReferenceOrderedDatum implements Comparable {
|
|||
public abstract long getStart();
|
||||
public abstract long getStop();
|
||||
|
||||
public int compareTo( Object x ) {
|
||||
if ( this == x ) return 0;
|
||||
|
||||
ReferenceOrderedDatum that = (ReferenceOrderedDatum)x;
|
||||
|
||||
public static int compareContigs( final String thisContig, final String thatContig ) {
|
||||
if ( refContigOrdering != null ) {
|
||||
if ( ! refContigOrdering.containsKey(this.getContig()) ) {
|
||||
if ( ! refContigOrdering.containsKey(that.getContig()) ) {
|
||||
if ( ! refContigOrdering.containsKey(thisContig) ) {
|
||||
if ( ! refContigOrdering.containsKey(thatContig) ) {
|
||||
// Use regular sorted order
|
||||
int cmpContig = getContig().compareTo(that.getContig());
|
||||
if ( cmpContig != 0 )return cmpContig;
|
||||
return thisContig.compareTo(thatContig);
|
||||
}
|
||||
else {
|
||||
// this is always bigger if that is in the key set
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if ( ! refContigOrdering.containsKey(that.getContig()) )
|
||||
else if ( ! refContigOrdering.containsKey(thatContig) )
|
||||
return -1;
|
||||
else {
|
||||
assert refContigOrdering.containsKey(this.getContig()) : this;
|
||||
assert refContigOrdering.containsKey(that.getContig()) : that;
|
||||
assert refContigOrdering.containsKey(thisContig);// : this;
|
||||
assert refContigOrdering.containsKey(thatContig);// : that;
|
||||
|
||||
final int thisO = refContigOrdering.get(this.getContig());
|
||||
final int thatO = refContigOrdering.get(that.getContig());
|
||||
final int thisO = refContigOrdering.get(thisContig);
|
||||
final int thatO = refContigOrdering.get(thatContig);
|
||||
if ( thisO < thatO ) return -1;
|
||||
if ( thisO > thatO ) return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
int cmpContig = getContig().compareTo(that.getContig());
|
||||
if ( cmpContig != 0 )return cmpContig;
|
||||
return thisContig.compareTo(thatContig);
|
||||
}
|
||||
}
|
||||
|
||||
public int compareTo( Object x ) {
|
||||
if ( this == x ) return 0;
|
||||
|
||||
ReferenceOrderedDatum that = (ReferenceOrderedDatum)x;
|
||||
|
||||
final int cmpContig = compareContigs( this.getContig(), that.getContig() );
|
||||
if ( cmpContig != 0 ) return cmpContig;
|
||||
if ( this.getStart() < that.getStart() ) return -1;
|
||||
if ( this.getStart() > that.getStart() ) return 1;
|
||||
if ( this.getStop() < that.getStop() ) return -1;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
package edu.mit.broad.sting.utils;
|
||||
|
||||
import edu.mit.broad.sam.SAMRecord;
|
||||
import edu.mit.broad.sam.SAMSequenceRecord;
|
||||
import edu.mit.broad.picard.reference.ReferenceSequenceFileFactory;
|
||||
import edu.mit.broad.picard.reference.ReferenceSequence;
|
||||
import edu.mit.broad.picard.reference.ReferenceSequenceFile;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -63,4 +67,20 @@ public class Utils {
|
|||
}
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public static void setupRefContigOrdering(final ReferenceSequenceFile refFile) {
|
||||
List<SAMSequenceRecord> refContigs = refFile.getSequenceDictionary();
|
||||
HashMap<String, Integer> refContigOrdering = new HashMap<String, Integer>();
|
||||
|
||||
int i = 0;
|
||||
System.out.printf("Prepared reference sequence contig dictionary%n order ->");
|
||||
for ( SAMSequenceRecord contig : refContigs ) {
|
||||
System.out.printf(" %s", contig.getSequenceName());
|
||||
refContigOrdering.put(contig.getSequenceName(), i);
|
||||
i++;
|
||||
}
|
||||
System.out.printf("%n Total elements -> %d%n", refContigOrdering.size());
|
||||
|
||||
ReferenceOrderedDatum.setContigOrdering(refContigOrdering);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue