Skip to content
Snippets Groups Projects
Commit 238d4d73 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Added bam_to_fastq option

parent 3af83757
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ import scala.collection.JavaConversions._
import java.io.File
import nl.lumc.sasc.biopet.extensions.gatk.{ CombineVariants, CombineGVCFs }
import nl.lumc.sasc.biopet.extensions.picard.AddOrReplaceReadGroups
import nl.lumc.sasc.biopet.extensions.picard.SamToFastq
import nl.lumc.sasc.biopet.pipelines.bammetrics.BamMetrics
import nl.lumc.sasc.biopet.pipelines.mapping.Mapping
import org.broadinstitute.gatk.queue.QScript
......@@ -169,36 +170,48 @@ class GatkPipeline(val root: Configurable) extends QScript with MultiSampleQScri
var bamFile = new File(runConfig("bam").toString)
if (!bamFile.exists) throw new IllegalStateException("Bam in config does not exist, file: " + bamFile)
var readGroupOke = true
val inputSam = new SAMFileReader(bamFile)
val header = inputSam.getFileHeader.getReadGroups
for (readGroup <- inputSam.getFileHeader.getReadGroups) {
if (readGroup.getSample != sampleID) logger.warn("Sample ID readgroup in bam file is not the same")
if (readGroup.getLibrary != runID) logger.warn("Library ID readgroup in bam file is not the same")
if (readGroup.getSample != sampleID || readGroup.getLibrary != runID) readGroupOke = false
}
inputSam.close
if (!readGroupOke) {
if (config("correct_readgroups", default = false)) {
logger.info("Correcting readgroups, file:" + bamFile)
val aorrg = AddOrReplaceReadGroups(this, bamFile, new File(runDir + sampleID + "-" + runID + ".bam"))
aorrg.RGID = sampleID + "-" + runID
aorrg.RGLB = runID
aorrg.RGSM = sampleID
if (runConfig.contains("PL")) aorrg.RGPL = runConfig("PL").toString
else aorrg.RGPL = "illumina"
if (runConfig.contains("PU")) aorrg.RGPU = runConfig("PU").toString
else aorrg.RGPU = "na"
if (runConfig.contains("CN")) aorrg.RGCN = runConfig("CN").toString
add(aorrg, isIntermediate = true)
bamFile = aorrg.output
} else throw new IllegalStateException("Readgroup sample and/or library of input bamfile is not correct, file: " + bamFile +
"\nPossible to set 'correct_readgroups' to true on config to automatic fix this")
if (config("bam_to_fastq", default = false).getBoolean) {
val samToFastq = SamToFastq(this, bamFile, runDir + sampleID + "-" + runID + ".R1.fastq", runDir + sampleID + "-" + runID + ".R1.fastq")
add(samToFastq)
val mapping = Mapping.loadFromLibraryConfig(this, runConfig, sampleConfig, runDir, startJobs = false)
mapping.input_R1 = samToFastq.fastqR1
mapping.input_R2 = samToFastq.fastqR2
mapping.init
mapping.biopetScript
addAll(mapping.functions) // Add functions of mapping to curent function pool
libraryOutput.mappedBamFile = mapping.outputFiles("finalBamFile")
} else {
var readGroupOke = true
val inputSam = new SAMFileReader(bamFile)
val header = inputSam.getFileHeader.getReadGroups
for (readGroup <- inputSam.getFileHeader.getReadGroups) {
if (readGroup.getSample != sampleID) logger.warn("Sample ID readgroup in bam file is not the same")
if (readGroup.getLibrary != runID) logger.warn("Library ID readgroup in bam file is not the same")
if (readGroup.getSample != sampleID || readGroup.getLibrary != runID) readGroupOke = false
}
inputSam.close
if (!readGroupOke) {
if (config("correct_readgroups", default = false)) {
logger.info("Correcting readgroups, file:" + bamFile)
val aorrg = AddOrReplaceReadGroups(this, bamFile, new File(runDir + sampleID + "-" + runID + ".bam"))
aorrg.RGID = sampleID + "-" + runID
aorrg.RGLB = runID
aorrg.RGSM = sampleID
if (runConfig.contains("PL")) aorrg.RGPL = runConfig("PL").toString
else aorrg.RGPL = "illumina"
if (runConfig.contains("PU")) aorrg.RGPU = runConfig("PU").toString
else aorrg.RGPU = "na"
if (runConfig.contains("CN")) aorrg.RGCN = runConfig("CN").toString
add(aorrg, isIntermediate = true)
bamFile = aorrg.output
} else throw new IllegalStateException("Readgroup sample and/or library of input bamfile is not correct, file: " + bamFile +
"\nPossible to set 'correct_readgroups' to true on config to automatic fix this")
}
addAll(BamMetrics(this, bamFile, runDir + "metrics/").functions)
libraryOutput.mappedBamFile = bamFile
}
addAll(BamMetrics(this, bamFile, runDir + "metrics/").functions)
libraryOutput.mappedBamFile = bamFile
} else logger.error("Sample: " + sampleID + ": No R1 found for run: " + runConfig)
val gatkVariantcalling = new GatkVariantcalling(this)
......
......@@ -305,7 +305,8 @@ class Mapping(val root: Configurable) extends QScript with BiopetQScript {
}
object Mapping extends PipelineCommand {
def loadFromLibraryConfig(root: Configurable, runConfig: Map[String, Any], sampleConfig: Map[String, Any], runDir: String): Mapping = {
def loadFromLibraryConfig(root: Configurable, runConfig: Map[String, Any], sampleConfig: Map[String, Any],
runDir: String, startJobs: Boolean = true): Mapping = {
val mapping = new Mapping(root)
logger.debug("Mapping runconfig: " + runConfig)
......@@ -322,9 +323,11 @@ object Mapping extends PipelineCommand {
if (runConfig.contains("PU")) mapping.RGPU = runConfig("PU").toString
if (runConfig.contains("CN")) mapping.RGCN = runConfig("CN").toString
mapping.outputDir = runDir
mapping.init
mapping.biopetScript
if (startJobs) {
mapping.init
mapping.biopetScript
}
return mapping
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment