Optimize getCurrentContigLength and getLocForOffset in ActivityProfile

This commit is contained in:
Mark DePristo 2013-01-23 14:13:21 -05:00
parent 26ef400f85
commit cd91e365f4
1 changed files with 9 additions and 3 deletions

View File

@ -49,6 +49,12 @@ public class ActivityProfile {
protected GenomeLoc regionStartLoc = null; protected GenomeLoc regionStartLoc = null;
protected GenomeLoc regionStopLoc = 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 * Create a new empty ActivityProfile
* @param parser the parser we can use to create genome locs, cannot be null * @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() ) { if ( start < 0 || start > getCurrentContigLength() ) {
return null; return null;
} else { } 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") @Requires("regionStartLoc != null")
@Ensures("result > 0") @Ensures("result > 0")
private int getCurrentContigLength() { private int getCurrentContigLength() {
// TODO -- fix performance problem with getContigInfo return contigLength;
return parser.getContigInfo(regionStartLoc.getContig()).getSequenceLength();
} }
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
@ -190,6 +195,7 @@ public class ActivityProfile {
if ( regionStartLoc == null ) { if ( regionStartLoc == null ) {
regionStartLoc = loc; regionStartLoc = loc;
regionStopLoc = loc; regionStopLoc = loc;
contigLength = parser.getContigInfo(regionStartLoc.getContig()).getSequenceLength();
} else { } else {
// TODO -- need to figure out where to add loc as the regions will be popping off the front // TODO -- need to figure out where to add loc as the regions will be popping off the front
if ( regionStopLoc.getStart() != loc.getStart() - 1 ) if ( regionStopLoc.getStart() != loc.getStart() - 1 )