From 3861212dabe036344f2010689a53791208e70bf0 Mon Sep 17 00:00:00 2001 From: David Roazen Date: Thu, 11 Oct 2012 19:33:37 -0400 Subject: [PATCH] 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 --- .../gatk/datasources/reads/FilePointer.java | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/FilePointer.java b/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/FilePointer.java index 639887cf3..197015641 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/FilePointer.java +++ b/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/FilePointer.java @@ -58,10 +58,20 @@ public class FilePointer { */ 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 locations ) { this.locations.addAll(locations); this.isRegionUnmapped = checkUnmappedStatus(); - validateLocations(); + + validateAllLocations(); + if ( locations.size() > 0 ) { + contigIndex = locations.get(0).getContigIndex(); + } } public FilePointer( final GenomeLoc... locations ) { @@ -88,7 +98,7 @@ public class FilePointer { return foundUnmapped; } - private void validateLocations() { + private void validateAllLocations() { // Unmapped and monolithic FilePointers are exempted from the one-contig-only restriction if ( isRegionUnmapped || isMonolithic ) { return; @@ -98,13 +108,22 @@ public class FilePointer { for ( GenomeLoc location : locations ) { 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(); } } + 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 * @@ -183,15 +202,12 @@ public class FilePointer { } public void addLocation(final GenomeLoc location) { - this.locations.add(location); - checkUnmappedStatus(); - validateLocations(); - } + validateLocation(location); - public void addLocations( final List locations ) { - this.locations.addAll(locations); - checkUnmappedStatus(); - validateLocations(); + this.locations.add(location); + if ( contigIndex == null ) { + contigIndex = location.getContigIndex(); + } } public void addFileSpans(final SAMReaderID id, final SAMFileSpan fileSpan) {