Commit 7eb9af74 authored by bow's avatar bow

Merge branch 'feature-bed_check' into 'develop'

Init bed check

fixes #298 

See merge request !401
parents 09fa0b3f d08b6c72
......@@ -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.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(), biopetError = true))
roiBedFiles.foreach(BedCheck.checkBedFileToReference(_, referenceFasta(), biopetError = true))
}
/** Script to add jobs */
......
......@@ -61,9 +61,9 @@ class BamMetricsTest extends TestNGSuite with Matchers {
def testBamMetrics(rois: Int, amplicon: Boolean, rna: Boolean, wgs: Boolean) = {
val map = ConfigUtils.mergeMaps(Map("output_dir" -> BamMetricsTest.outputDir, "rna_metrics" -> rna, "wgs_metrics" -> wgs),
Map(BamMetricsTest.executables.toSeq: _*)) ++
(if (amplicon) Map("amplicon_bed" -> "amplicon.bed") else Map()) ++
(if (amplicon) Map("amplicon_bed" -> BamMetricsTest.ampliconBed.getAbsolutePath) else Map()) ++
(if (rna) Map("annotation_refflat" -> "transcripts.refFlat") else Map()) ++
Map("regions_of_interest" -> (1 to rois).map("roi_" + _ + ".bed").toList)
Map("regions_of_interest" -> (1 to rois).map(BamMetricsTest.roi(_).getAbsolutePath).toList)
val bammetrics: BamMetrics = initPipeline(map)
bammetrics.inputBam = BamMetricsTest.bam
......@@ -94,6 +94,14 @@ object BamMetricsTest {
val bam = new File(outputDir, "input" + File.separator + "bla.bam")
Files.touch(bam)
val ampliconBed = new File(outputDir, "input" + File.separator + "amplicon_bed.bed")
Files.touch(ampliconBed)
def roi(i: Int): File = {
val roi = new File(outputDir, "input" + File.separator + s"roi${i}.bed")
Files.touch(roi)
roi
}
private def copyFile(name: String): Unit = {
val is = getClass.getResourceAsStream("/" + name)
......
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 + s", Bedfile: $bedFile")
}
} else bedrecords.validateContigs(reference)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment