diff --git a/build.xml b/build.xml index 4861d577f..584e0808c 100644 --- a/build.xml +++ b/build.xml @@ -329,8 +329,8 @@ - + diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/shards/IndexDelimitedLocusShardStrategy.java b/java/src/org/broadinstitute/sting/gatk/datasources/shards/IndexDelimitedLocusShardStrategy.java index 0e38f7782..5d4c9537c 100755 --- a/java/src/org/broadinstitute/sting/gatk/datasources/shards/IndexDelimitedLocusShardStrategy.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/shards/IndexDelimitedLocusShardStrategy.java @@ -63,25 +63,35 @@ public class IndexDelimitedLocusShardStrategy implements ShardStrategy { * @param locations List of locations for which to load data. */ IndexDelimitedLocusShardStrategy(SAMDataSource dataSource, GenomeLocSortedSet locations) { - if(!(dataSource instanceof BlockDrivenSAMDataSource)) - throw new StingException("Cannot power an IndexDelimitedLocusShardStrategy with this data source."); + if(dataSource != null) { + // Shard based on reads. + // TODO: Push this sharding into the data source. + if(!(dataSource instanceof BlockDrivenSAMDataSource)) + throw new StingException("Cannot power an IndexDelimitedLocusShardStrategy with this data source."); - List intervals; - if(locations == null) { - // If no locations were passed in, shard the entire BAM file. - SAMFileHeader header = dataSource.getHeader(); - intervals = new ArrayList(); + List intervals; + if(locations == null) { + // If no locations were passed in, shard the entire BAM file. + SAMFileHeader header = dataSource.getHeader(); + intervals = new ArrayList(); - for(SAMSequenceRecord sequenceRecord: header.getSequenceDictionary().getSequences()) - intervals.add(GenomeLocParser.createGenomeLoc(sequenceRecord.getSequenceName(),1,sequenceRecord.getSequenceLength())); + for(SAMSequenceRecord sequenceRecord: header.getSequenceDictionary().getSequences()) + intervals.add(GenomeLocParser.createGenomeLoc(sequenceRecord.getSequenceName(),1,sequenceRecord.getSequenceLength())); + } + else + intervals = locations.toList(); + + + this.dataSource = (BlockDrivenSAMDataSource)dataSource; + filePointers.addAll(IntervalSharder.shardIntervals(this.dataSource,intervals,this.dataSource.getNumIndexLevels()-1)); + } + else { + this.dataSource = null; + for(GenomeLoc interval: locations) + filePointers.add(new FilePointer(interval)); } - else - intervals = locations.toList(); - - this.dataSource = (BlockDrivenSAMDataSource)dataSource; - filePointers.addAll(IntervalSharder.shardIntervals(this.dataSource,intervals,this.dataSource.getNumIndexLevels()-1)); - filePointerIterator = filePointers.iterator(); + filePointerIterator = filePointers.iterator(); } /** @@ -100,7 +110,7 @@ public class IndexDelimitedLocusShardStrategy implements ShardStrategy { */ public IndexDelimitedLocusShard next() { FilePointer nextFilePointer = filePointerIterator.next(); - Map> chunksBounding = dataSource.getFilePointersBounding(nextFilePointer.bin); + Map> chunksBounding = dataSource!=null ? dataSource.getFilePointersBounding(nextFilePointer.bin) : null; return new IndexDelimitedLocusShard(nextFilePointer.locations,chunksBounding,Shard.ShardType.LOCUS_INTERVAL); } diff --git a/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/BlockDrivenSAMDataSource.java b/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/BlockDrivenSAMDataSource.java index 0761e9480..13c4d91a9 100644 --- a/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/BlockDrivenSAMDataSource.java +++ b/java/src/org/broadinstitute/sting/gatk/datasources/simpleDataSources/BlockDrivenSAMDataSource.java @@ -64,8 +64,12 @@ public class BlockDrivenSAMDataSource extends SAMDataSource { ReadGroupMapping mapping = new ReadGroupMapping(); List readGroups = reader.getFileHeader().getReadGroups(); - for(SAMReadGroupRecord readGroup: readGroups) - mapping.put(readGroup.getReadGroupId(),headerMerger.getReadGroupId(reader,readGroup.getReadGroupId())); + for(SAMReadGroupRecord readGroup: readGroups) { + if(headerMerger.hasReadGroupCollisions()) + mapping.put(readGroup.getReadGroupId(),headerMerger.getReadGroupId(reader,readGroup.getReadGroupId())); + else + mapping.put(readGroup.getReadGroupId(),readGroup.getReadGroupId()); + } mergedReadGroupMappings.put(id,mapping); } @@ -110,7 +114,10 @@ public class BlockDrivenSAMDataSource extends SAMDataSource { Map> filePointers = new HashMap>(); for(SAMFileReader reader: readers) { SAMFileReader2 reader2 = (SAMFileReader2)reader; - filePointers.put(reader2,reader2.getFilePointersBounding(bin)); + if(bin != null) + filePointers.put(reader2,reader2.getFilePointersBounding(bin)); + else + filePointers.put(reader2,Collections.emptyList()); } return filePointers; }