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

Added default_clip_mode option

parent 302c6fff
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ class Cutadapt(val globalConfig: Config) extends CommandLineFunction {
def this() = this(new Config(Map()))
analysisName = "cutadapt"
val config: Config = Config.mergeConfigs(globalConfig.getAsConfig("cutadapt"), globalConfig)
logger.debug("Config for " + this.analysisName + ": " + config)
@Input(doc="Cutadapt exe", required=false)
var cutadapt_exe: File = new File(config.getAsString("exe","/usr/local/bin/cutadapt"))
......@@ -18,17 +19,22 @@ class Cutadapt(val globalConfig: Config) extends CommandLineFunction {
@Input(doc="Fastq contams file", required=false) var contams_file: File = _
@Output(doc="Output fastq file") var fastq_output: File = _
var default_clip_mode = config.getAsString("default_clip_mode", "3")
var opt_adapter: Set[String] = config.getAsListOfStrings("adapter", Nil).to[Set]
var opt_anywhere: Set[String] = config.getAsListOfStrings("anywhere", Nil).to[Set]
var opt_front: Set[String] = config.getAsListOfStrings("front", Nil).to[Set]
var opt_discard: Boolean = config.getAsBoolean("discard",false)
var opt_minimum_length: String = config.getAsInt("minimum_length", 1).toString
var opt_maximum_length: String = if (config.contains("maximum_length")) config.getAsInt("maximum_length").toString else null
var opt_maximum_length: String = config.getAsString("maximum_length", null)
def commandLine = {
def init() {
this.addJobReportBinding("version", getVersion)
this.getContamsFromFile
}
def commandLine = {
init()
if (!opt_adapter.isEmpty || !opt_anywhere.isEmpty || !opt_front.isEmpty) {
required(cutadapt_exe) +
// options
......@@ -53,7 +59,13 @@ class Cutadapt(val globalConfig: Config) extends CommandLineFunction {
if (contams_file.exists()) {
for (line <- fromFile(contams_file).getLines) {
var s: String = line.substring(line.lastIndexOf("\t")+1, line.size)
opt_adapter += s
if (default_clip_mode == "3") opt_adapter += s
else if (default_clip_mode == "5") opt_front += s
else if (default_clip_mode == "both") opt_anywhere += s
else {
opt_adapter += s
logger.warn("Option default_clip_mode should be '3', '5' or 'both', falling back to default: '3'")
}
logger.info("Adapter: " + s + " found in: " + fastq_input)
}
} else logger.warn("File : " + contams_file + " does not exist")
......@@ -61,11 +73,22 @@ class Cutadapt(val globalConfig: Config) extends CommandLineFunction {
}
private var version: String = _
def getVersion : String = {
if (version == null) {
val v: String = (cutadapt_exe + " --version").!!.replace("\n", "")
if (!v.isEmpty) version = v
var versionCommand = cutadapt_exe + " --version"
var versionRegex = """(.*)"""
def getVersion: String = getVersion(versionCommand, versionRegex)
def getVersion(cmd:String, regex:String) : String = {
val REG = regex.r
if (cmd.! != 0) {
logger.warn("Version command: '" + cmd + "' give a none-zero exit code, version not found")
return "NA"
}
for (line <- cmd.!!.split("\n")) {
line match {
case REG(m) => return m
case _ =>
}
}
return version
logger.warn("Version command: '" + cmd + "' give a exit code 0 but no version was found, executeble oke?")
return "NA"
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment