Class TransformingVcfLineParser

java.lang.Object
org.pharmgkb.parser.vcf.TransformingVcfLineParser
All Implemented Interfaces:
Closeable, AutoCloseable, VcfLineParser

public class TransformingVcfLineParser extends Object implements VcfLineParser, Closeable
Applies a transformation to a VCF file. This is a streaming VcfLineParser that applies a VcfTransformation and writes the VCF. More generally, can apply to a single VCF stream a set of transformations and corresponding writers.

Example:


   VcfTransformation transformation1 = new VcfTransformation() {
       public void transformMetadata(VcfMetadata metadata) {
           metadata.getRawProperties().put("Test", "123"); // adds ##Test=123
       }
   };
   VcfTransformation transformation2 = new VcfTransformation() {
       public void transformDataLine(VcfMetadata metadata, VcfPosition position, List<VcfSample> sampleData) {
           position.setQuality("0");
       }
   };
   TransformingVcfLineParser.Builder builder = new TransformingVcfLineParser.Builder();
   builder.addTransformation(transformation1, file1);
   builder.addTransformation(transformation2, file2);
   try (TransformingVcfLineParser lineParser = builder.build()) {
       try (VcfParser parser = new VcfParser.Builder().fromFile(input.toPath()).parseWith(transformer).build()) {
           parser.parse(); // prints transformed VCFs to file1 and file2
       }
   }