Some quick and dirty fixes to support querying unmapped BAM files.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1228 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
e4152af387
commit
bfe90af5e2
|
|
@ -177,6 +177,10 @@ public class SAMDataSource implements SimpleDataSource {
|
|||
private StingSAMIterator seekRead( ReadShard shard ) throws SimpleDataSourceLoadException {
|
||||
StingSAMIterator iter = null;
|
||||
|
||||
// If there are no entries in the sequence dictionary, there can't possibly be any unmapped reads. Force state to 'unmapped'.
|
||||
if( isSequenceDictionaryEmpty() )
|
||||
intoUnmappedReads = true;
|
||||
|
||||
if (!intoUnmappedReads) {
|
||||
if (lastReadPos == null) {
|
||||
lastReadPos = GenomeLocParser.createGenomeLoc(getHeader().getSequenceDictionary().getSequence(0).getSequenceIndex(), 0, Integer.MAX_VALUE);
|
||||
|
|
@ -312,6 +316,14 @@ public class SAMDataSource implements SimpleDataSource {
|
|||
return bound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the BAM file is completely unsequenced. Requires that the resource pool be initialized.
|
||||
* @return True if the sequence dictionary is completely empty. False otherwise.
|
||||
*/
|
||||
private boolean isSequenceDictionaryEmpty() {
|
||||
return getHeader().getSequenceDictionary().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Even though the iterator has seeked to the correct location, there may be multiple reads at that location,
|
||||
* and we may have given some of them out already. Move the iterator to the correct location using the readsAtLastPos variable
|
||||
|
|
|
|||
|
|
@ -154,7 +154,17 @@ public class MergingSamRecordIterator2 implements CloseableIterator<SAMRecord>,
|
|||
}
|
||||
final SAMRecordComparator comparator = getComparator();
|
||||
for (final SAMFileReader reader : samHeaderMerger.getReaders()) {
|
||||
Iterator<SAMRecord> recordIter = reader.queryUnmapped();
|
||||
Iterator<SAMRecord> recordIter = null;
|
||||
if( reader.hasIndex() ) {
|
||||
recordIter = reader.queryUnmapped();
|
||||
}
|
||||
else {
|
||||
// HACK: Supporting completely unmapped BAM files is easy. Let's do a quick check to make sure
|
||||
// these BAMs aren't partially indexed.
|
||||
if( reader.getFileHeader().getSequenceDictionary().size() > 0 )
|
||||
throw new StingException("Partially mapped BAM files without indices are not supported");
|
||||
recordIter = reader.iterator();
|
||||
}
|
||||
final ComparableSamRecordIterator iterator = new ComparableSamRecordIterator(reader, recordIter, comparator);
|
||||
addIfNotEmpty(iterator);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue