2009-02-28 01:07:57 +08:00
|
|
|
package edu.mit.broad.sting.utils;
|
|
|
|
|
|
2009-03-02 07:32:23 +08:00
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Ugly global variable defining the optional ordering of contig elements
|
|
|
|
|
//
|
2009-02-28 01:07:57 +08:00
|
|
|
/**
|
|
|
|
|
* Created by IntelliJ IDEA.
|
|
|
|
|
* User: mdepristo
|
|
|
|
|
* Date: Feb 27, 2009
|
|
|
|
|
* Time: 10:49:47 AM
|
|
|
|
|
* To change this template use File | Settings | File Templates.
|
|
|
|
|
*/
|
2009-03-02 07:32:23 +08:00
|
|
|
public abstract class ReferenceOrderedDatum implements Comparable {
|
|
|
|
|
public static HashMap<String, Integer> refContigOrdering = null;
|
|
|
|
|
public static void setContigOrdering(HashMap<String, Integer> rco) {
|
|
|
|
|
refContigOrdering = rco;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-01 04:47:48 +08:00
|
|
|
public ReferenceOrderedDatum() { }
|
2009-02-28 01:07:57 +08:00
|
|
|
|
2009-03-01 04:47:48 +08:00
|
|
|
public abstract void parseLine(final String[] parts);
|
2009-02-28 01:07:57 +08:00
|
|
|
|
2009-03-01 04:47:48 +08:00
|
|
|
public abstract String toString();
|
|
|
|
|
public abstract String toSimpleString();
|
2009-03-02 07:32:23 +08:00
|
|
|
public abstract String repl();
|
2009-02-28 01:07:57 +08:00
|
|
|
|
2009-03-01 04:47:48 +08:00
|
|
|
public abstract String getContig();
|
|
|
|
|
public abstract long getStart();
|
|
|
|
|
public abstract long getStop();
|
2009-03-02 07:32:23 +08:00
|
|
|
|
|
|
|
|
public int compareTo( Object x ) {
|
|
|
|
|
if ( this == x ) return 0;
|
|
|
|
|
|
|
|
|
|
ReferenceOrderedDatum that = (ReferenceOrderedDatum)x;
|
|
|
|
|
|
|
|
|
|
if ( refContigOrdering != null ) {
|
|
|
|
|
if ( ! refContigOrdering.containsKey(this.getContig()) ) {
|
|
|
|
|
if ( ! refContigOrdering.containsKey(that.getContig()) ) {
|
|
|
|
|
// Use regular sorted order
|
|
|
|
|
int cmpContig = getContig().compareTo(that.getContig());
|
|
|
|
|
if ( cmpContig != 0 )return cmpContig;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// this is always bigger if that is in the key set
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ( ! refContigOrdering.containsKey(that.getContig()) )
|
|
|
|
|
return -1;
|
|
|
|
|
else {
|
|
|
|
|
assert refContigOrdering.containsKey(this.getContig()) : this;
|
|
|
|
|
assert refContigOrdering.containsKey(that.getContig()) : that;
|
|
|
|
|
|
|
|
|
|
final int thisO = refContigOrdering.get(this.getContig());
|
|
|
|
|
final int thatO = refContigOrdering.get(that.getContig());
|
|
|
|
|
if ( thisO < thatO ) return -1;
|
|
|
|
|
if ( thisO > thatO ) return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
int cmpContig = getContig().compareTo(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;
|
|
|
|
|
if ( this.getStop() > that.getStop() ) return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2009-02-28 01:07:57 +08:00
|
|
|
}
|