From 85ff983a591ee964dcf56cbe062a3573ec4f2c63 Mon Sep 17 00:00:00 2001 From: hanna Date: Mon, 7 Mar 2011 23:00:17 +0000 Subject: [PATCH] Failed to include some required GenomeLoc utilities in my last commit. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5397 348d0f76-0448-11de-a6fe-93d51630548a --- .../broadinstitute/sting/utils/GenomeLoc.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/java/src/org/broadinstitute/sting/utils/GenomeLoc.java b/java/src/org/broadinstitute/sting/utils/GenomeLoc.java index df0b358a5..a36248dfa 100644 --- a/java/src/org/broadinstitute/sting/utils/GenomeLoc.java +++ b/java/src/org/broadinstitute/sting/utils/GenomeLoc.java @@ -122,6 +122,17 @@ public class GenomeLoc implements Comparable, Cloneable, Serializable Math.max( getStop(), that.getStop()) ); } + /** + * Splits the contig into to regions: [start,split point) and [split point, end]. + * @param splitPoint The point at which to split the contig. Must be contained in the given interval. + * @return A two element array consisting of the genome loc before the split and the one after. + */ + public GenomeLoc[] split(final int splitPoint) { + if(splitPoint < getStart() || splitPoint > getStop()) + throw new ReviewedStingException(String.format("Unable to split contig %s at split point %d; split point is not contained in region.",this,splitPoint)); + return new GenomeLoc[] { new GenomeLoc(getContig(),contigIndex,getStart(),splitPoint-1), new GenomeLoc(getContig(),contigIndex,splitPoint,getStop()) }; + } + public GenomeLoc intersect( GenomeLoc that ) throws ReviewedStingException { if(GenomeLoc.isUnmapped(this) || GenomeLoc.isUnmapped(that)) { if(! GenomeLoc.isUnmapped(this) || !GenomeLoc.isUnmapped(that)) @@ -171,6 +182,16 @@ public class GenomeLoc implements Comparable, Cloneable, Serializable return ( comparison == -1 || ( comparison == 0 && this.getStop() < that.getStart() )); } + /** + * Tests whether any portion of this contig is before that contig. + * @param that Other contig to test. + * @return True if the start of this contig is before the start of the that contig. + */ + public final boolean startsBefore(final GenomeLoc that) { + int comparison = this.compareContigs(that); + return ( comparison == -1 || ( comparison == 0 && this.getStart() < that.getStart() )); + } + /** * Tests whether this contig is completely after contig 'that'. * @param that Contig to test against.