diff --git a/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.scala b/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.scala index 78bf5f309f77ea2916715a0681640b4d1400cd72..7ea77993bb7e068792d152576fa2cf914f84bfea 100644 --- a/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.scala +++ b/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.scala @@ -17,15 +17,16 @@ package nl.lumc.sasc.biopet.pipelines.bammetrics import java.io.File -import nl.lumc.sasc.biopet.core.annotations.{ RibosomalRefFlat, AnnotationRefFlat } +import nl.lumc.sasc.biopet.core.annotations.{AnnotationRefFlat, RibosomalRefFlat} import nl.lumc.sasc.biopet.utils.config.Configurable import nl.lumc.sasc.biopet.core.summary.SummaryQScript -import nl.lumc.sasc.biopet.core.{ Reference, BiopetFifoPipe, PipelineCommand, SampleLibraryTag } -import nl.lumc.sasc.biopet.extensions.bedtools.{ BedtoolsCoverage, BedtoolsIntersect } +import nl.lumc.sasc.biopet.core.{BiopetFifoPipe, PipelineCommand, Reference, SampleLibraryTag} +import nl.lumc.sasc.biopet.extensions.bedtools.{BedtoolsCoverage, BedtoolsIntersect} import nl.lumc.sasc.biopet.extensions.picard._ import nl.lumc.sasc.biopet.extensions.samtools.SamtoolsFlagstat import nl.lumc.sasc.biopet.pipelines.bammetrics.scripts.CoverageStats import nl.lumc.sasc.biopet.extensions.tools.BiopetFlagstat +import nl.lumc.sasc.biopet.utils.intervals.BedCheck import org.broadinstitute.gatk.queue.QScript class BamMetrics(val root: Configurable) extends QScript @@ -72,6 +73,8 @@ class BamMetrics(val root: Configurable) extends QScript /** executed before script */ def init(): Unit = { inputFiles :+= new InputFile(inputBam) + ampliconBedFile.foreach(BedCheck.checkBedFileToReference(_, referenceFasta())) + roiBedFiles.foreach(BedCheck.checkBedFileToReference(_, referenceFasta())) } /** Script to add jobs */ diff --git a/biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedCheck.scala b/biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedCheck.scala new file mode 100644 index 0000000000000000000000000000000000000000..081ea5bd38f8b53ae3fd6a980303582dd8f929d5 --- /dev/null +++ b/biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/intervals/BedCheck.scala @@ -0,0 +1,27 @@ +package nl.lumc.sasc.biopet.utils.intervals + +import java.io.File +import scala.collection.mutable.Set + +import nl.lumc.sasc.biopet.utils.Logging + +/** + * Created by pjvanthof on 14/05/16. + */ +object BedCheck { + private val cache: Set[(File, File)] = Set() + + def checkBedFileToReference(bedFile: File, reference: File, biopetError: Boolean = false, ignoreCache: Boolean = false): Unit = { + if (ignoreCache || !cache.contains((bedFile, reference))) { + cache.add((bedFile, reference)) + val bedrecords = BedRecordList.fromFile(bedFile) + if (biopetError) { + try { + bedrecords.validateContigs(reference) + } catch { + case e: IllegalArgumentException => Logging.addError(e.getMessage) + } + } else bedrecords.validateContigs(reference) + } + } +}