diff --git a/external-example/.gitignore b/external-example/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..77146859b6e12b32e90cc6f6d388ebc878d548d6
--- /dev/null
+++ b/external-example/.gitignore
@@ -0,0 +1,14 @@
+# Project-related
+dependency-reduced-pom.xml
+git.properties
+
+# gedit
+*~
+# Vim
+*.swp
+# IntelliJ
+.idea/*
+*.iml
+target/
+public/target/
+protected/target/
diff --git a/external-example/README.md b/external-example/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..956c6ccf2746212b45f3650ef917147bdd9ed800
--- /dev/null
+++ b/external-example/README.md
@@ -0,0 +1 @@
+Test implementation of Magpie 2.0
\ No newline at end of file
diff --git a/external-example/pom.xml b/external-example/pom.xml
new file mode 100644
index 0000000000000000000000000000000000000000..da0d2258fc90fe3cc9a49b76504be5388c683fa1
--- /dev/null
+++ b/external-example/pom.xml
@@ -0,0 +1,294 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <!--TODO: replace groupId -->
+    <groupId>org.example.group</groupId>
+
+    <!--TODO: replace artifactId -->
+    <artifactId>ExternalExample</artifactId>
+
+    <!--TODO: replace version, for a new pipeline it's advised to start with '0.1.0-SNAPSHOT' -->
+    <version>0.1.0-SNAPSHOT</version>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <scoverage.plugin.version>1.0.4</scoverage.plugin.version>
+        <sting.shade.phase>package</sting.shade.phase>
+
+        <!--
+        TODO: replace app.main.class, this is the class that get executed when running the jar file
+        This can be any executable that have a main method. In Biopet any pipeline can be used as direct executable.
+        Value for direct pipeline: 'org.example.group.pipelines.SimplePipeline'
+        In the given example is an extension of the biopet executable. In this example there are multiple pipelines in 1 executable.
+
+        It's also possible to make your own main function and call the main function with it's argument of the pipeline from there.
+        -->
+        <app.main.class>org.example.group.ExecutableExample</app.main.class>
+    </properties>
+
+    <dependencies>
+        <!--
+        In here maven dependencies can be placed, when importing a biopet pipeline 'Biopet-Framework' is not required.
+        When only using the framework without pipeline you need to import BiopetFramework.
+        It's advised to not use different versions of the pipeline and the framework.
+         -->
+        <dependency>
+            <groupId>nl.lumc.sasc</groupId>
+            <artifactId>BiopetCore</artifactId>
+
+            <!--TODO: replace version of pipeline to a fixed version -->
+            <version>0.5.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>nl.lumc.sasc</groupId>
+            <artifactId>BiopetExtensions</artifactId>
+            <version>0.5.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>nl.lumc.sasc</groupId>
+            <artifactId>Shiva</artifactId>
+
+            <!--TODO: replace version of pipeline to a fixed version -->
+            <version>0.5.0-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <sourceDirectory>${basedir}/src/main/scala</sourceDirectory>
+        <testSourceDirectory>${basedir}/src/test/scala</testSourceDirectory>
+        <testResources>
+            <testResource>
+                <directory>${basedir}/src/test/resources</directory>
+                <includes>
+                    <include>**/*</include>
+                </includes>
+            </testResource>
+        </testResources>
+        <resources>
+            <resource>
+                <directory>${basedir}/src/main/resources</directory>
+                <includes>
+                    <include>**/*</include>
+                </includes>
+            </resource>
+        </resources>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-shade-plugin</artifactId>
+                <version>2.4.1</version>
+                <configuration>
+                    <!--suppress MavenModelInspection -->
+                    <finalName>${project.artifactId}-${project.version}-${git.commit.id.abbrev}</finalName>
+                    <transformers>
+                        <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                            <manifestEntries>
+                                <Main-Class>${app.main.class}</Main-Class>
+                                <!--suppress MavenModelInspection -->
+                                <X-Compile-Source-JDK>${maven.compile.source}</X-Compile-Source-JDK>
+                                <!--suppress MavenModelInspection -->
+                                <X-Compile-Target-JDK>${maven.compile.target}</X-Compile-Target-JDK>
+                            </manifestEntries>
+                        </transformer>
+                    </transformers>
+                    <filters>
+                    </filters>
+                </configuration>
+                <executions>
+                    <execution>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>shade</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.18.1</version>
+                <configuration>
+                    <forkCount>1C</forkCount>
+                    <workingDirectory>${project.build.directory}</workingDirectory>
+                </configuration>
+            </plugin>
+            <plugin>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <version>2.10</version>
+                <executions>
+                    <execution>
+                        <id>copy-installed</id>
+                        <phase>prepare-package</phase>
+                        <goals>
+                            <goal>list</goal>
+                        </goals>
+                        <configuration>
+                            <outputFile>${project.build.outputDirectory}/dependency_list.txt</outputFile>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>net.alchim31.maven</groupId>
+                <artifactId>scala-maven-plugin</artifactId>
+                <version>3.2.0</version>
+                <executions>
+                    <execution>
+                        <id>scala-compile</id>
+                        <goals>
+                            <goal>compile</goal>
+                            <goal>testCompile</goal>
+                        </goals>
+                        <configuration>
+                            <args>
+                                <arg>-dependencyfile</arg>
+                                <arg>${project.build.directory}/.scala_dependencies</arg>
+                                <arg>-deprecation</arg>
+                                <arg>-feature</arg>
+                            </args>
+                        </configuration>
+                    </execution>
+                </executions>
+                <!-- ... (see other usage or goals for details) ... -->
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <version>2.5</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.3.2</version>
+                <configuration>
+                    <showDeprecation>true</showDeprecation>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.scalariform</groupId>
+                <artifactId>scalariform-maven-plugin</artifactId>
+                <version>0.1.4</version>
+                <executions>
+                    <execution>
+                        <phase>process-sources</phase>
+                        <goals>
+                            <goal>format</goal>
+                        </goals>
+                        <configuration>
+                            <rewriteArrowSymbols>false</rewriteArrowSymbols>
+                            <alignParameters>true</alignParameters>
+                            <alignSingleLineCaseStatements_maxArrowIndent>40
+                            </alignSingleLineCaseStatements_maxArrowIndent>
+                            <alignSingleLineCaseStatements>true</alignSingleLineCaseStatements>
+                            <compactStringConcatenation>false</compactStringConcatenation>
+                            <compactControlReadability>false</compactControlReadability>
+                            <doubleIndentClassDeclaration>false</doubleIndentClassDeclaration>
+                            <formatXml>true</formatXml>
+                            <indentLocalDefs>false</indentLocalDefs>
+                            <indentPackageBlocks>true</indentPackageBlocks>
+                            <indentSpaces>2</indentSpaces>
+                            <placeScaladocAsterisksBeneathSecondAsterisk>false
+                            </placeScaladocAsterisksBeneathSecondAsterisk>
+                            <preserveDanglingCloseParenthesis>true</preserveDanglingCloseParenthesis>
+                            <preserveSpaceBeforeArguments>false</preserveSpaceBeforeArguments>
+                            <rewriteArrowSymbols>false</rewriteArrowSymbols>
+                            <spaceBeforeColon>false</spaceBeforeColon>
+                            <spaceInsideBrackets>false</spaceInsideBrackets>
+                            <spaceInsideParentheses>false</spaceInsideParentheses>
+                            <spacesWithinPatternBinders>true</spacesWithinPatternBinders>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>pl.project13.maven</groupId>
+                <artifactId>git-commit-id-plugin</artifactId>
+                <version>2.1.10</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>revision</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <prefix>git</prefix>
+                    <dateFormat>dd.MM.yyyy '@' HH:mm:ss z</dateFormat>
+                    <verbose>false</verbose>
+                    <!-- TODO: This directory need to be changed depening where your .git folder is relative from this pom.xml -->
+                    <dotGitDirectory>${basedir}/../.git</dotGitDirectory>
+                    <useNativeGit>true</useNativeGit>
+                    <skipPoms>false</skipPoms>
+                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
+                    <generateGitPropertiesFilename>src/main/resources/git.properties</generateGitPropertiesFilename>
+                    <failOnNoGitDirectory>false</failOnNoGitDirectory>
+                    <abbrevLength>8</abbrevLength>
+                    <skip>false</skip>
+                    <gitDescribe>
+                        <skip>false</skip>
+                        <always>false</always>
+                        <abbrev>8</abbrev>
+                        <dirty>-dirty</dirty>
+                        <forceLongFormat>false</forceLongFormat>
+                    </gitDescribe>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>com.mycila</groupId>
+                <artifactId>license-maven-plugin</artifactId>
+                <version>2.6</version>
+                <configuration>
+                    <excludes>
+                        <exclude>**/*git*</exclude>
+                        <exclude>**/License*</exclude>
+                        <exclude>**/*.bam</exclude>
+                        <exclude>**/*.bai</exclude>
+                        <exclude>**/*.gtf</exclude>
+                        <exclude>**/*.fq</exclude>
+                        <exclude>**/*.sam</exclude>
+                        <exclude>**/*.bed</exclude>
+                        <exclude>**/*.refFlat</exclude>
+                        <exclude>**/*.R</exclude>
+                        <exclude>**/*.rscript</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.scoverage</groupId>
+                <artifactId>scoverage-maven-plugin</artifactId>
+                <version>${scoverage.plugin.version}</version>
+                <configuration>
+                    <scalaVersion>2.10.2</scalaVersion>
+                    <!-- other parameters -->
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <reporting>
+        <plugins>
+            <plugin>
+                <groupId>org.scoverage</groupId>
+                <artifactId>scoverage-maven-plugin</artifactId>
+                <version>${scoverage.plugin.version}</version>
+            </plugin>
+        </plugins>
+    </reporting>
+</project>
\ No newline at end of file
diff --git a/external-example/src/main/scala/org/example/group/ExecutableExample.scala b/external-example/src/main/scala/org/example/group/ExecutableExample.scala
new file mode 100644
index 0000000000000000000000000000000000000000..fe0aaa13d57d5380f8eb14bf984145992ce297e8
--- /dev/null
+++ b/external-example/src/main/scala/org/example/group/ExecutableExample.scala
@@ -0,0 +1,19 @@
+package org.example.group
+
+import nl.lumc.sasc.biopet.utils.{ BiopetExecutable, MainCommand }
+
+/**
+ * Created by pjvanthof on 30/08/15.
+ */
+object ExecutableExample extends BiopetExecutable {
+
+  /** This list defines the pipeline that are usable from the executable */
+  def pipelines: List[MainCommand] = List(
+    org.example.group.pipelines.MultisamplePipeline,
+    org.example.group.pipelines.BiopetPipeline,
+    org.example.group.pipelines.SimplePipeline
+  )
+
+  /** This list defines the (biopet)tools that are usable from the executable */
+  def tools: List[MainCommand] = Nil
+}
diff --git a/external-example/src/main/scala/org/example/group/pipelines/BiopetPipeline.scala b/external-example/src/main/scala/org/example/group/pipelines/BiopetPipeline.scala
new file mode 100644
index 0000000000000000000000000000000000000000..6099047a6e5153c15df565d3e70179006ef4ceac
--- /dev/null
+++ b/external-example/src/main/scala/org/example/group/pipelines/BiopetPipeline.scala
@@ -0,0 +1,47 @@
+package org.example.group.pipelines
+
+import nl.lumc.sasc.biopet.core.PipelineCommand
+import nl.lumc.sasc.biopet.utils.config.Configurable
+import nl.lumc.sasc.biopet.core.summary.SummaryQScript
+import nl.lumc.sasc.biopet.pipelines.shiva.Shiva
+import nl.lumc.sasc.biopet.utils.config.Configurable
+import org.broadinstitute.gatk.queue.QScript
+
+/**
+ * Created by pjvan_thof on 8/28/15.
+ */
+//TODO: Replace class Name
+class BiopetPipeline(val root: Configurable) extends QScript with SummaryQScript {
+  def this() = this(null)
+
+  /** Only required when using [[SummaryQScript]] */
+  def summaryFile = new File(outputDir, "magpie.summary.json")
+
+  /** Only required when using [[SummaryQScript]] */
+  def summaryFiles: Map[String, File] = Map()
+
+  /** Only required when using [[SummaryQScript]] */
+  def summarySettings = Map()
+
+  // This method can be used to initialize some classes where needed
+  def init(): Unit = {
+  }
+
+  // This method is the actual pipeline
+  def biopetScript: Unit = {
+
+    // Executing a biopet pipeline inside
+    val shiva = new Shiva(this)
+    shiva.init()
+    shiva.biopetScript()
+    addAll(shiva.functions)
+
+    /* Only required when using [[SummaryQScript]] */
+    addSummaryQScript(shiva)
+
+    // From here you can use the output files of shiva as input file of other jobs
+  }
+}
+
+//TODO: Replace object Name, must be the same as the class of the pipeline
+object BiopetPipeline extends PipelineCommand
diff --git a/external-example/src/main/scala/org/example/group/pipelines/MultisamplePipeline.scala b/external-example/src/main/scala/org/example/group/pipelines/MultisamplePipeline.scala
new file mode 100644
index 0000000000000000000000000000000000000000..ee66d89663c22868958720615a83c5d72f85e8f7
--- /dev/null
+++ b/external-example/src/main/scala/org/example/group/pipelines/MultisamplePipeline.scala
@@ -0,0 +1,64 @@
+package org.example.group.pipelines
+
+import nl.lumc.sasc.biopet.core.{ PipelineCommand, MultiSampleQScript }
+import nl.lumc.sasc.biopet.utils.config.Configurable
+import nl.lumc.sasc.biopet.utils.config.Configurable
+import org.broadinstitute.gatk.queue.QScript
+
+/**
+ * Created by pjvanthof on 30/08/15.
+ */
+class MultisamplePipeline(val root: Configurable) extends QScript with MultiSampleQScript {
+  qscript =>
+  def this() = this(null)
+
+  def init: Unit = {
+  }
+
+  def biopetScript: Unit = {
+    addSamplesJobs() // This executes jobs for all samples
+  }
+
+  def addMultiSampleJobs: Unit = {
+    // this code will be executed after all code of all samples is executed
+  }
+
+  def summaryFile: File = new File(outputDir, "MultisamplePipeline.summary.json")
+
+  //TODO: Add summary
+  def summaryFiles: Map[String, File] = Map()
+
+  //TODO: Add summary
+  def summarySettings: Map[String, Any] = Map()
+
+  def makeSample(id: String) = new Sample(id)
+  class Sample(sampleId: String) extends AbstractSample(sampleId) {
+
+    def makeLibrary(id: String) = new Library(id)
+    class Library(libId: String) extends AbstractLibrary(libId) {
+      //TODO: Add summary
+      def summaryFiles: Map[String, File] = Map()
+
+      //TODO: Add summary
+      def summaryStats: Map[String, Any] = Map()
+
+      def addJobs: Unit = {
+        //TODO: add library specific jobs
+      }
+    }
+
+    //TODO: Add summary
+    def summaryFiles: Map[String, File] = Map()
+
+    //TODO: Add summary
+    def summaryStats: Map[String, Any] = Map()
+
+    def addJobs: Unit = {
+      addPerLibJobs() // This add jobs for each library
+      //TODO: add sample specific jobs
+    }
+  }
+
+}
+
+object MultisamplePipeline extends PipelineCommand
\ No newline at end of file
diff --git a/external-example/src/main/scala/org/example/group/pipelines/SimplePipeline.scala b/external-example/src/main/scala/org/example/group/pipelines/SimplePipeline.scala
new file mode 100644
index 0000000000000000000000000000000000000000..f24b0f6152a03979d74c2f7337760cdc06c9e3be
--- /dev/null
+++ b/external-example/src/main/scala/org/example/group/pipelines/SimplePipeline.scala
@@ -0,0 +1,38 @@
+package org.example.group.pipelines
+
+import nl.lumc.sasc.biopet.core.{ BiopetQScript, PipelineCommand }
+import nl.lumc.sasc.biopet.utils.config.Configurable
+import nl.lumc.sasc.biopet.extensions.{ Gzip, Cat }
+import org.broadinstitute.gatk.queue.QScript
+
+/**
+ * Created by pjvanthof on 30/08/15.
+ */
+//TODO: Replace class name, must be the same as the class of the pipeline
+class SimplePipeline(val root: Configurable) extends QScript with BiopetQScript {
+  // A constructor without arguments is needed if this pipeline is a root pipeline
+  def this() = this(null)
+
+  @Input(required = true)
+  var inputFile: File = null
+
+  /** This method can be used to initialize some classes where needed */
+  def init(): Unit = {
+  }
+
+  /** This method is the actual pipeline */
+  def biopetScript: Unit = {
+    val cat = new Cat(this)
+    cat.input :+= inputFile
+    cat.output = new File(outputDir, "file.out")
+    add(cat)
+
+    val gzip = new Gzip(this)
+    gzip.input :+= cat.output
+    gzip.output = new File(outputDir, "file.out.gz")
+    add(gzip)
+  }
+}
+
+//TODO: Replace object name, must be the same as the class of the pipeline
+object SimplePipeline extends PipelineCommand
diff --git a/pom.xml b/pom.xml
index 9390bf9a13c0362d75f158b08d2e99d3ad8d181f..143a9095a763bbdcc323dc6e4299e534e5f0bc33 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,5 +16,6 @@
     <modules>
         <module>public</module>
         <module>protected</module>
+        <module>external-example</module>
     </modules>
 </project>
diff --git a/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/ApplyRecalibration.scala b/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/ApplyRecalibration.scala
index 203354565b98b05a36d8227859823ee721ae60ee..8b8ea7d5a97ca2095c981b1b11a3bae6496583a8 100644
--- a/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/ApplyRecalibration.scala
+++ b/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/ApplyRecalibration.scala
@@ -14,8 +14,8 @@ class ApplyRecalibration(val root: Configurable) extends org.broadinstitute.gatk
 
   override val defaultThreads = 3
 
