From 5f1b67c1de1509d8a2940b6117ebf18f1c5def50 Mon Sep 17 00:00:00 2001 From: hanna Date: Tue, 3 Aug 2010 03:48:26 +0000 Subject: [PATCH] Coping out and forcing the entire GATK (and associated JVM) to use US English locale. Method to force JVM into proper locale exists in CommandLineProgram and is disabled by default, but implementers of CommandLineProgram can opt in to the forced US locale by calling a static method. Question for the VCF developers: I removed the code to explicitly output doubles in US locale. Do you / how do you want to handle this in applications that use Tribble outside the GATK? git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@3917 348d0f76-0448-11de-a6fe-93d51630548a --- java/src/org/broad/tribble/vcf/VCFConstants.java | 4 ---- .../sting/commandline/CommandLineProgram.java | 12 ++++++++---- .../broadinstitute/sting/gatk/CommandLineGATK.java | 8 ++++++++ .../sting/utils/genotype/vcf/VCFWriter.java | 4 ++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/java/src/org/broad/tribble/vcf/VCFConstants.java b/java/src/org/broad/tribble/vcf/VCFConstants.java index 179c69a55..616261287 100755 --- a/java/src/org/broad/tribble/vcf/VCFConstants.java +++ b/java/src/org/broad/tribble/vcf/VCFConstants.java @@ -25,11 +25,7 @@ package org.broad.tribble.vcf; -import java.util.Locale; - public final class VCFConstants { - public static final Locale VCF_LOCALE = Locale.US; - // standard INFO/FORMAT field keys public static final String ANCESTRAL_ALLELE_KEY = "AA"; public static final String ALLELE_COUNT_KEY = "AC"; diff --git a/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java b/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java index 2d6c710ca..bedca9043 100644 --- a/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java +++ b/java/src/org/broadinstitute/sting/commandline/CommandLineProgram.java @@ -32,10 +32,7 @@ import org.broadinstitute.sting.utils.help.HelpFormatter; import java.io.File; import java.io.IOException; import java.io.PrintStream; -import java.util.Collection; -import java.util.Collections; -import java.util.EnumSet; -import java.util.Enumeration; +import java.util.*; public abstract class CommandLineProgram { @@ -400,4 +397,11 @@ public abstract class CommandLineProgram { public void generateErrorLog(PrintStream stream, Exception e) { stream.println(e.getStackTrace().toString()); } + + /** + * A hack to ensure that numbers are always formatted in the US style. + */ + protected static void forceJVMLocaleToUSEnglish() { + Locale.setDefault(Locale.US); + } } diff --git a/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java b/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java index 98db32ecb..07fde5082 100755 --- a/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java +++ b/java/src/org/broadinstitute/sting/gatk/CommandLineGATK.java @@ -88,6 +88,14 @@ public class CommandLineGATK extends CommandLineExecutable { return argCollection; } + /** + * The very first thing that the GATK does is forces the JVM locale into US English, so that we don't have + * to think about number formatting issues. + */ + { + forceJVMLocaleToUSEnglish(); + } + /** * Required main method implementation. */ diff --git a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFWriter.java b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFWriter.java index 0d604e622..d8a77c6b0 100644 --- a/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFWriter.java +++ b/java/src/org/broadinstitute/sting/utils/genotype/vcf/VCFWriter.java @@ -217,7 +217,7 @@ public class VCFWriter { } private String getQualValue(double qual) { - String s = String.format(VCFConstants.VCF_LOCALE, VCFConstants.DOUBLE_PRECISION_FORMAT_STRING, qual); + String s = String.format(VCFConstants.DOUBLE_PRECISION_FORMAT_STRING, qual); if ( s.endsWith(VCFConstants.DOUBLE_PRECISION_INT_SUFFIX) ) s = s.substring(0, s.length() - VCFConstants.DOUBLE_PRECISION_INT_SUFFIX.length()); return s; @@ -365,7 +365,7 @@ public class VCFWriter { if ( val == null ) result = VCFConstants.MISSING_VALUE_v4; else if ( val instanceof Double ) - result = String.format(VCFConstants.VCF_LOCALE, VCFConstants.DOUBLE_PRECISION_FORMAT_STRING, (Double)val); + result = String.format(VCFConstants.DOUBLE_PRECISION_FORMAT_STRING, (Double)val); else if ( val instanceof Boolean ) result = (Boolean)val ? "" : null; // empty string for true, null for false else if ( val instanceof List ) {