Created ListAnnotations utility (extends CommandLineProgram)

--Refactored listAnnotations basic method out of VA into HelpUtils
	--HelpUtils.listAnnotations() is now called by both VA and the new ListAnnotations utility (lives in sting.tools)
	--This way we keep the VA --list option but we also offer a way to list annotations without a full valid VA command-line, which was a pain users continually complained about
	--We could get rid of the VA --list option altogether ...?
This commit is contained in:
Geraldine Van der Auwera 2013-03-15 16:34:29 -04:00
parent 95a9ed853d
commit 6b4d88ebe9
5 changed files with 129 additions and 31 deletions

View File

@ -36,10 +36,10 @@ import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.walkers.*;
import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.*;
import org.broadinstitute.sting.utils.help.HelpConstants;
import org.broadinstitute.sting.utils.help.HelpUtils;
import org.broadinstitute.sting.utils.variant.GATKVCFUtils;
import org.broadinstitute.sting.utils.BaseUtils;
import org.broadinstitute.sting.utils.SampleUtils;
import org.broadinstitute.sting.utils.classloader.PluginManager;
import org.broadinstitute.variant.vcf.*;
import org.broadinstitute.sting.utils.help.DocumentedGATKFeature;
import org.broadinstitute.variant.variantcontext.VariantContext;
@ -47,7 +47,6 @@ import org.broadinstitute.variant.variantcontext.writer.VariantContextWriter;
import java.util.*;
/**
* Annotates variant calls with context information.
*
@ -165,7 +164,7 @@ public class VariantAnnotator extends RodWalker<Integer, Integer> implements Ann
protected Boolean USE_ALL_ANNOTATIONS = false;
/**
* Note that the --list argument requires a fully resolved and correct command-line to work.
* Note that the --list argument requires a fully resolved and correct command-line to work. As a simpler alternative, you can use ListAnnotations (see Help Utilities).
*/
@Argument(fullName="list", shortName="ls", doc="List the available annotations and exit", required=false)
protected Boolean LIST = false;
@ -177,7 +176,7 @@ public class VariantAnnotator extends RodWalker<Integer, Integer> implements Ann
protected Boolean ALWAYS_APPEND_DBSNP_ID = false;
public boolean alwaysAppendDbsnpId() { return ALWAYS_APPEND_DBSNP_ID; }
@Argument(fullName="MendelViolationGenotypeQualityThreshold",shortName="mvq",required=false,doc="The genotype quality treshold in order to annotate mendelian violation ratio")
@Argument(fullName="MendelViolationGenotypeQualityThreshold",shortName="mvq",required=false,doc="The genotype quality threshold in order to annotate mendelian violation ratio")
public double minGenotypeQualityP = 0.0;
@Argument(fullName="requireStrictAlleleMatch", shortName="strict", doc="If provided only comp tracks that exactly match both reference and alternate alleles will be counted as concordant", required=false)
@ -185,33 +184,14 @@ public class VariantAnnotator extends RodWalker<Integer, Integer> implements Ann
private VariantAnnotatorEngine engine;
private void listAnnotationsAndExit() {
System.out.println("\nStandard annotations in the list below are marked with a '*'.");
List<Class<? extends InfoFieldAnnotation>> infoAnnotationClasses = new PluginManager<InfoFieldAnnotation>(InfoFieldAnnotation.class).getPlugins();
System.out.println("\nAvailable annotations for the VCF INFO field:");
for (int i = 0; i < infoAnnotationClasses.size(); i++)
System.out.println("\t" + (StandardAnnotation.class.isAssignableFrom(infoAnnotationClasses.get(i)) ? "*" : "") + infoAnnotationClasses.get(i).getSimpleName());
System.out.println();
List<Class<? extends GenotypeAnnotation>> genotypeAnnotationClasses = new PluginManager<GenotypeAnnotation>(GenotypeAnnotation.class).getPlugins();
System.out.println("\nAvailable annotations for the VCF FORMAT field:");
for (int i = 0; i < genotypeAnnotationClasses.size(); i++)
System.out.println("\t" + (StandardAnnotation.class.isAssignableFrom(genotypeAnnotationClasses.get(i)) ? "*" : "") + genotypeAnnotationClasses.get(i).getSimpleName());
System.out.println();
System.out.println("\nAvailable classes/groups of annotations:");
for ( Class c : new PluginManager<AnnotationType>(AnnotationType.class).getInterfaces() )
System.out.println("\t" + c.getSimpleName());
System.out.println();
System.exit(0);
}
/**
* Prepare the output file and the list of available features.
*/
public void initialize() {
if ( LIST )
listAnnotationsAndExit();
HelpUtils.listAnnotations();
System.exit(0);
// get the list of all sample names from the variant VCF input rod, if applicable
List<String> rodName = Arrays.asList(variantCollection.variants.getName());

View File

@ -35,7 +35,6 @@ import org.broadinstitute.sting.commandline.Argument;
import org.broadinstitute.sting.commandline.Input;
import org.broadinstitute.sting.commandline.Output;
import org.broadinstitute.sting.commandline.CommandLineProgram;
import org.broadinstitute.sting.gatk.CommandLineGATK;
import org.broadinstitute.sting.utils.help.DocumentedGATKFeature;
import org.broadinstitute.sting.utils.help.HelpConstants;
import org.broadinstitute.variant.bcf2.BCF2Codec;
@ -54,7 +53,7 @@ import java.util.*;
/**
*
* Concatenates VCF files of non-overlapped genome intervals, all with the same set of samples.
* Concatenates VCF files of non-overlapped genome intervals, all with the same set of samples
*
* <p>
* The main purpose of this tool is to speed up the gather function when using scatter-gather parallelization.
@ -80,10 +79,14 @@ import java.util.*;
* A combined VCF. The output file should be 'name.vcf' or 'name.VCF'.
* <\p>
*
* <h3>Important note</h3>
* <p>This is a command-line utility that bypasses the GATK engine. As a result, the command-line you must use to
* invoke it is a little different from other GATK tools (see example below), and it does not accept any of the
* classic "CommandLineGATK" arguments.</p>
*
* <h3>Examples</h3>
* <h3>Example</h3>
* <pre>
* java -cp dist/GenomeAnalysisTK.jar org.broadinstitute.sting.tools.CatVariants \
* java -cp GenomeAnalysisTK.jar org.broadinstitute.sting.tools.CatVariants \
* -R ref.fasta \
* -V input1.vcf \
* -V input2.vcf \
@ -95,7 +98,7 @@ import java.util.*;
* @since Jan 2012
*/
@DocumentedGATKFeature( groupName = HelpConstants.DOCS_CAT_VARMANIP, extraDocs = {CommandLineGATK.class} )
@DocumentedGATKFeature( groupName = HelpConstants.DOCS_CAT_VARMANIP )
public class CatVariants extends CommandLineProgram {
// setup the logging system, used by some codecs
private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getRootLogger();
@ -124,7 +127,7 @@ public class CatVariants extends CommandLineProgram {
* print usage information
*/
private static void printUsage() {
System.err.println("Usage: java -cp dist/GenomeAnalysisTK.jar org.broadinstitute.sting.tools.AppendVariants <reference> <input VCF or BCF files> <outputFile> [sorted (optional)]");
System.err.println("Usage: java -cp dist/GenomeAnalysisTK.jar org.broadinstitute.sting.tools.CatVariants <reference> <input VCF or BCF files> <outputFile> [sorted (optional)]");
System.err.println(" The input files can be of type: VCF (ends in .vcf or .VCF)");
System.err.println(" BCF2 (ends in .bcf or .BCF)");
System.err.println(" Output file must be vcf or bcf file (.vcf or .bcf)");

View File

@ -0,0 +1,85 @@
/*
* Copyright (c) 2012 The Broad Institute
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.broadinstitute.sting.tools;
import org.broadinstitute.sting.commandline.CommandLineProgram;
import org.broadinstitute.sting.utils.exceptions.UserException;
import org.broadinstitute.sting.utils.help.DocumentedGATKFeature;
import org.broadinstitute.sting.utils.help.HelpConstants;
import org.broadinstitute.sting.utils.help.HelpUtils;
/**
* Utility program to print a list of available annotations
*
* <p>This is a very simple utility tool that retrieves available annotations for use with tools such as
* UnifiedGenotyper, HaplotypeCaller and VariantAnnotator.</p>
*
* <h3>Important note</h3>
* <p>This is a command-line utility that bypasses the GATK engine. As a result, the command-line you must use to
* invoke it is a little different from other GATK tools (see usage below), and it does not accept any of the
* classic "CommandLineGATK" arguments.</p>
*
* <h3>Usage</h3>
* <pre>java -cp GenomeAnalysisTK.jar org.broadinstitute.sting.tools.ListAnnotations</pre>
*
* @author vdauwera
* @since 3/14/13
*/
@DocumentedGATKFeature( groupName = HelpConstants.DOCS_CAT_HELPUTILS )
public class ListAnnotations extends CommandLineProgram {
/*
* Print usage information
*
* TODO: would be more convenient if we could just call the program by name instead of the full classpath
*/
private static void printUsage() {
System.err.println("Usage: java -cp dist/GenomeAnalysisTK.jar org.broadinstitute.sting.tools.ListAnnotations");
System.err.println(" Prints a list of available annotations and exits.");
}
// TODO: override CommandLineProgram bit that offers version, logging etc arguments. We don't need that stuff here and it makes the doc confusing.
@Override
protected int execute() throws Exception {
HelpUtils.listAnnotations();
return 0;
}
public static void main(String[] args){
try {
ListAnnotations instance = new ListAnnotations();
start(instance, args);
System.exit(CommandLineProgram.result);
} catch ( UserException e ) {
printUsage();
exitSystemWithUserError(e);
} catch ( Exception e ) {
exitSystemWithError(e);
}
}
}

View File

@ -56,6 +56,7 @@ public class HelpConstants {
public final static String DOCS_CAT_VARDISC = "Variant Discovery Tools";
public final static String DOCS_CAT_VARMANIP = "Variant Evaluation and Manipulation Tools";
public final static String DOCS_CAT_TEST = "Testing Tools";
public final static String DOCS_CAT_HELPUTILS = "Help Utilities";
public static String forumPost(String post) {
return GATK_FORUM_URL + post;

View File

@ -28,9 +28,15 @@ package org.broadinstitute.sting.utils.help;
import com.sun.javadoc.FieldDoc;
import com.sun.javadoc.PackageDoc;
import com.sun.javadoc.ProgramElementDoc;
import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.AnnotationType;
import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.GenotypeAnnotation;
import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.InfoFieldAnnotation;
import org.broadinstitute.sting.gatk.walkers.annotator.interfaces.StandardAnnotation;
import org.broadinstitute.sting.utils.classloader.JVMUtils;
import org.broadinstitute.sting.utils.classloader.PluginManager;
import java.lang.reflect.Field;
import java.util.List;
public class HelpUtils {
@ -70,4 +76,27 @@ public class HelpUtils {
String.format("%s", doc.name());
}
/**
* Simple method to print a list of available annotations.
*/
public static void listAnnotations() {
System.out.println("\nThis is a list of available Variant Annotations for use with tools such as UnifiedGenotyper, HaplotypeCaller and VariantAnnotator. Please see the Technical Documentation for more details about these annotations:");
System.out.println("http://www.broadinstitute.org/gatk/gatkdocs/");
System.out.println("\nStandard annotations in the list below are marked with a '*'.");
List<Class<? extends InfoFieldAnnotation>> infoAnnotationClasses = new PluginManager<InfoFieldAnnotation>(InfoFieldAnnotation.class).getPlugins();
System.out.println("\nAvailable annotations for the VCF INFO field:");
for (int i = 0; i < infoAnnotationClasses.size(); i++)
System.out.println("\t" + (StandardAnnotation.class.isAssignableFrom(infoAnnotationClasses.get(i)) ? "*" : "") + infoAnnotationClasses.get(i).getSimpleName());
System.out.println();
List<Class<? extends GenotypeAnnotation>> genotypeAnnotationClasses = new PluginManager<GenotypeAnnotation>(GenotypeAnnotation.class).getPlugins();
System.out.println("\nAvailable annotations for the VCF FORMAT field:");
for (int i = 0; i < genotypeAnnotationClasses.size(); i++)
System.out.println("\t" + (StandardAnnotation.class.isAssignableFrom(genotypeAnnotationClasses.get(i)) ? "*" : "") + genotypeAnnotationClasses.get(i).getSimpleName());
System.out.println();
System.out.println("\nAvailable classes/groups of annotations:");
for ( Class c : new PluginManager<AnnotationType>(AnnotationType.class).getInterfaces() )
System.out.println("\t" + c.getSimpleName());
System.out.println();
}
}