-  override def beforeGraph() {
-    super.beforeGraph()
+  override def freezeFieldValues() {
+    super.freezeFieldValues()
 
     nt = Option(getThreads)
     memoryLimit = Option(nt.getOrElse(1) * 2)
diff --git a/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/BaseRecalibrator.scala b/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/BaseRecalibrator.scala
index fbe2317e93d83c2fa6d3da58a9224dc6ba15a803..d51a28375b07aea9d3462f9d2b5f185fc2f4b629 100644
--- a/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/BaseRecalibrator.scala
+++ b/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/BaseRecalibrator.scala
@@ -20,7 +20,6 @@ object BaseRecalibrator {
     val br = new BaseRecalibrator(root)
     br.input_file :+= input
     br.out = output
-    br.beforeGraph()
     br
   }
 }
\ No newline at end of file
diff --git a/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/GatkGeneral.scala b/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/GatkGeneral.scala
index 1d8de140b277d349095ae459f700ed5437888b16..f0073f0116b99a92fcace99ec1979a907e29eb14 100644
--- a/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/GatkGeneral.scala
+++ b/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/GatkGeneral.scala
@@ -5,32 +5,39 @@
  */
 package nl.lumc.sasc.biopet.extensions.gatk.broad
 
-import nl.lumc.sasc.biopet.core.{ BiopetJavaCommandLineFunction, Reference }
+import nl.lumc.sasc.biopet.core.{ CommandLineResources, Reference, BiopetJavaCommandLineFunction }
+import org.broadinstitute.gatk.engine.phonehome.GATKRunReport
 import org.broadinstitute.gatk.queue.extensions.gatk.CommandLineGATK
 
-trait GatkGeneral extends CommandLineGATK with BiopetJavaCommandLineFunction with Reference {
+trait GatkGeneral extends CommandLineGATK with CommandLineResources with Reference {
   memoryLimit = Option(3)
 
   override def subPath = "gatk" :: super.subPath
 
   jarFile = config("gatk_jar")
 
+  reference_sequence = referenceFasta()
+
   override def defaultCoreMemory = 4.0
   override def faiRequired = true
 
   if (config.contains("intervals")) intervals = config("intervals").asFileList
   if (config.contains("exclude_intervals")) excludeIntervals = config("exclude_intervals").asFileList
+
+  Option(config("et").value) match {
+    case Some("NO_ET")  => et = GATKRunReport.PhoneHomeOption.NO_ET
+    case Some("AWS")    => et = GATKRunReport.PhoneHomeOption.AWS
+    case Some("STDOUT") => et = GATKRunReport.PhoneHomeOption.STDOUT
+    case Some(x)        => throw new IllegalArgumentException(s"Unknown et option for gatk: $x")
+    case _              =>
+  }
+
   if (config.contains("gatk_key")) gatk_key = config("gatk_key")
   if (config.contains("pedigree")) pedigree = config("pedigree")
 
-  override def versionRegex = """(.*)""".r
-  override def versionExitcode = List(0, 1)
-  override def versionCommand = executable + " -jar " + jarFile + " -version"
-
-  override def getVersion = super.getVersion.collect { case v => "Gatk " + v }
+  //override def versionRegex = """(.*)""".r
+  //override def versionExitcode = List(0, 1)
+  //override def versionCommand = executable + " -jar " + jarFile + " -version"
 
-  override def beforeGraph(): Unit = {
-    super.beforeGraph()
-    if (reference_sequence == null) reference_sequence = referenceFasta()
-  }
+  //override def getVersion = super.getVersion.collect { case v => "Gatk " + v }
 }
diff --git a/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/HaplotypeCaller.scala b/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/HaplotypeCaller.scala
index 30c7f890ac877194478119c9ee5187f283da6718..514879f9d2b96088a6e5b3e30eb969d44740934b 100644
--- a/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/HaplotypeCaller.scala
+++ b/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/HaplotypeCaller.scala
@@ -38,11 +38,11 @@ class HaplotypeCaller(val root: Configurable) extends org.broadinstitute.gatk.qu
     stand_emit_conf = config("stand_emit_conf", default = 0)
   }
 
-  override def beforeGraph() {
-    super.beforeGraph()
+  override def freezeFieldValues() {
+    super.freezeFieldValues()
     if (bamOutput != null && nct.getOrElse(1) > 1) {
-      threads = 1
       logger.warn("BamOutput is on, nct/threads is forced to set on 1, this option is only for debug")
+      nCoresRequest = Some(1)
     }
     nct = Some(getThreads)
     memoryLimit = Option(memoryLimit.getOrElse(2.0) * nct.getOrElse(1))
diff --git a/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/UnifiedGenotyper.scala b/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/UnifiedGenotyper.scala
index a135b70c12e3f1deebb718b4ca788a9d0ebd5dce..70d988f4b057572bc1c110ad597c232d6093a2cc 100644
--- a/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/UnifiedGenotyper.scala
+++ b/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/UnifiedGenotyper.scala
@@ -28,8 +28,8 @@ class UnifiedGenotyper(val root: Configurable) extends org.broadinstitute.gatk.q
 
   override val defaultThreads = 1
 
-  override def beforeGraph() {
-    super.beforeGraph()
+  override def freezeFieldValues() {
+    super.freezeFieldValues()
 
     genotype_likelihoods_model = org.broadinstitute.gatk.tools.walkers.genotyper.GenotypeLikelihoodsCalculationModel.Model.BOTH
     nct = Some(getThreads)
diff --git a/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/VariantEval.scala b/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/VariantEval.scala
index 9329c394d15bc0428a1c11077896a5026876be91..fdb6e7e27b08793f44fb94d82c5ceef0033d4ed5 100644
--- a/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/VariantEval.scala
+++ b/protected/biopet-gatk-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/broad/VariantEval.scala
@@ -10,9 +10,6 @@ import java.io.File
 import nl.lumc.sasc.biopet.utils.config.Configurable
 
 class VariantEval(val root: Configurable) extends org.broadinstitute.gatk.queue.extensions.gatk.VariantEval with GatkGeneral {
-  override def beforeGraph() {
-    super.beforeGraph()
-  }
 }
 
 object VariantEval {
@@ -22,7 +19,6 @@ object VariantEval {
     vareval.eval = Seq(sample)
     vareval.comp = Seq(compareWith)
     vareval.out = output
-    vareval.beforeGraph()
     vareval
   }
 
@@ -36,7 +32,6 @@ object VariantEval {
     vareval.ST = ST
     vareval.noEV = true
     vareval.EV = EV
-    vareval.beforeGraph()
     vareval
   }
 
diff --git a/protected/biopet-gatk-pipelines/src/test/scala/nl/lumc/sasc/biopet/pipelines/gatk/ShivaTest.scala b/protected/biopet-gatk-pipelines/src/test/scala/nl/lumc/sasc/biopet/pipelines/gatk/ShivaTest.scala
index 9395daa1da479d97d5b5bd822379be5085b67c6c..66f0bfcc564503567782bcc1e35b0cc0899e6212 100644
--- a/protected/biopet-gatk-pipelines/src/test/scala/nl/lumc/sasc/biopet/pipelines/gatk/ShivaTest.scala
+++ b/protected/biopet-gatk-pipelines/src/test/scala/nl/lumc/sasc/biopet/pipelines/gatk/ShivaTest.scala
@@ -74,8 +74,6 @@ class ShivaTest extends TestNGSuite with Matchers {
       val numberLibs = (if (sample1) 1 else 0) + (if (sample2) 1 else 0) + (if (sample3) 2 else 0)
       val numberSamples = (if (sample1) 1 else 0) + (if (sample2) 1 else 0) + (if (sample3) 1 else 0)
 
-      pipeline.functions.count(_.isInstanceOf[BwaMem]) shouldBe numberLibs
-      pipeline.functions.count(_.isInstanceOf[SortSam]) shouldBe numberLibs
       pipeline.functions.count(_.isInstanceOf[MarkDuplicates]) shouldBe (numberLibs + (if (sample3) 1 else 0))
 
       // Gatk preprocess
@@ -93,6 +91,12 @@ class ShivaTest extends TestNGSuite with Matchers {
 
 object ShivaTest {
   val outputDir = Files.createTempDir()
+  new File(outputDir, "input").mkdirs()
+  def inputTouch(name: String): String = {
+    val file = new File(outputDir, "input" + File.separator + name)
+    Files.touch(file)
+    file.getAbsolutePath
+  }
 
   private def copyFile(name: String): Unit = {
     val is = getClass.getResourceAsStream("/" + name)
@@ -136,8 +140,8 @@ object ShivaTest {
   val sample1 = Map(
     "samples" -> Map("sample1" -> Map("libraries" -> Map(
       "lib1" -> Map(
-        "R1" -> "1_1_R1.fq",
-        "R2" -> "1_1_R2.fq"
+        "R1" -> inputTouch("1_1_R1.fq"),
+        "R2" -> inputTouch("1_1_R2.fq")
       )
     )
     )))
@@ -145,8 +149,8 @@ object ShivaTest {
   val sample2 = Map(
     "samples" -> Map("sample2" -> Map("libraries" -> Map(
       "lib1" -> Map(
-        "R1" -> "2_1_R1.fq",
-        "R2" -> "2_1_R2.fq"
+        "R1" -> inputTouch("2_1_R1.fq"),
+        "R2" -> inputTouch("2_1_R2.fq")
       )
     )
     )))
@@ -154,12 +158,12 @@ object ShivaTest {
   val sample3 = Map(
     "samples" -> Map("sample3" -> Map("libraries" -> Map(
       "lib1" -> Map(
-        "R1" -> "3_1_R1.fq",
-        "R2" -> "3_1_R2.fq"
+        "R1" -> inputTouch("3_1_R1.fq"),
+        "R2" -> inputTouch("3_1_R2.fq")
       ),
       "lib2" -> Map(
-        "R1" -> "3_2_R1.fq",
-        "R2" -> "3_2_R2.fq"
+        "R1" -> inputTouch("3_2_R1.fq"),
+        "R2" -> inputTouch("3_2_R2.fq")
       )
     )
     )))
diff --git a/protected/biopet-gatk-pipelines/src/test/scala/nl/lumc/sasc/biopet/pipelines/gatk/ShivaVariantcallingTest.scala b/protected/biopet-gatk-pipelines/src/test/scala/nl/lumc/sasc/biopet/pipelines/gatk/ShivaVariantcallingTest.scala
index 2c60207a82fae9da823eb02d7a860b5dd8be1834..8e8a1eddf9e5d6b5aab36c4c6fea7d35ea2da82e 100644
--- a/protected/biopet-gatk-pipelines/src/test/scala/nl/lumc/sasc/biopet/pipelines/gatk/ShivaVariantcallingTest.scala
+++ b/protected/biopet-gatk-pipelines/src/test/scala/nl/lumc/sasc/biopet/pipelines/gatk/ShivaVariantcallingTest.scala
@@ -73,7 +73,7 @@ class ShivaVariantcallingTest extends TestNGSuite with Matchers {
     val map = Map("variantcallers" -> callers.toList)
     val pipeline = initPipeline(map)
 
-    pipeline.inputBams = (for (n <- 1 to bams) yield new File("bam_" + n + ".bam")).toList
+    pipeline.inputBams = (for (n <- 1 to bams) yield ShivaVariantcallingTest.inputTouch("bam_" + n + ".bam")).toList
 
     val illegalArgumentException = pipeline.inputBams.isEmpty ||
       (!raw && !bcftools &&
@@ -107,6 +107,12 @@ class ShivaVariantcallingTest extends TestNGSuite with Matchers {
 
 object ShivaVariantcallingTest {
   val outputDir = Files.createTempDir()
+  new File(outputDir, "input").mkdirs()
+  def inputTouch(name: String): File = {
+    val file = new File(outputDir, "input" + File.separator + name).getAbsoluteFile
+    Files.touch(file)
+    file
+  }
 
   private def copyFile(name: String): Unit = {
     val is = getClass.getResourceAsStream("/" + name)
diff --git a/protected/biopet-protected-package/src/main/scala/nl/lumc/sasc/biopet/BiopetExecutableProtected.scala b/protected/biopet-protected-package/src/main/scala/nl/lumc/sasc/biopet/BiopetExecutableProtected.scala
index 4e725bb0b1e2002a323cc22f38c86b53ca4f14af..9155e7dbacf4fd624694ac06a1ddf24c69071afe 100644
--- a/protected/biopet-protected-package/src/main/scala/nl/lumc/sasc/biopet/BiopetExecutableProtected.scala
+++ b/protected/biopet-protected-package/src/main/scala/nl/lumc/sasc/biopet/BiopetExecutableProtected.scala
@@ -8,7 +8,7 @@ package nl.lumc.sasc.biopet
 import nl.lumc.sasc.biopet.utils.{ BiopetExecutable, MainCommand }
 
 object BiopetExecutableProtected extends BiopetExecutable {
-  def pipelines: List[MainCommand] = BiopetExecutablePublic.pipelines ::: List(
+  def pipelines: List[MainCommand] = BiopetExecutablePublic.publicPipelines ::: List(
     nl.lumc.sasc.biopet.pipelines.gatk.Shiva,
     nl.lumc.sasc.biopet.pipelines.gatk.ShivaVariantcalling,
     nl.lumc.sasc.biopet.pipelines.gatk.Basty)
diff --git a/public/bam2wig/src/main/scala/nl/lumc/sasc/biopet/pipelines/bamtobigwig/Bam2Wig.scala b/public/bam2wig/src/main/scala/nl/lumc/sasc/biopet/pipelines/bamtobigwig/Bam2Wig.scala
index 451350227e5620ae612212eb341e0acae49ad958..fb9e39611fd861f9158503581f17d4bd12e6cb30 100644
--- a/public/bam2wig/src/main/scala/nl/lumc/sasc/biopet/pipelines/bamtobigwig/Bam2Wig.scala
+++ b/public/bam2wig/src/main/scala/nl/lumc/sasc/biopet/pipelines/bamtobigwig/Bam2Wig.scala
@@ -35,6 +35,7 @@ class Bam2Wig(val root: Configurable) extends QScript with BiopetQScript {
   var bamFile: File = null
 
   def init(): Unit = {
+    inputFiles :+= new InputFile(bamFile)
   }
 
   def biopetScript(): Unit = {
diff --git a/public/bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/insertSize.ssp b/public/bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/insertSize.ssp
index 45f8da529dbab9bcd5c9a7dd6d93fd730b87715b..ba6692dd7af137c57e51d023438995f136d2e477 100644
--- a/public/bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/insertSize.ssp
+++ b/public/bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/insertSize.ssp
@@ -42,7 +42,7 @@
 #end
 
 #if (showPlot)
-    #{ BammetricsReport.insertSizePlot(outputDir, "insertsize", summary, !sampleLevel, sampleId = sampleId) }#
+    #{ BammetricsReport.insertSizePlot(outputDir, "insertsize", summary, !sampleLevel, sampleId = sampleId, libId = libId) }#
 
     <div class="panel-body">
     <img src="insertsize.png" class="img-responsive" />
diff --git a/public/bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/wgsHistogram.ssp b/public/bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/wgsHistogram.ssp
index 9905a23cfdcb9ac10ba96b1bb2ed43b3686604b8..e900774e0788d03fc5180444fbbb6bd875ad253e 100644
--- a/public/bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/wgsHistogram.ssp
+++ b/public/bammetrics/src/main/resources/nl/lumc/sasc/biopet/pipelines/bammetrics/wgsHistogram.ssp
@@ -36,7 +36,7 @@
 #end
 
 #if (showPlot)
-    #{ BammetricsReport.wgsHistogramPlot(outputDir, "wgs", summary, !sampleLevel, sampleId = sampleId) }#
+    #{ BammetricsReport.wgsHistogramPlot(outputDir, "wgs", summary, !sampleLevel, sampleId = sampleId, libId = libId) }#
 
     <div class="panel-body">
     <img src="wgs.png" class="img-responsive" />
diff --git a/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.scala b/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.scala
index 24b0a29b1a7ce265ea145f404203f614da550884..f6a6dc090defdb238f76b68f21189faf38fd207c 100644
--- a/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.scala
+++ b/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.scala
@@ -71,7 +71,8 @@ class BamMetrics(val root: Configurable) extends QScript with SummaryQScript wit
   }
 
   /** executed before script */
-  def init() {
+  def init(): Unit = {
+    inputFiles :+= new InputFile(inputBam)
   }
 
   /** Script to add jobs */
@@ -186,8 +187,13 @@ class BamMetrics(val root: Configurable) extends QScript with SummaryQScript wit
 
 object BamMetrics extends PipelineCommand {
   /** Make default implementation of BamMetrics and runs script already */
-  def apply(root: Configurable, bamFile: File, outputDir: File): BamMetrics = {
+  def apply(root: Configurable,
+            bamFile: File, outputDir: File,
+            sampleId: Option[String] = None,
+            libId: Option[String] = None): BamMetrics = {
     val bamMetrics = new BamMetrics(root)
+    bamMetrics.sampleId = sampleId
+    bamMetrics.libId = libId
     bamMetrics.inputBam = bamFile
     bamMetrics.outputDir = outputDir
 
diff --git a/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BammetricsReport.scala b/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BammetricsReport.scala
index f4138e12ec607ecfdcc9538347c83fbe6c9d4d16..babc43f721b9a1bd4d03f6930a97e4cb454f4187 100644
--- a/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BammetricsReport.scala
+++ b/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BammetricsReport.scala
@@ -156,14 +156,15 @@ object BammetricsReport extends ReportBuilder {
                      prefix: String,
                      summary: Summary,
                      libraryLevel: Boolean = false,
-                     sampleId: Option[String] = None): Unit = {
+                     sampleId: Option[String] = None,
+                     libId: Option[String] = None): Unit = {
     val tsvFile = new File(outputDir, prefix + ".tsv")
     val pngFile = new File(outputDir, prefix + ".png")
     val tsvWriter = new PrintWriter(tsvFile)
     if (libraryLevel) {
       tsvWriter.println((for (
         sample <- summary.samples if sampleId.isEmpty || sampleId.get == sample;
-        lib <- summary.libraries(sample)
+        lib <- summary.libraries(sample) if libId.isEmpty || libId.get == lib
       ) yield s"$sample-$lib")
         .mkString("library\t", "\t", ""))
     } else {
@@ -198,7 +199,7 @@ object BammetricsReport extends ReportBuilder {
     if (libraryLevel) {
       for (
         sample <- summary.samples if sampleId.isEmpty || sampleId.get == sample;
-        lib <- summary.libraries(sample)
+        lib <- summary.libraries(sample) if libId.isEmpty || libId.get == lib
       ) fill(sample, Some(lib))
     } else if (sampleId.isDefined) fill(sampleId.get, None)
     else summary.samples.foreach(fill(_, None))
@@ -208,7 +209,7 @@ object BammetricsReport extends ReportBuilder {
       if (libraryLevel) {
         for (
           sample <- summary.samples if sampleId.isEmpty || sampleId.get == sample;
-          lib <- summary.libraries(sample)
+          lib <- summary.libraries(sample) if libId.isEmpty || libId.get == lib
         ) tsvWriter.print("\t" + counts.getOrElse(s"$sample-$lib", "0"))
       } else {
         for (sample <- summary.samples if sampleId.isEmpty || sampleId.get == sample) {
@@ -243,14 +244,15 @@ object BammetricsReport extends ReportBuilder {
                        prefix: String,
                        summary: Summary,
                        libraryLevel: Boolean = false,
-                       sampleId: Option[String] = None): Unit = {
+                       sampleId: Option[String] = None,
+                       libId: Option[String] = None): Unit = {
     val tsvFile = new File(outputDir, prefix + ".tsv")
     val pngFile = new File(outputDir, prefix + ".png")
     val tsvWriter = new PrintWriter(tsvFile)
     if (libraryLevel) {
       tsvWriter.println((for (
         sample <- summary.samples if sampleId.isEmpty || sampleId.get == sample;
-        lib <- summary.libraries(sample)
+        lib <- summary.libraries(sample) if libId.isEmpty || libId.get == lib
       ) yield s"$sample-$lib")
         .mkString("library\t", "\t", ""))
     } else {
@@ -285,7 +287,7 @@ object BammetricsReport extends ReportBuilder {
     if (libraryLevel) {
       for (
         sample <- summary.samples if sampleId.isEmpty || sampleId.get == sample;
-        lib <- summary.libraries(sample)
+        lib <- summary.libraries(sample) if libId.isEmpty || libId.get == lib
       ) fill(sample, Some(lib))
     } else if (sampleId.isDefined) fill(sampleId.get, None)
     else summary.samples.foreach(fill(_, None))
@@ -295,8 +297,10 @@ object BammetricsReport extends ReportBuilder {
       if (libraryLevel) {
         for (
           sample <- summary.samples if sampleId.isEmpty || sampleId.get == sample;
-          lib <- summary.libraries(sample)
-        ) tsvWriter.print("\t" + counts.getOrElse(s"$sample-$lib", "0"))
+          lib <- summary.libraries(sample) if libId.isEmpty || libId.get == lib
+        ) {
+          tsvWriter.print("\t" + counts.getOrElse(s"$sample-$lib", "0"))
+        }
       } else {
         for (sample <- summary.samples if sampleId.isEmpty || sampleId.get == sample) {
           tsvWriter.print("\t" + counts.getOrElse(sample, "0"))
diff --git a/public/bammetrics/src/test/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetricsTest.scala b/public/bammetrics/src/test/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetricsTest.scala
index 7e97b4a78e1176b1603a7ae5aec10057c4bd0175..33304cb198807f46d3801ddfc9b05eaa7d555fe4 100644
--- a/public/bammetrics/src/test/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetricsTest.scala
+++ b/public/bammetrics/src/test/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetricsTest.scala
@@ -69,7 +69,7 @@ class BamMetricsTest extends TestNGSuite with Matchers {
       Map("regions_of_interest" -> (1 to rois).map("roi_" + _ + ".bed").toList)
     val bammetrics: BamMetrics = initPipeline(map)
 
-    bammetrics.inputBam = new File("input.bam")
+    bammetrics.inputBam = BamMetricsTest.bam
     bammetrics.sampleId = Some("1")
     bammetrics.libId = Some("1")
     bammetrics.script()
@@ -98,6 +98,10 @@ class BamMetricsTest extends TestNGSuite with Matchers {
 
 object BamMetricsTest {
   val outputDir = Files.createTempDir()
+  new File(outputDir, "input").mkdirs()
+
+  val bam = new File(outputDir, "input" + File.separator + "bla.bam")
+  Files.touch(bam)
 
   private def copyFile(name: String): Unit = {
     val is = getClass.getResourceAsStream("/" + name)
diff --git a/public/basty/src/main/scala/nl/lumc/sasc/biopet/pipelines/basty/BastyTrait.scala b/public/basty/src/main/scala/nl/lumc/sasc/biopet/pipelines/basty/BastyTrait.scala
index 09528f1b674b6d48b49d022b3d79b82a3d31d9b9..d9085369f0316b6a0474fe02cd15ef07c683713a 100644
--- a/public/basty/src/main/scala/nl/lumc/sasc/biopet/pipelines/basty/BastyTrait.scala
+++ b/public/basty/src/main/scala/nl/lumc/sasc/biopet/pipelines/basty/BastyTrait.scala
@@ -89,6 +89,8 @@ trait BastyTrait extends MultiSampleQScript {
     addAll(shiva.functions)
     addSummaryQScript(shiva)
 
+    inputFiles :::= shiva.inputFiles
+
     addSamplesJobs()
   }
 
@@ -135,7 +137,6 @@ trait BastyTrait extends MultiSampleQScript {
       val numBoot = config("boot_runs", default = 100, submodule = "raxml").asInt
       val bootList = for (t <- 0 until numBoot) yield {
         val raxmlBoot = new Raxml(this)
-        raxmlBoot.threads = 1
         raxmlBoot.input = variants
         raxmlBoot.m = config("raxml_ml_model", default = "GTRGAMMAX")
         raxmlBoot.p = Some(seed)
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunction.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunction.scala
index 30c400bc52d8ab439089f238864858fa32ef6832..254e783cb9e31718a8b0759e7ce0d55c152d203d 100644
--- a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunction.scala
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunction.scala
@@ -15,25 +15,276 @@
  */
 package nl.lumc.sasc.biopet.core
 
-/**
- * This class is for commandline programs where the executable is a non JVM based program
- */
-abstract class BiopetCommandLineFunction extends BiopetCommandLineFunctionTrait {
+import java.io.{ PrintWriter, File, FileInputStream }
+import java.security.MessageDigest
+
+import nl.lumc.sasc.biopet.utils.Logging
+import org.broadinstitute.gatk.utils.commandline.{ Output, Input }
+import org.broadinstitute.gatk.utils.runtime.ProcessSettings
+import org.ggf.drmaa.JobTemplate
+
+import scala.collection.mutable
+import scala.io.Source
+import scala.sys.process.{ Process, ProcessLogger }
+import scala.util.matching.Regex
+import scala.collection.JavaConversions._
+
+/** Biopet command line trait to auto check executable and cluster values */
+trait BiopetCommandLineFunction extends CommandLineResources { biopetFunction =>
+  analysisName = configName
+
+  @Input(doc = "deps", required = false)
+  var deps: List[File] = Nil
+
+  @Output
+  var outputFiles: List[File] = Nil
+
+  var executable: String = _
+
+  /** This is the default shell for drmaa jobs */
+  def defaultRemoteCommand = "bash"
+  private val remoteCommand: String = config("remote_command", default = defaultRemoteCommand)
+
+  private def changeScript(file: File): Unit = {
+    val lines = Source.fromFile(file).getLines().toList
+    val writer = new PrintWriter(file)
+    writer.println("set -eubf")
+    writer.println("set -o pipefail")
+    lines.foreach(writer.println(_))
+    writer.close()
+  }
+
+  // This overrides the default "sh" from queue. For Biopet the default is "bash"
+  updateJobRun = {
+    case jt: JobTemplate => {
+      changeScript(new File(jt.getArgs.head.toString))
+      jt.setRemoteCommand(remoteCommand)
+    }
+    case ps: ProcessSettings => {
+      changeScript(new File(ps.getCommand.tail.head))
+      ps.setCommand(Array(remoteCommand) ++ ps.getCommand.tail)
+    }
+  }
+
+  /**
+   * Can override this method. This is executed just before the job is ready to run.
+   * Can check on run time files from pipeline here
+   */
+  def beforeCmd() {}
+
+  /** Can override this method. This is executed after the script is done en queue starts to generate the graph */
+  def beforeGraph() {}
+
+  override def freezeFieldValues() {
+    preProcessExecutable()
+    beforeGraph()
+    internalBeforeGraph()
+
+    super.freezeFieldValues()
+  }
+
+  /** Set default output file, threads and vmem for current job */
+  final def internalBeforeGraph(): Unit = {
+
+    pipesJobs.foreach(_.beforeGraph())
+    pipesJobs.foreach(_.internalBeforeGraph())
+
+  }
+
+  /** can override this value is executable may not be converted to CanonicalPath */
+  val executableToCanonicalPath = true
+
+  /**
+   * Checks executable. Follow full CanonicalPath, checks if it is existing and do a md5sum on it to store in job report
+   */
+  protected[core] def preProcessExecutable() {
+    if (!BiopetCommandLineFunction.executableMd5Cache.contains(executable)) {
+      if (executable != null) {
+        if (!BiopetCommandLineFunction.executableCache.contains(executable)) {
+          try {
+            val oldExecutable = executable
+            val buffer = new StringBuffer()
+            val cmd = Seq("which", executable)
+            val process = Process(cmd).run(ProcessLogger(buffer.append(_)))
+            if (process.exitValue == 0) {
+              executable = buffer.toString
+              val file = new File(executable)
+              if (executableToCanonicalPath) executable = file.getCanonicalPath
+              else executable = file.getAbsolutePath
+            } else Logging.addError("executable: '" + executable + "' not found, please check config")
+            BiopetCommandLineFunction.executableCache += oldExecutable -> executable
+            BiopetCommandLineFunction.executableCache += executable -> executable
+          } catch {
+            case ioe: java.io.IOException =>
+              logger.warn(s"Could not use 'which' on '$executable', check on executable skipped: " + ioe)
+          }
+        } else executable = BiopetCommandLineFunction.executableCache(executable)
+
+        if (!BiopetCommandLineFunction.executableMd5Cache.contains(executable)) {
+          if (new File(executable).exists()) {
+            val is = new FileInputStream(executable)
+            val cnt = is.available
+            val bytes = Array.ofDim[Byte](cnt)
+            is.read(bytes)
+            is.close()
+            val temp = MessageDigest.getInstance("MD5").digest(bytes).map("%02X".format(_)).mkString.toLowerCase
+            BiopetCommandLineFunction.executableMd5Cache += executable -> temp
+          } else BiopetCommandLineFunction.executableMd5Cache += executable -> "file_does_not_exist"
+        }
+      }
+    }
+    val md5 = BiopetCommandLineFunction.executableMd5Cache.get(executable)
+    addJobReportBinding("md5sum_exe", md5.getOrElse("None"))
+  }
+
+  /** executes checkExecutable method and fill job report */
+  final protected def preCmdInternal() {
+    preProcessExecutable()
+    beforeCmd()
+
+    addJobReportBinding("cores", nCoresRequest match {
+      case Some(n) if n > 0 => n
+      case _                => 1
+    })
+    addJobReportBinding("version", getVersion)
+  }
+
+  /** Command to get version of executable */
+  protected[core] def versionCommand: String = null
+
+  /** Regex to get version from version command output */
+  protected[core] def versionRegex: Regex = null
+
+  /** Allowed exit codes for the version command */
+  protected[core] def versionExitcode = List(0)
+
+  /** Executes the version command */
+  private[core] def getVersionInternal: Option[String] = {
+    if (versionCommand == null || versionRegex == null) None
+    else getVersionInternal(versionCommand, versionRegex)
+  }
+
+  /** Executes the version command */
+  private[core] def getVersionInternal(versionCommand: String, versionRegex: Regex): Option[String] = {
+    if (versionCommand == null || versionRegex == null) return None
+    val exe = new File(versionCommand.trim.split(" ")(0))
+    if (!exe.exists()) return None
+    val stdout = new StringBuffer()
+    val stderr = new StringBuffer()
+    def outputLog = "Version command: \n" + versionCommand +
+      "\n output log: \n stdout: \n" + stdout.toString +
+      "\n stderr: \n" + stderr.toString
+    val process = Process(versionCommand).run(ProcessLogger(stdout append _ + "\n", stderr append _ + "\n"))
+    if (!versionExitcode.contains(process.exitValue())) {
+      logger.warn("getVersion give exit code " + process.exitValue + ", version not found \n" + outputLog)
+      return None
+    }
+    for (line <- stdout.toString.split("\n") ++ stderr.toString.split("\n")) {
+      line match {
+        case versionRegex(m) => return Some(m)
+        case _               =>
+      }
+    }
+    logger.warn("getVersion give a exit code " + process.exitValue + " but no version was found, executable correct? \n" + outputLog)
+    None
+  }
+
+  /** Get version from cache otherwise execute the version command  */
+  def getVersion: Option[String] = {
+    if (!BiopetCommandLineFunction.executableCache.contains(executable))
+      preProcessExecutable()
+    if (!BiopetCommandLineFunction.versionCache.contains(versionCommand))
+      getVersionInternal match {
+        case Some(version) => BiopetCommandLineFunction.versionCache += versionCommand -> version
+        case _             =>
+      }
+    BiopetCommandLineFunction.versionCache.get(versionCommand)
+  }
+
+  private[core] var _inputAsStdin = false
+  def inputAsStdin = _inputAsStdin
+  private[core] var _outputAsStdout = false
+  def outputAsStsout = _outputAsStdout
+
+  /**
+   * This operator sends stdout to `that` and combine this into 1 command line function
+   * @param that Function that will read from stdin
+   * @return BiopetPipe function
+   */
+  def |(that: BiopetCommandLineFunction): BiopetCommandLineFunction = {
+    this._outputAsStdout = true
+    that._inputAsStdin = true
+    this.beforeGraph()
+    this.internalBeforeGraph()
+    that.beforeGraph()
+    that.internalBeforeGraph()
+    this match {
+      case p: BiopetPipe => {
+        p.commands.last._outputAsStdout = true
+        new BiopetPipe(p.commands ::: that :: Nil)
+      }
+      case _ => new BiopetPipe(List(this, that))
+    }
+  }
+
+  /**
+   * This operator can be used to give a program a file as stdin
+   * @param file File that will become stdin for this program
+   * @return It's own class
+   */
+  def :<:(file: File): BiopetCommandLineFunction = {
+    this._inputAsStdin = true
+    this.stdinFile = Some(file)
+    this
+  }
+
+  /**
+   * This operator can be used to give a program a file write it's atdout
+   * @param file File that will become stdout for this program
+   * @return It's own class
+   */
+  def >(file: File): BiopetCommandLineFunction = {
+    this._outputAsStdout = true
+    this.stdoutFile = Some(file)
+    this
+  }
+
+  @Output(required = false)
+  private[core] var stdoutFile: Option[File] = None
+
+  @Input(required = false)
+  private[core] var stdinFile: Option[File] = None
+
   /**
    * This function needs to be implemented to define the command that is executed
    * @return Command to run
    */
-  protected def cmdLine: String
+  protected[core] def cmdLine: String
 
   /**
    * implementing a final version of the commandLine from org.broadinstitute.gatk.queue.function.CommandLineFunction
    * User needs to implement cmdLine instead
    * @return Command to run
    */
-  final def commandLine: String = {
+  override final def commandLine: String = {
     preCmdInternal()
-    val cmd = cmdLine
+    val cmd = cmdLine +
+      stdinFile.map(file => " < " + required(file.getAbsoluteFile)).getOrElse("") +
+      stdoutFile.map(file => " > " + required(file.getAbsoluteFile)).getOrElse("")
     addJobReportBinding("command", cmd)
     cmd
   }
+
+  private[core] var pipesJobs: List[BiopetCommandLineFunction] = Nil
+  def addPipeJob(job: BiopetCommandLineFunction) {
+    pipesJobs :+= job
+    pipesJobs = pipesJobs.distinct
+  }
+}
+
+/** stores global caches */
+object BiopetCommandLineFunction {
+  private[core] val versionCache: mutable.Map[String, String] = mutable.Map()
+  private[core] val executableMd5Cache: mutable.Map[String, String] = mutable.Map()
+  private[core] val executableCache: mutable.Map[String, String] = mutable.Map()
 }
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunctionTrait.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunctionTrait.scala
deleted file mode 100644
index 6084bb7b6a3b45f5ca184fe4c2634d8888846c77..0000000000000000000000000000000000000000
--- a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetCommandLineFunctionTrait.scala
+++ /dev/null
@@ -1,236 +0,0 @@
-/**
- * Biopet is built on top of GATK Queue for building bioinformatic
- * pipelines. It is mainly intended to support LUMC SHARK cluster which is running
- * SGE. But other types of HPC that are supported by GATK Queue (such as PBS)
- * should also be able to execute Biopet tools and pipelines.
- *
- * Copyright 2014 Sequencing Analysis Support Core - Leiden University Medical Center
- *
- * Contact us at: sasc@lumc.nl
- *
- * A dual licensing mode is applied. The source code within this project that are
- * not part of GATK Queue is freely available for non-commercial use under an AGPL
- * license; For commercial users or users who do not want to follow the AGPL
- * license, please contact us to obtain a separate license.
- */
-package nl.lumc.sasc.biopet.core
-
-import java.io.{ File, FileInputStream }
-import java.security.MessageDigest
-
-import nl.lumc.sasc.biopet.utils.Logging
-import nl.lumc.sasc.biopet.utils.config.Configurable
-import org.broadinstitute.gatk.queue.function.CommandLineFunction
-import org.broadinstitute.gatk.utils.commandline.Input
-
-import scala.collection.mutable
-import scala.sys.process.{ Process, ProcessLogger }
-import scala.util.matching.Regex
-
-/** Biopet command line trait to auto check executable and cluster values */
-trait BiopetCommandLineFunctionTrait extends CommandLineFunction with Configurable {
-  analysisName = configName
-
-  @Input(doc = "deps", required = false)
-  var deps: List[File] = Nil
-
-  var threads = 0
-  def defaultThreads = 1
-
-  var vmem: Option[String] = config("vmem")
-  protected def defaultCoreMemory: Double = 1.0
-  protected def defaultVmemFactor: Double = 1.4
-  var vmemFactor: Double = config("vmem_factor", default = defaultVmemFactor)
-
-  var residentFactor: Double = config("resident_factor", default = 1.2)
-
-  private var coreMemory: Double = _
-
-  var executable: String = _
-
-  /**
-   * Can override this method. This is executed just before the job is ready to run.
-   * Can check on run time files from pipeline here
-   */
-  protected[core] def beforeCmd() {}
-
-  /** Can override this method. This is executed after the script is done en queue starts to generate the graph */
-  protected[core] def beforeGraph() {}
-
-  /** Set default output file, threads and vmem for current job */
-  override def freezeFieldValues() {
-    preProcessExecutable()
-    beforeGraph()
-    if (jobOutputFile == null) jobOutputFile = new File(firstOutput.getAbsoluteFile.getParent, "." + firstOutput.getName + "." + configName + ".out")
-
-    if (threads == 0) threads = getThreads(defaultThreads)
-    if (threads > 1) nCoresRequest = Option(threads)
-
-    coreMemory = config("core_memory", default = defaultCoreMemory).asDouble + (0.5 * retry)
-
-    if (config.contains("memory_limit")) memoryLimit = config("memory_limit")
-    else memoryLimit = Some(coreMemory * threads)
-
-    if (config.contains("resident_limit")) residentLimit = config("resident_limit")
-    else residentLimit = Some((coreMemory + (0.5 * retry)) * residentFactor)
-
-    if (!config.contains("vmem")) vmem = Some((coreMemory * (vmemFactor + (0.5 * retry))) + "G")
-    if (vmem.isDefined) jobResourceRequests :+= "h_vmem=" + vmem.get
-    jobName = configName + ":" + (if (firstOutput != null) firstOutput.getName else jobOutputFile)
-
-    super.freezeFieldValues()
-  }
-
-  var retry = 0
-
-  override def setupRetry(): Unit = {
-    super.setupRetry()
-    if (vmem.isDefined) jobResourceRequests = jobResourceRequests.filterNot(_.contains("h_vmem="))
-    logger.info("Auto raise memory on retry")
-    retry += 1
-    this.freeze()
-  }
-
-  /** can override this value is executable may not be converted to CanonicalPath */
-  val executableToCanonicalPath = true
-
-  /**
-   * Checks executable. Follow full CanonicalPath, checks if it is existing and do a md5sum on it to store in job report
-   */
-  protected[core] def preProcessExecutable() {
-    if (!BiopetCommandLineFunctionTrait.executableMd5Cache.contains(executable)) {
-      try if (executable != null) {
-        if (!BiopetCommandLineFunctionTrait.executableCache.contains(executable)) {
-          val oldExecutable = executable
-          val buffer = new StringBuffer()
-          val cmd = Seq("which", executable)
-          val process = Process(cmd).run(ProcessLogger(buffer.append(_)))
-          if (process.exitValue == 0) {
-            executable = buffer.toString
-            val file = new File(executable)
-            if (executableToCanonicalPath) executable = file.getCanonicalPath
-            else executable = file.getAbsolutePath
-          } else {
-            Logging.addError("executable: '" + executable + "' not found, please check config")
-          }
-          BiopetCommandLineFunctionTrait.executableCache += oldExecutable -> executable
-          BiopetCommandLineFunctionTrait.executableCache += executable -> executable
-        } else {
-          executable = BiopetCommandLineFunctionTrait.executableCache(executable)
-        }
-
-        if (!BiopetCommandLineFunctionTrait.executableMd5Cache.contains(executable)) {
-          val is = new FileInputStream(executable)
-          val cnt = is.available
-          val bytes = Array.ofDim[Byte](cnt)
-          is.read(bytes)
-          is.close()
-          val temp = MessageDigest.getInstance("MD5").digest(bytes).map("%02X".format(_)).mkString.toLowerCase
-          BiopetCommandLineFunctionTrait.executableMd5Cache += executable -> temp
-        }
-      } catch {
-        case ioe: java.io.IOException => logger.warn("Could not use 'which', check on executable skipped: " + ioe)
-      }
-    }
-    val md5 = BiopetCommandLineFunctionTrait.executableMd5Cache.get(executable)
-    addJobReportBinding("md5sum_exe", md5.getOrElse("None"))
-  }
-
-  /** executes checkExecutable method and fill job report */
-  final protected def preCmdInternal() {
-    preProcessExecutable()
-    beforeCmd()
-
-    addJobReportBinding("cores", nCoresRequest match {
-      case Some(n) if n > 0 => n
-      case _                => 1
-    })
-    addJobReportBinding("version", getVersion)
-  }
-
-  /** Command to get version of executable */
-  protected def versionCommand: String = null
-
-  /** Regex to get version from version command output */
-  protected def versionRegex: Regex = null
-
-  /** Allowed exit codes for the version command */
-  protected def versionExitcode = List(0)
-
-  /** Executes the version command */
-  private[core] def getVersionInternal: Option[String] = {
-    if (versionCommand == null || versionRegex == null) None
-    else getVersionInternal(versionCommand, versionRegex)
-  }
-
-  /** Executes the version command */
-  private[core] def getVersionInternal(versionCommand: String, versionRegex: Regex): Option[String] = {
-    if (versionCommand == null || versionRegex == null) return None
-    val exe = new File(versionCommand.trim.split(" ")(0))
-    if (!exe.exists()) return None
-    val stdout = new StringBuffer()
-    val stderr = new StringBuffer()
-    def outputLog = "Version command: \n" + versionCommand +
-      "\n output log: \n stdout: \n" + stdout.toString +
-      "\n stderr: \n" + stderr.toString
-    val process = Process(versionCommand).run(ProcessLogger(stdout append _ + "\n", stderr append _ + "\n"))
-    if (!versionExitcode.contains(process.exitValue())) {
-      logger.warn("getVersion give exit code " + process.exitValue + ", version not found \n" + outputLog)
-      return None
-    }
-    for (line <- stdout.toString.split("\n") ++ stderr.toString.split("\n")) {
-      line match {
-        case versionRegex(m) => return Some(m)
-        case _               =>
-      }
-    }
-    logger.warn("getVersion give a exit code " + process.exitValue + " but no version was found, executable correct? \n" + outputLog)
-    None
-  }
-
-  /** Get version from cache otherwise execute the version command  */
-  def getVersion: Option[String] = {
-    if (!BiopetCommandLineFunctionTrait.executableCache.contains(executable))
-      preProcessExecutable()
-    if (!BiopetCommandLineFunctionTrait.versionCache.contains(versionCommand))
-      getVersionInternal match {
-        case Some(version) => BiopetCommandLineFunctionTrait.versionCache += versionCommand -> version
-        case _             =>
-      }
-    BiopetCommandLineFunctionTrait.versionCache.get(versionCommand)
-  }
-
-  def getThreads: Int = getThreads(defaultThreads)
-
-  /**
-   * Get threads from config
-   * @param default default when not found in config
-   * @return number of threads
-   */
-  def getThreads(default: Int): Int = {
-    val maxThreads: Int = config("maxthreads", default = 24)
-    val threads: Int = config("threads", default = default)
-    if (maxThreads > threads) threads
-    else maxThreads
-  }
-
-  /**
-   * Get threads from config
-   * @param default default when not found in config
-   * @param module Module when this is difrent from default
-   * @return number of threads
-   */
-  def getThreads(default: Int, module: String): Int = {
-    val maxThreads: Int = config("maxthreads", default = 24, submodule = module)
-    val threads: Int = config("threads", default = default, submodule = module)
-    if (maxThreads > threads) threads
-    else maxThreads
-  }
-}
-
-/** stores global caches */
-object BiopetCommandLineFunctionTrait {
-  private[core] val versionCache: mutable.Map[String, String] = mutable.Map()
-  private[core] val executableMd5Cache: mutable.Map[String, String] = mutable.Map()
-  private[core] val executableCache: mutable.Map[String, String] = mutable.Map()
-}
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetFifoPipe.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetFifoPipe.scala
new file mode 100644
index 0000000000000000000000000000000000000000..ee06edb0a666a543c108c891092d5ac8ca7e23a6
--- /dev/null
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetFifoPipe.scala
@@ -0,0 +1,150 @@
+package nl.lumc.sasc.biopet.core
+
+import java.io.File
+
+import nl.lumc.sasc.biopet.utils.config.Configurable
+
+/**
+ * Created by pjvan_thof on 9/29/15.
+ */
+class BiopetFifoPipe(val root: Configurable,
+                     protected var commands: List[BiopetCommandLineFunction]) extends BiopetCommandLineFunction {
+
+  def fifos: List[File] = {
+    val outputs: Map[BiopetCommandLineFunction, Seq[File]] = try {
+      commands.map(x => x -> x.outputs).toMap
+    } catch {
+      case e: NullPointerException => Map()
+    }
+
+    val inputs: Map[BiopetCommandLineFunction, Seq[File]] = try {
+      commands.map(x => x -> x.inputs).toMap
+    } catch {
+      case e: NullPointerException => Map()
+    }
+
+    for (
+      cmdOutput <- commands;
+      cmdInput <- commands if cmdOutput != cmdInput && outputs.contains(cmdOutput);
+      outputFile <- outputs(cmdOutput) if inputs.contains(cmdInput);
+      inputFile <- inputs(cmdInput) if outputFile == inputFile
+    ) yield outputFile
+  }
+
+  override def beforeGraph(): Unit = {
+    val outputs: Map[BiopetCommandLineFunction, Seq[File]] = try {
+      commands.map(x => x -> x.outputs).toMap
+    } catch {
+      case e: NullPointerException => Map()
+    }
+
+    val inputs: Map[BiopetCommandLineFunction, Seq[File]] = try {
+      commands.map(x => x -> x.inputs).toMap
+    } catch {
+      case e: NullPointerException => Map()
+    }
+
+    val fifoFiles = fifos
+
+    outputFiles :::= outputs.values.toList.flatten.filter(!fifoFiles.contains(_))
+    outputFiles = outputFiles.distinct
+
+    deps :::= inputs.values.toList.flatten.filter(!fifoFiles.contains(_))
+    deps = deps.distinct
+  }
+
+  override def beforeCmd(): Unit = {
+    commands.foreach { cmd =>
+      cmd.beforeGraph()
+      cmd.internalBeforeGraph()
+      cmd.beforeCmd()
+    }
+  }
+
+  def cmdLine = {
+    val fifosFiles = this.fifos
+    fifosFiles.filter(_.exists()).map(required("rm", _)).mkString("\n\n", " \n", " \n\n") +
+      fifosFiles.map(required("mkfifo", _)).mkString("\n\n", "\n", "\n\n") +
+      commands.map(_.commandLine).mkString("\n\n", " & \n", " & \n\n") +
+      BiopetFifoPipe.waitScript +
+      fifosFiles.map(required("rm", _)).mkString("\n\n", " \n", " \n\n") +
+      BiopetFifoPipe.endScript
+  }
+
+  override def setResources(): Unit = {
+    combineResources(commands)
+  }
+
+  override def setupRetry(): Unit = {
+    super.setupRetry()
+    commands.foreach(_.setupRetry())
+    combineResources(commands)
+  }
+
+  override def freezeFieldValues(): Unit = {
+    super.freezeFieldValues()
+    commands.foreach(_.qSettings = qSettings)
+  }
+}
+
+object BiopetFifoPipe {
+  val waitScript =
+    """
+      |
+      |allJobs=`jobs -p`
+      |jobs=$allJobs
+      |
+      |echo [`date`] pids: $jobs
+      |
+      |FAIL="0"
+      |
+      |while echo $jobs | grep -e "\w" > /dev/null
+      |do
+      |	for job in $jobs
+      |	do
+      |		if ps | grep "$job " | grep -v grep > /dev/null
+      |		then
+      |		    echo [`date`] $job still running > /dev/null
+      |		else
+      |		    jobs=`echo $jobs | sed "s/${job}//"`
+      |			wait $job || FAIL=$?
+      |			if echo $FAIL | grep -ve "^0$" > /dev/null
+      |			then
+      |			    echo [`date`] $job fails with exitcode: $FAIL
+      |				break
+      |			fi
+      |			echo [`date`] $job done
+      |		fi
+      |	done
+      |	if echo $FAIL | grep -ve "^0$" > /dev/null
+      |    then
+      |        break
+      |    fi
+      |	sleep 1
+      |done
+      |
+      |if echo $FAIL | grep -ve "^0$" > /dev/null
+      |then
+      |    echo [`date`] kill other pids: $jobs
+      |    kill $jobs
+      |fi
+      |
+      |echo [`date`] Done
+      |
+      |
+    """.stripMargin
+
+  val endScript =
+    """
+      |
+      |if [ "$FAIL" == "0" ];
+      |then
+      |echo [`date`] "BiopetFifoPipe Done"
+      |else
+      |echo [`date`] BiopetFifoPipe "FAIL! ($FAIL)"
+      |exit $FAIL
+      |fi
+      |
+      |
+    """.stripMargin
+}
\ No newline at end of file
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetJavaCommandLineFunction.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetJavaCommandLineFunction.scala
index d51442e3a25fbd030c16e3e126802e58cc6c2064..3f75cb92128b26bfb2681a2a25cfb5436c9ac5f6 100644
--- a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetJavaCommandLineFunction.scala
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetJavaCommandLineFunction.scala
@@ -18,38 +18,49 @@ package nl.lumc.sasc.biopet.core
 import org.broadinstitute.gatk.queue.function.JavaCommandLineFunction
 
 /** Biopet commandline class for java based programs */
-trait BiopetJavaCommandLineFunction extends JavaCommandLineFunction with BiopetCommandLineFunctionTrait {
+trait BiopetJavaCommandLineFunction extends JavaCommandLineFunction with BiopetCommandLineFunction {
   executable = config("java", default = "java", submodule = "java", freeVar = false)
 
   javaGCThreads = config("java_gc_threads")
   javaGCHeapFreeLimit = config("java_gc_heap_freelimit")
   javaGCTimeLimit = config("java_gc_timelimit")
 
-  override protected def defaultVmemFactor: Double = 2.0
+  override def defaultVmemFactor: Double = 2.0
 
   /** Constructs java opts, this adds scala threads */
   override def javaOpts = super.javaOpts +
-    optional("-Dscala.concurrent.context.numThreads=", threads, spaceSeparated = false, escape = false)
+    optional("-Dscala.concurrent.context.numThreads=", threads, spaceSeparated = false)
+
+  override def beforeGraph(): Unit = {
+    setResources()
+    if (javaMemoryLimit.isEmpty && memoryLimit.isDefined)
+      javaMemoryLimit = memoryLimit
+
+    if (javaMainClass != null && javaClasspath.isEmpty)
+      javaClasspath = JavaCommandLineFunction.currentClasspath
+
+    //threads = getThreads(defaultThreads)
+  }
 
   /** Creates command to execute extension */
-  override def commandLine: String = {
+  def cmdLine: String = {
     preCmdInternal()
-    val cmd = super.commandLine
-    val finalCmd = executable + cmd.substring(cmd.indexOf(" "))
-    cmd
+    required(executable) +
+      javaOpts +
+      javaExecutable
   }
 
   def javaVersionCommand: String = executable + " -version"
 
   def getJavaVersion: Option[String] = {
-    if (!BiopetCommandLineFunctionTrait.executableCache.contains(executable))
+    if (!BiopetCommandLineFunction.executableCache.contains(executable))
       preProcessExecutable()
-    if (!BiopetCommandLineFunctionTrait.versionCache.contains(javaVersionCommand))
+    if (!BiopetCommandLineFunction.versionCache.contains(javaVersionCommand))
       getVersionInternal(javaVersionCommand, """java version "(.*)"""".r) match {
-        case Some(version) => BiopetCommandLineFunctionTrait.versionCache += javaVersionCommand -> version
+        case Some(version) => BiopetCommandLineFunction.versionCache += javaVersionCommand -> version
         case _             =>
       }
-    BiopetCommandLineFunctionTrait.versionCache.get(javaVersionCommand)
+    BiopetCommandLineFunction.versionCache.get(javaVersionCommand)
   }
 
   override def setupRetry(): Unit = {
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetPipe.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetPipe.scala
new file mode 100644
index 0000000000000000000000000000000000000000..8b5e9fbaefe84175828c9a3f844c2120bb9ba259
--- /dev/null
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetPipe.scala
@@ -0,0 +1,74 @@
+package nl.lumc.sasc.biopet.core
+
+import java.io.File
+
+import nl.lumc.sasc.biopet.utils.config.Configurable
+import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
+
+/**
+ * This class can pipe multiple BiopetCommandFunctions to 1 job
+ *
+ * Created by pjvanthof on 08/09/15.
+ */
+class BiopetPipe(val commands: List[BiopetCommandLineFunction]) extends BiopetCommandLineFunction {
+
+  @Input
+  lazy val input: List[File] = try {
+    commands.flatMap(_.inputs)
+  } catch {
+    case e: Exception => Nil
+  }
+
+  @Output
+  lazy val output: List[File] = try {
+    commands.flatMap(_.outputs)
+  } catch {
+    case e: Exception => Nil
+  }
+
+  pipesJobs :::= commands
+
+  override def beforeGraph() {
+    super.beforeGraph()
+
+    stdoutFile = stdoutFile.map(_.getAbsoluteFile)
+    stdinFile = stdinFile.map(_.getAbsoluteFile)
+
+    if (stdoutFile.isDefined || _outputAsStdout) {
+      commands.last.stdoutFile = None
+      commands.last._outputAsStdout = true
+    }
+
+    if (commands.head.stdinFile.isDefined) commands.head._inputAsStdin = true
+
+    val inputOutput = input.filter(x => output.contains(x))
+    require(inputOutput.isEmpty, "File found as input and output in the same job, files: " + inputOutput.mkString(", "))
+  }
+
+  override def setResources(): Unit = {
+    combineResources(pipesJobs)
+  }
+
+  override def setupRetry(): Unit = {
+    super.setupRetry()
+    commands.foreach(_.setupRetry())
+    combineResources(commands)
+  }
+
+  override def defaultCoreMemory = 0.0
+  override def defaultThreads = 0
+
+  val root: Configurable = commands.head.root
+  override def configName = commands.map(_.configName).mkString("-")
+  def cmdLine: String = {
+    "(" + commands.head.cmdLine + (if (commands.head.stdinFile.isDefined) {
+      " < " + required(commands.head.stdinFile.map(_.getAbsoluteFile))
+    } else "") + " | " + commands.tail.map(_.cmdLine).mkString(" | ") +
+      (if (commands.last.stdoutFile.isDefined) " > " + required(commands.last.stdoutFile.map(_.getAbsoluteFile)) else "") + ")"
+  }
+
+  override def freezeFieldValues(): Unit = {
+    super.freezeFieldValues()
+    commands.foreach(_.qSettings = qSettings)
+  }
+}
\ No newline at end of file
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetQScript.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetQScript.scala
index f35c07a0a4497fa4a36e0b34a1b640cf8f03364c..1109f30da9fcb53cd622935b8451d6ab551d0205 100644
--- a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetQScript.scala
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/BiopetQScript.scala
@@ -48,6 +48,10 @@ trait BiopetQScript extends Configurable with GatkLogging {
 
   var outputFiles: Map[String, File] = Map()
 
+  type InputFile = BiopetQScript.InputFile
+
+  var inputFiles: List[InputFile] = Nil
+
   /** Get implemented from org.broadinstitute.gatk.queue.QScript */
   var qSettings: QSettings
 
@@ -75,9 +79,10 @@ trait BiopetQScript extends Configurable with GatkLogging {
       case _                            =>
     }
     for (function <- functions) function match {
-      case f: BiopetCommandLineFunctionTrait =>
+      case f: BiopetCommandLineFunction =>
         f.preProcessExecutable()
         f.beforeGraph()
+        f.internalBeforeGraph()
         f.commandLine
       case _ =>
     }
@@ -86,7 +91,16 @@ trait BiopetQScript extends Configurable with GatkLogging {
       globalConfig.writeReport(qSettings.runName, new File(outputDir, ".log/" + qSettings.runName))
     else Logging.addError("Parent of output dir: '" + outputDir.getParent + "' is not writeable, outputdir can not be created")
 
-    reportClass.foreach(add(_))
+    inputFiles.foreach { i =>
+      if (!i.file.exists()) Logging.addError(s"Input file does not exist: ${i.file}")
+      else if (!i.file.canRead()) Logging.addError(s"Input file can not be read: ${i.file}")
+    }
+
+    this match {
+      case q: MultiSampleQScript if q.onlySamples.nonEmpty && !q.samples.forall(x => q.onlySamples.contains(x._1)) =>
+        logger.info("Write report is skipped because sample flag is used")
+      case _ => reportClass.foreach(add(_))
+    }
 
     Logging.checkErrors()
   }
@@ -103,3 +117,7 @@ trait BiopetQScript extends Configurable with GatkLogging {
     add(function)
   }
 }
+
+object BiopetQScript {
+  protected case class InputFile(file: File, md5: Option[String] = None)
+}
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/CommandLineResources.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/CommandLineResources.scala
new file mode 100644
index 0000000000000000000000000000000000000000..300cd4cdb0d240f19c709ac53e35b180e8675504
--- /dev/null
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/CommandLineResources.scala
@@ -0,0 +1,98 @@
+package nl.lumc.sasc.biopet.core
+
+import java.io.File
+
+import nl.lumc.sasc.biopet.utils.config.Configurable
+import org.broadinstitute.gatk.queue.function.CommandLineFunction
+
+/**
+ * Created by pjvanthof on 01/10/15.
+ */
+trait CommandLineResources extends CommandLineFunction with Configurable {
+
+  def defaultThreads = 1
+  final def threads = nCoresRequest match {
+    case Some(i) => i
+    case _ => {
+      val t = getThreads
+      nCoresRequest = Some(t)
+      t
+    }
+  }
+
+  var vmem: Option[String] = config("vmem")
+  def defaultCoreMemory: Double = 1.0
+  def defaultVmemFactor: Double = 1.4
+  var vmemFactor: Double = config("vmem_factor", default = defaultVmemFactor)
+
+  var residentFactor: Double = config("resident_factor", default = 1.2)
+
+  private var _coreMemory: Double = 2.0
+  def coreMemeory = _coreMemory
+
+  var retry = 0
+
+  override def freezeFieldValues(): Unit = {
+    setResources()
+    if (vmem.isDefined) jobResourceRequests :+= "h_vmem=" + vmem.get
+    super.freezeFieldValues()
+  }
+
+  def getThreads: Int = getThreads(defaultThreads)
+
+  /**
+   * Get threads from config
+   * @param default default when not found in config
+   * @return number of threads
+   */
+  private def getThreads(default: Int): Int = {
+    val maxThreads: Int = config("maxthreads", default = 24)
+    val threads: Int = config("threads", default = default)
+    if (maxThreads > threads) threads
+    else maxThreads
+  }
+
+  def setResources(): Unit = {
+    val firstOutput = try {
+      this.firstOutput
+    } catch {
+      case e: NullPointerException => null
+    }
+
+    if (jobOutputFile == null && firstOutput != null)
+      jobOutputFile = new File(firstOutput.getAbsoluteFile.getParent, "." + firstOutput.getName + "." + configName + ".out")
+
+    nCoresRequest = Option(threads)
+
+    _coreMemory = config("core_memory", default = defaultCoreMemory).asDouble +
+      (0.5 * retry)
+
+    if (config.contains("memory_limit")) memoryLimit = config("memory_limit")
+    else memoryLimit = Some(_coreMemory * threads)
+
+    if (config.contains("resident_limit")) residentLimit = config("resident_limit")
+    else residentLimit = Some((_coreMemory + (0.5 * retry)) * residentFactor)
+
+    if (!config.contains("vmem")) vmem = Some((_coreMemory * (vmemFactor + (0.5 * retry))) + "G")
+    jobName = configName + ":" + (if (firstOutput != null) firstOutput.getName else jobOutputFile)
+  }
+
+  override def setupRetry(): Unit = {
+    super.setupRetry()
+    if (vmem.isDefined) jobResourceRequests = jobResourceRequests.filterNot(_.contains("h_vmem="))
+    logger.info("Auto raise memory on retry")
+    retry += 1
+    this.freeze()
+  }
+
+  protected def combineResources(commands: List[CommandLineResources]): Unit = {
+    commands.foreach(_.setResources())
+    nCoresRequest = Some(commands.map(_.threads).sum)
+
+    _coreMemory = commands.map(cmd => cmd.coreMemeory * (cmd.threads.toDouble / threads.toDouble)).sum
+    memoryLimit = Some(_coreMemory * threads)
+    residentLimit = Some((_coreMemory + (0.5 * retry)) * residentFactor)
+    vmem = Some((_coreMemory * (vmemFactor + (0.5 * retry))) + "G")
+  }
+
+}
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/MultiSampleQScript.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/MultiSampleQScript.scala
index d8756c7b91cd27b330b4697aab0d94c9f436c98a..17631709f12db8a3e3b25253afc49fadd3820e32 100644
--- a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/MultiSampleQScript.scala
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/MultiSampleQScript.scala
@@ -26,7 +26,7 @@ trait MultiSampleQScript extends SummaryQScript {
   qscript =>
 
   @Argument(doc = "Only Sample", shortName = "s", required = false, fullName = "sample")
-  private val onlySamples: List[String] = Nil
+  private[core] val onlySamples: List[String] = Nil
 
   require(globalConfig.map.contains("samples"), "No Samples found in config")
 
@@ -131,7 +131,7 @@ trait MultiSampleQScript extends SummaryQScript {
 
   /** Runs addAndTrackJobs method for each sample */
   final def addSamplesJobs() {
-    if (onlySamples.isEmpty) {
+    if (onlySamples.isEmpty || samples.forall(x => onlySamples.contains(x._1))) {
       samples.foreach { case (sampleId, sample) => sample.addAndTrackJobs() }
       addMultiSampleJobs()
     } else onlySamples.foreach(sampleId => samples.get(sampleId) match {
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/Reference.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/Reference.scala
index 7a7013fd6dd8eecec23b33801894ef660fc22660..be479a8fa972fe896fb8d45cd74708944ba4ba64 100644
--- a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/Reference.scala
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/Reference.scala
@@ -74,8 +74,8 @@ trait Reference extends Configurable {
     val fai = new File(file.getAbsolutePath + ".fai")
 
     this match {
-      case c: BiopetCommandLineFunctionTrait => c.deps :::= dict :: fai :: Nil
-      case _                                 =>
+      case c: BiopetCommandLineFunction => c.deps :::= dict :: fai :: Nil
+      case _                            =>
     }
 
     file
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/ToolCommandFuntion.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/ToolCommandFuntion.scala
index dcb50896014e5c6b96fc9940a74a0dacabc94bd8..81220f9cb9d56703dfd7bebcddc0c14fa9966e0d 100644
--- a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/ToolCommandFuntion.scala
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/ToolCommandFuntion.scala
@@ -10,6 +10,11 @@ trait ToolCommandFuntion extends BiopetJavaCommandLineFunction {
 
   override def getVersion = Some("Biopet " + FullVersion)
 
+  override def beforeGraph(): Unit = {
+    javaMainClass = toolObject.getClass.getName.takeWhile(_ != '$')
+    super.beforeGraph()
+  }
+
   override def freezeFieldValues(): Unit = {
     javaMainClass = toolObject.getClass.getName.takeWhile(_ != '$')
     super.freezeFieldValues()
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/extensions/CheckChecksum.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/extensions/CheckChecksum.scala
new file mode 100644
index 0000000000000000000000000000000000000000..0ae2587f7928bb8d8cfe3e157f79fec7afff031a
--- /dev/null
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/extensions/CheckChecksum.scala
@@ -0,0 +1,40 @@
+package nl.lumc.sasc.biopet.core.extensions
+
+import java.io.File
+
+import nl.lumc.sasc.biopet.core.summary.WriteSummary
+import org.broadinstitute.gatk.queue.function.InProcessFunction
+import org.broadinstitute.gatk.utils.commandline.{ Argument, Input }
+
+/**
+ * This class checks md5sums and give an exit code 1 when md5sum is not the same
+ *
+ * Created by pjvanthof on 16/08/15.
+ */
+class CheckChecksum extends InProcessFunction {
+  @Input(required = true)
+  var inputFile: File = _
+
+  @Input(required = true)
+  var checksumFile: File = _
+
+  @Argument(required = true)
+  var checksum: String = _
+
+  override def freezeFieldValues(): Unit = {
+    super.freezeFieldValues()
+    jobOutputFile = new File(checksumFile.getParentFile, checksumFile.getName + ".check.out")
+  }
+
+  /** Exits whenever the input md5sum is not the same as the output md5sum */
+  def run: Unit = {
+    val outputChecksum = WriteSummary.parseChecksum(checksumFile).toLowerCase
+
+    if (outputChecksum != checksum.toLowerCase) {
+      logger.error(s"Input file: '$inputFile' md5sum is not as expected, aborting pipeline")
+
+      // 130 Simulates a ctr-C
+      Runtime.getRuntime.halt(130)
+    }
+  }
+}
\ No newline at end of file
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportBuilder.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportBuilder.scala
index 6c1bc388153f37d746cbf8a173a5ecc85c7201d5..ae7c08e8eb1d20e68d238a5fe4bb3a1f48306626 100644
--- a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportBuilder.scala
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/report/ReportBuilder.scala
@@ -54,8 +54,8 @@ trait ReportBuilderExtension extends ToolCommandFuntion {
   }
 
   /** Command to generate the report */
-  override def commandLine: String = {
-    super.commandLine +
+  override def cmdLine: String = {
+    super.cmdLine +
       required("--summary", summaryFile) +
       required("--outputDir", outputDir) +
       args.map(x => required("-a", x._1 + "=" + x._2)).mkString
@@ -231,6 +231,7 @@ object ReportBuilder {
       case Some(template) => template
       case _ =>
         val tempFile = File.createTempFile("ssp-template", new File(location).getName)
+        tempFile.deleteOnExit()
         IoUtils.copyStreamToFile(getClass.getResourceAsStream(location), tempFile)
         templateCache += location -> tempFile
         tempFile
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/summary/SummaryQScript.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/summary/SummaryQScript.scala
index 52c77fe8a63a090f2c4bb776da39647f9a35379e..ab2f64546a7f79e8432ec1ac7ff0ab19427cccfc 100644
--- a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/summary/SummaryQScript.scala
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/summary/SummaryQScript.scala
@@ -18,7 +18,7 @@ package nl.lumc.sasc.biopet.core.summary
 import java.io.File
 
 import nl.lumc.sasc.biopet.core._
-import nl.lumc.sasc.biopet.core.extensions.Md5sum
+import nl.lumc.sasc.biopet.core.extensions.{ CheckChecksum, Md5sum }
 
 import scala.collection.mutable
 
@@ -27,7 +27,7 @@ import scala.collection.mutable
  *
  * Created by pjvan_thof on 2/14/15.
  */
-trait SummaryQScript extends BiopetQScript {
+trait SummaryQScript extends BiopetQScript { qscript =>
 
   /** Key is sample/library, None is sample or library is not applicable */
   private[summary] var summarizables: Map[(String, Option[String], Option[String]), List[Summarizable]] = Map()
@@ -116,10 +116,24 @@ trait SummaryQScript extends BiopetQScript {
       //TODO: add more checksums types
     }
 
+    for (inputFile <- inputFiles) {
+      inputFile.md5 match {
+        case Some(checksum) => {
+          val checkMd5 = new CheckChecksum
+          checkMd5.inputFile = inputFile.file
+          require(SummaryQScript.md5sumCache.contains(inputFile.file), "Md5 job is not executed, checksum file can't be found")
+          checkMd5.checksumFile = SummaryQScript.md5sumCache(inputFile.file)
+          checkMd5.checksum = checksum
+          add(checkMd5)
+        }
+        case _ =>
+      }
+    }
+
     for ((_, summarizableList) <- summarizables; summarizable <- summarizableList) {
       summarizable match {
-        case f: BiopetCommandLineFunctionTrait => f.beforeGraph()
-        case _                                 =>
+        case f: BiopetCommandLineFunction => f.beforeGraph()
+        case _                            =>
       }
     }
 
@@ -135,7 +149,11 @@ trait SummaryQScript extends BiopetQScript {
     for ((_, file) <- this.summaryFiles)
       addChecksum(file)
 
-    add(writeSummary)
+    this match {
+      case q: MultiSampleQScript if q.onlySamples.nonEmpty && !q.samples.forall(x => q.onlySamples.contains(x._1)) =>
+        logger.info("Write summary is skipped because sample flag is used")
+      case _ => add(writeSummary)
+    }
   }
 }
 
diff --git a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/summary/WriteSummary.scala b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/summary/WriteSummary.scala
index 3db4607d6288f84b204033ee3db186ee76771935..6e7f8248c0693ed0df4c3a372b8885e1908187a7 100644
--- a/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/summary/WriteSummary.scala
+++ b/public/biopet-core/src/main/scala/nl/lumc/sasc/biopet/core/summary/WriteSummary.scala
@@ -18,7 +18,7 @@ package nl.lumc.sasc.biopet.core.summary
 import java.io.{ File, PrintWriter }
 
 import nl.lumc.sasc.biopet.utils.config.Configurable
-import nl.lumc.sasc.biopet.core.{ BiopetCommandLineFunction, BiopetCommandLineFunctionTrait, BiopetJavaCommandLineFunction, SampleLibraryTag }
+import nl.lumc.sasc.biopet.core.{ BiopetCommandLineFunction, BiopetJavaCommandLineFunction, SampleLibraryTag }
 import nl.lumc.sasc.biopet.utils.ConfigUtils
 import nl.lumc.sasc.biopet.{ LastCommitHash, Version }
 import org.broadinstitute.gatk.queue.function.{ InProcessFunction, QFunction }
@@ -71,16 +71,16 @@ class WriteSummary(val root: Configurable) extends InProcessFunction with Config
       val files = parseFiles(qscript.summaryFiles)
       val settings = qscript.summarySettings
       val executables: Map[String, Any] = {
-        (for (f <- qscript.functions if f.isInstanceOf[BiopetCommandLineFunctionTrait]) yield {
+        (for (f <- qscript.functions if f.isInstanceOf[BiopetCommandLineFunction]) yield {
           f match {
             case f: BiopetJavaCommandLineFunction =>
               f.configName -> Map("version" -> f.getVersion.getOrElse(None),
-                "java_md5" -> BiopetCommandLineFunctionTrait.executableMd5Cache.getOrElse(f.executable, None),
+                "java_md5" -> BiopetCommandLineFunction.executableMd5Cache.getOrElse(f.executable, None),
                 "java_version" -> f.getJavaVersion,
                 "jar_path" -> f.jarFile)
             case f: BiopetCommandLineFunction =>
               f.configName -> Map("version" -> f.getVersion.getOrElse(None),
-                "md5" -> BiopetCommandLineFunctionTrait.executableMd5Cache.getOrElse(f.executable, None),
+                "md5" -> BiopetCommandLineFunction.executableMd5Cache.getOrElse(f.executable, None),
                 "path" -> f.executable)
             case _ => throw new IllegalStateException("This should not be possible")
           }
@@ -153,10 +153,11 @@ class WriteSummary(val root: Configurable) extends InProcessFunction with Config
   def parseFile(file: File): Map[String, Any] = {
     val map: mutable.Map[String, Any] = mutable.Map()
     map += "path" -> file.getAbsolutePath
-    if (md5sum) map += "md5" -> parseChecksum(SummaryQScript.md5sumCache(file))
+    if (md5sum) map += "md5" -> WriteSummary.parseChecksum(SummaryQScript.md5sumCache(file))
     map.toMap
   }
-
+}
+object WriteSummary {
   /** Retrive checksum from file */
   def parseChecksum(checksumFile: File): String = {
     Source.fromFile(checksumFile).getLines().toList.head.split(" ")(0)
diff --git a/public/biopet-core/src/test/scala/nl/lumc/sasc/biopet/core/BiopetPipeTest.scala b/public/biopet-core/src/test/scala/nl/lumc/sasc/biopet/core/BiopetPipeTest.scala
new file mode 100644
index 0000000000000000000000000000000000000000..bac6932ddecd94dcbeb6ff6648edd5461ddced13
--- /dev/null
+++ b/public/biopet-core/src/test/scala/nl/lumc/sasc/biopet/core/BiopetPipeTest.scala
@@ -0,0 +1,45 @@
+package nl.lumc.sasc.biopet.core
+
+import org.scalatest.Matchers
+import org.scalatest.testng.TestNGSuite
+import org.testng.annotations.Test
+
+/**
+ * Created by pjvanthof on 09/09/15.
+ */
+class BiopetPipeTest extends TestNGSuite with Matchers {
+  class Pipe1 extends BiopetCommandLineFunction {
+    val root = null
+    def cmdLine = "pipe1" +
+      (if (!inputAsStdin) " input1 " else "") +
+      (if (!outputAsStsout) " output1 " + "")
+  }
+
+  class Pipe2 extends BiopetCommandLineFunction {
+    val root = null
+    def cmdLine = "pipe2" +
+      (if (!inputAsStdin) " input2 " else "") +
+      (if (!outputAsStsout) " output2 " + "")
+  }
+
+  @Test def testPipeCommands: Unit = {
+    val pipe1 = new Pipe1
+    val pipe2 = new Pipe2
+    pipe1.commandLine.contains("pipe1") shouldBe true
+    pipe1.commandLine.contains("input1") shouldBe true
+    pipe1.commandLine.contains("output1") shouldBe true
+    pipe2.commandLine.contains("pipe2") shouldBe true
+    pipe2.commandLine.contains("input2") shouldBe true
+    pipe2.commandLine.contains("output2") shouldBe true
+  }
+
+  @Test def testPipe: Unit = {
+    val pipe = new Pipe1 | new Pipe2
+    pipe.commandLine.contains("pipe1") shouldBe true
+    pipe.commandLine.contains("input1") shouldBe true
+    pipe.commandLine.contains("output1") shouldBe false
+    pipe.commandLine.contains("pipe2") shouldBe true
+    pipe.commandLine.contains("input2") shouldBe false
+    pipe.commandLine.contains("output2") shouldBe true
+  }
+}
diff --git a/public/biopet-extentsions/pom.xml b/public/biopet-extensions/pom.xml
similarity index 100%
rename from public/biopet-extentsions/pom.xml
rename to public/biopet-extensions/pom.xml
diff --git a/public/biopet-extentsions/src/main/resources/nl/lumc/sasc/biopet/extensions/breakdancer/breakdancer2vcf.py b/public/biopet-extensions/src/main/resources/nl/lumc/sasc/biopet/extensions/breakdancer/breakdancer2vcf.py
similarity index 100%
rename from public/biopet-extentsions/src/main/resources/nl/lumc/sasc/biopet/extensions/breakdancer/breakdancer2vcf.py
rename to public/biopet-extensions/src/main/resources/nl/lumc/sasc/biopet/extensions/breakdancer/breakdancer2vcf.py
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Bgzip.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Bgzip.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Bgzip.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Bgzip.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Bowtie.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Bowtie.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Bowtie.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Bowtie.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cat.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cat.scala
similarity index 89%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cat.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cat.scala
index 74901be9ca04722b54877032e0654d14d057ceb4..695b5ca3ae5e6943a4da481714a6bf1c7aa7c855 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cat.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cat.scala
@@ -34,13 +34,17 @@ class Cat(val root: Configurable) extends BiopetCommandLineFunction {
   executable = config("exe", default = "cat")
 
   /** return commandline to execute */
-  def cmdLine = required(executable) + repeat(input) + " > " + required(output)
+  def cmdLine = required(executable) +
+    (if (inputAsStdin) "" else repeat(input)) +
+    (if (outputAsStsout) "" else " > " + required(output))
 }
 
 /**
  * Object for constructors for cat
  */
 object Cat {
+  def apply(root: Configurable): Cat = new Cat(root)
+
   /**
    * Basis constructor
    * @param root root object for config
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cufflinks.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cufflinks.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cufflinks.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cufflinks.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cuffquant.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cuffquant.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cuffquant.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cuffquant.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cutadapt.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cutadapt.scala
similarity index 97%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cutadapt.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cutadapt.scala
index f6278426ee4f76c8b4cca1cc1a40863ce22b24eb..43dd6826912c4390f0ac30148081536ac3ac7d05 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cutadapt.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Cutadapt.scala
@@ -33,7 +33,7 @@ class Cutadapt(val root: Configurable) extends BiopetCommandLineFunction with Su
   @Input(doc = "Input fastq file")
   var fastq_input: File = _
 
-  @Output(doc = "Output fastq file")
+  @Output
   var fastq_output: File = _
 
   @Output(doc = "Output statistics file")
@@ -63,8 +63,8 @@ class Cutadapt(val root: Configurable) extends BiopetCommandLineFunction with Su
     optional("-M", opt_maximum_length) +
     // input / output
     required(fastq_input) +
-    required("--output", fastq_output) +
-    " > " + required(stats_output)
+    (if (outputAsStsout) "" else required("--output", fastq_output) +
+      " > " + required(stats_output))
 
   /** Output summary stats */
   def summaryStats: Map[String, Any] = {
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Fastqc.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Fastqc.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Fastqc.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Fastqc.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Freebayes.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Freebayes.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Freebayes.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Freebayes.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Gsnap.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Gsnap.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Gsnap.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Gsnap.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Gzip.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Gzip.scala
similarity index 84%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Gzip.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Gzip.scala
index cdd44e6b2ba95ceff528ad4c136ade3c693cb03f..98bd00339c83e2a955372da3344c7a1f5debb257 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Gzip.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Gzip.scala
@@ -28,15 +28,19 @@ class Gzip(val root: Configurable) extends BiopetCommandLineFunction {
   @Output(doc = "Unzipped file", required = true)
   var output: File = _
 
-  executable = config("exe", default = "gzip")
+  executable = config("exe", default = "gzip", freeVar = false)
 
   override def versionRegex = """gzip (.*)""".r
   override def versionCommand = executable + " --version"
 
-  def cmdLine = required(executable) + " -c " + repeat(input) + " > " + required(output)
+  def cmdLine = required(executable) + " -c " +
+    (if (inputAsStdin) "" else repeat(input)) +
+    (if (outputAsStsout) "" else " > " + required(output))
 }
 
 object Gzip {
+  def apply(root: Configurable): Gzip = new Gzip(root)
+
   def apply(root: Configurable, input: List[File], output: File): Gzip = {
     val gzip = new Gzip(root)
     gzip.input = input
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/HtseqCount.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/HtseqCount.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/HtseqCount.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/HtseqCount.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Ln.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Ln.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Ln.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Ln.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Pbzip2.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Pbzip2.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Pbzip2.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Pbzip2.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Raxml.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Raxml.scala
similarity index 98%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Raxml.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Raxml.scala
index ae017f08881677cb60620f0f860c1dea2765ccee..f2f6eb21b9eaa2dc9956429906723f72f4400ee4 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Raxml.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Raxml.scala
@@ -74,7 +74,6 @@ class Raxml(val root: Configurable) extends BiopetCommandLineFunction {
   /** Sets correct output files to job */
   override def beforeGraph() {
     require(w != null)
-    if (threads == 0) threads = getThreads
     executable = if (threads > 1 && executableThreads.isDefined) executableThreads.get else executableNonThreads
     super.beforeGraph()
     out :::= List(Some(getInfoFile), getBestTreeFile, getBootstrapFile, getBipartitionsFile).flatten
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/RunGubbins.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/RunGubbins.scala
similarity index 97%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/RunGubbins.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/RunGubbins.scala
index 53539ac9f9ae9ca46e3a7543e5375e690e916e6a..5334ab9cfe64a98f2d4c81745404c11006884044 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/RunGubbins.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/RunGubbins.scala
@@ -34,9 +34,6 @@ class RunGubbins(val root: Configurable) extends BiopetCommandLineFunction {
   @Input(doc = "Fasta file", shortName = "FQ")
   var fastafile: File = _
 
-  @Output(doc = "Output", shortName = "out")
-  var outputFiles: List[File] = Nil
-
   @Argument(required = true)
   var outputDirectory: File = null
 
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Sha1sum.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Sha1sum.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Sha1sum.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Sha1sum.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Sickle.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Sickle.scala
similarity index 93%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Sickle.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Sickle.scala
index 938d36e432f9162942980f0da99be084bf455fa8..fe88be1adc2bda814157a0578ff9e4bfa622fb0a 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Sickle.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Sickle.scala
@@ -36,7 +36,7 @@ class Sickle(val root: Configurable) extends BiopetCommandLineFunction with Summ
   @Input(doc = "R2 input", required = false)
   var input_R2: File = _
 
-  @Output(doc = "R1 output")
+  @Output(doc = "R1 output", required = false)
   var output_R1: File = _
 
   @Output(doc = "R2 output", required = false)
@@ -48,8 +48,6 @@ class Sickle(val root: Configurable) extends BiopetCommandLineFunction with Summ
   @Output(doc = "stats output")
   var output_stats: File = _
 
-  var fastqc: Fastqc = _
-
   executable = config("exe", default = "sickle", freeVar = false)
   var qualityType: Option[String] = config("qualitytype")
   var qualityThreshold: Option[Int] = config("qualityThreshold")
@@ -76,15 +74,15 @@ class Sickle(val root: Configurable) extends BiopetCommandLineFunction with Summ
         required("-s", output_singles)
     } else cmd += required("se")
     cmd +
-      required("-f", input_R1) +
+      (if (inputAsStdin) required("-f", new File("/dev/stdin")) else required("-f", input_R1)) +
       required("-t", qualityType) +
-      required("-o", output_R1) +
+      (if (outputAsStsout) required("-o", new File("/dev/stdout")) else required("-o", output_R1)) +
       optional("-q", qualityThreshold) +
       optional("-l", lengthThreshold) +
       conditional(noFiveprime, "-x") +
       conditional(discardN, "-n") +
-      conditional(quiet, "--quiet") +
-      " > " + required(output_stats)
+      conditional(quiet || outputAsStsout, "--quiet") +
+      (if (outputAsStsout) "" else " > " + required(output_stats))
   }
 
   /** returns stats map for summary */
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Stampy.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Stampy.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Stampy.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Stampy.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Star.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Star.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Star.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Star.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Tabix.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Tabix.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Tabix.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Tabix.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Tophat.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Tophat.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Tophat.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Tophat.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/VariantEffectPredictor.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/VariantEffectPredictor.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/VariantEffectPredictor.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/VariantEffectPredictor.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/WigToBigWig.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/WigToBigWig.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/WigToBigWig.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/WigToBigWig.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Zcat.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Zcat.scala
similarity index 73%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Zcat.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Zcat.scala
index 974f5e9140be562da77bd4f167888b6945d9a70b..5c7ebd0ca6382584bc45b455527e50bdede1a673 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/Zcat.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/Zcat.scala
@@ -23,10 +23,10 @@ import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
 
 /** Extension for zcat */
 class Zcat(val root: Configurable) extends BiopetCommandLineFunction {
-  @Input(doc = "Zipped file")
-  var input: File = _
+  @Input(doc = "Zipped file", required = true)
+  var input: List[File] = _
 
-  @Output(doc = "Unzipped file")
+  @Output(doc = "Unzipped file", required = true)
   var output: File = _
 
   executable = config("exe", default = "zcat")
@@ -35,12 +35,24 @@ class Zcat(val root: Configurable) extends BiopetCommandLineFunction {
   override def versionCommand = executable + " --version"
 
   /** Returns command to execute */
-  def cmdLine = required(executable) + required(input) + " > " + required(output)
+  def cmdLine = required(executable) +
+    (if (inputAsStdin) "" else required(input)) +
+    (if (outputAsStsout) "" else " > " + required(output))
 }
 
 object Zcat {
   /** Returns a default zcat */
+  def apply(root: Configurable): Zcat = new Zcat(root)
+
+  /** Returns Zcat with input and output files */
   def apply(root: Configurable, input: File, output: File): Zcat = {
+    val zcat = new Zcat(root)
+    zcat.input = input :: Nil
+    zcat.output = output
+    zcat
+  }
+
+  def apply(root: Configurable, input: List[File], output: File): Zcat = {
     val zcat = new Zcat(root)
     zcat.input = input
     zcat.output = output
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bcftools/Bcftools.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bcftools/Bcftools.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bcftools/Bcftools.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bcftools/Bcftools.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bcftools/BcftoolsCall.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bcftools/BcftoolsCall.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bcftools/BcftoolsCall.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bcftools/BcftoolsCall.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/Bedtools.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/Bedtools.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/Bedtools.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/Bedtools.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/BedtoolsCoverage.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/BedtoolsCoverage.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/BedtoolsCoverage.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/BedtoolsCoverage.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/BedtoolsGroupby.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/BedtoolsGroupby.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/BedtoolsGroupby.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/BedtoolsGroupby.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/BedtoolsIntersect.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/BedtoolsIntersect.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/BedtoolsIntersect.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bedtools/BedtoolsIntersect.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/Breakdancer.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/Breakdancer.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/Breakdancer.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/Breakdancer.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/BreakdancerCaller.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/BreakdancerCaller.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/BreakdancerCaller.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/BreakdancerCaller.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/BreakdancerConfig.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/BreakdancerConfig.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/BreakdancerConfig.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/BreakdancerConfig.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/BreakdancerVCF.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/BreakdancerVCF.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/BreakdancerVCF.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/breakdancer/BreakdancerVCF.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/Bwa.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/Bwa.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/Bwa.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/Bwa.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaAln.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaAln.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaAln.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaAln.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaMem.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaMem.scala
similarity index 98%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaMem.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaMem.scala
index 31c65252872c4ac3c01493bbf4ddc8abb6f5456e..5cbd73852e6a084a212a52052eebe1525bac3730 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaMem.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaMem.scala
@@ -111,6 +111,6 @@ class BwaMem(val root: Configurable) extends Bwa with Reference {
       required(reference) +
       required(R1) +
       optional(R2) +
-      " > " + required(output)
+      (if (outputAsStsout) "" else " > " + required(output))
   }
 }
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaSampe.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaSampe.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaSampe.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaSampe.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaSamse.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaSamse.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaSamse.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/bwa/BwaSamse.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/clever/CleverCaller.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/clever/CleverCaller.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/clever/CleverCaller.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/clever/CleverCaller.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/Conifer.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/Conifer.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/Conifer.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/Conifer.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferAnalyze.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferAnalyze.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferAnalyze.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferAnalyze.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferCall.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferCall.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferCall.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferCall.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferExport.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferExport.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferExport.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferExport.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferRPKM.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferRPKM.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferRPKM.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/conifer/ConiferRPKM.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/delly/Delly.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/delly/Delly.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/delly/Delly.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/delly/Delly.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/delly/DellyCaller.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/delly/DellyCaller.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/delly/DellyCaller.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/delly/DellyCaller.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/CombineVariants.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/CombineVariants.scala
similarity index 97%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/CombineVariants.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/CombineVariants.scala
index 2b4ebcc3866aad7fd2308f3b3d6755abadf5931b..144a91f21ae0479438fdb78f9432632d22584318 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/CombineVariants.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/CombineVariants.scala
@@ -55,7 +55,7 @@ class CombineVariants(val root: Configurable) extends Gatk {
     }
   }
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     (for (file <- inputFiles) yield {
       inputMap.get(file) match {
         case Some(name) => required("-V:" + name, file)
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/Gatk.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/Gatk.scala
similarity index 95%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/Gatk.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/Gatk.scala
index a738a17100d211623eb70648ca96081532432e9c..108253762bab534ab7740512da5ec692158dd0d4 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/Gatk.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/gatk/Gatk.scala
@@ -49,6 +49,8 @@ abstract class Gatk extends BiopetJavaCommandLineFunction with Reference {
   @Input(required = false)
   var pedigree: List[File] = config("pedigree", default = Nil)
 
+  var et: Option[String] = config("et")
+
   override def versionRegex = """(.*)""".r
   override def versionExitcode = List(0, 1)
   override def versionCommand = executable + " -jar " + jarFile + " -version"
@@ -61,10 +63,11 @@ abstract class Gatk extends BiopetJavaCommandLineFunction with Reference {
     if (reference == null) reference = referenceFasta()
   }
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("-T", analysisType) +
     required("-R", reference) +
     optional("-K", gatkKey) +
+    optional("-et", et) +
     repeat("-I", intervals) +
     repeat("-XL", excludeIntervals) +
     repeat("-ped", pedigree)
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/igvtools/IGVTools.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/igvtools/IGVTools.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/igvtools/IGVTools.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/igvtools/IGVTools.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/igvtools/IGVToolsCount.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/igvtools/IGVToolsCount.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/igvtools/IGVToolsCount.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/igvtools/IGVToolsCount.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/kraken/Kraken.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/kraken/Kraken.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/kraken/Kraken.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/kraken/Kraken.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/kraken/KrakenReport.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/kraken/KrakenReport.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/kraken/KrakenReport.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/kraken/KrakenReport.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/macs2/Macs2.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/macs2/Macs2.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/macs2/Macs2.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/macs2/Macs2.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/macs2/Macs2CallPeak.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/macs2/Macs2CallPeak.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/macs2/Macs2CallPeak.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/macs2/Macs2CallPeak.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/AddOrReplaceReadGroups.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/AddOrReplaceReadGroups.scala
similarity index 98%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/AddOrReplaceReadGroups.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/AddOrReplaceReadGroups.scala
index f2f7a1031a0892dc47605822f3a8f0ad1a656fdf..c9b30feeeb796c1b932c7aa61d4ccbd8a2c41837 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/AddOrReplaceReadGroups.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/AddOrReplaceReadGroups.scala
@@ -64,7 +64,7 @@ class AddOrReplaceReadGroups(val root: Configurable) extends Picard {
   var RGPI: Option[Int] = _
 
   /** Returns command to execute */
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("INPUT=", input, spaceSeparated = false) +
     required("OUTPUT=", output, spaceSeparated = false) +
     required("SORT_ORDER=", sortOrder, spaceSeparated = false) +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/BedToIntervalList.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/BedToIntervalList.scala
similarity index 97%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/BedToIntervalList.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/BedToIntervalList.scala
index 99f42e2b6e99f04c40880a2437bec242a386d672..5f3513fd7c22f0b81db0c739f6bb9b70237dc8d7 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/BedToIntervalList.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/BedToIntervalList.scala
@@ -38,7 +38,7 @@ class BedToIntervalList(val root: Configurable) extends Picard with Reference {
   @Output(doc = "Output interval list", required = true)
   var output: File = null
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("SEQUENCE_DICTIONARY=", dict, spaceSeparated = false) +
     required("INPUT=", input, spaceSeparated = false) +
     required("OUTPUT=", output, spaceSeparated = false)
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CalculateHsMetrics.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CalculateHsMetrics.scala
similarity index 98%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CalculateHsMetrics.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CalculateHsMetrics.scala
index 23351a6459e283f4c5330e80a7a34918e6dd276a..ea7c37b5aef79dc59c942db3ae9127e90e853396 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CalculateHsMetrics.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CalculateHsMetrics.scala
@@ -56,7 +56,7 @@ class CalculateHsMetrics(val root: Configurable) extends Picard with Summarizabl
   }
 
   /** Returns command to execute */
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("INPUT=", input, spaceSeparated = false) +
     required("OUTPUT=", output, spaceSeparated = false) +
     optional("REFERENCE_SEQUENCE=", reference, spaceSeparated = false) +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectAlignmentSummaryMetrics.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectAlignmentSummaryMetrics.scala
similarity index 98%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectAlignmentSummaryMetrics.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectAlignmentSummaryMetrics.scala
index 7a02e7be2165472094085b1700f60d08d75b667c..ff19efe11676d2ca66adc172790080f9a9823783 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectAlignmentSummaryMetrics.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectAlignmentSummaryMetrics.scala
@@ -53,7 +53,7 @@ class CollectAlignmentSummaryMetrics(val root: Configurable) extends Picard with
   var stopAfter: Option[Long] = config("stopAfter")
 
   /** Returns command to execute */
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("INPUT=", input, spaceSeparated = false) +
     required("OUTPUT=", output, spaceSeparated = false) +
     optional("REFERENCE_SEQUENCE=", reference, spaceSeparated = false) +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectGcBiasMetrics.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectGcBiasMetrics.scala
similarity index 98%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectGcBiasMetrics.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectGcBiasMetrics.scala
index 52ddd61758c50c27f7a3f8def6dc69f6815f4c9d..ada8007283b76122005cc5d4e6a0a39c161ea1aa 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectGcBiasMetrics.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectGcBiasMetrics.scala
@@ -60,7 +60,7 @@ class CollectGcBiasMetrics(val root: Configurable) extends Picard with Summariza
   }
 
   /** Returns command to execute */
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     repeat("INPUT=", input, spaceSeparated = false) +
     required("OUTPUT=", output, spaceSeparated = false) +
     optional("CHART_OUTPUT=", outputChart, spaceSeparated = false) +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectInsertSizeMetrics.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectInsertSizeMetrics.scala
similarity index 98%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectInsertSizeMetrics.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectInsertSizeMetrics.scala
index b94b623c867019bf65d39987a796fa0808336b66..3c4693b5ead3929b9b1bf7eac95b69c3bed0c83c 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectInsertSizeMetrics.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectInsertSizeMetrics.scala
@@ -62,7 +62,7 @@ class CollectInsertSizeMetrics(val root: Configurable) extends Picard with Summa
   }
 
   /** Returns command to execute */
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("INPUT=", input, spaceSeparated = false) +
     required("OUTPUT=", output, spaceSeparated = false) +
     optional("HISTOGRAM_FILE=", outputHistogram, spaceSeparated = false) +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectMultipleMetrics.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectMultipleMetrics.scala
similarity index 98%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectMultipleMetrics.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectMultipleMetrics.scala
index 0ecc053022d3aaefdded69907d97618a891322d0..5ddaa72341c6a35b6cc9070c6d50cc48e80b7551 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectMultipleMetrics.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectMultipleMetrics.scala
@@ -54,9 +54,6 @@ class CollectMultipleMetrics(val root: Configurable) extends Picard with Summari
   @Argument(doc = "Stop after processing N reads", required = false)
   var stopAfter: Option[Long] = config("stop_after")
 
-  @Output
-  protected var outputFiles: List[File] = Nil
-
   override def beforeGraph(): Unit = {
     super.beforeGraph()
     if (reference == null) reference = referenceFasta()
@@ -79,7 +76,7 @@ class CollectMultipleMetrics(val root: Configurable) extends Picard with Summari
     }
   }
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("INPUT=", input, spaceSeparated = false) +
     required("OUTPUT=", outputName, spaceSeparated = false) +
     conditional(assumeSorted, "ASSUME_SORTED=true") +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectRnaSeqMetrics.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectRnaSeqMetrics.scala
similarity index 98%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectRnaSeqMetrics.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectRnaSeqMetrics.scala
index 112c6afe42bbe93275d8713d74c330dc93b4bd5f..2aca96da6ebe993381766f50fc699c1c04233b0d 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectRnaSeqMetrics.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectRnaSeqMetrics.scala
@@ -90,7 +90,7 @@ class CollectRnaSeqMetrics(val root: Configurable) extends Picard with Summariza
     "metrics" -> Picard.getMetrics(output).getOrElse(Map()),
     "histogram" -> Picard.getHistogram(output).getOrElse(Map()))
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("INPUT=", input, spaceSeparated = false) +
     required("REF_FLAT=", refFlat, spaceSeparated = false) +
     required("OUTPUT=", output, spaceSeparated = false) +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectTargetedPcrMetrics.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectTargetedPcrMetrics.scala
similarity index 98%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectTargetedPcrMetrics.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectTargetedPcrMetrics.scala
index 537ed3eea0eebfd88980bd41a29358591077e96a..7ec9598e98326dd1477a9d079bf4fe09b31e75af 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectTargetedPcrMetrics.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectTargetedPcrMetrics.scala
@@ -60,7 +60,7 @@ class CollectTargetedPcrMetrics(val root: Configurable) extends Picard with Summ
     if (reference == null) reference = referenceFasta()
   }
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("INPUT=", input, spaceSeparated = false) +
     required("OUTPUT=", output, spaceSeparated = false) +
     required("REFERENCE_SEQUENCE=", reference, spaceSeparated = false) +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectWgsMetrics.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectWgsMetrics.scala
similarity index 98%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectWgsMetrics.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectWgsMetrics.scala
index 97b429e3ff9c702fbe06b5efb07b6557b4ee44c9..6756f736623693564c344ca11da4a864d1c27977 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectWgsMetrics.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectWgsMetrics.scala
@@ -62,7 +62,7 @@ class CollectWgsMetrics(val root: Configurable) extends Picard with Summarizable
     if (reference == null) reference = referenceFasta()
   }
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("INPUT=", input, spaceSeparated = false) +
     required("OUTPUT=", output, spaceSeparated = false) +
     required("REFERENCE_SEQUENCE=", reference, spaceSeparated = false) +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/GatherBamFiles.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/GatherBamFiles.scala
similarity index 96%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/GatherBamFiles.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/GatherBamFiles.scala
index 0a7acc94375dc2457419ea82bd0730ad3ea63846..514c9394e8e6d8e663402cc03267fa70c6a2dc73 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/GatherBamFiles.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/GatherBamFiles.scala
@@ -30,7 +30,7 @@ class GatherBamFiles(val root: Configurable) extends Picard {
   @Output(doc = "The output file to bam file to", required = true)
   var output: File = _
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     repeat("INPUT=", input, spaceSeparated = false) +
     required("OUTPUT=", output, spaceSeparated = false)
 }
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/MarkDuplicates.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/MarkDuplicates.scala
similarity index 99%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/MarkDuplicates.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/MarkDuplicates.scala
index f7a77d20d459f8cbc8bfee32b12ece7e99d7a2eb..04a61ae0f9af329ac49252f93ccad829c60b7088 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/MarkDuplicates.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/MarkDuplicates.scala
@@ -80,7 +80,7 @@ class MarkDuplicates(val root: Configurable) extends Picard with Summarizable {
   }
 
   /** Returns command to execute */
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     repeat("INPUT=", input, spaceSeparated = false) +
     required("OUTPUT=", output, spaceSeparated = false) +
     required("METRICS_FILE=", outputMetrics, spaceSeparated = false) +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/MergeSamFiles.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/MergeSamFiles.scala
similarity index 98%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/MergeSamFiles.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/MergeSamFiles.scala
index d358ba4e6b0d78c60a4d67d07f337be82750ea6f..5e90a5a625c992436a340a874bf60015c19b44ab 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/MergeSamFiles.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/MergeSamFiles.scala
@@ -54,7 +54,7 @@ class MergeSamFiles(val root: Configurable) extends Picard {
   }
 
   /** Returns command to execute */
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     repeat("INPUT=", input, spaceSeparated = false) +
     required("OUTPUT=", output, spaceSeparated = false) +
     required("SORT_ORDER=", sortOrder, spaceSeparated = false) +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/Picard.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/Picard.scala
similarity index 99%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/Picard.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/Picard.scala
index 9d00e0608818e3e76ece3eb9bfc35464fe3e0754..02678aac229d0113b19b8e2d3dfbb4eca53793ad 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/Picard.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/Picard.scala
@@ -68,7 +68,7 @@ abstract class Picard extends BiopetJavaCommandLineFunction {
     else super.getVersion
   }
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("TMP_DIR=" + jobTempDir) +
     optional("VERBOSITY=", verbosity, spaceSeparated = false) +
     conditional(quiet, "QUIET=TRUE") +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/ReorderSam.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/ReorderSam.scala
similarity index 97%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/ReorderSam.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/ReorderSam.scala
index c52d15d42e7a338ab0cb879ecf595f92bbe561ad..39a4fd184fdb73ea853e0b4a0419151773a377dc 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/ReorderSam.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/ReorderSam.scala
@@ -45,7 +45,7 @@ class ReorderSam(val root: Configurable) extends Picard with Reference {
     if (reference == null) reference = referenceFasta()
   }
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     conditional(allowIncompleteDictConcordance, "ALLOW_INCOMPLETE_DICT_CONCORDANCE=TRUE") +
     conditional(allowContigLengthDiscordance, "ALLOW_CONTIG_LENGTH_DISCORDANCE=TRUE") +
     required("REFERENCE=", reference, spaceSeparated = false) +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/SamToFastq.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/SamToFastq.scala
similarity index 98%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/SamToFastq.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/SamToFastq.scala
index 6b26f48b8fafdcec9f79f39bd73d5c558f66f78f..b686e80225de8203af40b765764a0c1021e4446d 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/SamToFastq.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/SamToFastq.scala
@@ -73,7 +73,7 @@ class SamToFastq(val root: Configurable) extends Picard {
   var includeNonPrimaryAlignments: Boolean = config("includeNonPrimaryAlignments", default = false)
 
   /** Returns command to execute */
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("INPUT=", input, spaceSeparated = false) +
     required("FASTQ=", fastqR1, spaceSeparated = false) +
     optional("SECOND_END_FASTQ=", fastqR2, spaceSeparated = false) +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/SortSam.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/SortSam.scala
similarity index 77%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/SortSam.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/SortSam.scala
index 078e794a5f14823e69b315c1f494efa4a1acc097..d9094ee5fa15c8caacd9a2c4823ccda7734c97e6 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/SortSam.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/SortSam.scala
@@ -31,31 +31,32 @@ class SortSam(val root: Configurable) extends Picard {
   var output: File = _
 
   @Argument(doc = "Sort order of output file Required. Possible values: {unsorted, queryname, coordinate} ", required = true)
-  var sortOrder: String = _
+  var sortOrder: String = config("sort_order", default = "coordinate")
 
   @Output(doc = "Bam Index", required = true)
   private var outputIndex: File = _
 
   override def beforeGraph() {
     super.beforeGraph()
+    if (outputAsStsout) createIndex = false
     if (createIndex) outputIndex = new File(output.getAbsolutePath.stripSuffix(".bam") + ".bai")
   }
 
   /** Returns command to execute */
-  override def commandLine = super.commandLine +
-    required("INPUT=", input, spaceSeparated = false) +
-    required("OUTPUT=", output, spaceSeparated = false) +
+  override def cmdLine = super.cmdLine +
+    (if (inputAsStdin) required("INPUT=", new File("/dev/stdin"), spaceSeparated = false)
+    else required("INPUT=", input, spaceSeparated = false)) +
+    (if (outputAsStsout) required("OUTPUT=", new File("/dev/stdout"), spaceSeparated = false)
+    else required("OUTPUT=", output, spaceSeparated = false)) +
     required("SORT_ORDER=", sortOrder, spaceSeparated = false)
 }
 
 object SortSam {
   /** Returns default SortSam */
-  def apply(root: Configurable, input: File, output: File, sortOrder: String = null): SortSam = {
+  def apply(root: Configurable, input: File, output: File): SortSam = {
     val sortSam = new SortSam(root)
     sortSam.input = input
     sortSam.output = output
-    if (sortOrder == null) sortSam.sortOrder = "coordinate"
-    else sortSam.sortOrder = sortOrder
     sortSam
   }
 }
\ No newline at end of file
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/Sambamba.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/Sambamba.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/Sambamba.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/Sambamba.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaFlagstat.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaFlagstat.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaFlagstat.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaFlagstat.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaIndex.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaIndex.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaIndex.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaIndex.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaMarkdup.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaMarkdup.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaMarkdup.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaMarkdup.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaMerge.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaMerge.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaMerge.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaMerge.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaView.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaView.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaView.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/sambamba/SambambaView.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/Samtools.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/Samtools.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/Samtools.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/Samtools.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsFlagstat.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsFlagstat.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsFlagstat.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsFlagstat.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsMpileup.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsMpileup.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsMpileup.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsMpileup.scala
diff --git a/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsSort.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsSort.scala
new file mode 100644
index 0000000000000000000000000000000000000000..c8f9cf52007e9a74e344e3f78d74ec4ab1d2ac27
--- /dev/null
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsSort.scala
@@ -0,0 +1,37 @@
+package nl.lumc.sasc.biopet.extensions.samtools
+
+import java.io.File
+
+import nl.lumc.sasc.biopet.utils.config.Configurable
+import org.broadinstitute.gatk.utils.commandline.{Input, Output}
+
+/**
+ * Created by pjvanthof on 22/09/15.
+ */
+class SamtoolsSort(val root: Configurable) extends Samtools {
+
+  @Input(required = true)
+  var input: File = _
+
+  @Output
+  var output: File = _
+
+  var compresion: Option[Int] = config("l")
+  var outputFormat: Option[String] = config("O")
+  var sortByName: Boolean = config("sort_by_name", default = false)
+  var prefix: String = _
+
+  override def beforeGraph(): Unit = {
+    super.beforeGraph()
+    prefix = config("prefix", default = new File(System.getProperty("java.io.tmpdir"), output.getName))
+  }
+
+  def cmdLine = required(executable) + required("sort") +
+    optional("-m", (coreMemeory + "G")) +
+    optional("-@", threads) +
+    optional("-O", outputFormat) +
+    required("-T", prefix) +
+    conditional(sortByName, "-n") +
+    (if (outputAsStsout) "" else required("-o", output)) +
+    (if (inputAsStdin) "" else required(input))
+}
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsView.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsView.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsView.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/samtools/SamtoolsView.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/seqtk/Seqtk.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/seqtk/Seqtk.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/seqtk/Seqtk.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/seqtk/Seqtk.scala
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/seqtk/SeqtkSeq.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/seqtk/SeqtkSeq.scala
similarity index 93%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/seqtk/SeqtkSeq.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/seqtk/SeqtkSeq.scala
index 157f5d6500317b52dcaed70220d9eed5fd2bde4b..d69faa092303665a1c493686f3a1752010a9ef2a 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/seqtk/SeqtkSeq.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/seqtk/SeqtkSeq.scala
@@ -25,14 +25,14 @@ import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
  * Wrapper for the seqtk seq subcommand.
  * Written based on seqtk version 1.0-r63-dirty.
  */
-class SeqtkSeq(val root: Configurable) extends Seqtk with Summarizable {
+class SeqtkSeq(val root: Configurable) extends Seqtk {
 
   /** input file */
-  @Input(doc = "Input file (FASTQ or FASTA)")
+  @Input(doc = "Input file (FASTQ or FASTA)", required = true)
   var input: File = _
 
   /** output file */
-  @Output(doc = "Output file")
+  @Output(doc = "Output file", required = true)
   var output: File = _
 
   /** mask bases with quality lower than INT [0] */
@@ -106,8 +106,8 @@ class SeqtkSeq(val root: Configurable) extends Seqtk with Summarizable {
       conditional(flag1, "-1") +
       conditional(flag2, "-2") +
       conditional(V, "-V") +
-      required(input) +
-      " > " + required(output)
+      (if (inputAsStdin) "" else required(input)) +
+      (if (outputAsStsout) "" else " > " + required(output))
   }
 
   /**
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/varscan/Mpileup2cns.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/varscan/Mpileup2cns.scala
similarity index 96%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/varscan/Mpileup2cns.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/varscan/Mpileup2cns.scala
index 773e466981ef703c8fc8f91b91b51b25b33d3054..0379c36d9ace680b7833bf226912504bb619f8e2 100644
--- a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/varscan/Mpileup2cns.scala
+++ b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/varscan/Mpileup2cns.scala
@@ -47,8 +47,8 @@ class Mpileup2cns(val root: Configurable) extends Varscan {
     variants.foreach { case v => require(validValues.contains(v), "variants value must be either 0 or 1") }
   }
 
-  override def commandLine = {
-    val baseCommand = super.commandLine + required("mpileup2cns") +
+  override def cmdLine = {
+    val baseCommand = super.cmdLine + required("mpileup2cns") +
       required("", input) +
       required("--min-coverage", minCoverage) +
       required("--min-reads2", minReads2) +
diff --git a/public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/varscan/Varscan.scala b/public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/varscan/Varscan.scala
similarity index 100%
rename from public/biopet-extentsions/src/main/scala/nl/lumc/sasc/biopet/extensions/varscan/Varscan.scala
rename to public/biopet-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/varscan/Varscan.scala
diff --git a/public/biopet-extentsions/src/test/resources/log4j.properties b/public/biopet-extensions/src/test/resources/log4j.properties
similarity index 100%
rename from public/biopet-extentsions/src/test/resources/log4j.properties
rename to public/biopet-extensions/src/test/resources/log4j.properties
diff --git a/public/biopet-extentsions/src/test/resources/nl/lumc/sasc/biopet/extensions/picard/picard.alignmentMetrics b/public/biopet-extensions/src/test/resources/nl/lumc/sasc/biopet/extensions/picard/picard.alignmentMetrics
similarity index 100%
rename from public/biopet-extentsions/src/test/resources/nl/lumc/sasc/biopet/extensions/picard/picard.alignmentMetrics
rename to public/biopet-extensions/src/test/resources/nl/lumc/sasc/biopet/extensions/picard/picard.alignmentMetrics
diff --git a/public/biopet-extentsions/src/test/resources/nl/lumc/sasc/biopet/extensions/picard/picard.dedup.metrics b/public/biopet-extensions/src/test/resources/nl/lumc/sasc/biopet/extensions/picard/picard.dedup.metrics
similarity index 100%
rename from public/biopet-extentsions/src/test/resources/nl/lumc/sasc/biopet/extensions/picard/picard.dedup.metrics
rename to public/biopet-extensions/src/test/resources/nl/lumc/sasc/biopet/extensions/picard/picard.dedup.metrics
diff --git a/public/biopet-extentsions/src/test/resources/nl/lumc/sasc/biopet/extensions/picard/picard.insertsizemetrics b/public/biopet-extensions/src/test/resources/nl/lumc/sasc/biopet/extensions/picard/picard.insertsizemetrics
similarity index 100%
rename from public/biopet-extentsions/src/test/resources/nl/lumc/sasc/biopet/extensions/picard/picard.insertsizemetrics
rename to public/biopet-extensions/src/test/resources/nl/lumc/sasc/biopet/extensions/picard/picard.insertsizemetrics
diff --git a/public/biopet-extentsions/src/test/scala/nl/lumc/sasc/biopet/extensions/GsnapTest.scala b/public/biopet-extensions/src/test/scala/nl/lumc/sasc/biopet/extensions/GsnapTest.scala
similarity index 100%
rename from public/biopet-extentsions/src/test/scala/nl/lumc/sasc/biopet/extensions/GsnapTest.scala
rename to public/biopet-extensions/src/test/scala/nl/lumc/sasc/biopet/extensions/GsnapTest.scala
diff --git a/public/biopet-extentsions/src/test/scala/nl/lumc/sasc/biopet/extensions/HtseqCountTest.scala b/public/biopet-extensions/src/test/scala/nl/lumc/sasc/biopet/extensions/HtseqCountTest.scala
similarity index 100%
rename from public/biopet-extentsions/src/test/scala/nl/lumc/sasc/biopet/extensions/HtseqCountTest.scala
rename to public/biopet-extensions/src/test/scala/nl/lumc/sasc/biopet/extensions/HtseqCountTest.scala
diff --git a/public/biopet-extentsions/src/test/scala/nl/lumc/sasc/biopet/extensions/LnTest.scala b/public/biopet-extensions/src/test/scala/nl/lumc/sasc/biopet/extensions/LnTest.scala
similarity index 100%
rename from public/biopet-extentsions/src/test/scala/nl/lumc/sasc/biopet/extensions/LnTest.scala
rename to public/biopet-extensions/src/test/scala/nl/lumc/sasc/biopet/extensions/LnTest.scala
diff --git a/public/biopet-extentsions/src/test/scala/nl/lumc/sasc/biopet/extensions/picard/CollectAlignmentSummaryMetricsTest.scala b/public/biopet-extensions/src/test/scala/nl/lumc/sasc/biopet/extensions/picard/CollectAlignmentSummaryMetricsTest.scala
similarity index 100%
rename from public/biopet-extentsions/src/test/scala/nl/lumc/sasc/biopet/extensions/picard/CollectAlignmentSummaryMetricsTest.scala
rename to public/biopet-extensions/src/test/scala/nl/lumc/sasc/biopet/extensions/picard/CollectAlignmentSummaryMetricsTest.scala
diff --git a/public/biopet-extentsions/src/test/scala/nl/lumc/sasc/biopet/extensions/picard/CollectInsertSizeMetricsTest.scala b/public/biopet-extensions/src/test/scala/nl/lumc/sasc/biopet/extensions/picard/CollectInsertSizeMetricsTest.scala
similarity index 100%
rename from public/biopet-extentsions/src/test/scala/nl/lumc/sasc/biopet/extensions/picard/CollectInsertSizeMetricsTest.scala
rename to public/biopet-extensions/src/test/scala/nl/lumc/sasc/biopet/extensions/picard/CollectInsertSizeMetricsTest.scala
diff --git a/public/biopet-extentsions/src/test/scala/nl/lumc/sasc/biopet/extensions/picard/MarkDuplicatesTest.scala b/public/biopet-extensions/src/test/scala/nl/lumc/sasc/biopet/extensions/picard/MarkDuplicatesTest.scala
similarity index 100%
rename from public/biopet-extentsions/src/test/scala/nl/lumc/sasc/biopet/extensions/picard/MarkDuplicatesTest.scala
rename to public/biopet-extensions/src/test/scala/nl/lumc/sasc/biopet/extensions/picard/MarkDuplicatesTest.scala
diff --git a/public/biopet-public-package/src/main/scala/nl/lumc/sasc/biopet/BiopetExecutablePublic.scala b/public/biopet-public-package/src/main/scala/nl/lumc/sasc/biopet/BiopetExecutablePublic.scala
index 36770bb18747691afc468bf7cdff14d444478b81..b4109a45e70b0dd111463cddb3df7f2ebf74d14f 100644
--- a/public/biopet-public-package/src/main/scala/nl/lumc/sasc/biopet/BiopetExecutablePublic.scala
+++ b/public/biopet-public-package/src/main/scala/nl/lumc/sasc/biopet/BiopetExecutablePublic.scala
@@ -27,8 +27,7 @@ object BiopetExecutablePublic extends BiopetExecutable {
     nl.lumc.sasc.biopet.pipelines.bamtobigwig.Bam2Wig,
     nl.lumc.sasc.biopet.pipelines.carp.Carp,
     nl.lumc.sasc.biopet.pipelines.toucan.Toucan,
-    nl.lumc.sasc.biopet.pipelines.shiva.ShivaSvCalling,
-    nl.lumc.sasc.biopet.pipelines.gears.Gears
+    nl.lumc.sasc.biopet.pipelines.shiva.ShivaSvCalling
   )
 
   def pipelines: List[MainCommand] = List(
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BastyGenerateFasta.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BastyGenerateFasta.scala
index 9b0020ae21e8626f3f987aaec2d1bd2921374bed..bc1d672269421ce7be6d64d15d0f8841c81332a1 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BastyGenerateFasta.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BastyGenerateFasta.scala
@@ -55,7 +55,7 @@ class BastyGenerateFasta(val root: Configurable) extends ToolCommandFuntion with
     reference = referenceFasta()
   }
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     optional("--inputVcf", inputVcf) +
     optional("--bamFile", bamFile) +
     optional("--outputVariants", outputVariants) +
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BedToInterval.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BedToInterval.scala
index bab2f7c0ae0fa260a78ff366d9e9f4a6c177d9f6..f7f00d0f94d43dcc45724c3ed4b61715072b88c1 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BedToInterval.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BedToInterval.scala
@@ -38,7 +38,7 @@ class BedToInterval(val root: Configurable) extends ToolCommandFuntion {
 
   override def defaultCoreMemory = 1.0
 
-  override def commandLine = super.commandLine + required("-I", input) + required("-b", bamFile) + required("-o", output)
+  override def cmdLine = super.cmdLine + required("-I", input) + required("-b", bamFile) + required("-o", output)
 }
 
 object BedToInterval {
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BedtoolsCoverageToCounts.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BedtoolsCoverageToCounts.scala
index 817b6d3f2792168a8f4fdf8549fa3c16c858e21e..00a77a5e9d9ac4ec1e5c2d02ed350cdf53b10d5d 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BedtoolsCoverageToCounts.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BedtoolsCoverageToCounts.scala
@@ -32,7 +32,7 @@ class BedtoolsCoverageToCounts(val root: Configurable) extends ToolCommandFuntio
 
   override def defaultCoreMemory = 3.0
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("-I", input) +
     required("-o", output)
 }
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BiopetFlagstat.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BiopetFlagstat.scala
index ff06bc963764f07563aa4ca0e2926119ba667c9b..5dc69cb07a34f04ed2cc32e7069875649c3aa32b 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BiopetFlagstat.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/BiopetFlagstat.scala
@@ -37,7 +37,7 @@ class BiopetFlagstat(val root: Configurable) extends ToolCommandFuntion with Sum
 
   override def defaultCoreMemory = 6.0
 
-  override def commandLine = super.commandLine + required("-I", input) + required("-s", summaryFile) + " > " + required(output)
+  override def cmdLine = super.cmdLine + required("-I", input) + required("-s", summaryFile) + " > " + required(output)
 
   def summaryFiles: Map[String, File] = Map()
 
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/FastqSplitter.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/FastqSplitter.scala
index df7e32e19bacfc8021ec015fcf019f9f16f61fe2..7348048447ca6c614b3b43ba915b228e042e9a37 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/FastqSplitter.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/FastqSplitter.scala
@@ -37,7 +37,7 @@ class FastqSplitter(val root: Configurable) extends ToolCommandFuntion {
   override def defaultCoreMemory = 4.0
 
   /** * Generate command to execute */
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("-I", input) +
     repeat("-o", output)
 }
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/FastqSync.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/FastqSync.scala
index 90100c8e7942afe8dd105ca64ba2ff5990747b7f..f7829bb8e96cf7f09c318f61a59695d5c11a3a47 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/FastqSync.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/FastqSync.scala
@@ -17,7 +17,7 @@ package nl.lumc.sasc.biopet.extensions.tools
 
 import java.io.File
 
-import nl.lumc.sasc.biopet.core.ToolCommandFuntion
+import nl.lumc.sasc.biopet.core.{ BiopetCommandLineFunction, ToolCommandFuntion }
 import nl.lumc.sasc.biopet.core.summary.Summarizable
 import nl.lumc.sasc.biopet.utils.config.Configurable
 import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
@@ -34,29 +34,34 @@ class FastqSync(val root: Configurable) extends ToolCommandFuntion with Summariz
 
   def toolObject = nl.lumc.sasc.biopet.tools.FastqSync
 
-  @Input(doc = "Original FASTQ file (read 1 or 2)", shortName = "r", required = true)
+  /** Original FASTQ file (read 1 or 2) */
+  @Input(required = true)
   var refFastq: File = null
 
-  @Input(doc = "Input read 1 FASTQ file", shortName = "i", required = true)
+  /** "Input read 1 FASTQ file" */
+  @Input(required = true)
   var inputFastq1: File = null
 
-  @Input(doc = "Input read 2 FASTQ file", shortName = "j", required = true)
+  /** Input read 2 FASTQ file */
+  @Input(required = true)
   var inputFastq2: File = null
 
-  @Output(doc = "Output read 1 FASTQ file", shortName = "o", required = true)
+  /** Output read 1 FASTQ file */
+  @Output(required = true)
   var outputFastq1: File = null
 
-  @Output(doc = "Output read 2 FASTQ file", shortName = "p", required = true)
+  /** Output read 2 FASTQ file */
+  @Output(required = true)
   var outputFastq2: File = null
 
-  @Output(doc = "Sync statistics", required = true)
+  /** Sync statistics */
+  @Output(required = true)
   var outputStats: File = null
 
   override def defaultCoreMemory = 4.0
 
-  // executed command line
-  override def commandLine =
-    super.commandLine +
+  override def cmdLine =
+    super.cmdLine +
       required("-r", refFastq) +
       required("-i", inputFastq1) +
       required("-j", inputFastq2) +
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/MergeAlleles.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/MergeAlleles.scala
index eedb51fdd1bb9d07d405299cb9dbf913681fbb96..504c7cb7c830cf8d1fa067b9048e7f23f4e3fe06 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/MergeAlleles.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/MergeAlleles.scala
@@ -43,7 +43,7 @@ class MergeAlleles(val root: Configurable) extends ToolCommandFuntion {
     if (output.getName.endsWith(".vcf")) outputIndex = new File(output.getAbsolutePath + ".idx")
   }
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     repeat("-I", input) +
     required("-o", output) +
     required("-R", reference)
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/MergeTables.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/MergeTables.scala
index 96a421db3e706d0220df76b6acfd5aab9cda9480..15ca55b6a524b283418ad67476d41b384541beb7 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/MergeTables.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/MergeTables.scala
@@ -65,8 +65,8 @@ class MergeTables(val root: Configurable) extends ToolCommandFuntion {
   var delimiter: Option[String] = config("delimiter")
 
   // executed command line
-  override def commandLine =
-    super.commandLine +
+  override def cmdLine =
+    super.cmdLine +
       required("-i", idColumnIndices.mkString(",")) +
       required("-a", valueColumnIndex) +
       optional("-n", idColumnName) +
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/MpileupToVcf.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/MpileupToVcf.scala
index 5a3e1e3f26588c103a4bf5e0a190aa223d064450..60797ce9ca7f491a9dff0cf3a2379570cc6d91f5 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/MpileupToVcf.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/MpileupToVcf.scala
@@ -57,7 +57,7 @@ class MpileupToVcf(val root: Configurable) extends ToolCommandFuntion with Refer
   }
 
   override def beforeCmd(): Unit = {
-    if (sample == null && inputBam.exists()) {
+    if (sample == null && inputBam.exists() && inputBam.length() > 0) {
       val inputSam = SamReaderFactory.makeDefault.open(inputBam)
       val readGroups = inputSam.getFileHeader.getReadGroups
       val samples = readGroups.map(readGroup => readGroup.getSample).distinct
@@ -66,14 +66,14 @@ class MpileupToVcf(val root: Configurable) extends ToolCommandFuntion with Refer
     }
   }
 
-  override def commandLine = {
+  override def cmdLine = {
     (if (inputMpileup == null) {
       val samtoolsMpileup = new SamtoolsMpileup(this)
       samtoolsMpileup.reference = referenceFasta()
       samtoolsMpileup.input = List(inputBam)
       samtoolsMpileup.cmdPipe + " | "
     } else "") +
-      super.commandLine +
+      super.cmdLine +
       required("-o", output) +
       optional("--minDP", minDP) +
       optional("--minAP", minAP) +
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/PrefixFastq.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/PrefixFastq.scala
index 302aa11586119a6602f29b0b452ed0645aeb2c37..dca36baf399c3f90725f61843ead5ed4416a08ab 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/PrefixFastq.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/PrefixFastq.scala
@@ -44,7 +44,7 @@ class PrefixFastq(val root: Configurable) extends ToolCommandFuntion {
    * Creates command to execute extension
    * @return
    */
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("-i", inputFastq) +
     required("-o", outputFastq) +
     optional("-s", prefixSeq)
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SageCountFastq.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SageCountFastq.scala
index 2ee9d97e17ef35cbf6573bf0fa91bb5fc8f76b2c..0e71324dba7091729f044ff6b0815c04d5c937dd 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SageCountFastq.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SageCountFastq.scala
@@ -32,7 +32,7 @@ class SageCountFastq(val root: Configurable) extends ToolCommandFuntion {
 
   override def defaultCoreMemory = 3.0
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("-I", input) +
     required("-o", output)
 }
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SageCreateLibrary.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SageCreateLibrary.scala
index 4b287d2cefaf98c777ca2ad44084f74bfacf5047..a2d79430f008d0a5818d98ae6ded6258ab74be0a 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SageCreateLibrary.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SageCreateLibrary.scala
@@ -44,7 +44,7 @@ class SageCreateLibrary(val root: Configurable) extends ToolCommandFuntion {
 
   override def defaultCoreMemory = 3.0
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("-I", input) +
     optional("--tag", tag) +
     optional("--length", length) +
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SageCreateTagCounts.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SageCreateTagCounts.scala
index d0779973b4484f29264bc574af6d898e1df8804d..30e7f524f65000789653085e4c6443a4e8a6d4a8 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SageCreateTagCounts.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SageCreateTagCounts.scala
@@ -44,7 +44,7 @@ class SageCreateTagCounts(val root: Configurable) extends ToolCommandFuntion {
 
   override def defaultCoreMemory = 3.0
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("-I", input) +
     required("--tagLib", tagLib) +
     optional("--countSense", countSense) +
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SeqStat.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SeqStat.scala
index cc7a8e6ede5bb1ba0d318639e8b9320a0ae8024a..3f1cf95a447f3f13827a27b82073fbf98e628495 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SeqStat.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SeqStat.scala
@@ -24,7 +24,7 @@ class SeqStat(val root: Configurable) extends ToolCommandFuntion with Summarizab
 
   override def defaultCoreMemory = 2.5
 
-  override def commandLine = super.commandLine + required("-i", input) + required("-o", output)
+  override def cmdLine = super.cmdLine + required("-i", input) + required("-o", output)
 
   def summaryStats: Map[String, Any] = {
     val map = ConfigUtils.fileToConfigMap(output)
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SquishBed.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SquishBed.scala
index 558c93f8532b95ccd3dfa33e3265f0fbebda8104..f42f635be866d88fd92c9991c93f93afb9e880cd 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SquishBed.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/SquishBed.scala
@@ -20,7 +20,7 @@ class SquishBed(val root: Configurable) extends ToolCommandFuntion {
 
   var strandSensitive: Boolean = config("strandSensitive", default = false)
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("-I", input) +
     required("-o", output) +
     conditional(strandSensitive, "-s")
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VcfFilter.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VcfFilter.scala
index 60d550532dfd30150e63f11096237356aa182a1a..06af56f025692658ad19c4e8375e7b81fbe599fc 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VcfFilter.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VcfFilter.scala
@@ -38,7 +38,7 @@ class VcfFilter(val root: Configurable) extends ToolCommandFuntion {
 
   override def defaultCoreMemory = 3.0
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("-I", inputVcf) +
     required("-o", outputVcf) +
     optional("--minSampleDepth", minSampleDepth) +
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VcfStats.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VcfStats.scala
index 3fd09a67fb74b3759ec3f00c51344f88afc53231..d0024681b727e6f72fdc31da7483bb7b1c98b4f6 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VcfStats.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VcfStats.scala
@@ -69,7 +69,7 @@ class VcfStats(val root: Configurable) extends ToolCommandFuntion with Summariza
   }
 
   /** Creates command to execute extension */
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("-I", input) +
     required("-o", outputDir) +
     repeat("--infoTag", infoTags) +
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VcfWithVcf.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VcfWithVcf.scala
index 5ab877502eaef6133b51a1927c83b94dc5b7b3ba..e956f5c93f5de3d9243de7bb5c9c1684de8f3fa4 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VcfWithVcf.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VcfWithVcf.scala
@@ -50,7 +50,7 @@ class VcfWithVcf(val root: Configurable) extends ToolCommandFuntion {
     if (fields.isEmpty) throw new IllegalArgumentException("No fields found for VcfWithVcf")
   }
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("-I", input) +
     required("-o", output) +
     required("-s", secondaryVcf) +
diff --git a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VepNormalizer.scala b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VepNormalizer.scala
index 4379b990dd585b012b15a44a7fc0605a7772b898..229f39628c9d1f8f8e23400b96a4fea957028e71 100644
--- a/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VepNormalizer.scala
+++ b/public/biopet-tools-extensions/src/main/scala/nl/lumc/sasc/biopet/extensions/tools/VepNormalizer.scala
@@ -45,7 +45,7 @@ class VepNormalizer(val root: Configurable) extends ToolCommandFuntion {
 
   override def defaultCoreMemory = 4.0
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     required("-I", inputVCF) +
     required("-O", outputVcf) +
     required("-m", mode) +
diff --git a/public/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/BedToInterval.scala b/public/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/BedToInterval.scala
index 4a08e55eca849eb40e0de7867f9504e83ac26cdb..f9646c4c9ebe7473e5ccb39e833d8ae87176b84a 100644
--- a/public/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/BedToInterval.scala
+++ b/public/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/BedToInterval.scala
@@ -19,7 +19,7 @@ import java.io.{ File, PrintWriter }
 
 import htsjdk.samtools.{ SAMSequenceRecord, SamReaderFactory }
 import nl.lumc.sasc.biopet.utils.ToolCommand
-import nl.lumc.sasc.biopet.utils.config.Configurable
+import scala.collection.JavaConversions._
 
 import scala.io.Source
 
@@ -52,8 +52,7 @@ object BedToInterval extends ToolCommand {
     val writer = new PrintWriter(commandArgs.outputFile)
 
     val inputSam = SamReaderFactory.makeDefault.open(commandArgs.bamFile)
-    val refs = for (SQ <- inputSam.getFileHeader.getSequenceDictionary.getSequences.toArray) yield {
-      val record = SQ.asInstanceOf[SAMSequenceRecord]
+    val refs = for (record <- inputSam.getFileHeader.getSequenceDictionary.getSequences) yield {
       writer.write("@SQ\tSN:" + record.getSequenceName + "\tLN:" + record.getSequenceLength + "\n")
       record.getSequenceName -> record.getSequenceLength
     }
diff --git a/public/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/VcfStats.scala b/public/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/VcfStats.scala
index 960c4921debd6e58f45fa00bbb9dc0864dd11c60..62b04375f630ab59fea18d9c1d974bdf038cb767 100644
--- a/public/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/VcfStats.scala
+++ b/public/biopet-tools/src/main/scala/nl/lumc/sasc/biopet/tools/VcfStats.scala
@@ -625,6 +625,7 @@ object VcfStats extends ToolCommand {
   def executeRscript(resource: String, args: Array[String]): Unit = {
     val is = getClass.getResourceAsStream(resource)
     val file = File.createTempFile("script.", "." + resource)
+    file.deleteOnExit()
     val os = new FileOutputStream(file)
     org.apache.commons.io.IOUtils.copy(is, os)
     os.close()
diff --git a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/BastyGenerateFastaTest.scala b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/BastyGenerateFastaTest.scala
index ebe393bfab7bdb8fedec024319e99a5b0ec29a07..d9d8c1bee6bf96bcc98a372585b5a89454775e08 100644
--- a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/BastyGenerateFastaTest.scala
+++ b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/BastyGenerateFastaTest.scala
@@ -31,6 +31,7 @@ class BastyGenerateFastaTest extends TestNGSuite with MockitoSugar with Matchers
 
   @Test def testMainVcf = {
     val tmp = File.createTempFile("basty_out", ".fa")
+    tmp.deleteOnExit()
     val tmppath = tmp.getAbsolutePath
     tmp.deleteOnExit()
 
@@ -40,6 +41,7 @@ class BastyGenerateFastaTest extends TestNGSuite with MockitoSugar with Matchers
 
   @Test def testMainVcfAndBam = {
     val tmp = File.createTempFile("basty_out", ".fa")
+    tmp.deleteOnExit()
     val tmppath = tmp.getAbsolutePath
     tmp.deleteOnExit()
 
@@ -49,6 +51,7 @@ class BastyGenerateFastaTest extends TestNGSuite with MockitoSugar with Matchers
 
   @Test def testMainVcfAndBamMore = {
     val tmp = File.createTempFile("basty_out", ".fa")
+    tmp.deleteOnExit()
     val tmppath = tmp.getAbsolutePath
     tmp.deleteOnExit()
 
diff --git a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/BiopetFlagstatTest.scala b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/BiopetFlagstatTest.scala
index 758cb6be6d6aa0a75c2ec1830e0fa3334beb7626..d919fe400154683f5fef7a061ce76c60aab5f5e7 100644
--- a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/BiopetFlagstatTest.scala
+++ b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/BiopetFlagstatTest.scala
@@ -56,6 +56,7 @@ class BiopetFlagstatTest extends TestNGSuite with MockitoSugar with Matchers {
   def testMain() = {
     //TODO: Test output file
     val output = File.createTempFile("testMain", ".biopetflagstat")
+    output.deleteOnExit()
     main(Array("-I", bam.getAbsolutePath, "-o", output.toString))
   }
 
diff --git a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/FastqSplitterTest.scala b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/FastqSplitterTest.scala
index ffa8be0bcb6c2cf15bf0ad00efeeb54e903eb3df..dd66b204fab38a4fd26fb011ffe6739faf304009 100644
--- a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/FastqSplitterTest.scala
+++ b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/FastqSplitterTest.scala
@@ -23,7 +23,7 @@ class FastqSplitterTest extends TestNGSuite with MockitoSugar with Matchers {
   @Test
   def testMain() = {
     val temp = File.createTempFile("out", ".fastq")
-
+    temp.deleteOnExit()
     val args = Array("-I", fq, "-o", temp.getAbsolutePath)
     main(args)
   }
@@ -31,6 +31,7 @@ class FastqSplitterTest extends TestNGSuite with MockitoSugar with Matchers {
   @Test
   def testManyOutMain() = {
     val files = (0 until 10).map(_ => File.createTempFile("out", ".fastq"))
+    files.foreach(_.deleteOnExit())
     var args = Array("-I", fq)
     files.foreach(x => args ++= Array("-o", x.getAbsolutePath))
     main(args)
diff --git a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/FindRepeatsPacBioTest.scala b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/FindRepeatsPacBioTest.scala
index b6de2f8bcca896e8979c2e21fc5bb8651524610a..907270b8c31f3eb152766f03a612101f754ba6c9 100644
--- a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/FindRepeatsPacBioTest.scala
+++ b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/FindRepeatsPacBioTest.scala
@@ -29,6 +29,7 @@ class FindRepeatsPacBioTest extends TestNGSuite with MockitoSugar with Matchers
   def testMain() = {
 
     val outputFile = File.createTempFile("repeats", ".tsv")
+    outputFile.deleteOnExit()
     val args = Array("-I", bam, "-b", bed, "-o", outputFile.toString)
     main(args)
   }
diff --git a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/MpileupToVcfTest.scala b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/MpileupToVcfTest.scala
index 032f9a913373c0f3be617e45cc26a928ca69821d..e708bc654b3c81699dcab85bfc07a7e21cd3ea94 100644
--- a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/MpileupToVcfTest.scala
+++ b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/MpileupToVcfTest.scala
@@ -28,6 +28,7 @@ class MpileupToVcfTest extends TestNGSuite with MockitoSugar with Matchers {
   @Test
   def testMain() = {
     val tmp = File.createTempFile("mpileup", ".vcf")
+    tmp.deleteOnExit()
     val args = Array("-I", pileup, "--sample", "test", "-o", tmp.getAbsolutePath)
 
     main(args)
@@ -36,6 +37,7 @@ class MpileupToVcfTest extends TestNGSuite with MockitoSugar with Matchers {
   @Test
   def validateOutVcf() = {
     val tmp = File.createTempFile("mpileup", ".vcf")
+    tmp.deleteOnExit()
     val args = Array("-I", pileup, "--sample", "test", "-o", tmp.getAbsolutePath, "--minDP", "1", "--minAP", "1")
     main(args)
 
@@ -51,6 +53,7 @@ class MpileupToVcfTest extends TestNGSuite with MockitoSugar with Matchers {
   @Test
   def extraValidateOutVcf() = {
     val tmp = File.createTempFile("mpileup", ".vcf")
+    tmp.deleteOnExit()
     val args = Array("-I", pileup, "--sample", "test", "-o", tmp.getAbsolutePath, "--minDP", "1", "--minAP", "1")
     main(args)
 
diff --git a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/PrefixFastqTest.scala b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/PrefixFastqTest.scala
index 41db9e3ae268a62860fd3fbe9a27e4430165429e..611557d836636aebc71f90e70707035033df6b97 100644
--- a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/PrefixFastqTest.scala
+++ b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/PrefixFastqTest.scala
@@ -26,6 +26,7 @@ class PrefixFastqTest extends TestNGSuite with MockitoSugar with Matchers {
   @Test
   def testMain() = {
     val temp = File.createTempFile("out", ".fastq")
+    temp.deleteOnExit()
 
     val args = Array("-i", fq, "-o", temp.getAbsolutePath, "-s", "AAA")
     main(args)
@@ -34,6 +35,7 @@ class PrefixFastqTest extends TestNGSuite with MockitoSugar with Matchers {
   @Test
   def testOutput() = {
     val temp = File.createTempFile("out", ".fastq")
+    temp.deleteOnExit()
 
     val args = Array("-i", fq, "-o", temp.getAbsolutePath, "-s", "AAA")
     main(args)
diff --git a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SageCountFastqTest.scala b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SageCountFastqTest.scala
index 15d3074c95313c6f2a084c41b4d0a4787bdedddb..5c7731c6dd2ec60b7c8cd01f84c6929026d7e007 100644
--- a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SageCountFastqTest.scala
+++ b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SageCountFastqTest.scala
@@ -22,6 +22,7 @@ class SageCountFastqTest extends TestNGSuite with MockitoSugar with Matchers {
   @Test
   def testMain() = {
     val temp = File.createTempFile("out", ".fastq")
+    temp.deleteOnExit()
 
     val args = Array("-I", fq, "-o", temp.getAbsolutePath)
     main(args)
diff --git a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SageCreateLibaryTest.scala b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SageCreateLibaryTest.scala
index 48038ea6f476fd89a945f53cf3d3608661fbcc9c..c86c1ba5a9787c0cdcce00293309500d6f6e4b86 100644
--- a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SageCreateLibaryTest.scala
+++ b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SageCreateLibaryTest.scala
@@ -29,9 +29,13 @@ class SageCreateLibaryTest extends TestNGSuite with MockitoSugar with Matchers {
 
     val input = resourcePath("/mini.transcriptome.fa")
     val output = File.createTempFile("sageCreateLibrary", ".tsv")
+    output.deleteOnExit()
     val noTagsOutput = File.createTempFile("sageCreateLibrary", ".tsv")
+    noTagsOutput.deleteOnExit()
     val antiTagsOutput = File.createTempFile("sageCreateLibrary", ".tsv")
+    antiTagsOutput.deleteOnExit()
     val allGenesOutput = File.createTempFile("sageCreateLibrary", ".tsv")
+    allGenesOutput.deleteOnExit()
 
     val args = Array("-I", input, "-o", output.getAbsolutePath, "--tag", "CATG",
       "--length", "17", "--noTagsOutput", noTagsOutput.getAbsolutePath, "--noAntiTagsOutput",
@@ -52,9 +56,13 @@ class SageCreateLibaryTest extends TestNGSuite with MockitoSugar with Matchers {
   def testOutPut = {
     val input = resourcePath("/mini.transcriptome.fa")
     val output = File.createTempFile("sageCreateLibrary", ".tsv")
+    output.deleteOnExit()
     val noTagsOutput = File.createTempFile("sageCreateLibrary", ".tsv")
+    noTagsOutput.deleteOnExit()
     val antiTagsOutput = File.createTempFile("sageCreateLibrary", ".tsv")
+    antiTagsOutput.deleteOnExit()
     val allGenesOutput = File.createTempFile("sageCreateLibrary", ".tsv")
+    allGenesOutput.deleteOnExit()
 
     val args = Array("-I", input, "-o", output.getAbsolutePath, "--tag", "CATG",
       "--length", "17", "--noTagsOutput", noTagsOutput.getAbsolutePath, "--noAntiTagsOutput",
diff --git a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SageCreateTagCountsTest.scala b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SageCreateTagCountsTest.scala
index b47c507856ec251878057a3823d47d57160045e9..ecd1dae87d5c43a88e722cbb12f7eb18ece3a9b8 100644
--- a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SageCreateTagCountsTest.scala
+++ b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SageCreateTagCountsTest.scala
@@ -26,9 +26,13 @@ class SageCreateTagCountsTest extends TestNGSuite with MockitoSugar with Matcher
     val tagLib = resourcePath("/sageTest.tsv")
 
     val sense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
+    sense.deleteOnExit()
     val allSense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
+    allSense.deleteOnExit()
     val antiSense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
+    antiSense.deleteOnExit()
     val allAntiSense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
+    allAntiSense.deleteOnExit()
 
     noException should be thrownBy main(Array("-I", input, "--tagLib", tagLib,
       "--countSense", sense.getAbsolutePath, "--countAllSense", allSense.getAbsolutePath,
@@ -50,9 +54,13 @@ class SageCreateTagCountsTest extends TestNGSuite with MockitoSugar with Matcher
     val tagLib = resourcePath("/sageTest.tsv")
 
     val sense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
+    sense.deleteOnExit()
     val allSense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
+    allSense.deleteOnExit()
     val antiSense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
+    antiSense.deleteOnExit()
     val allAntiSense = File.createTempFile("SageCreateTagCountsTEst", ".tsv")
+    allAntiSense.deleteOnExit()
 
     main(Array("-I", input, "--tagLib", tagLib, "--countSense", sense.getAbsolutePath,
       "--countAllSense", allSense.getAbsolutePath, "--countAntiSense", antiSense.getAbsolutePath,
diff --git a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SamplesTsvToJsonTest.scala b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SamplesTsvToJsonTest.scala
index 9866ad47a8efbfad5f34868b82fe415f6e6b8c28..e8a09a9d7cb9af569f2084c95a1b6c2e7f1e1aad 100644
--- a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SamplesTsvToJsonTest.scala
+++ b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SamplesTsvToJsonTest.scala
@@ -21,6 +21,7 @@ class SamplesTsvToJsonTest extends TestNGSuite with MockitoSugar with Matchers {
   def testCorrectSampleTsv = {
     val tsv = resourcePath("/sample.tsv")
     val output = File.createTempFile("testCorrectSampleTsv", ".json")
+    output.deleteOnExit()
 
     noException should be thrownBy main(Array("-i", tsv, "-o", output.toString))
   }
@@ -29,6 +30,7 @@ class SamplesTsvToJsonTest extends TestNGSuite with MockitoSugar with Matchers {
   def testNoSampleColumn() = {
     val tsv = resourcePath("/no_sample.tsv")
     val output = File.createTempFile("testNoSampleColumn", ".json")
+    output.deleteOnExit()
     val thrown = the[IllegalStateException] thrownBy main(Array("-i", tsv, "-o", output.toString))
     thrown.getMessage should equal("Sample column does not exist in: " + tsv)
   }
@@ -37,6 +39,7 @@ class SamplesTsvToJsonTest extends TestNGSuite with MockitoSugar with Matchers {
   def testNumberInLibs = {
     val tsv = resourcePath("/number.tsv")
     val output = File.createTempFile("testNumberInLibs", ".json")
+    output.deleteOnExit()
     val thrown = the[IllegalStateException] thrownBy main(Array("-i", tsv, "-o", output.toString))
     thrown.getMessage should equal("Sample or library may not start with a number")
   }
@@ -45,6 +48,7 @@ class SamplesTsvToJsonTest extends TestNGSuite with MockitoSugar with Matchers {
   def testSampleIDs = {
     val tsv = resourcePath("/same.tsv")
     val output = File.createTempFile("testSampleIDs", ".json")
+    output.deleteOnExit()
     val thrown = the[IllegalStateException] thrownBy main(Array("-i", tsv, "-o", output.toString))
     thrown.getMessage should equal("Combination of Sample_ID_1 and Lib_ID_1 is found multiple times")
 
diff --git a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SummaryToTsvTest.scala b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SummaryToTsvTest.scala
index 6071fceaaed85a943a4f973ac713d24e8b708952..4f921affbc090031b83c0ee5fea3c64b9c9bdf4c 100644
--- a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SummaryToTsvTest.scala
+++ b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/SummaryToTsvTest.scala
@@ -24,6 +24,7 @@ class SummaryToTsvTest extends TestNGSuite with MockitoSugar with Matchers {
   def testMain = {
     val tsv = resourcePath("/test.summary.json")
     val output = File.createTempFile("main", "tsv")
+    output.deleteOnExit()
 
     noException should be thrownBy main(Array("-s", tsv, "-p", "something=flexiprep:settings:skip_trim",
       "-m", "root", "-o", output.toString))
diff --git a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/VcfWithVcfTest.scala b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/VcfWithVcfTest.scala
index af8ff6267d5c73dad9eaa10762b1d356a2641626..a6a70881012480a8e92b9aac1c689e4456f9f8c7 100644
--- a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/VcfWithVcfTest.scala
+++ b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/VcfWithVcfTest.scala
@@ -47,50 +47,57 @@ class VcfWithVcfTest extends TestNGSuite with MockitoSugar with Matchers {
   val rand = new Random()
 
   @Test def testOutputTypeVcf() = {
-    val tmpPath = File.createTempFile("VcfWithVcf_", ".vcf").getAbsolutePath
-    val arguments = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpPath, "-f", "CSQ")
+    val tmpFile = File.createTempFile("VcfWithVcf_", ".vcf")
+    tmpFile.deleteOnExit()
+    val arguments = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpFile.getAbsolutePath, "-f", "CSQ")
     main(arguments)
   }
 
   @Test def testOutputTypeVcfGz() = {
-    val tmpPath = File.createTempFile("VcfWithVcf_", ".vcf.gz").getAbsolutePath
-    val arguments = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpPath, "-f", "CSQ")
+    val tmpFile = File.createTempFile("VcfWithVcf_", ".vcf.gz")
+    tmpFile.deleteOnExit()
+    val arguments = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpFile.getAbsolutePath, "-f", "CSQ")
     main(arguments)
   }
 
   @Test def testOutputTypeBcf() = {
-    val tmpPath = File.createTempFile("VcfWithVcf_", ".bcf").getAbsolutePath
-    val arguments = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpPath, "-f", "CSQ")
+    val tmpFile = File.createTempFile("VcfWithVcf_", ".bcf")
+    tmpFile.deleteOnExit()
+    val arguments = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpFile.getAbsolutePath, "-f", "CSQ")
     main(arguments)
   }
 
   @Test def testOutputFieldException = {
-    val tmpPath = File.createTempFile("VCFWithVCf", ".vcf").getAbsolutePath
-    val args = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpPath, "-f", "CSQ:AC")
+    val tmpFile = File.createTempFile("VCFWithVCf", ".vcf")
+    tmpFile.deleteOnExit()
+    val args = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpFile.getAbsolutePath, "-f", "CSQ:AC")
     an[IllegalArgumentException] should be thrownBy main(args)
     val thrown = the[IllegalArgumentException] thrownBy main(args)
     thrown.getMessage should equal("Field 'AC' already exists in input vcf")
   }
 
   @Test def testInputFieldException = {
-    val tmpPath = File.createTempFile("VCFWithVCf", ".vcf").getAbsolutePath
-    val args = Array("-I", unveppedPath, "-s", unveppedPath, "-o", tmpPath, "-f", "CSQ:NEW_CSQ")
+    val tmpFile = File.createTempFile("VCFWithVCf", ".vcf")
+    tmpFile.deleteOnExit()
+    val args = Array("-I", unveppedPath, "-s", unveppedPath, "-o", tmpFile.getAbsolutePath, "-f", "CSQ:NEW_CSQ")
     an[IllegalArgumentException] should be thrownBy main(args)
     val thrown = the[IllegalArgumentException] thrownBy main(args)
     thrown.getMessage should equal("Field 'CSQ' does not exist in secondary vcf")
   }
 
   @Test def testMinMethodException = {
-    val tmpPath = File.createTempFile("VcfWithVcf_", ".vcf").getAbsolutePath
-    val args = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpPath, "-f", "CSQ:CSQ:min")
+    val tmpFile = File.createTempFile("VcfWithVcf_", ".vcf")
+    tmpFile.deleteOnExit()
+    val args = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpFile.getAbsolutePath, "-f", "CSQ:CSQ:min")
     an[IllegalArgumentException] should be thrownBy main(args)
     val thrown = the[IllegalArgumentException] thrownBy main(args)
     thrown.getMessage should equal("Type of field CSQ is not numeric")
   }
 
   @Test def testMaxMethodException = {
-    val tmpPath = File.createTempFile("VcfWithVcf_", ".vcf").getAbsolutePath
-    val args = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpPath, "-f", "CSQ:CSQ:max")
+    val tmpFile = File.createTempFile("VcfWithVcf_", ".vcf")
+    tmpFile.deleteOnExit()
+    val args = Array("-I", unveppedPath, "-s", veppedPath, "-o", tmpFile.getAbsolutePath, "-f", "CSQ:CSQ:max")
     an[IllegalArgumentException] should be thrownBy main(args)
     val thrown = the[IllegalArgumentException] thrownBy main(args)
     thrown.getMessage should equal("Type of field CSQ is not numeric")
diff --git a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/VepNormalizerTest.scala b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/VepNormalizerTest.scala
index 5a12e9b579296b58a2764fdaa0b5b916717e384f..53aeddfaf1d6ba87f9e89ac29b31edff8fc5e01b 100644
--- a/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/VepNormalizerTest.scala
+++ b/public/biopet-tools/src/test/scala/nl/lumc/sasc/biopet/tools/VepNormalizerTest.scala
@@ -47,38 +47,44 @@ class VepNormalizerTest extends TestNGSuite with MockitoSugar with Matchers {
   val rand = new Random()
 
   @Test def testGzOutputExplode(): Unit = {
-    val tmpPath = File.createTempFile("VepNormalizer_", ".vcf.gz").getAbsolutePath
-    val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpPath, "-m", "explode")
+    val tmpFile = File.createTempFile("VepNormalizer_", ".vcf.gz")
+    tmpFile.deleteOnExit()
+    val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpFile.getAbsolutePath, "-m", "explode")
     main(arguments)
   }
 
   @Test def testVcfOutputExplode(): Unit = {
-    val tmpPath = File.createTempFile("VepNormalizer_", ".vcf").getAbsolutePath
-    val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpPath, "-m", "explode")
+    val tmpFile = File.createTempFile("VepNormalizer_", ".vcf")
+    tmpFile.deleteOnExit()
+    val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpFile.getAbsolutePath, "-m", "explode")
     main(arguments)
   }
 
   @Test def testBcfOutputExplode(): Unit = {
-    val tmp_path = File.createTempFile("VepNormalizer_", ".bcf").getAbsolutePath
-    val arguments: Array[String] = Array("-I", vepped_path, "-O", tmp_path, "-m", "explode")
+    val tmpFile = File.createTempFile("VepNormalizer_", ".bcf")
+    tmpFile.deleteOnExit()
+    val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpFile.getAbsolutePath, "-m", "explode")
     main(arguments)
   }
 
   @Test def testGzOutputStandard(): Unit = {
-    val tmp_path = File.createTempFile("VepNormalizer_", ".vcf.gz").getAbsolutePath
-    val arguments: Array[String] = Array("-I", vepped_path, "-O", tmp_path, "-m", "standard")
+    val tmpFile = File.createTempFile("VepNormalizer_", ".vcf.gz")
+    tmpFile.deleteOnExit()
+    val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpFile.getAbsolutePath, "-m", "standard")
     main(arguments)
   }
 
   @Test def testVcfOutputStandard(): Unit = {
-    val tmp_path = File.createTempFile("VepNormalizer_", ".vcf").getAbsolutePath
-    val arguments: Array[String] = Array("-I", vepped_path, "-O", tmp_path, "-m", "standard")
+    val tmpFile = File.createTempFile("VepNormalizer_", ".vcf")
+    tmpFile.deleteOnExit()
+    val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpFile.getAbsolutePath, "-m", "standard")
     main(arguments)
   }
 
   @Test def testBcfOutputStandard(): Unit = {
-    val tmp_path = File.createTempFile("VepNormalizer_", ".bcf").getAbsolutePath
-    val arguments: Array[String] = Array("-I", vepped_path, "-O", tmp_path, "-m", "standard")
+    val tmpFile = File.createTempFile("VepNormalizer_", ".bcf")
+    tmpFile.deleteOnExit()
+    val arguments: Array[String] = Array("-I", vepped_path, "-O", tmpFile.getAbsolutePath, "-m", "standard")
     main(arguments)
   }
 
diff --git a/public/biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/rscript/LinePlot.scala b/public/biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/rscript/LinePlot.scala
index fb0e2f0a0706a56c6063c2a2fa2dc199bfee573c..1954609198b33dcaa380eaafa3534f463ef43d4c 100644
--- a/public/biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/rscript/LinePlot.scala
+++ b/public/biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/rscript/LinePlot.scala
@@ -48,5 +48,5 @@ class LinePlot(val root: Configurable) extends Rscript {
     ylabel.map(Seq("--ylabel", _)).getOrElse(Seq()) ++
     llabel.map(Seq("--llabel", _)).getOrElse(Seq()) ++
     title.map(Seq("--title", _)).getOrElse(Seq()) ++
-    (if (removeZero) Seq("--removeZero") else Seq())
+    (if (removeZero) Seq("--removeZero", "true") else Seq())
 }
diff --git a/public/biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/rscript/Rscript.scala b/public/biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/rscript/Rscript.scala
index 685108d0cb7f31cebfcc4b998017ae0a4c91726f..3dfac894eeb591a84a31b3fd5bcfa88c34619192 100644
--- a/public/biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/rscript/Rscript.scala
+++ b/public/biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/rscript/Rscript.scala
@@ -28,7 +28,11 @@ trait Rscript extends Configurable {
     } else {
       val rScript: File = dir match {
         case Some(dir) => new File(dir, script.getName)
-        case _         => File.createTempFile(script.getName, ".R")
+        case _ => {
+          val file = File.createTempFile(script.getName, ".R")
+          file.deleteOnExit()
+          file
+        }
       }
       if (!rScript.getParentFile.exists) rScript.getParentFile.mkdirs
 
diff --git a/public/biopet-utils/src/test/scala/nl/lumc/sasc/biopet/utils/ConfigUtilsTest.scala b/public/biopet-utils/src/test/scala/nl/lumc/sasc/biopet/utils/ConfigUtilsTest.scala
index ad8ff00ee2e8a09026168efbf99f5926b4583c50..6bac74cdf9f3bf6148a78b05271593242d9b2d07 100644
--- a/public/biopet-utils/src/test/scala/nl/lumc/sasc/biopet/utils/ConfigUtilsTest.scala
+++ b/public/biopet-utils/src/test/scala/nl/lumc/sasc/biopet/utils/ConfigUtilsTest.scala
@@ -228,6 +228,7 @@ class ConfigUtilsTest extends TestNGSuite with Matchers {
 object ConfigUtilsTest {
   def writeTemp(text: String, extension: String): File = {
     val file = File.createTempFile("TestConfigUtils.", extension)
+    file.deleteOnExit()
     val w = new PrintWriter(file)
     w.write(text)
     w.close()
diff --git a/public/biopet-utils/src/test/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecordListTest.scala b/public/biopet-utils/src/test/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecordListTest.scala
index b748006c2800d5e86aad9e5f918a3d4bf5894c2c..0490b28db7dbf199a9b01c1b48c6783f11720f7d 100644
--- a/public/biopet-utils/src/test/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecordListTest.scala
+++ b/public/biopet-utils/src/test/scala/nl/lumc/sasc/biopet/utils/intervals/BedRecordListTest.scala
@@ -39,6 +39,7 @@ class BedRecordListTest extends TestNGSuite with Matchers {
     records.header shouldBe Nil
 
     val tempFile = File.createTempFile("region", ".bed")
+    tempFile.deleteOnExit()
     records.writeToFile(tempFile)
     BedRecordList.fromFile(tempFile) shouldBe records
     tempFile.delete()
@@ -50,6 +51,7 @@ class BedRecordListTest extends TestNGSuite with Matchers {
     records.header shouldBe BedRecordListTest.ucscHeader.split("\n").toList
 
     val tempFile = File.createTempFile("region", ".bed")
+    tempFile.deleteOnExit()
     records.writeToFile(tempFile)
     BedRecordList.fromFile(tempFile) shouldBe records
     tempFile.delete()
@@ -129,13 +131,6 @@ class BedRecordListTest extends TestNGSuite with Matchers {
     list.scatter(100).allRecords.size shouldBe 15
     list.scatter(100).length shouldBe 1500
   }
-
-  @AfterClass
-  def end: Unit = {
-    BedRecordListTest.bedFile.delete()
-    BedRecordListTest.corruptBedFile.delete()
-    BedRecordListTest.bedFileUcscHeader.delete()
-  }
 }
 
 object BedRecordListTest {
@@ -149,6 +144,9 @@ object BedRecordListTest {
                      |chr22	2000	6000	cloneB	900	-	2000	6000	0	2	433,399	0,3601""".stripMargin
 
   val bedFile = File.createTempFile("regions", ".bed")
+  bedFile.deleteOnExit()
   val corruptBedFile = File.createTempFile("regions", ".bed")
+  corruptBedFile.deleteOnExit()
   val bedFileUcscHeader = File.createTempFile("regions", ".bed")
+  bedFileUcscHeader.deleteOnExit()
 }
\ No newline at end of file
diff --git a/public/carp/src/main/scala/nl/lumc/sasc/biopet/pipelines/carp/Carp.scala b/public/carp/src/main/scala/nl/lumc/sasc/biopet/pipelines/carp/Carp.scala
index 1233eecd6cf1c49d7f57ae27b398d8998b8c3494..71b51067a73baaf49c7d1a095d13d1fa584e7e96 100644
--- a/public/carp/src/main/scala/nl/lumc/sasc/biopet/pipelines/carp/Carp.scala
+++ b/public/carp/src/main/scala/nl/lumc/sasc/biopet/pipelines/carp/Carp.scala
@@ -78,6 +78,10 @@ class Carp(val root: Configurable) extends QScript with MultiSampleQScript with
         if (config.contains("R1")) {
           mapping.input_R1 = config("R1")
           if (config.contains("R2")) mapping.input_R2 = config("R2")
+
+          inputFiles :+= new InputFile(mapping.input_R1, config("R1_md5"))
+          mapping.input_R2.foreach(inputFiles :+= new InputFile(_, config("R2_md5")))
+
           mapping.init()
           mapping.biopetScript()
           addAll(mapping.functions)
@@ -107,7 +111,7 @@ class Carp(val root: Configurable) extends QScript with MultiSampleQScript with
         add(merge)
       }
 
-      val bamMetrics = BamMetrics(qscript, bamFile, new File(sampleDir, "metrics"))
+      val bamMetrics = BamMetrics(qscript, bamFile, new File(sampleDir, "metrics"), sampleId = Some(sampleId))
       addAll(bamMetrics.functions)
       addSummaryQScript(bamMetrics)
       addAll(Bam2Wig(qscript, bamFile).functions)
diff --git a/public/carp/src/main/scala/nl/lumc/sasc/biopet/pipelines/carp/CarpReport.scala b/public/carp/src/main/scala/nl/lumc/sasc/biopet/pipelines/carp/CarpReport.scala
index c5f2256b0c4cf7c4815c305bab8907573449c5a4..59a07dca040ff07f81438b59697953563b97d972 100644
--- a/public/carp/src/main/scala/nl/lumc/sasc/biopet/pipelines/carp/CarpReport.scala
+++ b/public/carp/src/main/scala/nl/lumc/sasc/biopet/pipelines/carp/CarpReport.scala
@@ -76,7 +76,7 @@ object CarpReport extends MultisampleReportBuilder {
     ), List(
       "Alignment" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp",
         if (summary.libraries(sampleId).size > 1) Map("showPlot" -> true) else Map()),
-      "Preprocessing" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp", Map("sampleLevel" -> true)),
+      "Merged" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/bammetrics/alignmentSummary.ssp", Map("sampleLevel" -> true)),
       "QC reads" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp"),
       "QC bases" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp")
     ), args)
diff --git a/public/carp/src/test/scala/nl/lumc/sasc/biopet/pipelines/carp/CarpTest.scala b/public/carp/src/test/scala/nl/lumc/sasc/biopet/pipelines/carp/CarpTest.scala
index c361908fa1110ef7133639e91912acab5cce0da9..1f5efdc2fb950dfca40e7a870bba7da984db0c41 100644
--- a/public/carp/src/test/scala/nl/lumc/sasc/biopet/pipelines/carp/CarpTest.scala
+++ b/public/carp/src/test/scala/nl/lumc/sasc/biopet/pipelines/carp/CarpTest.scala
@@ -81,8 +81,8 @@ class CarpTest extends TestNGSuite with Matchers {
       val numberSamples = (if (sample1) 1 else 0) + (if (sample2) 1 else 0) + (if (sample3) 1 else 0) +
         (if (threatment) 1 else 0) + (if (control) 1 else 0)
 
-      carp.functions.count(_.isInstanceOf[BwaMem]) shouldBe numberLibs
-      carp.functions.count(_.isInstanceOf[SortSam]) shouldBe numberLibs
+      //carp.functions.count(_.isInstanceOf[BwaMem]) shouldBe numberLibs
+      //carp.functions.count(_.isInstanceOf[SortSam]) shouldBe numberLibs
       carp.functions.count(_.isInstanceOf[MergeSamFiles]) shouldBe (if (sample3) 1 else 0)
 
       carp.functions.count(_.isInstanceOf[Macs2CallPeak]) shouldBe (numberSamples + (if (threatment) 1 else 0))
@@ -97,6 +97,12 @@ class CarpTest extends TestNGSuite with Matchers {
 
 object CarpTest {
   val outputDir = Files.createTempDir()
+  new File(outputDir, "input").mkdirs()
+  def inputTouch(name: String): String = {
+    val file = new File(outputDir, "input" + File.separator + name)
+    Files.touch(file)
+    file.getAbsolutePath
+  }
 
   private def copyFile(name: String): Unit = {
     val is = getClass.getResourceAsStream("/" + name)
@@ -127,8 +133,8 @@ object CarpTest {
   val sample1 = Map(
     "samples" -> Map("sample1" -> Map("libraries" -> Map(
       "lib1" -> Map(
-        "R1" -> "1_1_R1.fq",
-        "R2" -> "1_1_R2.fq"
+        "R1" -> inputTouch("1_1_R1.fq"),
+        "R2" -> inputTouch("1_1_R2.fq")
       )
     )
     )))
@@ -136,8 +142,8 @@ object CarpTest {
   val sample2 = Map(
     "samples" -> Map("sample2" -> Map("libraries" -> Map(
       "lib1" -> Map(
-        "R1" -> "2_1_R1.fq",
-        "R2" -> "2_1_R2.fq"
+        "R1" -> inputTouch("2_1_R1.fq"),
+        "R2" -> inputTouch("2_1_R2.fq")
       )
     )
     )))
@@ -145,12 +151,12 @@ object CarpTest {
   val sample3 = Map(
     "samples" -> Map("sample3" -> Map("libraries" -> Map(
       "lib1" -> Map(
-        "R1" -> "3_1_R1.fq",
-        "R2" -> "3_1_R2.fq"
+        "R1" -> inputTouch("3_1_R1.fq"),
+        "R2" -> inputTouch("3_1_R2.fq")
       ),
       "lib2" -> Map(
-        "R1" -> "3_2_R1.fq",
-        "R2" -> "3_2_R2.fq"
+        "R1" -> inputTouch("3_2_R1.fq"),
+        "R2" -> inputTouch("3_2_R2.fq")
       )
     )
     )))
@@ -158,8 +164,8 @@ object CarpTest {
   val threatment1 = Map(
     "samples" -> Map("threatment" -> Map("control" -> "control1", "libraries" -> Map(
       "lib1" -> Map(
-        "R1" -> "threatment_1_R1.fq",
-        "R2" -> "threatment_1_R2.fq"
+        "R1" -> inputTouch("threatment_1_R1.fq"),
+        "R2" -> inputTouch("threatment_1_R2.fq")
       )
     )
     )))
@@ -167,8 +173,8 @@ object CarpTest {
   val control1 = Map(
     "samples" -> Map("control1" -> Map("libraries" -> Map(
       "lib1" -> Map(
-        "R1" -> "control_1_R1.fq",
-        "R2" -> "control_1_R2.fq"
+        "R1" -> inputTouch("control_1_R1.fq"),
+        "R2" -> inputTouch("control_1_R2.fq")
       )
     )
     )))
diff --git a/public/flexiprep/src/main/resources/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp b/public/flexiprep/src/main/resources/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp
index c327a7cef9b16719f1ec4be35ee556005c9bee2e..b2f0057b3dc437c496c4a161af515c11f9a3d80e 100644
--- a/public/flexiprep/src/main/resources/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp
+++ b/public/flexiprep/src/main/resources/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepBaseSummary.ssp
@@ -129,7 +129,7 @@
                         #if (read == "R2") </tr><tr> #end
                         #{
                             val beforeTotal = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "seqstat_" + read, "bases", "num_total").getOrElse(0).toString.toLong
-                            val afterTotal = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "seqstat_" + read + "_after", "bases", "num_total").getOrElse(0).toString.toLong
+                            val afterTotal = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "seqstat_" + read + "_qc", "bases", "num_total").getOrElse(0).toString.toLong
                         }#
                         <td>${read}</td>
                         <td>${beforeTotal}</td>
diff --git a/public/flexiprep/src/main/resources/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp b/public/flexiprep/src/main/resources/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp
index 17065bb987d62f147e76a3c096f3db0847bcd265..4a0a60659f5276f7230fef7fabd4cc12f23ae4a4 100644
--- a/public/flexiprep/src/main/resources/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp
+++ b/public/flexiprep/src/main/resources/nl/lumc/sasc/biopet/pipelines/flexiprep/flexiprepReadSummary.ssp
@@ -133,7 +133,7 @@
                         #if (read == "R2") </tr><tr> #end
                         #{
                             val beforeTotal = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "seqstat_" + read, "reads", "num_total")
-                            val afterTotal = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "seqstat_" + read + "_after", "reads", "num_total")
+                            val afterTotal = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "seqstat_" + read + "_qc", "reads", "num_total")
                             val clippingDiscardedToShort = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "clipping_" + read, "num_reads_discarded_too_short").getOrElse(0).toString.toLong
                             val clippingDiscardedToLong = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "clipping_" + read, "num_reads_discarded_too_long").getOrElse(0).toString.toLong
                             val trimmingDiscarded = summary.getLibraryValue(sample, libId, "flexiprep", "stats", "trimming", "num_reads_discarded_" + read).getOrElse(0).toString.toLong
diff --git a/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Cutadapt.scala b/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Cutadapt.scala
deleted file mode 100644
index 63301b52ad02ad124ac820e791a1de4d385505d3..0000000000000000000000000000000000000000
--- a/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Cutadapt.scala
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * Biopet is built on top of GATK Queue for building bioinformatic
- * pipelines. It is mainly intended to support LUMC SHARK cluster which is running
- * SGE. But other types of HPC that are supported by GATK Queue (such as PBS)
- * should also be able to execute Biopet tools and pipelines.
- *
- * Copyright 2014 Sequencing Analysis Support Core - Leiden University Medical Center
- *
- * Contact us at: sasc@lumc.nl
- *
- * A dual licensing mode is applied. The source code within this project that are
- * not part of GATK Queue is freely available for non-commercial use under an AGPL
- * license; For commercial users or users who do not want to follow the AGPL
- * license, please contact us to obtain a separate license.
- */
-package nl.lumc.sasc.biopet.pipelines.flexiprep
-
-import java.io.File
-
-import nl.lumc.sasc.biopet.utils.config.Configurable
-import nl.lumc.sasc.biopet.extensions.Ln
-
-import scala.collection.mutable
-import scala.io.Source
-
-class Cutadapt(root: Configurable) extends nl.lumc.sasc.biopet.extensions.Cutadapt(root) {
-  var fastqc: Fastqc = _
-
-  override def beforeCmd() {
-    super.beforeCmd()
-
-    val foundAdapters = fastqc.foundAdapters.map(_.seq)
-    if (default_clip_mode == "3") opt_adapter ++= foundAdapters
-    else if (default_clip_mode == "5") opt_front ++= foundAdapters
-    else if (default_clip_mode == "both") opt_anywhere ++= foundAdapters
-  }
-
-  override def summaryStats: Map[String, Any] = {
-    val trimR = """.*Trimmed reads: *(\d*) .*""".r
-    val tooShortR = """.*Too short reads: *(\d*) .*""".r
-    val tooLongR = """.*Too long reads: *(\d*) .*""".r
-    val adapterR = """Adapter '([C|T|A|G]*)'.*trimmed (\d*) times.""".r
-
-    val stats: mutable.Map[String, Int] = mutable.Map("trimmed" -> 0, "tooshort" -> 0, "toolong" -> 0)
-    val adapter_stats: mutable.Map[String, List[Any]] = mutable.Map()
-
-    if (stats_output.exists) for (line <- Source.fromFile(stats_output).getLines()) {
-      line match {
-        case trimR(m)     => stats += ("trimmed" -> m.toInt)
-        case tooShortR(m) => stats += ("tooshort" -> m.toInt)
-        case tooLongR(m)  => stats += ("toolong" -> m.toInt)
-        case adapterR(adapter, count) =>
-          val adapterName = fastqc.foundAdapters.find(_.seq == adapter) match {
-            case None    => "unknown"
-            case Some(a) => a.name
-          }
-          adapter_stats += (adapterName -> List(adapter, count.toInt))
-        case _ =>
-      }
-    }
-
-    Map("num_reads_affected" -> stats("trimmed"),
-      "num_reads_discarded_too_short" -> stats("tooshort"),
-      "num_reads_discarded_too_long" -> stats("toolong"),
-      "adapters" -> adapter_stats.toMap
-    )
-  }
-  override def cmdLine = {
-    if (opt_adapter.nonEmpty || opt_anywhere.nonEmpty || opt_front.nonEmpty) {
-      analysisName = getClass.getSimpleName
-      super.cmdLine
-    } else {
-      analysisName = getClass.getSimpleName + "-ln"
-      Ln(this, fastq_input, fastq_output, relative = true).cmd
-    }
-  }
-}
-
-object Cutadapt {
-  def apply(root: Configurable, input: File, output: File): Cutadapt = {
-    val cutadapt = new Cutadapt(root)
-    cutadapt.fastq_input = input
-    cutadapt.fastq_output = output
-    cutadapt.stats_output = new File(output.getAbsolutePath.substring(0, output.getAbsolutePath.lastIndexOf(".")) + ".stats")
-    cutadapt
-  }
-}
diff --git a/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Fastqc.scala b/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Fastqc.scala
index 60fe0da7fbdf0f2ac24ee08bd929c7b66bdaf164..6c444bed885b3b4219728bf38423156b3d545064 100644
--- a/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Fastqc.scala
+++ b/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Fastqc.scala
@@ -181,9 +181,6 @@ class Fastqc(root: Configurable) extends nl.lumc.sasc.biopet.extensions.Fastqc(r
     } else Set()
   }
 
-  @Output
-  var outputFiles: List[File] = Nil
-
   def summaryFiles: Map[String, File] = {
     val outputFiles = Map("plot_duplication_levels" -> ("Images" + File.separator + "duplication_levels.png"),
       "plot_kmer_profiles" -> ("Images" + File.separator + "kmer_profiles.png"),
diff --git a/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Flexiprep.scala b/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Flexiprep.scala
index 16362f9e1ee2010b549ff82728934330f85925cd..aeab29b7d697093726674b263f916faf77bccd7d 100644
--- a/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Flexiprep.scala
+++ b/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/Flexiprep.scala
@@ -16,10 +16,10 @@
 package nl.lumc.sasc.biopet.pipelines.flexiprep
 
 import nl.lumc.sasc.biopet.core.summary.SummaryQScript
-import nl.lumc.sasc.biopet.core.{ PipelineCommand, SampleLibraryTag }
-import nl.lumc.sasc.biopet.extensions.{ Pbzip2, Zcat, Gzip, Sickle }
-import nl.lumc.sasc.biopet.extensions.tools.{ SeqStat, FastqSync }
+import nl.lumc.sasc.biopet.core.{ BiopetFifoPipe, PipelineCommand, SampleLibraryTag }
+import nl.lumc.sasc.biopet.extensions.{ Zcat, Gzip }
 import nl.lumc.sasc.biopet.utils.config.Configurable
+import nl.lumc.sasc.biopet.extensions.tools.{ SeqStat, FastqSync }
 import org.broadinstitute.gatk.queue.QScript
 
 class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with SampleLibraryTag {
@@ -45,11 +45,8 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
 
   /** Returns files to store in summary */
   def summaryFiles: Map[String, File] = {
-    if (!skipTrim || !skipClip)
-      Map("input_R1" -> input_R1, "output_R1" -> outputFiles("output_R1_gzip")) ++
-        (if (paired) Map("input_R2" -> input_R2.get, "output_R2" -> outputFiles("output_R2_gzip")) else Map())
-    else Map("input_R1" -> input_R1) ++
-      (if (paired) Map("input_R2" -> input_R2.get) else Map())
+    Map("input_R1" -> input_R1, "output_R1" -> fastqR1Qc) ++
+      (if (paired) Map("input_R2" -> input_R2.get, "output_R2" -> fastqR2Qc.get) else Map())
   }
 
   /** returns settings to store in summary */
@@ -85,6 +82,9 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
 
     paired = input_R2.isDefined
 
+    inputFiles :+= new InputFile(input_R1)
+    input_R2.foreach(inputFiles :+= new InputFile(_))
+
     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 R1_name = input_R1.getName
@@ -107,8 +107,8 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
   def biopetScript() {
     runInitialJobs()
 
-    val out = if (paired) runTrimClip(outputFiles("fastq_input_R1"), Some(outputFiles("fastq_input_R2")), outputDir)
-    else runTrimClip(outputFiles("fastq_input_R1"), outputDir)
+    if (paired) runTrimClip(input_R1, input_R2, outputDir)
+    else runTrimClip(input_R1, outputDir)
 
     val R1_files = for ((k, v) <- outputFiles if k.endsWith("output_R1")) yield v
     val R2_files = for ((k, v) <- outputFiles if k.endsWith("output_R2")) yield v
@@ -117,8 +117,8 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
 
   /** Add init non chunkable jobs */
   def runInitialJobs() {
-    outputFiles += ("fastq_input_R1" -> extractIfNeeded(input_R1, outputDir))
-    if (paired) outputFiles += ("fastq_input_R2" -> extractIfNeeded(input_R2.get, outputDir))
+    outputFiles += ("fastq_input_R1" -> input_R1)
+    if (paired) outputFiles += ("fastq_input_R2" -> input_R2.get)
 
     fastqc_R1 = Fastqc(this, input_R1, new File(outputDir, R1_name + ".fastqc/"))
     add(fastqc_R1)
@@ -131,9 +131,26 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
       addSummarizable(fastqc_R2, "fastqc_R2")
       outputFiles += ("fastqc_R2" -> fastqc_R2.output)
     }
+
+    val seqstat_R1 = SeqStat(this, input_R1, outputDir)
+    seqstat_R1.isIntermediate = true
+    add(seqstat_R1)
+    addSummarizable(seqstat_R1, "seqstat_R1")
+
+    if (paired) {
+      val seqstat_R2 = SeqStat(this, input_R2.get, outputDir)
+      seqstat_R2.isIntermediate = true
+      add(seqstat_R2)
+      addSummarizable(seqstat_R2, "seqstat_R2")
+    }
   }
 
-  //TODO: Refactor need to combine all this functions
+  def fastqR1Qc = if (paired)
+    new File(outputDir, s"${sampleId.getOrElse("x")}-${libId.getOrElse("x")}.R1.qc.sync.fq.gz")
+  else new File(outputDir, s"${sampleId.getOrElse("x")}-${libId.getOrElse("x")}.R1.qc.fq.gz")
+  def fastqR2Qc = if (paired)
+    Some(new File(outputDir, s"${sampleId.getOrElse("x")}-${libId.getOrElse("x")}.R2.qc.sync.fq.gz"))
+  else None
 
   /** Adds all chunkable jobs of flexiprep */
   def runTrimClip(R1_in: File, outDir: File, chunk: String): (File, Option[File], List[File]) =
@@ -150,111 +167,75 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
   /** Adds all chunkable jobs of flexiprep */
   def runTrimClip(R1_in: File, R2_in: Option[File], outDir: File, chunkarg: String): (File, Option[File], List[File]) = {
     val chunk = if (chunkarg.isEmpty || chunkarg.endsWith("_")) chunkarg else chunkarg + "_"
-    var results: Map[String, File] = Map()
 
     var R1 = R1_in
     var R2 = R2_in
-    var deps_R1 = R1 :: Nil
-    var deps_R2 = if (paired) R2.get :: Nil else Nil
-    def deps: List[File] = deps_R1 ::: deps_R2
-
-    val seqtkSeq_R1 = SeqtkSeq(this, R1, swapExt(outDir, R1, R1_ext, ".sanger" + R1_ext), fastqc_R1)
-    seqtkSeq_R1.isIntermediate = true
-    add(seqtkSeq_R1)
-    addSummarizable(seqtkSeq_R1, "seqtkSeq_R1")
-    R1 = seqtkSeq_R1.output
-    deps_R1 ::= R1
-
-    if (paired) {
-      val seqtkSeq_R2 = SeqtkSeq(this, R2.get, swapExt(outDir, R2.get, R2_ext, ".sanger" + R2_ext), fastqc_R2)
-      seqtkSeq_R2.isIntermediate = true
-      add(seqtkSeq_R2)
-      addSummarizable(seqtkSeq_R2, "seqtkSeq_R2")
-      R2 = Some(seqtkSeq_R2.output)
-      deps_R2 ::= R2.get
-    }
+    def deps: List[File] = Nil
 
-    val seqstat_R1 = SeqStat(this, R1, outDir)
-    seqstat_R1.isIntermediate = true
-    seqstat_R1.deps = deps_R1
-    add(seqstat_R1)
-    addSummarizable(seqstat_R1, "seqstat_R1")
+    val qcCmdR1 = new QcCommand(this, fastqc_R1)
+    qcCmdR1.input = R1_in
+    qcCmdR1.read = "R1"
+    qcCmdR1.output = if (paired) new File(fastqR1Qc.getAbsolutePath.stripSuffix(".gz"))
+    else fastqR1Qc
+    qcCmdR1.deps :+= fastqc_R1.output
+    qcCmdR1.isIntermediate = paired || !keepQcFastqFiles
+    addSummarizable(qcCmdR1, "qc_command_R1")
 
     if (paired) {
-      val seqstat_R2 = SeqStat(this, R2.get, outDir)
-      seqstat_R2.isIntermediate = true
-      seqstat_R2.deps = deps_R2
-      add(seqstat_R2)
-      addSummarizable(seqstat_R2, "seqstat_R2")
-    }
-
-    if (!skipClip) { // Adapter clipping
-
-      val cutadapt_R1 = Cutadapt(this, R1, swapExt(outDir, R1, R1_ext, ".clip" + R1_ext))
-      cutadapt_R1.fastqc = fastqc_R1
-      cutadapt_R1.isIntermediate = true
-      cutadapt_R1.deps = deps_R1
-      add(cutadapt_R1)
-      addSummarizable(cutadapt_R1, "clipping_R1")
-      R1 = cutadapt_R1.fastq_output
-      deps_R1 ::= R1
-      outputFiles += ("cutadapt_R1_stats" -> cutadapt_R1.stats_output)
-
-      if (paired) {
-        val cutadapt_R2 = Cutadapt(this, R2.get, swapExt(outDir, R2.get, R2_ext, ".clip" + R2_ext))
-        outputFiles += ("cutadapt_R2_stats" -> cutadapt_R2.stats_output)
-        cutadapt_R2.fastqc = fastqc_R2
-        cutadapt_R2.isIntermediate = true
-        cutadapt_R2.deps = deps_R2
-        add(cutadapt_R2)
-        addSummarizable(cutadapt_R2, "clipping_R2")
-        R2 = Some(cutadapt_R2.fastq_output)
-        deps_R2 ::= R2.get
-
-        val fqSync = new FastqSync(this)
-        fqSync.refFastq = cutadapt_R1.fastq_input
-        fqSync.inputFastq1 = cutadapt_R1.fastq_output
-        fqSync.inputFastq2 = cutadapt_R2.fastq_output
-        fqSync.outputFastq1 = swapExt(outDir, R1, R1_ext, ".sync" + R1_ext)
-        fqSync.outputFastq2 = swapExt(outDir, R2.get, R2_ext, ".sync" + R2_ext)
-        fqSync.outputStats = swapExt(outDir, R1, R1_ext, ".sync.stats")
-        fqSync.deps :::= deps
-        add(fqSync)
-        addSummarizable(fqSync, "fastq_sync")
-        outputFiles += ("syncStats" -> fqSync.outputStats)
-        R1 = fqSync.outputFastq1
-        R2 = Some(fqSync.outputFastq2)
-        deps_R1 ::= R1
-        deps_R2 ::= R2.get
+      val qcCmdR2 = new QcCommand(this, fastqc_R2)
+      qcCmdR2.input = R2_in.get
+      qcCmdR2.output = new File(fastqR2Qc.get.getAbsolutePath.stripSuffix(".gz"))
+      qcCmdR2.read = "R2"
+      addSummarizable(qcCmdR2, "qc_command_R2")
+
+      qcCmdR1.compress = false
+      qcCmdR2.compress = false
+
+      val fqSync = new FastqSync(this)
+      fqSync.refFastq = R1_in
+      fqSync.inputFastq1 = qcCmdR1.output
+      fqSync.inputFastq2 = qcCmdR2.output
+      fqSync.outputFastq1 = fastqR1Qc
+      fqSync.outputFastq2 = fastqR2Qc.get
+      fqSync.outputStats = new File(outDir, s"${sampleId.getOrElse("x")}-${libId.getOrElse("x")}.sync.stats")
+
+      val pipe = new BiopetFifoPipe(this, fqSync :: Nil) {
+        override def configName = "qc-cmd"
+
+        override def beforeGraph(): Unit = {
+          fqSync.beforeGraph()
+          super.beforeGraph()
+        }
+
+        override def beforeCmd(): Unit = {
+          qcCmdR1.beforeCmd()
+          qcCmdR2.beforeCmd()
+          fqSync.beforeCmd()
+          commands = qcCmdR1.jobs ::: qcCmdR2.jobs ::: fqSync :: Nil
+          super.beforeCmd()
+        }
       }
-    }
 
-    if (!skipTrim) { // Quality trimming
-      val sickle = new Sickle(this)
-      sickle.input_R1 = R1
-      sickle.output_R1 = swapExt(outDir, R1, R1_ext, ".trim" + R1_ext)
-      if (paired) {
-        sickle.input_R2 = R2.get
-        sickle.output_R2 = swapExt(outDir, R2.get, R2_ext, ".trim" + R2_ext)
-        sickle.output_singles = swapExt(outDir, R2.get, R2_ext, ".trim.singles" + R1_ext)
-      }
-      sickle.output_stats = swapExt(outDir, R1, R1_ext, ".trim.stats")
-      sickle.deps = deps
-      sickle.isIntermediate = true
-      add(sickle)
-      addSummarizable(sickle, "trimming")
-      R1 = sickle.output_R1
-      if (paired) R2 = Some(sickle.output_R2)
+      pipe.deps ::= fastqc_R1.output
+      pipe.deps ::= fastqc_R2.output
+      pipe.isIntermediate = !keepQcFastqFiles
+      add(pipe)
+
+      addSummarizable(fqSync, "fastq_sync")
+      outputFiles += ("syncStats" -> fqSync.outputStats)
+      R1 = fqSync.outputFastq1
+      R2 = Some(fqSync.outputFastq2)
+    } else {
+      add(qcCmdR1)
+      R1 = qcCmdR1.output
     }
 
     val seqstat_R1_after = SeqStat(this, R1, outDir)
-    seqstat_R1_after.deps = deps_R1
     add(seqstat_R1_after)
     addSummarizable(seqstat_R1_after, "seqstat_R1_qc")
 
     if (paired) {
       val seqstat_R2_after = SeqStat(this, R2.get, outDir)
-      seqstat_R2_after.deps = deps_R2
       add(seqstat_R2_after)
       addSummarizable(seqstat_R2_after, "seqstat_R2_qc")
     }
@@ -266,23 +247,24 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
 
   /** Adds last non chunkable jobs */
   def runFinalize(fastq_R1: List[File], fastq_R2: List[File]) {
-    if (fastq_R1.length != fastq_R2.length && paired) throw new IllegalStateException("R1 and R2 file number is not the same")
-    val R1 = new File(outputDir, R1_name + ".qc" + R1_ext + ".gz")
-    val R2 = new File(outputDir, R2_name + ".qc" + R2_ext + ".gz")
+    if (fastq_R1.length != fastq_R2.length && paired)
+      throw new IllegalStateException("R1 and R2 file number is not the same")
 
     if (!skipTrim || !skipClip) {
-      add(Gzip(this, fastq_R1, R1), !keepQcFastqFiles)
-      if (paired) add(Gzip(this, fastq_R2, R2), !keepQcFastqFiles)
+      if (fastq_R1.length > 1) {
+        add(Zcat(this, fastq_R1, fastqR1Qc) | new Gzip(this) > fastqR1Qc)
+        if (paired) add(Zcat(this, fastq_R2, fastqR2Qc.get) | new Gzip(this) > fastqR2Qc.get)
+      }
 
-      outputFiles += ("output_R1_gzip" -> R1)
-      if (paired) outputFiles += ("output_R2_gzip" -> R2)
+      outputFiles += ("output_R1_gzip" -> fastqR1Qc)
+      if (paired) outputFiles += ("output_R2_gzip" -> fastqR2Qc.get)
 
-      fastqc_R1_after = Fastqc(this, R1, new File(outputDir, R1_name + ".qc.fastqc/"))
+      fastqc_R1_after = Fastqc(this, fastqR1Qc, new File(outputDir, R1_name + ".qc.fastqc/"))
       add(fastqc_R1_after)
       addSummarizable(fastqc_R1_after, "fastqc_R1_qc")
 
       if (paired) {
-        fastqc_R2_after = Fastqc(this, R2, new File(outputDir, R2_name + ".qc.fastqc/"))
+        fastqc_R2_after = Fastqc(this, fastqR2Qc.get, new File(outputDir, R2_name + ".qc.fastqc/"))
         add(fastqc_R2_after)
         addSummarizable(fastqc_R2_after, "fastqc_R2_qc")
       }
@@ -290,25 +272,6 @@ class Flexiprep(val root: Configurable) extends QScript with SummaryQScript with
 
     addSummaryJobs()
   }
-
-  /** Extracts file if file is compressed */
-  def extractIfNeeded(file: File, runDir: File): File = {
-    if (file == null) file
-    else if (file.getName.endsWith(".gz") || file.getName.endsWith(".gzip")) {
-      var newFile: File = swapExt(runDir, file, ".gz", "")
-      if (file.getName.endsWith(".gzip")) newFile = swapExt(runDir, file, ".gzip", "")
-      val zcatCommand = Zcat(this, file, newFile)
-      zcatCommand.isIntermediate = true
-      add(zcatCommand)
-      newFile
-    } else if (file.getName.endsWith(".bz2")) {
-      val newFile = swapExt(runDir, file, ".bz2", "")
-      val pbzip2 = Pbzip2(this, file, newFile)
-      pbzip2.isIntermediate = true
-      add(pbzip2)
-      newFile
-    } else file
-  }
 }
 
 object Flexiprep extends PipelineCommand
diff --git a/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/FlexiprepReport.scala b/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/FlexiprepReport.scala
index c4988cd1e1b131a98d2d4dc52086fef58085e1bc..075077872a314c2a510478ff8a151a4ed7f5ba9c 100644
--- a/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/FlexiprepReport.scala
+++ b/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/FlexiprepReport.scala
@@ -95,7 +95,7 @@ object FlexiprepReport extends ReportBuilder {
     def getLine(summary: Summary, sample: String, lib: String): String = {
       val beforeTotal = new SummaryValue(List("flexiprep", "stats", "seqstat_" + read, "reads", "num_total"),
         summary, Some(sample), Some(lib)).value.getOrElse(0).toString.toLong
-      val afterTotal = new SummaryValue(List("flexiprep", "stats", "seqstat_" + read + "_after", "reads", "num_total"),
+      val afterTotal = new SummaryValue(List("flexiprep", "stats", "seqstat_" + read + "_qc", "reads", "num_total"),
         summary, Some(sample), Some(lib)).value.getOrElse(0).toString.toLong
       val clippingDiscardedToShort = new SummaryValue(List("flexiprep", "stats", "clipping_" + read, "num_reads_discarded_too_short"),
         summary, Some(sample), Some(lib)).value.getOrElse(0).toString.toLong
@@ -152,7 +152,7 @@ object FlexiprepReport extends ReportBuilder {
     def getLine(summary: Summary, sample: String, lib: String): String = {
       val beforeTotal = new SummaryValue(List("flexiprep", "stats", "seqstat_" + read, "bases", "num_total"),
         summary, Some(sample), Some(lib)).value.getOrElse(0).toString.toLong
-      val afterTotal = new SummaryValue(List("flexiprep", "stats", "seqstat_" + read + "_after", "bases", "num_total"),
+      val afterTotal = new SummaryValue(List("flexiprep", "stats", "seqstat_" + read + "_qc", "bases", "num_total"),
         summary, Some(sample), Some(lib)).value.getOrElse(0).toString.toLong
 
       val sb = new StringBuffer()
diff --git a/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/QcCommand.scala b/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/QcCommand.scala
new file mode 100644
index 0000000000000000000000000000000000000000..3e516b638398f008435c5c5a982e09efcc335a86
--- /dev/null
+++ b/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/QcCommand.scala
@@ -0,0 +1,144 @@
+package nl.lumc.sasc.biopet.pipelines.flexiprep
+
+import java.io.File
+
+import nl.lumc.sasc.biopet.core.summary.{ SummaryQScript, Summarizable }
+import nl.lumc.sasc.biopet.core.{ BiopetFifoPipe, BiopetCommandLineFunction, BiopetPipe }
+import nl.lumc.sasc.biopet.extensions.{ Cat, Gzip, Sickle, Cutadapt }
+import nl.lumc.sasc.biopet.extensions.seqtk.SeqtkSeq
+import nl.lumc.sasc.biopet.utils.config.Configurable
+import org.broadinstitute.gatk.utils.commandline.{ Output, Input }
+
+/**
+ * Created by pjvan_thof on 9/22/15.
+ */
+class QcCommand(val root: Configurable, val fastqc: Fastqc) extends BiopetCommandLineFunction with Summarizable {
+
+  val flexiprep = root match {
+    case f: Flexiprep => f
+    case _            => throw new IllegalArgumentException("This class may only be used inside Flexiprep")
+  }
+
+  @Input(required = true)
+  var input: File = _
+
+  @Output(required = true)
+  var output: File = _
+
+  var compress = true
+
+  var read: String = _
+
+  override def defaultCoreMemory = 2.0
+  override def defaultThreads = 3
+
+  val seqtk = new SeqtkSeq(root)
+  var clip: Option[Cutadapt] = None
+  var trim: Option[Sickle] = None
+  var outputCommand: BiopetCommandLineFunction = null
+
+  def jobs = (Some(seqtk) :: clip :: trim :: Some(outputCommand) :: Nil).flatten
+
+  def summaryFiles = Map()
+
+  def summaryStats = Map()
+
+  override def addToQscriptSummary(qscript: SummaryQScript, name: String): Unit = {
+    clip match {
+      case Some(job) => qscript.addSummarizable(job, s"clipping_$read")
+      case _         =>
+    }
+    trim match {
+      case Some(job) => qscript.addSummarizable(job, s"trimming_$read")
+      case _         =>
+    }
+  }
+
+  override def beforeGraph(): Unit = {
+    super.beforeGraph()
+    require(read != null)
+    deps ::= input
+    outputFiles :+= output
+  }
+
+  override def beforeCmd(): Unit = {
+    seqtk.input = input
+    seqtk.output = new File(output.getParentFile, input.getName + ".seqtk.fq")
+    seqtk.Q = fastqc.encoding match {
+      case null => None
+      case enc if enc.contains("Sanger / Illumina 1.9") => None
+      case enc if enc.contains("Illumina <1.3") => Option(64)
+      case enc if enc.contains("Illumina 1.3") => Option(64)
+      case enc if enc.contains("Illumina 1.5") => Option(64)
+      case _ => None
+    }
+    if (seqtk.Q.isDefined) seqtk.V = true
+
+    clip = if (!flexiprep.skipClip) {
+      val foundAdapters = fastqc.foundAdapters.map(_.seq)
+      if (foundAdapters.nonEmpty) {
+        val cutadept = new Cutadapt(root)
+        cutadept.fastq_input = seqtk.output
+        cutadept.fastq_output = new File(output.getParentFile, input.getName + ".cutadept.fq")
+        cutadept.stats_output = new File(flexiprep.outputDir, s"${flexiprep.sampleId.getOrElse("x")}-${flexiprep.libId.getOrElse("x")}.$read.clip.stats")
+        if (cutadept.default_clip_mode == "3") cutadept.opt_adapter ++= foundAdapters
+        else if (cutadept.default_clip_mode == "5") cutadept.opt_front ++= foundAdapters
+        else if (cutadept.default_clip_mode == "both") cutadept.opt_anywhere ++= foundAdapters
+        Some(cutadept)
+      } else None
+    } else None
+
+    trim = if (!flexiprep.skipTrim) {
+      val sickle = new Sickle(root)
+      sickle.output_stats = new File(flexiprep.outputDir, s"${flexiprep.sampleId.getOrElse("x")}-${flexiprep.libId.getOrElse("x")}.$read.trim.stats")
+      sickle.input_R1 = clip match {
+        case Some(clip) => clip.fastq_output
+        case _          => seqtk.output
+      }
+      sickle.output_R1 = new File(output.getParentFile, input.getName + ".sickle.fq")
+      Some(sickle)
+    } else None
+
+    val outputFile = (clip, trim) match {
+      case (_, Some(trim)) => trim.output_R1
+      case (Some(clip), _) => clip.fastq_output
+      case _               => seqtk.output
+    }
+
+    if (compress) outputCommand = {
+      val gzip = new Gzip(root)
+      gzip.output = output
+      outputFile :<: gzip
+    }
+    else outputCommand = {
+      val cat = new Cat(root)
+      cat.input = outputFile :: Nil
+      cat.output = output
+      cat
+    }
+
+    seqtk.beforeGraph()
+    clip.foreach(_.beforeGraph())
+    trim.foreach(_.beforeGraph())
+    outputCommand.beforeGraph()
+
+    seqtk.beforeCmd()
+    clip.foreach(_.beforeCmd())
+    trim.foreach(_.beforeCmd())
+    outputCommand.beforeCmd()
+  }
+
+  def cmdLine = {
+
+    val cmd = (clip, trim) match {
+      case (Some(clip), Some(trim)) => new BiopetFifoPipe(root, seqtk :: clip :: trim :: outputCommand :: Nil)
+      case (Some(clip), _)          => new BiopetFifoPipe(root, seqtk :: clip :: outputCommand :: Nil)
+      case (_, Some(trim))          => new BiopetFifoPipe(root, seqtk :: trim :: outputCommand :: Nil)
+      case _                        => new BiopetFifoPipe(root, seqtk :: outputCommand :: Nil)
+    }
+
+    //val cmds = (Some(seqtk) :: clip :: trim :: Some(new Gzip(root)) :: Nil).flatten
+    cmd.beforeGraph()
+    cmd.commandLine
+  }
+}
diff --git a/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/SeqtkSeq.scala b/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/SeqtkSeq.scala
deleted file mode 100644
index 2105a3c4a2dbc1d2a563c35a6b5e92d752bbefeb..0000000000000000000000000000000000000000
--- a/public/flexiprep/src/main/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/SeqtkSeq.scala
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * Biopet is built on top of GATK Queue for building bioinformatic
- * pipelines. It is mainly intended to support LUMC SHARK cluster which is running
- * SGE. But other types of HPC that are supported by GATK Queue (such as PBS)
- * should also be able to execute Biopet tools and pipelines.
- *
- * Copyright 2014 Sequencing Analysis Support Core - Leiden University Medical Center
- *
- * Contact us at: sasc@lumc.nl
- *
- * A dual licensing mode is applied. The source code within this project that are
- * not part of GATK Queue is freely available for non-commercial use under an AGPL
- * license; For commercial users or users who do not want to follow the AGPL
- * license, please contact us to obtain a separate license.
- */
-package nl.lumc.sasc.biopet.pipelines.flexiprep
-
-import java.io.File
-
-import nl.lumc.sasc.biopet.utils.config.Configurable
-import nl.lumc.sasc.biopet.extensions.Ln
-
-class SeqtkSeq(root: Configurable) extends nl.lumc.sasc.biopet.extensions.seqtk.SeqtkSeq(root) {
-  var fastqc: Fastqc = _
-
-  override def beforeCmd() {
-    super.beforeCmd()
-    if (fastqc != null && Q.isEmpty) {
-      val encoding = fastqc.encoding
-      Q = encoding match {
-        case null => None
-        case enc if enc.contains("Sanger / Illumina 1.9") => None
-        case enc if enc.contains("Illumina <1.3") => Option(64)
-        case enc if enc.contains("Illumina 1.3") => Option(64)
-        case enc if enc.contains("Illumina 1.5") => Option(64)
-        case _ => None
-      }
-      if (Q.isDefined) V = true
-    }
-  }
-
-  override def beforeGraph() {
-    if (fastqc != null) deps ::= fastqc.output
-  }
-
-  override def cmdLine = {
-    if (Q.isDefined) {
-      analysisName = getClass.getSimpleName
-      super.cmdLine
-    } else {
-      analysisName = getClass.getSimpleName + "-ln"
-      Ln(this, input, output).cmd
-    }
-  }
-}
-
-object SeqtkSeq {
-  def apply(root: Configurable, input: File, output: File, fastqc: Fastqc = null): SeqtkSeq = {
-    val seqtkSeq = new SeqtkSeq(root)
-    seqtkSeq.input = input
-    seqtkSeq.output = output
-    seqtkSeq.fastqc = fastqc
-    seqtkSeq
-  }
-}
\ No newline at end of file
diff --git a/public/flexiprep/src/test/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/FlexiprepTest.scala b/public/flexiprep/src/test/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/FlexiprepTest.scala
index 2cb3f0e7b36175d9bf7633d7d639e6b03612976f..f7f9dc2ab2d916e22c0a6858663f1a43773f7f22 100644
--- a/public/flexiprep/src/test/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/FlexiprepTest.scala
+++ b/public/flexiprep/src/test/scala/nl/lumc/sasc/biopet/pipelines/flexiprep/FlexiprepTest.scala
@@ -67,8 +67,8 @@ class FlexiprepTest extends TestNGSuite with Matchers {
     ), Map(FlexiprepTest.executables.toSeq: _*))
     val flexiprep: Flexiprep = initPipeline(map)
 
-    flexiprep.input_R1 = new File(flexiprep.outputDir, "bla_R1.fq" + (if (zipped) ".gz" else ""))
-    if (paired) flexiprep.input_R2 = Some(new File(flexiprep.outputDir, "bla_R2.fq" + (if (zipped) ".gz" else "")))
+    flexiprep.input_R1 = (if (zipped) FlexiprepTest.r1Zipped else FlexiprepTest.r1)
+    if (paired) flexiprep.input_R2 = Some((if (zipped) FlexiprepTest.r2Zipped else FlexiprepTest.r2))
     flexiprep.sampleId = Some("1")
     flexiprep.libId = Some("1")
     flexiprep.script()
@@ -79,12 +79,6 @@ class FlexiprepTest extends TestNGSuite with Matchers {
       else if (paired && !(skipClip && skipTrim)) 4
       else if (!paired && !(skipClip && skipTrim)) 2)
     flexiprep.functions.count(_.isInstanceOf[SeqStat]) shouldBe (if (paired) 4 else 2)
-    flexiprep.functions.count(_.isInstanceOf[Zcat]) shouldBe (if (zipped) if (paired) 2 else 1 else 0)
-    flexiprep.functions.count(_.isInstanceOf[SeqtkSeq]) shouldBe (if (paired) 2 else 1)
-    flexiprep.functions.count(_.isInstanceOf[Cutadapt]) shouldBe (if (skipClip) 0 else if (paired) 2 else 1)
-    flexiprep.functions.count(_.isInstanceOf[FastqSync]) shouldBe (if (skipClip) 0 else if (paired) 1 else 0)
-    flexiprep.functions.count(_.isInstanceOf[Sickle]) shouldBe (if (skipTrim) 0 else 1)
-    flexiprep.functions.count(_.isInstanceOf[Gzip]) shouldBe (if (skipClip && skipTrim) 0 else if (paired) 2 else 1)
   }
 
   // remove temporary run directory all tests in the class have been run
@@ -95,6 +89,16 @@ class FlexiprepTest extends TestNGSuite with Matchers {
 
 object FlexiprepTest {
   val outputDir = Files.createTempDir()
+  new File(outputDir, "input").mkdirs()
+
+  val r1 = new File(outputDir, "input" + File.separator + "R1.fq")
+  Files.touch(r1)
+  val r2 = new File(outputDir, "input" + File.separator + "R2.fq")
+  Files.touch(r2)
+  val r1Zipped = new File(outputDir, "input" + File.separator + "R1.fq.gz")
+  Files.touch(r1Zipped)
+  val r2Zipped = new File(outputDir, "input" + File.separator + "R2.fq.gz")
+  Files.touch(r2Zipped)
 
   val executables = Map(
     "seqstat" -> Map("exe" -> "test"),
diff --git a/public/gentrap/src/main/scala/nl/lumc/sasc/biopet/pipelines/gentrap/Gentrap.scala b/public/gentrap/src/main/scala/nl/lumc/sasc/biopet/pipelines/gentrap/Gentrap.scala
index 6ae0e69bb4410870b79e91731ff3c98f89f44445..724470df1091228bbdaf928b49ae7024f2bb70bd 100644
--- a/public/gentrap/src/main/scala/nl/lumc/sasc/biopet/pipelines/gentrap/Gentrap.scala
+++ b/public/gentrap/src/main/scala/nl/lumc/sasc/biopet/pipelines/gentrap/Gentrap.scala
@@ -843,6 +843,8 @@ class Gentrap(val root: Configurable) extends QScript
       def addJobs(): Unit = {
         // create per-library alignment file
         addAll(mappingJob.functions)
+        // Input file checking
+        inputFiles :::= mappingJob.inputFiles
         // add bigwig track
         addAll(bam2wigModule.functions)
         qscript.addSummaryQScript(mappingJob)
diff --git a/public/gentrap/src/main/scala/nl/lumc/sasc/biopet/pipelines/gentrap/extensions/CustomVarScan.scala b/public/gentrap/src/main/scala/nl/lumc/sasc/biopet/pipelines/gentrap/extensions/CustomVarScan.scala
index 1ce8465cae9c75dbcbed9c85374074202ff9b393..8871f481f3075d7eef52784583ccb5aadaa5b715 100644
--- a/public/gentrap/src/main/scala/nl/lumc/sasc/biopet/pipelines/gentrap/extensions/CustomVarScan.scala
+++ b/public/gentrap/src/main/scala/nl/lumc/sasc/biopet/pipelines/gentrap/extensions/CustomVarScan.scala
@@ -17,7 +17,7 @@ package nl.lumc.sasc.biopet.pipelines.gentrap.extensions
 
 import java.io.File
 
-import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
+import nl.lumc.sasc.biopet.core.{ Reference, BiopetCommandLineFunction }
 import nl.lumc.sasc.biopet.core.extensions.PythonCommandLineFunction
 import nl.lumc.sasc.biopet.utils.config.Configurable
 import nl.lumc.sasc.biopet.extensions.samtools.SamtoolsMpileup
@@ -28,16 +28,13 @@ import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
 /** Ad-hoc extension for VarScan variant calling that involves 6-command pipe */
 // FIXME: generalize piping instead of building something by hand like this!
 // Better to do everything quick and dirty here rather than something half-implemented with the objects
-class CustomVarScan(val root: Configurable) extends BiopetCommandLineFunction { wrapper =>
+class CustomVarScan(val root: Configurable) extends BiopetCommandLineFunction with Reference { wrapper =>
 
   override def configName = "customvarscan"
 
   @Input(doc = "Input BAM file", required = true)
   var input: File = null
 
-  @Input(doc = "Reference FASTA file", required = true)
-  var reference: File = config("reference")
-
   @Output(doc = "Output VCF file", required = true)
   var output: File = null
 
@@ -49,7 +46,6 @@ class CustomVarScan(val root: Configurable) extends BiopetCommandLineFunction {
     this.input = List(wrapper.input)
     override def configName = wrapper.configName
     disableBaq = true
-    reference = config("reference")
     depth = Option(1000000)
     outputMappingQuality = true
   }
@@ -92,7 +88,9 @@ class CustomVarScan(val root: Configurable) extends BiopetCommandLineFunction {
   }
 
   override def beforeGraph(): Unit = {
+    super.beforeGraph()
     require(output.toString.endsWith(".gz"), "Output must have a .gz file extension")
+    deps :+= referenceFasta()
   }
 
   def cmdLine: String = {
diff --git a/public/gentrap/src/test/scala/nl/lumc/sasc/biopet/pipelines/gentrap/GentrapTest.scala b/public/gentrap/src/test/scala/nl/lumc/sasc/biopet/pipelines/gentrap/GentrapTest.scala
index 140db66fd62dd850365b27137cc3df0891bd38a7..2b2ddaf259e8fa5ad382ef1aca1337826ecf0ad8 100644
--- a/public/gentrap/src/test/scala/nl/lumc/sasc/biopet/pipelines/gentrap/GentrapTest.scala
+++ b/public/gentrap/src/test/scala/nl/lumc/sasc/biopet/pipelines/gentrap/GentrapTest.scala
@@ -43,8 +43,8 @@ class GentrapTest extends TestNGSuite with Matchers {
 
   /** Convenience method for making library config */
   private def makeLibConfig(idx: Int, paired: Boolean = true) = {
-    val files = Map("R1" -> "test_R1.fq")
-    if (paired) (s"lib_$idx", files ++ Map("R2" -> "test_R2.fq"))
+    val files = Map("R1" -> GentrapTest.inputTouch("test_R1.fq"))
+    if (paired) (s"lib_$idx", files ++ Map("R2" -> GentrapTest.inputTouch("test_R2.fq")))
     else (s"lib_$idx", files)
   }
 
@@ -179,6 +179,12 @@ class GentrapTest extends TestNGSuite with Matchers {
 
 object GentrapTest {
   val outputDir = Files.createTempDir()
+  new File(outputDir, "input").mkdirs()
+  def inputTouch(name: String): String = {
+    val file = new File(outputDir, "input" + File.separator + name)
+    Files.touch(file)
+    file.getAbsolutePath
+  }
 
   private def copyFile(name: String): Unit = {
     val is = getClass.getResourceAsStream("/" + name)
diff --git a/public/mapping/src/main/scala/nl/lumc/sasc/biopet/pipelines/mapping/Mapping.scala b/public/mapping/src/main/scala/nl/lumc/sasc/biopet/pipelines/mapping/Mapping.scala
index ca064c97646697b62797e47c08e2cea1dce749bc..aeff9d559027f53cb1ab2715b0119f2f32451421 100644
--- a/public/mapping/src/main/scala/nl/lumc/sasc/biopet/pipelines/mapping/Mapping.scala
+++ b/public/mapping/src/main/scala/nl/lumc/sasc/biopet/pipelines/mapping/Mapping.scala
@@ -136,6 +136,9 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
     require(sampleId.isDefined, "Missing sample ID on mapping module")
     require(libId.isDefined, "Missing library ID on mapping module")
 
+    inputFiles :+= new InputFile(input_R1)
+    input_R2.foreach(inputFiles :+= new InputFile(_))
+
     paired = input_R2.isDefined
 
     if (readgroupId == null) readgroupId = sampleId.get + "-" + libId.get
@@ -172,26 +175,14 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
     var fastq_R1_output: List[File] = Nil
     var fastq_R2_output: List[File] = Nil
 
-    def removeGz(file: File): File = {
-      val absPath = file.getAbsolutePath
-      if (absPath.endsWith(".gz")) new File(absPath.substring(0, absPath.lastIndexOf(".gz")))
-      else if (absPath.endsWith(".gzip")) new File(absPath.substring(0, absPath.lastIndexOf(".gzip")))
-      else file
-    }
-
     val chunks: Map[File, (File, Option[File])] = {
-      if (chunking) {
-        (for (t <- 1 to numberChunks.getOrElse(1)) yield {
-          val chunkDir = new File(outputDir, "chunks" + File.separator + t)
-          chunkDir -> (removeGz(new File(chunkDir, input_R1.getName)),
-            if (paired) Some(removeGz(new File(chunkDir, input_R2.get.getName))) else None)
-        }).toMap
-      } else if (skipFlexiprep) {
-        Map(outputDir -> (
-          extractIfNeeded(input_R1, flexiprep.outputDir),
-          if (paired) Some(extractIfNeeded(input_R2.get, outputDir)) else None)
-        )
-      } else Map(outputDir -> (flexiprep.outputFiles("fastq_input_R1"), flexiprep.outputFiles.get("fastq_input_R2")))
+      if (chunking) (for (t <- 1 to numberChunks.getOrElse(1)) yield {
+        val chunkDir = new File(outputDir, "chunks" + File.separator + t)
+        chunkDir -> (new File(chunkDir, input_R1.getName),
+          if (paired) Some(new File(chunkDir, input_R2.get.getName)) else None)
+      }).toMap
+      else if (skipFlexiprep) Map(outputDir -> (input_R1, if (paired) input_R2 else None))
+      else Map(outputDir -> (flexiprep.input_R1, flexiprep.input_R2))
     }
 
     if (chunking) {
@@ -239,7 +230,7 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
         case _            => throw new IllegalStateException("Option aligner: '" + aligner + "' is not valid")
       }
       if (chunking && numberChunks.getOrElse(1) > 1 && config("chunk_metrics", default = false))
-        addAll(BamMetrics(this, outputBam, new File(chunkDir, "metrics")).functions)
+        addAll(BamMetrics(this, outputBam, new File(chunkDir, "metrics"), sampleId, libId).functions)
     }
     if (!skipFlexiprep) {
       flexiprep.runFinalize(fastq_R1_output, fastq_R2_output)
@@ -260,7 +251,7 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
     }
 
     if (!skipMetrics) {
-      val bamMetrics = BamMetrics(this, bamFile, new File(outputDir, "metrics"))
+      val bamMetrics = BamMetrics(this, bamFile, new File(outputDir, "metrics"), sampleId, libId)
       addAll(bamMetrics.functions)
       addSummaryQScript(bamMetrics)
     }
@@ -328,13 +319,10 @@ class Mapping(val root: Configurable) extends QScript with SummaryQScript with S
     if (paired) bwaCommand.R2 = R2.get
     bwaCommand.deps = deps
     bwaCommand.R = Some(getReadGroupBwa)
-    bwaCommand.output = swapExt(output.getParent, output, ".bam", ".sam")
-    bwaCommand.isIntermediate = true
-    add(bwaCommand)
-    val sortSam = SortSam(this, bwaCommand.output, output)
-    if (chunking || !skipMarkduplicates) sortSam.isIntermediate = true
-    add(sortSam)
-    sortSam.output
+    val sortSam = new SortSam(this)
+    sortSam.output = output
+    add(bwaCommand | sortSam, chunking || !skipMarkduplicates)
+    output
   }
 
   def addGsnap(R1: File, R2: Option[File], output: File, deps: List[File]): File = {
diff --git a/public/mapping/src/test/scala/nl/lumc/sasc/biopet/pipelines/mapping/MappingTest.scala b/public/mapping/src/test/scala/nl/lumc/sasc/biopet/pipelines/mapping/MappingTest.scala
index 849bffcb6998f31e8d527af465de68775b6e11a4..710ff17cb665d8bf41c4b1bb41eb7dceb9c81060 100644
--- a/public/mapping/src/test/scala/nl/lumc/sasc/biopet/pipelines/mapping/MappingTest.scala
+++ b/public/mapping/src/test/scala/nl/lumc/sasc/biopet/pipelines/mapping/MappingTest.scala
@@ -22,7 +22,7 @@ import nl.lumc.sasc.biopet.utils.config.Config
 import nl.lumc.sasc.biopet.extensions._
 import nl.lumc.sasc.biopet.extensions.bwa.{ BwaAln, BwaMem, BwaSampe, BwaSamse }
 import nl.lumc.sasc.biopet.extensions.picard.{ AddOrReplaceReadGroups, MarkDuplicates, MergeSamFiles, SortSam }
-import nl.lumc.sasc.biopet.pipelines.flexiprep.{ Cutadapt, Fastqc, SeqtkSeq }
+import nl.lumc.sasc.biopet.pipelines.flexiprep.Fastqc
 import nl.lumc.sasc.biopet.extensions.tools.{ FastqSync, SeqStat }
 import nl.lumc.sasc.biopet.utils.ConfigUtils
 import org.apache.commons.io.FileUtils
@@ -79,11 +79,11 @@ class MappingTest extends TestNGSuite with Matchers {
     val mapping: Mapping = initPipeline(map)
 
     if (zipped) {
-      mapping.input_R1 = new File(mapping.outputDir, "bla_R1.fq.gz")
-      if (paired) mapping.input_R2 = Some(new File(mapping.outputDir, "bla_R2.fq.gz"))
+      mapping.input_R1 = MappingTest.r1Zipped
+      if (paired) mapping.input_R2 = Some(MappingTest.r2Zipped)
     } else {
-      mapping.input_R1 = new File(mapping.outputDir, "bla_R1.fq")
-      if (paired) mapping.input_R2 = Some(new File(mapping.outputDir, "bla_R2.fq"))
+      mapping.input_R1 = MappingTest.r1
+      if (paired) mapping.input_R2 = Some(MappingTest.r2)
     }
     mapping.sampleId = Some("1")
     mapping.libId = Some("1")
@@ -91,16 +91,8 @@ class MappingTest extends TestNGSuite with Matchers {
 
     //Flexiprep
     mapping.functions.count(_.isInstanceOf[Fastqc]) shouldBe (if (skipFlexiprep) 0 else if (paired) 4 else 2)
-    mapping.functions.count(_.isInstanceOf[Zcat]) shouldBe (if (!zipped || (chunks > 1 && skipFlexiprep)) 0 else if (paired) 2 else 1)
-    mapping.functions.count(_.isInstanceOf[SeqStat]) shouldBe ((if (skipFlexiprep) 0 else if (paired) 4 else 2) * chunks)
-    mapping.functions.count(_.isInstanceOf[SeqtkSeq]) shouldBe ((if (skipFlexiprep) 0 else if (paired) 2 else 1) * chunks)
-    mapping.functions.count(_.isInstanceOf[Cutadapt]) shouldBe ((if (skipFlexiprep) 0 else if (paired) 2 else 1) * chunks)
-    mapping.functions.count(_.isInstanceOf[FastqSync]) shouldBe ((if (skipFlexiprep) 0 else if (paired && !skipFlexiprep) 1 else 0) * chunks)
-    mapping.functions.count(_.isInstanceOf[Sickle]) shouldBe ((if (skipFlexiprep) 0 else 1) * chunks)
-    mapping.functions.count(_.isInstanceOf[Gzip]) shouldBe (if (skipFlexiprep) 0 else if (paired) 2 else 1)
 
     //aligners
-    mapping.functions.count(_.isInstanceOf[BwaMem]) shouldBe ((if (aligner == "bwa-mem") 1 else 0) * chunks)
     mapping.functions.count(_.isInstanceOf[BwaAln]) shouldBe ((if (aligner == "bwa-aln") if (paired) 2 else 1 else 0) * chunks)
     mapping.functions.count(_.isInstanceOf[BwaSampe]) shouldBe ((if (aligner == "bwa-aln") if (paired) 1 else 0 else 0) * chunks)
     mapping.functions.count(_.isInstanceOf[BwaSamse]) shouldBe ((if (aligner == "bwa-aln") if (paired) 0 else 1 else 0) * chunks)
@@ -116,7 +108,7 @@ class MappingTest extends TestNGSuite with Matchers {
     }
 
     if (aligner != "tophat") { // FIXME
-      mapping.functions.count(_.isInstanceOf[SortSam]) shouldBe ((if (sort == "sortsam") 1 else 0) * chunks)
+      //mapping.functions.count(_.isInstanceOf[SortSam]) shouldBe ((if (sort == "sortsam") 1 else 0) * chunks)
       mapping.functions.count(_.isInstanceOf[AddOrReplaceReadGroups]) shouldBe ((if (sort == "replacereadgroups") 1 else 0) * chunks)
       mapping.functions.count(_.isInstanceOf[MergeSamFiles]) shouldBe (if (skipMarkDuplicate && chunks > 1) 1 else 0)
       mapping.functions.count(_.isInstanceOf[MarkDuplicates]) shouldBe (if (skipMarkDuplicate) 0 else 1)
@@ -131,6 +123,16 @@ class MappingTest extends TestNGSuite with Matchers {
 
 object MappingTest {
   val outputDir = Files.createTempDir()
+  new File(outputDir, "input").mkdirs()
+
+  val r1 = new File(outputDir, "input" + File.separator + "R1.fq")
+  Files.touch(r1)
+  val r2 = new File(outputDir, "input" + File.separator + "R2.fq")
+  Files.touch(r2)
+  val r1Zipped = new File(outputDir, "input" + File.separator + "R1.fq.gz")
+  Files.touch(r1Zipped)
+  val r2Zipped = new File(outputDir, "input" + File.separator + "R2.fq.gz")
+  Files.touch(r2Zipped)
 
   private def copyFile(name: String): Unit = {
     val is = getClass.getResourceAsStream("/" + name)
diff --git a/public/pom.xml b/public/pom.xml
index cf2ea52f0c710db8abf2ce1c1202a7dd12d80dd0..2c84b8058ac0923d99a58a0868ff85567abc6fd7 100644
--- a/public/pom.xml
+++ b/public/pom.xml
@@ -44,7 +44,7 @@
         <module>biopet-utils</module>
         <module>biopet-tools</module>
         <module>biopet-tools-extensions</module>
-        <module>biopet-extentsions</module>
+        <module>biopet-extensions</module>
         <module>biopet-tools-package</module>
     </modules>
 
diff --git a/public/sage/src/main/scala/nl/lumc/sasc/biopet/pipelines/sage/Sage.scala b/public/sage/src/main/scala/nl/lumc/sasc/biopet/pipelines/sage/Sage.scala
index dc1e216a6f3b90fb88dd68467a6fdda06e0f2b0e..c8b81c0c4d31d6424db74390390c758096478838 100644
--- a/public/sage/src/main/scala/nl/lumc/sasc/biopet/pipelines/sage/Sage.scala
+++ b/public/sage/src/main/scala/nl/lumc/sasc/biopet/pipelines/sage/Sage.scala
@@ -89,6 +89,8 @@ class Sage(val root: Configurable) extends QScript with MultiSampleQScript {
       mapping.sampleId = Some(sampleId)
 
       protected def addJobs(): Unit = {
+        inputFiles :+= new InputFile(inputFastq, config("R1_md5"))
+
         flexiprep.outputDir = new File(libDir, "flexiprep/")
         flexiprep.input_R1 = inputFastq
         flexiprep.init()
diff --git a/public/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaTrait.scala b/public/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaTrait.scala
index 3f65bf2a20864e2017f512981daa0d37aca52772..dafb2e1ccc5a72807aa37cc6858711afbfe78c23 100644
--- a/public/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaTrait.scala
+++ b/public/shiva/src/main/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaTrait.scala
@@ -136,51 +136,56 @@ trait ShivaTrait extends MultiSampleQScript with SummaryQScript with Reference {
           case (true, _) => mapping.foreach(mapping => {
             mapping.input_R1 = config("R1")
             mapping.input_R2 = config("R2")
+            inputFiles :+= new InputFile(mapping.input_R1, config("R1_md5"))
+            mapping.input_R2.foreach(inputFiles :+= new InputFile(_, config("R2_md5")))
           })
-          case (false, true) => config("bam_to_fastq", default = false).asBoolean match {
-            case true =>
-              val samToFastq = SamToFastq(qscript, config("bam"),
-                new File(libDir, sampleId + "-" + libId + ".R1.fastq"),
-                new File(libDir, sampleId + "-" + libId + ".R2.fastq"))
-              samToFastq.isIntermediate = true
-              qscript.add(samToFastq)
-              mapping.foreach(mapping => {
-                mapping.input_R1 = samToFastq.fastqR1
-                mapping.input_R2 = Some(samToFastq.fastqR2)
-              })
-            case false =>
-              val inputSam = SamReaderFactory.makeDefault.open(config("bam"))
-              val readGroups = inputSam.getFileHeader.getReadGroups
-
-              val readGroupOke = readGroups.forall(readGroup => {
-                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")
-                readGroup.getSample == sampleId && readGroup.getLibrary == libId
-              })
-              inputSam.close()
-
-              if (!readGroupOke) {
-                if (config("correct_readgroups", default = false).asBoolean) {
-                  logger.info("Correcting readgroups, file:" + config("bam"))
-                  val aorrg = AddOrReplaceReadGroups(qscript, config("bam"), bamFile.get)
-                  aorrg.RGID = sampleId + "-" + libId
-                  aorrg.RGLB = libId
-                  aorrg.RGSM = sampleId
-                  aorrg.isIntermediate = true
-                  qscript.add(aorrg)
-                } else throw new IllegalStateException("Sample readgroup and/or library of input bamfile is not correct, file: " + bamFile +
-                  "\nPlease note that it is possible to set 'correct_readgroups' to true in the config to automatic fix this")
-              } else {
-                val oldBamFile: File = config("bam")
-                val oldIndex: File = new File(oldBamFile.getAbsolutePath.stripSuffix(".bam") + ".bai")
-                val newIndex: File = new File(libDir, oldBamFile.getName.stripSuffix(".bam") + ".bai")
-                val baiLn = Ln(qscript, oldIndex, newIndex)
-                add(baiLn)
-
-                val bamLn = Ln(qscript, oldBamFile, bamFile.get)
-                bamLn.deps :+= baiLn.output
-                add(bamLn)
-              }
+          case (false, true) => {
+            inputFiles :+= new InputFile(config("bam"), config("bam_md5"))
+            config("bam_to_fastq", default = false).asBoolean match {
+              case true =>
+                val samToFastq = SamToFastq(qscript, config("bam"),
+                  new File(libDir, sampleId + "-" + libId + ".R1.fastq"),
+                  new File(libDir, sampleId + "-" + libId + ".R2.fastq"))
+                samToFastq.isIntermediate = true
+                qscript.add(samToFastq)
+                mapping.foreach(mapping => {
+                  mapping.input_R1 = samToFastq.fastqR1
+                  mapping.input_R2 = Some(samToFastq.fastqR2)
+                })
+              case false =>
+                val inputSam = SamReaderFactory.makeDefault.open(config("bam"))
+                val readGroups = inputSam.getFileHeader.getReadGroups
+
+                val readGroupOke = readGroups.forall(readGroup => {
+                  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")
+                  readGroup.getSample == sampleId && readGroup.getLibrary == libId
+                })
+                inputSam.close()
+
+                if (!readGroupOke) {
+                  if (config("correct_readgroups", default = false).asBoolean) {
+                    logger.info("Correcting readgroups, file:" + config("bam"))
+                    val aorrg = AddOrReplaceReadGroups(qscript, config("bam"), bamFile.get)
+                    aorrg.RGID = sampleId + "-" + libId
+                    aorrg.RGLB = libId
+                    aorrg.RGSM = sampleId
+                    aorrg.isIntermediate = true
+                    qscript.add(aorrg)
+                  } else throw new IllegalStateException("Sample readgroup and/or library of input bamfile is not correct, file: " + bamFile +
+                    "\nPlease note that it is possible to set 'correct_readgroups' to true in the config to automatic fix this")
+                } else {
+                  val oldBamFile: File = config("bam")
+                  val oldIndex: File = new File(oldBamFile.getAbsolutePath.stripSuffix(".bam") + ".bai")
+                  val newIndex: File = new File(libDir, oldBamFile.getName.stripSuffix(".bam") + ".bai")
+                  val baiLn = Ln(qscript, oldIndex, newIndex)
+                  add(baiLn)
+
+                  val bamLn = Ln(qscript, oldBamFile, bamFile.get)
+                  bamLn.deps :+= baiLn.output
+                  add(bamLn)
+                }
+            }
           }
           case _ => logger.warn("Sample: " + sampleId + "  Library: " + libId + ", no reads found")
         }
@@ -294,7 +299,7 @@ trait ShivaTrait extends MultiSampleQScript with SummaryQScript with Reference {
       addAll(vc.functions)
       addSummaryQScript(vc)
 
-      if (config("annotation", default = true).asBoolean) {
+      if (config("annotation", default = false).asBoolean) {
         val toucan = new Toucan(this)
         toucan.outputDir = new File(outputDir, "annotation")
         toucan.inputVCF = vc.finalFile
diff --git a/public/shiva/src/test/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaTest.scala b/public/shiva/src/test/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaTest.scala
index 56b6bf172b2d122b2ccd70818d3f9f92161e270d..53286ecde3d44e4e6ad91fe142a5740b4909ceca 100644
--- a/public/shiva/src/test/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaTest.scala
+++ b/public/shiva/src/test/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaTest.scala
@@ -62,7 +62,6 @@ class ShivaTest extends TestNGSuite with Matchers {
       ConfigUtils.mergeMaps(Map("multisample_variantcalling" -> multi,
         "single_sample_variantcalling" -> single,
         "library_variantcalling" -> library), m)
-
     }
 
     if (!sample1 && !sample2 && !sample3) { // When no samples
@@ -76,8 +75,6 @@ class ShivaTest extends TestNGSuite with Matchers {
       val numberLibs = (if (sample1) 1 else 0) + (if (sample2) 1 else 0) + (if (sample3) 2 else 0)
       val numberSamples = (if (sample1) 1 else 0) + (if (sample2) 1 else 0) + (if (sample3) 1 else 0)
 
-      pipeline.functions.count(_.isInstanceOf[BwaMem]) shouldBe numberLibs
-      pipeline.functions.count(_.isInstanceOf[SortSam]) shouldBe numberLibs
       pipeline.functions.count(_.isInstanceOf[MarkDuplicates]) shouldBe (numberLibs + (if (sample3) 1 else 0))
 
       pipeline.functions.count(_.isInstanceOf[VcfStats]) shouldBe (if (multi) 2 else 0) +
@@ -88,6 +85,12 @@ class ShivaTest extends TestNGSuite with Matchers {
 
 object ShivaTest {
   val outputDir = Files.createTempDir()
+  new File(outputDir, "input").mkdirs()
+  def inputTouch(name: String): String = {
+    val file = new File(outputDir, "input" + File.separator + name)
+    Files.touch(file)
+    file.getAbsolutePath
+  }
 
   private def copyFile(name: String): Unit = {
     val is = getClass.getResourceAsStream("/" + name)
@@ -131,8 +134,8 @@ object ShivaTest {
   val sample1 = Map(
     "samples" -> Map("sample1" -> Map("libraries" -> Map(
       "lib1" -> Map(
-        "R1" -> "1_1_R1.fq",
-        "R2" -> "1_1_R2.fq"
+        "R1" -> inputTouch("1_1_R1.fq"),
+        "R2" -> inputTouch("1_1_R2.fq")
       )
     )
     )))
@@ -140,8 +143,8 @@ object ShivaTest {
   val sample2 = Map(
     "samples" -> Map("sample2" -> Map("libraries" -> Map(
       "lib1" -> Map(
-        "R1" -> "2_1_R1.fq",
-        "R2" -> "2_1_R2.fq"
+        "R1" -> inputTouch("2_1_R1.fq"),
+        "R2" -> inputTouch("2_1_R2.fq")
       )
     )
     )))
@@ -149,12 +152,12 @@ object ShivaTest {
   val sample3 = Map(
     "samples" -> Map("sample3" -> Map("libraries" -> Map(
       "lib1" -> Map(
-        "R1" -> "3_1_R1.fq",
-        "R2" -> "3_1_R2.fq"
+        "R1" -> inputTouch("3_1_R1.fq"),
+        "R2" -> inputTouch("3_1_R2.fq")
       ),
       "lib2" -> Map(
-        "R1" -> "3_2_R1.fq",
-        "R2" -> "3_2_R2.fq"
+        "R1" -> inputTouch("3_2_R1.fq"),
+        "R2" -> inputTouch("3_2_R2.fq")
       )
     )
     )))
diff --git a/public/shiva/src/test/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaVariantcallingTest.scala b/public/shiva/src/test/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaVariantcallingTest.scala
index 0281d33f678804d7edd1620d204a0830d4f3201f..caeea0326d46e4b7673dae4a3d07f27c3cbd5f4e 100644
--- a/public/shiva/src/test/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaVariantcallingTest.scala
+++ b/public/shiva/src/test/scala/nl/lumc/sasc/biopet/pipelines/shiva/ShivaVariantcallingTest.scala
@@ -61,7 +61,7 @@ class ShivaVariantcallingTest extends TestNGSuite with Matchers {
     val map = Map("variantcallers" -> callers.toList)
     val pipeline = initPipeline(map)
 
-    pipeline.inputBams = (for (n <- 1 to bams) yield new File("bam_" + n + ".bam")).toList
+    pipeline.inputBams = (for (n <- 1 to bams) yield ShivaVariantcallingTest.inputTouch("bam_" + n + ".bam")).toList
 
     val illegalArgumentException = pipeline.inputBams.isEmpty || (!raw && !bcftools && !freebayes)
 
@@ -88,6 +88,12 @@ class ShivaVariantcallingTest extends TestNGSuite with Matchers {
 
 object ShivaVariantcallingTest {
   val outputDir = Files.createTempDir()
+  new File(outputDir, "input").mkdirs()
+  def inputTouch(name: String): File = {
+    val file = new File(outputDir, "input" + File.separator + name).getAbsoluteFile
+    Files.touch(file)
+    file
+  }
 
   private def copyFile(name: String): Unit = {
     val is = getClass.getResourceAsStream("/" + name)
diff --git a/public/toucan/src/main/scala/nl/lumc/sasc/biopet/pipelines/toucan/Toucan.scala b/public/toucan/src/main/scala/nl/lumc/sasc/biopet/pipelines/toucan/Toucan.scala
index 63188e25773568e33d86b524a4b00055fcead682..6ee0776713a5391296719ac6edc83819777fcf31 100644
--- a/public/toucan/src/main/scala/nl/lumc/sasc/biopet/pipelines/toucan/Toucan.scala
+++ b/public/toucan/src/main/scala/nl/lumc/sasc/biopet/pipelines/toucan/Toucan.scala
@@ -35,6 +35,7 @@ class Toucan(val root: Configurable) extends QScript with BiopetQScript with Sum
   var inputVCF: File = _
 
   def init(): Unit = {
+    inputFiles :+= new InputFile(inputVCF)
   }
 
   override def defaults = Map(
diff --git a/public/yamsvp/src/main/scala/nl/lumc/sasc/biopet/extensions/pindel/PindelConfig.scala b/public/yamsvp/src/main/scala/nl/lumc/sasc/biopet/extensions/pindel/PindelConfig.scala
index 55127e59f4be2b5e8248bfcffa45ae8cae3ffe5e..497fe21e342ed754e21f6be253b1ae5fdd0813fb 100644
--- a/public/yamsvp/src/main/scala/nl/lumc/sasc/biopet/extensions/pindel/PindelConfig.scala
+++ b/public/yamsvp/src/main/scala/nl/lumc/sasc/biopet/extensions/pindel/PindelConfig.scala
@@ -32,7 +32,7 @@ class PindelConfig(val root: Configurable) extends BiopetJavaCommandLineFunction
   @Argument(doc = "Insertsize")
   var insertsize: Option[Int] = _
 
-  override def commandLine = super.commandLine +
+  override def cmdLine = super.cmdLine +
     "-i" + required(input) +
     "-s" + required(insertsize) +
     "-o" + required(output)