From 485023ba8ed8f70020a10c9cc940139d5af4ee26 Mon Sep 17 00:00:00 2001 From: asivache Date: Thu, 22 Jul 2010 16:00:30 +0000 Subject: [PATCH] this.intersect(that) method added to GenomeLoc (returns intersection of two intervals or dies if the locations do not overlap) git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3852 348d0f76-0448-11de-a6fe-93d51630548a --- .../org/broadinstitute/sting/utils/GenomeLoc.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/java/src/org/broadinstitute/sting/utils/GenomeLoc.java b/java/src/org/broadinstitute/sting/utils/GenomeLoc.java index 0dc66f055..3a24da611 100644 --- a/java/src/org/broadinstitute/sting/utils/GenomeLoc.java +++ b/java/src/org/broadinstitute/sting/utils/GenomeLoc.java @@ -172,6 +172,16 @@ public class GenomeLoc implements Comparable, Cloneable, Serializable Math.max( getStop(), that.getStop()) ); } + public GenomeLoc intersect( GenomeLoc that ) throws StingException { + if (!(this.overlapsP(that))) { + throw new StingException("GenomeLoc::intersect(): The two genome loc's need to overlap"); + } + + return new GenomeLoc(getContig(), this.contigIndex, + Math.max(getStart(), that.getStart()), + Math.min( getStop(), that.getStop()) ); + } + public final boolean containsP(GenomeLoc that) { return onSameContig(that) && getStart() <= that.getStart() && getStop() >= that.getStop(); } @@ -214,7 +224,7 @@ public class GenomeLoc implements Comparable, Cloneable, Serializable return ( comparison == 1 || ( comparison == 0 && this.getStart() > that.getStop() )); } - + /** * Check to see whether two genomeLocs are equal.