diff --git a/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/AdapterSequence.scala b/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/AdapterSequence.scala new file mode 100644 index 0000000000000000000000000000000000000000..3e9cce9b24353d7a96711835d5896812085c8629 --- /dev/null +++ b/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/AdapterSequence.scala @@ -0,0 +1,4 @@ +package nl.lumc.sasc.biopet.pipelines.flexiprep + +/** Case class representing a known adapter sequence */ +case class AdapterSequence(name: String, seq: String) diff --git a/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Cutadapt.scala b/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Cutadapt.scala index 3cb06df0e160cb97b98710de74f7ca9fa31ce919..54d80126bfcd1e6a3f6ef60187ed8bff4d6ffd58 100644 --- a/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Cutadapt.scala +++ b/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Cutadapt.scala @@ -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 diff --git a/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Fastqc.scala b/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Fastqc.scala index 81aee7938c9f65a2ae970c13a07cc81d586f87c7..2dadd164ab0a8b9e22372fa1525467f3924bcc8d 100644 --- a/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Fastqc.scala +++ b/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Fastqc.scala @@ -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. * diff --git a/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/QcCommand.scala b/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/QcCommand.scala index c343be2297474025f70224024d827c1f21cfab78..2e9a1fa1967000ef88530546c41de93e7f9a39d8 100644 --- a/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/QcCommand.scala +++ b/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/QcCommand.scala @@ -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")