Commit 0eeaa7b5 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Merge branch 'feature-allow-custom-adapters' into 'develop'

Feature allow custom adapters

fixes #266 

See merge request !384
parents 275b3584 847b1265
package nl.lumc.sasc.biopet.pipelines.flexiprep
/** Case class representing a known adapter sequence */
case class AdapterSequence(name: String, seq: String)
......@@ -16,7 +16,6 @@
package nl.lumc.sasc.biopet.pipelines.flexiprep
import nl.lumc.sasc.biopet.utils.config.Configurable
import scala.collection.JavaConversions._
/**
* Cutadapt wrapper specific for Flexiprep.
......@@ -30,9 +29,29 @@ import scala.collection.JavaConversions._
*/
class Cutadapt(root: Configurable, fastqc: Fastqc) extends nl.lumc.sasc.biopet.extensions.Cutadapt(root) {
val ignoreFastqcAdapters: Boolean = config("ignore_fastqc_adapters", default = false)
val customAdaptersConfig: Map[String, Any] = config("custom_adapters", default = Map.empty)
/** Clipped adapter names from FastQC */
protected def seqToName: Map[String, String] = fastqc.foundAdapters
.map(adapter => adapter.seq -> adapter.name).toMap
protected def seqToName: Map[String, String] = {
if (!ignoreFastqcAdapters) {
(fastqc.foundAdapters ++ customAdapters)
.map(adapter => adapter.seq -> adapter.name).toMap
} else {
customAdapters.map(adapter => adapter.seq -> adapter.name).toMap
}
}
def customAdapters: Set[AdapterSequence] = {
customAdaptersConfig.flatMap(adapter => {
adapter match {
case (adapterName: String, sequence: String) =>
Some(AdapterSequence(adapterName, sequence))
case _ =>
throw new IllegalStateException(s"Custom adapter was setup wrong for: $adapter")
}
}).toSet
}
override def summaryStats: Map[String, Any] = {
val initStats = super.summaryStats
......
......@@ -150,9 +150,6 @@ class Fastqc(root: Configurable) extends nl.lumc.sasc.biopet.extensions.Fastqc(r
}
} else Map()
/** Case class representing a known adapter sequence */
protected case class AdapterSequence(name: String, seq: String)
/**
* Retrieves overrepresented sequences found by FastQ.
*
......
......@@ -102,9 +102,15 @@ class QcCommand(val root: Configurable, val fastqc: Fastqc) extends BiopetComman
addPipeJob(seqtk)
clip = if (!flexiprep.skipClip) {
val foundAdapters = fastqc.foundAdapters.map(_.seq)
val cutadapt = clip.getOrElse(new Cutadapt(root, fastqc))
val foundAdapters = if (!cutadapt.ignoreFastqcAdapters) {
fastqc.foundAdapters.map(_.seq) ++ cutadapt.customAdapters.map(_.seq)
} else {
cutadapt.customAdapters.map(_.seq)
}
if (foundAdapters.nonEmpty) {
val cutadapt = clip.getOrElse(new Cutadapt(root, fastqc))
cutadapt.fastqInput = seqtk.output
cutadapt.fastqOutput = new File(output.getParentFile, input.getName + ".cutadapt.fq")
cutadapt.statsOutput = new File(flexiprep.outputDir, s"${flexiprep.sampleId.getOrElse("x")}-${flexiprep.libId.getOrElse("x")}.$read.clip.stats")
......
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