Commit e82756e6 authored by Peter van 't Hof's avatar Peter van 't Hof

Switch to output classes for Arg parsing

parent 29b937d4
......@@ -22,7 +22,7 @@ import htsjdk.variant.variantcontext.writer.{
VariantContextWriterBuilder
}
import htsjdk.variant.vcf.{VCFFileReader, VCFHeaderLineCount, VCFHeaderLineType, VCFInfoHeaderLine}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import nl.lumc.sasc.biopet.utils.intervals.{BedRecord, BedRecordList}
import scala.collection.JavaConversions._
......@@ -51,9 +51,8 @@ object AnnotateVcfWithBed extends ToolCommand {
fieldName: String = null,
fieldDescription: String = "",
fieldType: String = "String")
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('I', "inputFile") required () unbounded () valueName "<vcf file>" action { (x, c) =>
c.copy(inputFile = x)
} text "Input VCF file. Mandatory field"
......
......@@ -17,7 +17,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.{File, PrintWriter}
import htsjdk.samtools.{SAMRecord, SamReaderFactory}
import nl.lumc.sasc.biopet.utils.{ConfigUtils, ToolCommand}
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ConfigUtils, ToolCommand}
import nl.lumc.sasc.biopet.utils.intervals.{BedRecord, BedRecordList}
import picard.annotation.{Gene, GeneAnnotationReader}
......@@ -35,9 +35,8 @@ object BaseCounter extends ToolCommand {
outputDir: File = null,
bamFile: File = null,
prefix: String = "output")
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('r', "refFlat") required () valueName "<file>" action { (x, c) =>
c.copy(refFlat = x)
} text "refFlat file. Mandatory"
......
......@@ -20,7 +20,7 @@ import htsjdk.samtools.SamReaderFactory
import htsjdk.samtools.reference.IndexedFastaSequenceFile
import htsjdk.variant.variantcontext.VariantContext
import htsjdk.variant.vcf.VCFFileReader
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import nl.lumc.sasc.biopet.utils.VcfUtils._
import scala.collection.JavaConversions._
......@@ -38,9 +38,8 @@ object BastyGenerateFasta extends ToolCommand {
minAD: Int = 8,
minDepth: Int = 8,
reference: File = null)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('V', "inputVcf") unbounded () valueName "<file>" action { (x, c) =>
c.copy(inputVcf = x)
} text "vcf file, needed for outputVariants and outputConsensusVariants" validate { x =>
......
......@@ -16,10 +16,10 @@ package nl.lumc.sasc.biopet.tools
import java.io.{File, PrintWriter}
import htsjdk.samtools.{SAMSequenceRecord, SamReaderFactory}
import nl.lumc.sasc.biopet.utils.ToolCommand
import scala.collection.JavaConversions._
import htsjdk.samtools.SamReaderFactory
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import scala.collection.JavaConversions._
import scala.io.Source
/**
......@@ -28,9 +28,8 @@ import scala.io.Source
object BedToInterval extends ToolCommand {
case class Args(inputFile: File = null, outputFile: File = null, bamFile: File = null)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('I', "inputFile") required () valueName "<file>" action { (x, c) =>
c.copy(inputFile = x)
}
......
......@@ -16,15 +16,15 @@ package nl.lumc.sasc.biopet.tools
import java.io.{File, PrintWriter}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import scala.collection.{SortedMap, mutable}
import scala.io.Source
object BedtoolsCoverageToCounts extends ToolCommand {
case class Args(input: File = null, output: File = null) extends AbstractArgs
case class Args(input: File = null, output: File = null)
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('I', "input") required () valueName "<file>" action { (x, c) =>
c.copy(input = x)
} text "Coverage file produced with bedtools"
......
......@@ -23,7 +23,7 @@ import htsjdk.variant.variantcontext.writer.{
VariantContextWriterBuilder
}
import htsjdk.variant.vcf.{VCFFileReader, VCFHeaderLineCount, VCFHeaderLineType, VCFInfoHeaderLine}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import scala.collection.JavaConversions._
import scala.collection.mutable
......@@ -49,9 +49,8 @@ object CheckAllelesVcfInBam extends ToolCommand {
samples: List[String] = Nil,
bamFiles: List[File] = Nil,
minMapQual: Int = 1)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('I', "inputFile") required () maxOccurs 1 valueName "<file>" action { (x, c) =>
c.copy(inputFile = x)
} text "VCF file"
......
......@@ -16,7 +16,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.{File, PrintWriter}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import scala.io.Source
......@@ -31,9 +31,8 @@ object DownloadNcbiAssembly extends ToolCommand {
contigNameHeader: Option[String] = None,
mustHaveOne: List[(String, String)] = List(),
mustNotHave: List[(String, String)] = List())
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('a', "assembly_report") required () unbounded () valueName "<file>" action {
(x, c) =>
c.copy(assemblyReport = x)
......
......@@ -19,7 +19,7 @@ import java.io.File
import htsjdk.samtools.{QueryInterval, SamReaderFactory, ValidationStringency}
import htsjdk.samtools.fastq.{BasicFastqWriter, FastqReader, FastqRecord}
import htsjdk.samtools.util.Interval
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import scala.collection.JavaConverters._
import scala.collection.mutable.{Set => MSet}
......@@ -181,10 +181,9 @@ object ExtractAlignedFastq extends ToolCommand {
outputFastq2: Option[File] = None,
minMapQ: Int = 0,
commonSuffixLength: Int = 0)
extends AbstractArgs
/** Command line argument parser */
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
head(s"""
|$commandName - Select aligned FASTQ records
......
......@@ -2,7 +2,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.{File, PrintWriter}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import nl.lumc.sasc.biopet.utils.annotation.Feature
import scala.io.Source
......@@ -15,9 +15,8 @@ object ExtractTagsFromGtf extends ToolCommand {
gtfFile: File = null,
tags: List[String] = Nil,
feature: Option[String] = None)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('o', "output") required () unbounded () valueName "<file>" action { (x, c) =>
c.copy(outputFile = x)
} text "Input refFlat file. Mandatory"
......
......@@ -17,7 +17,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.File
import htsjdk.samtools.fastq.{AsyncFastqWriter, BasicFastqWriter, FastqReader}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import scala.util.matching.Regex
import scala.collection.JavaConversions._
......@@ -33,9 +33,8 @@ object FastqFilter extends ToolCommand {
* @param outputFile output fastq files
*/
case class Args(inputFile: File = null, outputFile: File = null, idRegex: Option[Regex] = None)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('I', "inputFile") required () valueName "<file>" action { (x, c) =>
c.copy(inputFile = x)
} text "Path to input file"
......
......@@ -17,7 +17,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.File
import htsjdk.samtools.fastq.{AsyncFastqWriter, BasicFastqWriter, FastqReader}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
object FastqSplitter extends ToolCommand {
......@@ -26,9 +26,9 @@ object FastqSplitter extends ToolCommand {
* @param inputFile input fastq file
* @param outputFile output fastq files
*/
case class Args(inputFile: File = null, outputFile: List[File] = Nil) extends AbstractArgs
case class Args(inputFile: File = null, outputFile: List[File] = Nil)
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('I', "inputFile") required () valueName "<file>" action { (x, c) =>
c.copy(inputFile = x)
} text "Path to input file"
......
......@@ -17,7 +17,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.File
import htsjdk.samtools.fastq.{AsyncFastqWriter, BasicFastqWriter, FastqReader, FastqRecord}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import scala.annotation.tailrec
import scala.collection.JavaConverters._
......@@ -111,9 +111,8 @@ object FastqSync extends ToolCommand {
inputFastq2: File = new File(""),
outputFastq1: File = new File(""),
outputFastq2: File = new File(""))
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
head(s"""
|$commandName - Sync paired-end FASTQ files.
......
......@@ -16,7 +16,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.{File, PrintStream}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import scala.collection.mutable.ListBuffer
import scala.io.Source
......@@ -35,9 +35,8 @@ object FindOverlapMatch extends ToolCommand {
filterSameNames: Boolean = true,
rowSampleRegex: Option[Regex] = None,
columnSampleRegex: Option[Regex] = None)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('i', "input") required () unbounded () valueName "<file>" action { (x, c) =>
c.copy(inputMetrics = x)
} text "Input should be a table where the first row and column have the ID's, those can be different"
......
......@@ -14,19 +14,18 @@
*/
package nl.lumc.sasc.biopet.tools
import java.io.{PrintWriter, File}
import java.io.{File, PrintWriter}
import htsjdk.samtools.{QueryInterval, SAMRecord, SamReaderFactory, ValidationStringency}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import scala.collection.JavaConversions._
import scala.io.Source
object FindRepeatsPacBio extends ToolCommand {
case class Args(inputBam: File = null, outputFile: Option[File] = None, inputBed: File = null)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('I', "inputBam") required () maxOccurs 1 valueName "<file>" action { (x, c) =>
c.copy(inputBam = x)
} text "Path to input file"
......
......@@ -24,7 +24,7 @@ import htsjdk.variant.variantcontext.writer.{
}
import htsjdk.variant.variantcontext.{Allele, GenotypeBuilder, VariantContextBuilder}
import htsjdk.variant.vcf._
import nl.lumc.sasc.biopet.utils.{FastaUtils, ToolCommand}
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, FastaUtils, ToolCommand}
import scala.collection.JavaConversions._
import scala.io.Source
......@@ -41,9 +41,8 @@ object GensToVcf extends ToolCommand {
referenceFasta: File = null,
contig: String = null,
sortInput: Boolean = false)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('g', "inputGenotypes") required () maxOccurs 1 valueName "<file>" action { (x, c) =>
c.copy(inputGenotypes = x)
} text "Input genotypes"
......
package nl.lumc.sasc.biopet.tools
import nl.lumc.sasc.biopet.utils.{FastaUtils, ToolCommand}
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, FastaUtils, ToolCommand}
import java.io.{File, PrintWriter}
import nl.lumc.sasc.biopet.utils.annotation.{Exon, Feature, Gene, Transcript}
......@@ -14,9 +14,8 @@ import scala.io.Source
object GtfToRefflat extends ToolCommand {
case class Args(refFlat: File = null, gtfFile: File = null, referenceFasta: Option[File] = None)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('r', "refFlat") required () unbounded () valueName "<file>" action { (x, c) =>
c.copy(refFlat = x)
} text "Input refFlat file. Mandatory"
......
......@@ -18,7 +18,7 @@ import java.io.{File, PrintWriter}
import htsjdk.variant.variantcontext.VariantContext
import htsjdk.variant.vcf.VCFFileReader
import nl.lumc.sasc.biopet.utils.{VcfUtils, ToolCommand}
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand, VcfUtils}
import nl.lumc.sasc.biopet.utils.intervals.BedRecord
import scala.collection.JavaConversions._
......@@ -35,9 +35,8 @@ object GvcfToBed extends ToolCommand {
sample: Option[String] = None,
minGenomeQuality: Int = 0,
inverse: Boolean = false)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('I', "inputVcf") required () maxOccurs 1 valueName "<file>" action { (x, c) =>
c.copy(inputVcf = x)
} text "Input vcf file"
......
......@@ -20,7 +20,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.{File, PrintWriter}
import nl.lumc.sasc.biopet.utils.ConfigUtils._
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
......@@ -60,9 +60,8 @@ object KrakenReportToJson extends ToolCommand {
case class Args(krakenreport: File = null,
outputJson: Option[File] = None,
skipNames: Boolean = false)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
head(s"""
|$commandName - Convert Kraken-report (full) output to JSON
......
......@@ -23,7 +23,7 @@ import htsjdk.variant.variantcontext.writer.{
}
import htsjdk.variant.variantcontext.{Allele, VariantContext, VariantContextBuilder}
import htsjdk.variant.vcf.{VCFFileReader, VCFHeader}
import nl.lumc.sasc.biopet.utils.{FastaUtils, ToolCommand}
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, FastaUtils, ToolCommand}
import nl.lumc.sasc.biopet.utils.config.Configurable
import scala.collection.JavaConversions._
......@@ -32,9 +32,8 @@ import scala.collection.{SortedMap, mutable}
object MergeAlleles extends ToolCommand {
case class Args(inputFiles: List[File] = Nil, outputFile: File = null, reference: File = null)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('I', "inputVcf") minOccurs 2 required () unbounded () valueName "<file>" action {
(x, c) =>
c.copy(inputFiles = x :: c.inputFiles)
......
......@@ -14,9 +14,9 @@
*/
package nl.lumc.sasc.biopet.tools
import java.io.{PrintWriter, File}
import java.io.{File, PrintWriter}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import scala.io.Source
......@@ -27,9 +27,8 @@ object MergeOtuMaps extends ToolCommand {
case class Args(inputFiles: List[File] = Nil,
outputFile: File = null,
skipPrefix: List[String] = Nil)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('I', "input") minOccurs 2 required () unbounded () valueName "<file>" action {
(x, c) =>
c.copy(inputFiles = x :: c.inputFiles)
......
......@@ -16,7 +16,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.{BufferedWriter, File, FileWriter, OutputStreamWriter}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import scala.collection.mutable.{Set => MutSet}
import scala.io.{BufferedSource, Source}
......@@ -121,10 +121,9 @@ object MergeTables extends ToolCommand {
fallbackString: String = "-",
delimiter: Char = '\t',
out: File = new File("-"))
extends AbstractArgs
/** Command line argument parser */
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
import scopt.Read
......
......@@ -18,7 +18,7 @@ import java.io.{File, PrintWriter}
import cern.jet.random.Binomial
import cern.jet.random.engine.RandomEngine
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
......@@ -35,9 +35,8 @@ object MpileupToVcf extends ToolCommand {
ploidy: Int = 2,
seqError: Double = 0.005,
refCalls: Boolean = false)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('I', "input") valueName "<file>" action { (x, c) =>
c.copy(input = x)
} text "input, default is stdin"
......
......@@ -3,7 +3,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.{File, PrintWriter}
import htsjdk.samtools.SamReaderFactory
import nl.lumc.sasc.biopet.utils.{BamUtils, ToolCommand}
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, BamUtils, ToolCommand}
import nl.lumc.sasc.biopet.utils.intervals.BedRecordList
import scala.collection.JavaConversions._
......@@ -19,9 +19,8 @@ object MultiCoverage extends ToolCommand {
bamFiles: List[File] = Nil,
outputFile: File = null,
mean: Boolean = false)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('L', "bedFile") required () maxOccurs 1 unbounded () valueName "<file>" action {
(x, c) =>
c.copy(bedFile = x)
......
......@@ -2,7 +2,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.{File, PrintWriter}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import scala.io.Source
......@@ -17,9 +17,8 @@ object NcbiReportToContigMap extends ToolCommand {
contigNameHeader: String = null,
names: List[String] =
List("Sequence-Name", "UCSC-style-name", "GenBank-Accn", "RefSeq-Accn"))
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('a', "assembly_report") required () unbounded () valueName "<file>" action {
(x, c) =>
c.copy(assemblyReport = x)
......
......@@ -17,7 +17,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.File
import htsjdk.samtools.fastq.{AsyncFastqWriter, BasicFastqWriter, FastqReader, FastqRecord}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import nl.lumc.sasc.biopet.utils.config.Configurable
object PrefixFastq extends ToolCommand {
......@@ -28,9 +28,9 @@ object PrefixFastq extends ToolCommand {
* @param output output fastq file (can be zipper)
* @param seq Seq to prefix the reads with
*/
case class Args(input: File = null, output: File = null, seq: String = null) extends AbstractArgs
case class Args(input: File = null, output: File = null, seq: String = null)
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('i', "input") required () maxOccurs 1 valueName "<file>" action { (x, c) =>
c.copy(input = x)
}
......
......@@ -18,7 +18,7 @@ import java.io.{File, PrintWriter}
import java.util
import htsjdk.variant.vcf.VCFFileReader
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, ToolCommand}
import nl.lumc.sasc.biopet.utils.rscript.ScatterPlot
import nl.lumc.sasc.biopet.utils.intervals.{BedRecord, BedRecordList}
......@@ -32,9 +32,8 @@ object RegionAfCount extends ToolCommand {
outputPrefix: String = null,
scatterpPlot: Boolean = false,
vcfFiles: List[File] = Nil)
extends AbstractArgs
class OptParser extends AbstractOptParser {
class OptParser extends AbstractOptParser[Args](commandName) {
opt[File]('b', "bedFile") unbounded () required () maxOccurs 1 valueName "<file>" action {
(x, c) =>
c.copy(bedFile = x)
......
......@@ -2,7 +2,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.{File, PrintWriter}
import nl.lumc.sasc.biopet.utils.{FastaUtils, ToolCommand}
import nl.lumc.sasc.biopet.utils.{AbstractOptParser, FastaUtils, ToolCommand}
import nl.lumc.sasc.biopet.utils.annotation.Feature
import scala.io.Source
......@@ -15,9 +15,8 @@ object ReplaceContigsGtfFile extends ToolCommand {
output: File = null,
contigs: Map[String, String] = Map(),
writeAsGff: Boolean = false)
extends AbstractA