Commit 3c83721a authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Adding input files to check

parent 37b9a6d3
...@@ -85,6 +85,9 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with ...@@ -85,6 +85,9 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
paired = input_R2.isDefined paired = input_R2.isDefined
inputFiles :+= InputFile(input_R1)
input_R2.foreach(inputFiles :+= InputFile(_))
if (input_R1.endsWith(".gz")) R1_name = input_R1.getName.substring(0, input_R1.getName.lastIndexOf(".gz")) if (input_R1.endsWith(".gz")) R1_name = input_R1.getName.substring(0, input_R1.getName.lastIndexOf(".gz"))
else if (input_R1.endsWith(".gzip")) R1_name = input_R1.getName.substring(0, input_R1.getName.lastIndexOf(".gzip")) else if (input_R1.endsWith(".gzip")) R1_name = input_R1.getName.substring(0, input_R1.getName.lastIndexOf(".gzip"))
else R1_name = input_R1.getName else R1_name = input_R1.getName
......
...@@ -137,6 +137,9 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S ...@@ -137,6 +137,9 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
require(sampleId.isDefined, "Missing sample ID on mapping module") require(sampleId.isDefined, "Missing sample ID on mapping module")
require(libId.isDefined, "Missing library ID on mapping module") require(libId.isDefined, "Missing library ID on mapping module")
inputFiles :+= InputFile(input_R1)
input_R2.foreach(inputFiles :+= InputFile(_))
paired = input_R2.isDefined paired = input_R2.isDefined
if (readgroupId == null) readgroupId = sampleId.get + "-" + libId.get if (readgroupId == null) readgroupId = sampleId.get + "-" + libId.get
......
...@@ -136,51 +136,56 @@ trait ShivaTrait extends MultiSampleQScript with SummaryQScript with Reference { ...@@ -136,51 +136,56 @@ trait ShivaTrait extends MultiSampleQScript with SummaryQScript with Reference {
case (true, _) => mapping.foreach(mapping => { case (true, _) => mapping.foreach(mapping => {
mapping.input_R1 = config("R1") mapping.input_R1 = config("R1")
mapping.input_R2 = config("R2") mapping.input_R2 = config("R2")
inputFiles :+= InputFile(mapping.input_R1, config("R1_md5"))
mapping.input_R2.foreach(inputFiles :+= InputFile(_, config("R2_md5")))
}) })
case (false, true) => config("bam_to_fastq", default = false).asBoolean match { case (false, true) => {
case true => inputFiles :+= InputFile(config("bam"), config("bam_md5"))
val samToFastq = SamToFastq(qscript, config("bam"), config("bam_to_fastq", default = false).asBoolean match {
new File(libDir, sampleId + "-" + libId + ".R1.fastq"), case true =>
new File(libDir, sampleId + "-" + libId + ".R2.fastq")) val samToFastq = SamToFastq(qscript, config("bam"),
samToFastq.isIntermediate = true new File(libDir, sampleId + "-" + libId + ".R1.fastq"),
qscript.add(samToFastq) new File(libDir, sampleId + "-" + libId + ".R2.fastq"))
mapping.foreach(mapping => { samToFastq.isIntermediate = true
mapping.input_R1 = samToFastq.fastqR1 qscript.add(samToFastq)
mapping.input_R2 = Some(samToFastq.fastqR2) mapping.foreach(mapping => {
}) mapping.input_R1 = samToFastq.fastqR1
case false => mapping.input_R2 = Some(samToFastq.fastqR2)
val inputSam = SamReaderFactory.makeDefault.open(config("bam")) })
val readGroups = inputSam.getFileHeader.getReadGroups case false =>
val inputSam = SamReaderFactory.makeDefault.open(config("bam"))
val readGroupOke = readGroups.forall(readGroup => { val readGroups = inputSam.getFileHeader.getReadGroups
if (readGroup.getSample != sampleId) logger.warn("Sample ID readgroup in bam file is not the same")
if (readGroup.getLibrary != libId) logger.warn("Library ID readgroup in bam file is not the same") val readGroupOke = readGroups.forall(readGroup => {
readGroup.getSample == sampleId && readGroup.getLibrary == libId if (readGroup.getSample != sampleId) logger.warn("Sample ID readgroup in bam file is not the same")
}) if (readGroup.getLibrary != libId) logger.warn("Library ID readgroup in bam file is not the same")
inputSam.close() readGroup.getSample == sampleId && readGroup.getLibrary == libId
})
if (!readGroupOke) { inputSam.close()
if (config("correct_readgroups", default = false).asBoolean) {
logger.info("Correcting readgroups, file:" + config("bam")) if (!readGroupOke) {
val aorrg = AddOrReplaceReadGroups(qscript, config("bam"), bamFile.get) if (config("correct_readgroups", default = false).asBoolean) {
aorrg.RGID = sampleId + "-" + libId logger.info("Correcting readgroups, file:" + config("bam"))
aorrg.RGLB = libId val aorrg = AddOrReplaceReadGroups(qscript, config("bam"), bamFile.get)
aorrg.RGSM = sampleId aorrg.RGID = sampleId + "-" + libId
aorrg.isIntermediate = true aorrg.RGLB = libId
qscript.add(aorrg) aorrg.RGSM = sampleId
} else throw new IllegalStateException("Sample readgroup and/or library of input bamfile is not correct, file: " + bamFile + aorrg.isIntermediate = true
"\nPlease note that it is possible to set 'correct_readgroups' to true in the config to automatic fix this") qscript.add(aorrg)
} else { } else throw new IllegalStateException("Sample readgroup and/or library of input bamfile is not correct, file: " + bamFile +
val oldBamFile: File = config("bam") "\nPlease note that it is possible to set 'correct_readgroups' to true in the config to automatic fix this")
val oldIndex: File = new File(oldBamFile.getAbsolutePath.stripSuffix(".bam") + ".bai") } else {
val newIndex: File = new File(libDir, oldBamFile.getName.stripSuffix(".bam") + ".bai") val oldBamFile: File = config("bam")
val baiLn = Ln(qscript, oldIndex, newIndex) val oldIndex: File = new File(oldBamFile.getAbsolutePath.stripSuffix(".bam") + ".bai")
add(baiLn) val newIndex: File = new File(libDir, oldBamFile.getName.stripSuffix(".bam") + ".bai")
val baiLn = Ln(qscript, oldIndex, newIndex)
val bamLn = Ln(qscript, oldBamFile, bamFile.get) add(baiLn)
bamLn.deps :+= baiLn.output
add(bamLn) val bamLn = Ln(qscript, oldBamFile, bamFile.get)
} bamLn.deps :+= baiLn.output
add(bamLn)
}
}
} }
case _ => logger.warn("Sample: " + sampleId + " Library: " + libId + ", no reads found") case _ => logger.warn("Sample: " + sampleId + " Library: " + libId + ", no reads found")
} }
......
Supports Markdown
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