From 55230ce5f3810b7612346d59c07989c5ab497f39 Mon Sep 17 00:00:00 2001 From: fromer Date: Wed, 20 Oct 2010 19:12:34 +0000 Subject: [PATCH] Added startsBefore, startsAfter, and minDistance [calculates distance between any pair of bases in the two GenomeLocs] git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4531 348d0f76-0448-11de-a6fe-93d51630548a --- .../broadinstitute/sting/utils/GenomeLoc.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/java/src/org/broadinstitute/sting/utils/GenomeLoc.java b/java/src/org/broadinstitute/sting/utils/GenomeLoc.java index 9809bff0d..2a91f7537 100644 --- a/java/src/org/broadinstitute/sting/utils/GenomeLoc.java +++ b/java/src/org/broadinstitute/sting/utils/GenomeLoc.java @@ -201,7 +201,7 @@ public class GenomeLoc implements Comparable, Cloneable, Serializable } public final int minus( final GenomeLoc that ) { - if ( this.contigIndex == that.contigIndex ) + if ( this.onSameContig(that) ) return (int) (this.getStart() - that.getStart()); else return Integer.MAX_VALUE; @@ -225,6 +225,36 @@ public class GenomeLoc implements Comparable, Cloneable, Serializable return ( comparison == 1 || ( comparison == 0 && this.getStart() > that.getStop() )); } + public final boolean startsBefore( GenomeLoc that ) { + int comparison = this.compareContigs(that); + return ( comparison == -1 || ( comparison == 0 && this.getStart() < that.getStart() )); + } + + public final boolean startsAfter( GenomeLoc that ) { + int comparison = this.compareContigs(that); + return ( comparison == 1 || ( comparison == 0 && this.getStart() > that.getStart() )); + } + + // Return the minimum distance between any pair of bases in this and that GenomeLocs: + public final int minDistance( final GenomeLoc that ) { + if (!this.onSameContig(that)) + return Integer.MAX_VALUE; + + int minDistance; + if (this.isBefore(that)) + minDistance = distanceFirstStopToSecondStart(this, that); + else if (that.isBefore(this)) + minDistance = distanceFirstStopToSecondStart(that, this); + else // this and that overlap [and possibly one contains the other]: + minDistance = 0; + + return minDistance; + } + + private static int distanceFirstStopToSecondStart(GenomeLoc locFirst, GenomeLoc locSecond) { + return (int) (locSecond.getStart() - locFirst.getStop()); + } + /**