From ccda4f6ec15494cfad6adefda6664155f0b8059e Mon Sep 17 00:00:00 2001 From: ebanks Date: Mon, 23 Aug 2010 18:46:08 +0000 Subject: [PATCH] More output consistency changes (updating wiki docs as I go along). git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4086 348d0f76-0448-11de-a6fe-93d51630548a --- .../walkers/annotator/VariantAnnotator.java | 28 ++++++++----------- .../filters/VariantFiltrationWalker.java | 13 ++------- .../walkers/genotyper/UnifiedGenotyper.java | 5 ++-- .../walkers/annotator/GenomicAnnotator.java | 22 +++++---------- .../GenomicAnnotatorIntegrationTest.java | 4 +-- 5 files changed, 27 insertions(+), 45 deletions(-) diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java index 9b617d3d8..9b1e97b94 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/annotator/VariantAnnotator.java @@ -45,7 +45,6 @@ import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.vcf.VCFUtils; import java.util.*; -import java.io.PrintStream; /** @@ -56,8 +55,9 @@ import java.io.PrintStream; @Reference(window=@Window(start=-50,stop=50)) @By(DataSource.REFERENCE) public class VariantAnnotator extends RodWalker { - @Output - protected PrintStream out; + + @Output(doc="File to which variants should be written",required=true) + protected VCFWriter vcfWriter = null; @Argument(fullName="sampleName", shortName="sample", doc="The sample (NA-ID) corresponding to the variant input (for non-VCF input only)", required=false) protected String sampleName = null; @@ -83,8 +83,6 @@ public class VariantAnnotator extends RodWalker { @Argument(fullName = "NO_HEADER", shortName = "NO_HEADER", doc = "Don't output the usual VCF header tag with the command line. FOR DEBUGGING PURPOSES ONLY. This option is required in order to pass integration tests.", required = false) protected Boolean NO_VCF_HEADER_LINE = false; - private VCFWriter vcfWriter; - private HashMap nonVCFsampleName = new HashMap(); private VariantAnnotatorEngine engine; @@ -94,19 +92,19 @@ public class VariantAnnotator extends RodWalker { private void listAnnotationsAndExit() { List> infoAnnotationClasses = PackageUtils.getClassesImplementingInterface(InfoFieldAnnotation.class); - out.println("\nAvailable annotations for the VCF INFO field:"); + System.out.println("\nAvailable annotations for the VCF INFO field:"); for (int i = 0; i < infoAnnotationClasses.size(); i++) - out.println("\t" + infoAnnotationClasses.get(i).getSimpleName()); - out.println(); + System.out.println("\t" + infoAnnotationClasses.get(i).getSimpleName()); + System.out.println(); List> genotypeAnnotationClasses = PackageUtils.getClassesImplementingInterface(GenotypeAnnotation.class); - out.println("\nAvailable annotations for the VCF FORMAT field:"); + System.out.println("\nAvailable annotations for the VCF FORMAT field:"); for (int i = 0; i < genotypeAnnotationClasses.size(); i++) - out.println("\t" + genotypeAnnotationClasses.get(i).getSimpleName()); - out.println(); - out.println("\nAvailable classes/groups of annotations:"); + System.out.println("\t" + genotypeAnnotationClasses.get(i).getSimpleName()); + System.out.println(); + System.out.println("\nAvailable classes/groups of annotations:"); for ( Class c : PackageUtils.getInterfacesExtendingInterface(AnnotationType.class) ) - out.println("\t" + c.getSimpleName()); - out.println(); + System.out.println("\t" + c.getSimpleName()); + System.out.println(); System.exit(0); } @@ -153,7 +151,6 @@ public class VariantAnnotator extends RodWalker { hInfo.add(new VCFHeaderLine("VariantAnnotator", "\"" + CommandLineUtils.createApproximateCommandLineArgumentString(getToolkit(), args, getClass()) + "\"")); } - vcfWriter = new StandardVCFWriter(out); VCFHeader vcfHeader = new VCFHeader(hInfo, samples); vcfWriter.writeHeader(vcfHeader); @@ -261,6 +258,5 @@ public class VariantAnnotator extends RodWalker { */ public void onTraversalDone(Integer result) { logger.info("Processed " + result + " loci.\n"); - vcfWriter.close(); } } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java b/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java index 5c0711e55..696c56200 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/filters/VariantFiltrationWalker.java @@ -41,7 +41,6 @@ import org.broadinstitute.sting.commandline.Output; import org.broadinstitute.sting.utils.vcf.VCFUtils; import java.util.*; -import java.io.PrintStream; /** @@ -50,8 +49,9 @@ import java.io.PrintStream; @Requires(value={},referenceMetaData=@RMD(name="variant", type=VariantContext.class)) @Reference(window=@Window(start=-50,stop=50)) public class VariantFiltrationWalker extends RodWalker { - @Output - protected PrintStream out; + + @Output(doc="File to which variants should be written",required=true) + protected VCFWriter writer = null; @Argument(fullName="filterExpression", shortName="filter", doc="One or more expression used with INFO fields to filter (see wiki docs for more info)", required=false) protected ArrayList FILTER_EXPS = new ArrayList(); @@ -78,9 +78,6 @@ public class VariantFiltrationWalker extends RodWalker { List filterExps; List genotypeFilterExps; - - private VCFWriter writer = null; - public static final String CLUSTERED_SNP_FILTER_NAME = "SnpCluster"; private ClusteredSnps clusteredSNPs = null; @@ -120,7 +117,6 @@ public class VariantFiltrationWalker extends RodWalker { hInfo.add(new VCFHeaderLine("VariantFiltration", "\"" + CommandLineUtils.createApproximateCommandLineArgumentString(getToolkit(), args, getClass()) + "\"")); } - writer = new StandardVCFWriter(out); writer.writeHeader(new VCFHeader(hInfo, new TreeSet(vc.getSampleNames()))); } @@ -249,8 +245,5 @@ public class VariantFiltrationWalker extends RodWalker { variantContextWindow.moveWindow(null); filter(); } - - if ( writer != null ) - writer.close(); } } diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java index 165ce2949..9d2170b7c 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/genotyper/UnifiedGenotyper.java @@ -48,11 +48,12 @@ import java.io.FileNotFoundException; @Reference(window=@Window(start=-20,stop=20)) @By(DataSource.REFERENCE) public class UnifiedGenotyper extends LocusWalker implements TreeReducible { + @ArgumentCollection private UnifiedArgumentCollection UAC = new UnifiedArgumentCollection(); // control the output - @Output(doc="File to which variants should be written",required=false) - public VCFWriter writer = null; + @Output(doc="File to which variants should be written",required=true) + protected VCFWriter writer = null; @Argument(fullName="variants_out",shortName="varout",doc="Please use --out instead",required=false) @Deprecated diff --git a/java/src/org/broadinstitute/sting/playground/gatk/walkers/annotator/GenomicAnnotator.java b/java/src/org/broadinstitute/sting/playground/gatk/walkers/annotator/GenomicAnnotator.java index 514c01aa7..82a32472c 100644 --- a/java/src/org/broadinstitute/sting/playground/gatk/walkers/annotator/GenomicAnnotator.java +++ b/java/src/org/broadinstitute/sting/playground/gatk/walkers/annotator/GenomicAnnotator.java @@ -26,9 +26,7 @@ package org.broadinstitute.sting.playground.gatk.walkers.annotator; -import java.io.File; import java.io.IOException; -import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -43,7 +41,6 @@ import java.util.TreeSet; import java.util.Map.Entry; import org.broad.tribble.util.variantcontext.VariantContext; -import org.broad.tribble.vcf.StandardVCFWriter; import org.broad.tribble.vcf.VCFHeader; import org.broad.tribble.vcf.VCFHeaderLine; import org.broad.tribble.vcf.VCFWriter; @@ -77,11 +74,13 @@ import org.broadinstitute.sting.utils.vcf.VCFUtils; //@Reference(window=@Window(start=-50,stop=50)) @By(DataSource.REFERENCE) public class GenomicAnnotator extends RodWalker, LinkedList> implements TreeReducible> { - @Output - protected PrintStream out; - @Argument(fullName="vcfOutput", shortName="vcf", doc="VCF file to which all variants should be written with annotations", required=true) - protected File VCF_OUT; + @Output(doc="File to which variants should be written",required=true) + protected VCFWriter vcfWriter = null; + + @Argument(fullName="vcfOutput", shortName="vcf", doc="Please use --out instead", required=false) + @Deprecated + protected String oldOutArg; @Argument(fullName="sampleName", shortName="sample", doc="The sample (NA-ID) corresponding to the variant input (for non-VCF input only)", required=false) protected String sampleName = null; @@ -95,9 +94,6 @@ public class GenomicAnnotator extends RodWalker, Link @Argument(fullName="oneToMany", shortName="m", doc="If more than one record from the same file matches a particular locus (for example, multiple dbSNP records with the same position), create multiple entries in the ouptut VCF file - one for each match. If a particular tabular file has J matches, and another tabular file has K matches for a given locus, then J*K output VCF records will be generated - one for each pair of K, J. If this flag is not provided, the multiple records are still generated, but they are stored in the INFO field of a single output VCF record, with their annotation keys differentiated by appending '_i' with i varying from 1 to K*J. ", required=false) protected Boolean ONE_TO_MANY = false; - - private VCFWriter vcfWriter; - private VariantAnnotatorEngine engine; private boolean strict = true; @@ -246,7 +242,6 @@ public class GenomicAnnotator extends RodWalker, Link hInfo.add(new VCFHeaderLine("annotatorReference", getToolkit().getArguments().referenceFile.getName())); hInfo.addAll(engine.getVCFAnnotationDescriptions()); - vcfWriter = new StandardVCFWriter(VCF_OUT); VCFHeader vcfHeader = new VCFHeader(hInfo, samples); vcfWriter.writeHeader(vcfHeader); } @@ -365,11 +360,8 @@ public class GenomicAnnotator extends RodWalker, Link final int counter = e.getValue(); //final float percent = 100 * counter /(float) totalOutputVCFRecords; //out.printf(" %-6.1f%% (%d) annotated with %s.\n", percent, counter, bindingName ); - out.printf(" %d annotated with %s.\n", counter, bindingName ); + System.out.printf(" %d annotated with %s.\n", counter, bindingName ); } - - - vcfWriter.close(); } diff --git a/java/test/org/broadinstitute/sting/playground/gatk/walkers/annotator/GenomicAnnotatorIntegrationTest.java b/java/test/org/broadinstitute/sting/playground/gatk/walkers/annotator/GenomicAnnotatorIntegrationTest.java index 1cf80f966..7b6236187 100755 --- a/java/test/org/broadinstitute/sting/playground/gatk/walkers/annotator/GenomicAnnotatorIntegrationTest.java +++ b/java/test/org/broadinstitute/sting/playground/gatk/walkers/annotator/GenomicAnnotatorIntegrationTest.java @@ -18,7 +18,7 @@ public class GenomicAnnotatorIntegrationTest extends WalkerTest { "-B variant,vcf,/humgen/gsa-hpprojects/GATK/data/Annotations/examples/CEU_hapmap_nogt_23_subset.vcf " + "-B dbsnp,AnnotatorInputTable,/humgen/gsa-hpprojects/GATK/data/Annotations/dbsnp/b130/snp130-b36-only-the-SNPs.txt " + "-m " + //generate many records from one input record if necessary - "-vcf %s " + + "-o %s " + "-BTI variant", 1, Arrays.asList(md5)); @@ -32,7 +32,7 @@ public class GenomicAnnotatorIntegrationTest extends WalkerTest { " -B variant,vcf,/humgen/gsa-hpprojects/GATK/data/Annotations/examples/CEU_hapmap_nogt_23_subset.vcf" + " -B dbsnp,AnnotatorInputTable,/humgen/gsa-hpprojects/GATK/data/Annotations/dbsnp/b130/snp130-b36-only-the-SNPs.txt" + " -m" + //generate many records from one input record if necessary - " -vcf %s" + + " -o %s" + " -BTI variant" + " -s dbsnp.name,dbsnp.refUCSC,dbsnp.strand,dbsnp.observed,dbsnp.avHet", 1,