Fix inefficiency in FilePointer GenomeLoc validation

Validation of GenomeLocs in the FilePointer class was extremely inefficient
when the GenomeLocs were added one at a time rather than all at once.

Appears to mostly fix GSA-604
This commit is contained in:
David Roazen 2012-10-11 19:33:37 -04:00
parent 9b19f5ce99
commit 3861212dab
1 changed files with 27 additions and 11 deletions

View File

@ -58,10 +58,20 @@ public class FilePointer {
*/ */
private boolean isMonolithic = false; private boolean isMonolithic = false;
/**
* Index of the contig covered by this FilePointer. Only meaningful for non-monolithic, mapped FilePointers
*/
private Integer contigIndex = null;
public FilePointer( List<GenomeLoc> locations ) { public FilePointer( List<GenomeLoc> locations ) {
this.locations.addAll(locations); this.locations.addAll(locations);
this.isRegionUnmapped = checkUnmappedStatus(); this.isRegionUnmapped = checkUnmappedStatus();
validateLocations();
validateAllLocations();
if ( locations.size() > 0 ) {
contigIndex = locations.get(0).getContigIndex();
}
} }
public FilePointer( final GenomeLoc... locations ) { public FilePointer( final GenomeLoc... locations ) {
@ -88,7 +98,7 @@ public class FilePointer {
return foundUnmapped; return foundUnmapped;
} }
private void validateLocations() { private void validateAllLocations() {
// Unmapped and monolithic FilePointers are exempted from the one-contig-only restriction // Unmapped and monolithic FilePointers are exempted from the one-contig-only restriction
if ( isRegionUnmapped || isMonolithic ) { if ( isRegionUnmapped || isMonolithic ) {
return; return;
@ -98,13 +108,22 @@ public class FilePointer {
for ( GenomeLoc location : locations ) { for ( GenomeLoc location : locations ) {
if ( previousContigIndex != null && previousContigIndex != location.getContigIndex() ) { if ( previousContigIndex != null && previousContigIndex != location.getContigIndex() ) {
throw new ReviewedStingException("File pointers must contain intervals from at most one contig"); throw new ReviewedStingException("Non-monolithic file pointers must contain intervals from at most one contig");
} }
previousContigIndex = location.getContigIndex(); previousContigIndex = location.getContigIndex();
} }
} }
private void validateLocation( GenomeLoc location ) {
if ( isRegionUnmapped != GenomeLoc.isUnmapped(location) ) {
throw new ReviewedStingException("BUG: File pointers cannot be mixed mapped/unmapped.");
}
if ( ! isRegionUnmapped && ! isMonolithic && contigIndex != null && contigIndex != location.getContigIndex() ) {
throw new ReviewedStingException("Non-monolithic file pointers must contain intervals from at most one contig");
}
}
/** /**
* Returns an immutable view of this FilePointer's file spans * Returns an immutable view of this FilePointer's file spans
* *
@ -183,15 +202,12 @@ public class FilePointer {
} }
public void addLocation(final GenomeLoc location) { public void addLocation(final GenomeLoc location) {
this.locations.add(location); validateLocation(location);
checkUnmappedStatus();
validateLocations();
}
public void addLocations( final List<GenomeLoc> locations ) { this.locations.add(location);
this.locations.addAll(locations); if ( contigIndex == null ) {
checkUnmappedStatus(); contigIndex = location.getContigIndex();
validateLocations(); }
} }
public void addFileSpans(final SAMReaderID id, final SAMFileSpan fileSpan) { public void addFileSpans(final SAMReaderID id, final SAMFileSpan fileSpan) {