Skip to content

Commit

Permalink
Support validation stringency in out formatters.
Browse files Browse the repository at this point in the history
  • Loading branch information
heuermh authored and fnothaft committed Mar 27, 2018
1 parent 1bfddc6 commit 5328a8f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
Expand Up @@ -30,10 +30,13 @@ import scala.collection.mutable.ListBuffer

/**
* OutFormatter that reads streaming BED format.
*
* @param stringency Validation stringency. Defaults to ValidationStringency.STRICT.
*/
case class BEDOutFormatter() extends OutFormatter[Feature] {
case class BEDOutFormatter(
val stringency: ValidationStringency = ValidationStringency.STRICT) extends OutFormatter[Feature] {

val bedParser = new BEDParser
val stringency = ValidationStringency.STRICT

/**
* Reads features from an input stream in BED format.
Expand Down
Expand Up @@ -30,10 +30,13 @@ import scala.collection.mutable.ListBuffer

/**
* OutFormatter that reads streaming GFF3 format.
*
* @param stringency Validation stringency. Defaults to ValidationStringency.STRICT.
*/
case class GFF3OutFormatter() extends OutFormatter[Feature] {
case class GFF3OutFormatter(
val stringency: ValidationStringency = ValidationStringency.STRICT) extends OutFormatter[Feature] {

val gff3Parser = new GFF3Parser
val stringency = ValidationStringency.STRICT

/**
* Reads features from an input stream in GFF3 format.
Expand Down
Expand Up @@ -30,10 +30,13 @@ import scala.collection.mutable.ListBuffer

/**
* OutFormatter that reads streaming GTF format.
*
* @param stringency Validation stringency. Defaults to ValidationStringency.STRICT.
*/
case class GTFOutFormatter() extends OutFormatter[Feature] {
case class GTFOutFormatter(
val stringency: ValidationStringency = ValidationStringency.STRICT) extends OutFormatter[Feature] {

val gtfParser = new GTFParser
val stringency = ValidationStringency.STRICT

/**
* Reads features from an input stream in GTF format.
Expand Down
Expand Up @@ -42,28 +42,49 @@ import scala.collection.mutable.ListBuffer
* OutFormatter that reads streaming VCF.
*
* @param conf Hadoop configuration.
* @param stringency Validation stringency.
* @param optHeaderLines Optional accumulator for VCF header lines.
*/
case class VCFOutFormatter(
@transient conf: Configuration,
val stringency: ValidationStringency,
val optHeaderLines: Option[CollectionAccumulator[VCFHeaderLine]]) extends OutFormatter[VariantContext] with Logging {

private val nestAnn = VariantContextConverter.getNestAnnotationInGenotypesProperty(conf)

/**
* OutFormatter that reads streaming VCF. Java-friendly no-arg constructor.
* OutFormatter that reads streaming VCF. Defaults to ValidationStringency.LENIENT.
* Java-friendly no-arg constructor.
*
* @param conf Hadoop configuration.
*/
def this(conf: Configuration) = this(conf, None)
def this(conf: Configuration) = this(conf, ValidationStringency.LENIENT, None)

/**
* OutFormatter that reads streaming VCF. Java-friendly constructor.
*
* @param conf Hadoop configuration.
* @param acc Accumulator for VCF header lines.
*/
def this(conf: Configuration, acc: CollectionAccumulator[VCFHeaderLine]) = this(conf, Some(acc))
def this(conf: Configuration, stringency: ValidationStringency) = this(conf, stringency, None)

/**
* OutFormatter that reads streaming VCF. Defaults to ValidationStringency.LENIENT.
* Java-friendly constructor.
*
* @param conf Hadoop configuration.
* @param acc Accumulator for VCF header lines.
*/
def this(conf: Configuration, acc: CollectionAccumulator[VCFHeaderLine]) = this(conf, ValidationStringency.LENIENT, Some(acc))

/**
* OutFormatter that reads streaming VCF. Defaults to ValidationStringency.LENIENT.
* Java-friendly constructor.
*
* @param conf Hadoop configuration.
* @param optHeaderLines Optional accumulator for VCF header lines.
*/
def this(conf: Configuration, optHeaderLines: Option[CollectionAccumulator[VCFHeaderLine]]) = this(conf, ValidationStringency.LENIENT, optHeaderLines)

/**
* Reads VariantContexts from an input stream. Autodetects VCF format.
Expand All @@ -83,14 +104,14 @@ case class VCFOutFormatter(
val header = codec.readActualHeader(lri).asInstanceOf[VCFHeader]

// merge header lines with our supported header lines
val lines = cleanAndMixInSupportedLines(headerLines(header), ValidationStringency.LENIENT, log)
val lines = cleanAndMixInSupportedLines(headerLines(header), stringency, log)

// accumulate header lines if desired
optHeaderLines.map(accumulator => lines.foreach(line => accumulator.add(line)))

// make converter
val converter = new VariantContextConverter(lines,
ValidationStringency.LENIENT,
stringency,
nestAnn)

@tailrec def convertIterator(iter: AsciiLineReaderIterator,
Expand Down

0 comments on commit 5328a8f

Please sign in to comment.