Skip to content

Commit

Permalink
added check for.bam.bai and .bai index files
Browse files Browse the repository at this point in the history
  • Loading branch information
akmorrow13 committed Dec 24, 2017
1 parent bbc4782 commit ee06eda
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ class ADAMContext(@transient val sc: SparkContext) extends Serializable with Log
// Otherwise, pathName is a directory and the entire path must be searched
// for indices.
val indexPath = if (pathName.endsWith(".bam")) {
new Path(pathName + ".bai")
new Path(pathName.toString.replace(".bam", "*.bai"))
} else {
path
}
Expand All @@ -1581,8 +1581,9 @@ class ADAMContext(@transient val sc: SparkContext) extends Serializable with Log
require(bamFiles.nonEmpty,
"Did not find any BAM files at %s.".format(path))

// look for index files named <pathname>.bam.bai and <pathname>.bai
val missingIndices = bamFiles.filterNot(f => {
indexFiles.contains(f.toString + ".bai")
indexFiles.contains(f.toString + ".bai") || indexFiles.contains(f.toString.dropRight(3) + "bai")
})

if (!missingIndices.isEmpty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,13 @@ class ADAMContextSuite extends ADAMFunSuite {
}
}

sparkTest("loadIndexedBam should work with indexed file with index naming format <filename>.bai") {
val refRegion = ReferenceRegion("1", 1, 100)
val path = testFile("indexed_bams/sorted.2.bam")
val reads = sc.loadIndexedBam(path, refRegion)
assert(reads.rdd.count == 1)
}

sparkTest("loadIndexedBam glob should throw exception without an index file") {
val refRegion = ReferenceRegion("1", 26472780, 26472790)
val path = new File(testFile("bams/small.bam")).getParent()
Expand Down

0 comments on commit ee06eda

Please sign in to comment.