From cd91e365f4a4f0dfb75a2455e80dc3447f676e22 Mon Sep 17 00:00:00 2001 From: Mark DePristo Date: Wed, 23 Jan 2013 14:13:21 -0500 Subject: [PATCH] Optimize getCurrentContigLength and getLocForOffset in ActivityProfile --- .../sting/utils/activeregion/ActivityProfile.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/utils/activeregion/ActivityProfile.java b/public/java/src/org/broadinstitute/sting/utils/activeregion/ActivityProfile.java index ab9095106..80484e12f 100644 --- a/public/java/src/org/broadinstitute/sting/utils/activeregion/ActivityProfile.java +++ b/public/java/src/org/broadinstitute/sting/utils/activeregion/ActivityProfile.java @@ -49,6 +49,12 @@ public class ActivityProfile { protected GenomeLoc regionStartLoc = null; protected GenomeLoc regionStopLoc = null; + /** + * A cached value of the regionStartLoc contig length, to make calls to + * getCurrentContigLength efficient + */ + protected int contigLength = -1; + /** * Create a new empty ActivityProfile * @param parser the parser we can use to create genome locs, cannot be null @@ -155,7 +161,7 @@ public class ActivityProfile { if ( start < 0 || start > getCurrentContigLength() ) { return null; } else { - return parser.createGenomeLoc(regionStartLoc.getContig(), start); + return parser.createGenomeLoc(regionStartLoc.getContig(), regionStartLoc.getContigIndex(), start, start); } } @@ -166,8 +172,7 @@ public class ActivityProfile { @Requires("regionStartLoc != null") @Ensures("result > 0") private int getCurrentContigLength() { - // TODO -- fix performance problem with getContigInfo - return parser.getContigInfo(regionStartLoc.getContig()).getSequenceLength(); + return contigLength; } // -------------------------------------------------------------------------------- @@ -190,6 +195,7 @@ public class ActivityProfile { if ( regionStartLoc == null ) { regionStartLoc = loc; regionStopLoc = loc; + contigLength = parser.getContigInfo(regionStartLoc.getContig()).getSequenceLength(); } else { // TODO -- need to figure out where to add loc as the regions will be popping off the front if ( regionStopLoc.getStart() != loc.getStart() - 1 )