Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADAM-1486] Respect validation stringency if BAM header load fails. #1525

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -595,9 +595,13 @@ class ADAMContext(@transient val sc: SparkContext) extends Serializable with Log
Some((sd, rg))
} catch {
case e: Throwable => {
log.error(
s"Loading failed for $fp:n${e.getMessage}\n\t${e.getStackTrace.take(25).map(_.toString).mkString("\n\t")}"
)
if (validationStringency == ValidationStringency.STRICT) {
throw e
} else if (validationStringency == ValidationStringency.LENIENT) {
log.error(
s"Loading failed for $fp:\n${e.getMessage}\n\t${e.getStackTrace.take(25).map(_.toString).mkString("\n\t")}"
)
}
None
}
}
Expand Down
3 changes: 3 additions & 0 deletions adam-core/src/test/resources/badheader.sam
@@ -0,0 +1,3 @@
@SQ SNN:1 LN:249250621
@SQ SN:2 LN:243199373
simread:1:26472783:false 16 1 26472784 60 75M * 0 0 GTATAAGAGCAGCCTTATTCCTATTTATAATCAGGGTGAAACACCTGTGCCAATGCCAAGACAGGGGTGCCAAGA * NM:i:0 AS:i:75 XS:i:0
Expand Up @@ -17,6 +17,7 @@
*/
package org.bdgenomics.adam.rdd

import htsjdk.samtools.{ SAMFormatException, ValidationStringency }
import java.io.{ File, FileNotFoundException }
import com.google.common.io.Files
import org.apache.hadoop.fs.Path
Expand Down Expand Up @@ -81,6 +82,13 @@ class ADAMContextSuite extends ADAMFunSuite {
assert(reads.count() === 20)
}

sparkTest("loading a sam file with a bad header and strict stringency should fail") {
val path = testFile("badheader.sam")
intercept[SAMFormatException] {
sc.loadBam(path, validationStringency = ValidationStringency.STRICT)
}
}

sparkTest("can read a small .CRAM file") {
val path = testFile("artificial.cram")
val referencePath = resourceUrl("artificial.fa").toString
Expand Down