[med-svn] [picard-tools] 02/04: Imported Upstream version 1.107
Charles Plessy
plessy at moszumanska.debian.org
Sat Mar 22 02:05:04 UTC 2014
This is an automated email from the git hooks/post-receive script.
plessy pushed a commit to branch upstream
in repository picard-tools.
commit ec0f0f94cf5b4e43c941ff999fe9b3cdd8b2f2bf
Author: Charles Plessy <plessy at debian.org>
Date: Sat Mar 22 10:43:05 2014 +0900
Imported Upstream version 1.107
---
build.xml | 13 ++++++---
.../picard/illumina/parser/readers/BclReader.java | 3 +-
src/java/net/sf/picard/sam/SamFormatConverter.java | 2 +-
src/java/net/sf/picard/util/MathUtil.java | 16 +++++++++--
src/java/net/sf/picard/util/SamLocusIterator.java | 4 +++
src/java/net/sf/samtools/util/TestUtil.java | 19 +++++++++----
.../writer/VariantContextWriterFactory.java | 29 +++++++++++++++----
.../variant/vcf/AbstractVCFCodec.java | 4 +--
.../org/broadinstitute/variant/vcf/VCFCodec.java | 4 +--
.../variant/vcf/VCFCompoundHeaderLine.java | 6 ++--
.../variant/vcf/VCFHeaderLineTranslator.java | 1 +
.../variant/vcf/VCFHeaderVersion.java | 24 +++++++++++++++-
.../net/sf/picard/vcf/VcfFormatConverterTest.java | 33 ++++++++++++++--------
.../variantcontext/writer/VCFWriterUnitTest.java | 2 +-
14 files changed, 119 insertions(+), 41 deletions(-)
diff --git a/build.xml b/build.xml
index 82e6061..473f51b 100755
--- a/build.xml
+++ b/build.xml
@@ -43,7 +43,7 @@
<!-- Get SVN revision, if available, otherwise leave it blank. -->
<exec executable="svnversion" outputproperty="repository.revision" failifexecutionfails="false"/>
<property name="repository.revision" value=""/>
- <property name="sam-version" value="1.106"/>
+ <property name="sam-version" value="1.107"/>
<property name="picard-version" value="${sam-version}"/>
<property name="tribble-version" value="${sam-version}"/>
<property name="variant-version" value="${sam-version}"/>
@@ -108,7 +108,7 @@
<compile-src includes="net/sf/picard/**/*.*"/>
</target>
- <target name="compile-tribble" depends="init" description="Compile tribble files without cleaning">
+ <target name="compile-tribble" depends="init, compile-sam-jdk" description="Compile tribble files without cleaning">
<compile-src includes="org/broad/tribble/**/*.*"/>
</target>
@@ -240,7 +240,7 @@
<javadoc
sourcepath="${src}"
destdir="javadoc"
- packagenames="net.sf.samtools.*, net.sf.picard.*"
+ packagenames="net.sf.samtools.*, net.sf.picard.*, org.broadinstitute.variant.*, org.broad.tribble.*"
windowtitle="SAM JDK API Documentation"
doctitle="<h1>SAM JDK API Documentation</h1>"
author="true"
@@ -248,7 +248,12 @@
use="true"
version="true"
failonerror="true">
- <classpath location="${java.home}/../lib/tools.jar"/>
+ <classpath>
+ <pathelement location="${java.home}/../lib/tools.jar" />
+ <fileset dir="${lib}">
+ <include name="**/*.jar" />
+ </fileset>
+ </classpath>
<link href="http://java.sun.com/j2se/1.5.0/docs/api/"/>
</javadoc>
<mkdir dir="${command-line-html-dir}"/>
diff --git a/src/java/net/sf/picard/illumina/parser/readers/BclReader.java b/src/java/net/sf/picard/illumina/parser/readers/BclReader.java
index 6fea411..7c87318 100644
--- a/src/java/net/sf/picard/illumina/parser/readers/BclReader.java
+++ b/src/java/net/sf/picard/illumina/parser/readers/BclReader.java
@@ -25,6 +25,7 @@ package net.sf.picard.illumina.parser.readers;
import net.sf.picard.PicardException;
import net.sf.picard.util.UnsignedTypeUtil;
+import net.sf.samtools.Defaults;
import net.sf.samtools.util.CloserUtil;
import java.io.*;
@@ -103,7 +104,7 @@ public class BclReader implements Iterator<BclReader.BclValue> {
// if necessary
final BufferedInputStream bufferedInputStream;
try {
- bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
+ bufferedInputStream = new BufferedInputStream(new FileInputStream(file), Defaults.BUFFER_SIZE);
inputStream = isGzip ? new GZIPInputStream(bufferedInputStream) : bufferedInputStream;
} catch (FileNotFoundException fnfe) {
throw new PicardException("File not found: (" + filePath + ")", fnfe);
diff --git a/src/java/net/sf/picard/sam/SamFormatConverter.java b/src/java/net/sf/picard/sam/SamFormatConverter.java
index 6747fc2..6cc2759 100644
--- a/src/java/net/sf/picard/sam/SamFormatConverter.java
+++ b/src/java/net/sf/picard/sam/SamFormatConverter.java
@@ -61,7 +61,7 @@ public class SamFormatConverter extends CommandLineProgram {
protected int doWork() {
IoUtil.assertFileIsReadable(INPUT);
IoUtil.assertFileIsWritable(OUTPUT);
- final SAMFileReader reader = new SAMFileReader(IoUtil.openFileForReading(INPUT));
+ final SAMFileReader reader = new SAMFileReader(INPUT);
final SAMFileWriter writer = new SAMFileWriterFactory().makeSAMOrBAMWriter(reader.getFileHeader(), true, OUTPUT);
if (CREATE_INDEX && writer.getFileHeader().getSortOrder() != SAMFileHeader.SortOrder.coordinate){
diff --git a/src/java/net/sf/picard/util/MathUtil.java b/src/java/net/sf/picard/util/MathUtil.java
index 039e18c..164e94c 100644
--- a/src/java/net/sf/picard/util/MathUtil.java
+++ b/src/java/net/sf/picard/util/MathUtil.java
@@ -91,12 +91,24 @@ public class MathUtil {
/** Returns the largest value stored in the array. */
public static double max(final double[] nums) {
+ return nums[indexOfMax(nums)];
+ }
+
+ /**
+ * Returns the index of the largest element in the array. If there are multiple equal maxima then
+ * the earliest one in the array is returned.
+ */
+ public static int indexOfMax(final double[] nums) {
double max = nums[0];
+ int index = 0;
for (int i = 1; i < nums.length; ++i) {
- if (nums[i] > max) max = nums[i];
+ if (nums[i] > max) {
+ max = nums[i];
+ index = i;
+ }
}
- return max;
+ return index;
}
/** Returns the smallest value stored in the array. */
diff --git a/src/java/net/sf/picard/util/SamLocusIterator.java b/src/java/net/sf/picard/util/SamLocusIterator.java
index f5df237..94e280a 100644
--- a/src/java/net/sf/picard/util/SamLocusIterator.java
+++ b/src/java/net/sf/picard/util/SamLocusIterator.java
@@ -229,6 +229,10 @@ public class SamLocusIterator implements Iterable<SamLocusIterator.LocusInfo>, C
* or loci in the target mask that have yet to be covered.
*/
public boolean hasNext() {
+ if (this.samIterator == null) {
+ iterator();
+ }
+
while (complete.isEmpty() && ((!accumulator.isEmpty()) || samHasMore() || hasRemainingMaskBases())) {
final LocusInfo locusInfo = next();
if (locusInfo != null) {
diff --git a/src/java/net/sf/samtools/util/TestUtil.java b/src/java/net/sf/samtools/util/TestUtil.java
index 9416f94..d45d74b 100644
--- a/src/java/net/sf/samtools/util/TestUtil.java
+++ b/src/java/net/sf/samtools/util/TestUtil.java
@@ -30,7 +30,7 @@ import java.io.IOException;
public class TestUtil {
- public static File getTempDirecory(final String prefix, final String suffix) {
+ public static File getTempDirectory(final String prefix, final String suffix) {
final File tempDirectory;
try {
tempDirectory = File.createTempFile(prefix, suffix);
@@ -44,13 +44,20 @@ public class TestUtil {
tempDirectory.deleteOnExit();
return tempDirectory;
}
-
+
/**
- * Little test utility to help tests that create multiple levels of subdirectories
- * clean up after themselves.
- *
- * @param directory The directory to be deleted (along with its subdirectories)
+ * @deprecated Use properly spelled method.
*/
+ public static File getTempDirecory(final String prefix, final String suffix) {
+ return getTempDirectory(prefix, suffix);
+ }
+
+ /**
+ * Little test utility to help tests that create multiple levels of subdirectories
+ * clean up after themselves.
+ *
+ * @param directory The directory to be deleted (along with its subdirectories)
+ */
public static void recursiveDelete(final File directory) {
for (final File f : directory.listFiles()) {
if (f.isDirectory()) {
diff --git a/src/java/org/broadinstitute/variant/variantcontext/writer/VariantContextWriterFactory.java b/src/java/org/broadinstitute/variant/variantcontext/writer/VariantContextWriterFactory.java
index ee23333..a4961b8 100644
--- a/src/java/org/broadinstitute/variant/variantcontext/writer/VariantContextWriterFactory.java
+++ b/src/java/org/broadinstitute/variant/variantcontext/writer/VariantContextWriterFactory.java
@@ -26,6 +26,7 @@
package org.broadinstitute.variant.variantcontext.writer;
import net.sf.samtools.SAMSequenceDictionary;
+import net.sf.samtools.util.BlockCompressedOutputStream;
import org.broad.tribble.index.IndexCreator;
import java.io.*;
@@ -75,7 +76,7 @@ public class VariantContextWriterFactory {
options.contains(Options.INDEX_ON_THE_FLY),
options.contains(Options.DO_NOT_WRITE_GENOTYPES));
else {
- return new VCFWriter(location, output, refDict,
+ return new VCFWriter(location, maybeBgzfWrapOutputStream(location, output, options), refDict,
options.contains(Options.INDEX_ON_THE_FLY),
options.contains(Options.DO_NOT_WRITE_GENOTYPES),
options.contains(Options.ALLOW_MISSING_FIELDS_IN_HEADER));
@@ -94,13 +95,27 @@ public class VariantContextWriterFactory {
options.contains(Options.INDEX_ON_THE_FLY),
options.contains(Options.DO_NOT_WRITE_GENOTYPES));
else {
- return new VCFWriter(location, output, refDict, indexCreator,
+ return new VCFWriter(location, maybeBgzfWrapOutputStream(location, output, options), refDict, indexCreator,
options.contains(Options.INDEX_ON_THE_FLY),
options.contains(Options.DO_NOT_WRITE_GENOTYPES),
options.contains(Options.ALLOW_MISSING_FIELDS_IN_HEADER));
}
}
+ private static OutputStream maybeBgzfWrapOutputStream(final File location, OutputStream output,
+ final EnumSet<Options> options) {
+ if (options.contains(Options.INDEX_ON_THE_FLY) &&
+ (isCompressedVcf(location) || output instanceof BlockCompressedOutputStream)) {
+ throw new IllegalArgumentException("VCF index creation not supported for vcf.gz output format.");
+ }
+ if (!(output instanceof BlockCompressedOutputStream)) {
+ if (isCompressedVcf(location)) {
+ output = new BlockCompressedOutputStream(output, location);
+ }
+ }
+ return output;
+ }
+
/**
* Should we output a BCF file based solely on the name of the file at location?
*
@@ -115,11 +130,15 @@ public class VariantContextWriterFactory {
return options.contains(Options.FORCE_BCF) || (location != null && location.getName().contains(".bcf"));
}
- public static VariantContextWriter sortOnTheFly(final VariantContextWriter innerWriter, int maxCachingStartDistance) {
+ public static boolean isCompressedVcf(final File location) {
+ return location != null && location.getName().endsWith(".gz");
+ }
+
+ public static VariantContextWriter sortOnTheFly(final VariantContextWriter innerWriter, final int maxCachingStartDistance) {
return sortOnTheFly(innerWriter, maxCachingStartDistance, false);
}
- public static VariantContextWriter sortOnTheFly(final VariantContextWriter innerWriter, int maxCachingStartDistance, boolean takeOwnershipOfInner) {
+ public static VariantContextWriter sortOnTheFly(final VariantContextWriter innerWriter, final int maxCachingStartDistance, final boolean takeOwnershipOfInner) {
return new SortingVariantContextWriter(innerWriter, maxCachingStartDistance, takeOwnershipOfInner);
}
@@ -131,7 +150,7 @@ public class VariantContextWriterFactory {
protected static OutputStream openOutputStream(final File location) {
try {
return new FileOutputStream(location);
- } catch (FileNotFoundException e) {
+ } catch (final FileNotFoundException e) {
throw new RuntimeException(location + ": Unable to create VCF writer", e);
}
}
diff --git a/src/java/org/broadinstitute/variant/vcf/AbstractVCFCodec.java b/src/java/org/broadinstitute/variant/vcf/AbstractVCFCodec.java
index 9975488..8071181 100644
--- a/src/java/org/broadinstitute/variant/vcf/AbstractVCFCodec.java
+++ b/src/java/org/broadinstitute/variant/vcf/AbstractVCFCodec.java
@@ -697,8 +697,8 @@ public abstract class AbstractVCFCodec extends AsciiFeatureCodec<VariantContext>
}
// check to make sure we found a genotype field if our version is less than 4.1 file
- if ( version != VCFHeaderVersion.VCF4_1 && genotypeAlleleLocation == -1 )
- generateException("Unable to find the GT field for the record; the GT field is required in VCF4.0");
+ if ( ! version.isAtLeastAsRecentAs(VCFHeaderVersion.VCF4_1) && genotypeAlleleLocation == -1 )
+ generateException("Unable to find the GT field for the record; the GT field is required before VCF4.1");
if ( genotypeAlleleLocation > 0 )
generateException("Saw GT field at position " + genotypeAlleleLocation + ", but it must be at the first position for genotypes when present");
diff --git a/src/java/org/broadinstitute/variant/vcf/VCFCodec.java b/src/java/org/broadinstitute/variant/vcf/VCFCodec.java
index 5107ff7..fad90ca 100644
--- a/src/java/org/broadinstitute/variant/vcf/VCFCodec.java
+++ b/src/java/org/broadinstitute/variant/vcf/VCFCodec.java
@@ -92,9 +92,9 @@ public class VCFCodec extends AbstractVCFCodec {
throw new TribbleException.InvalidHeader(lineFields[1] + " is not a supported version");
foundHeaderVersion = true;
version = VCFHeaderVersion.toHeaderVersion(lineFields[1]);
- if ( version == VCFHeaderVersion.VCF3_3 || version == VCFHeaderVersion.VCF3_2 )
+ if ( ! version.isAtLeastAsRecentAs(VCFHeaderVersion.VCF4_0) )
throw new TribbleException.InvalidHeader("This codec is strictly for VCFv4; please use the VCF3 codec for " + lineFields[1]);
- if ( version != VCFHeaderVersion.VCF4_0 && version != VCFHeaderVersion.VCF4_1 )
+ if ( version != VCFHeaderVersion.VCF4_0 && version != VCFHeaderVersion.VCF4_1 && version != VCFHeaderVersion.VCF4_2 )
throw new TribbleException.InvalidHeader("This codec is strictly for VCFv4 and does not support " + lineFields[1]);
}
headerStrings.add(lineIterator.next());
diff --git a/src/java/org/broadinstitute/variant/vcf/VCFCompoundHeaderLine.java b/src/java/org/broadinstitute/variant/vcf/VCFCompoundHeaderLine.java
index d7f63e2..89adce6 100644
--- a/src/java/org/broadinstitute/variant/vcf/VCFCompoundHeaderLine.java
+++ b/src/java/org/broadinstitute/variant/vcf/VCFCompoundHeaderLine.java
@@ -158,10 +158,8 @@ public abstract class VCFCompoundHeaderLine extends VCFHeaderLine implements VCF
countType = VCFHeaderLineCount.A;
} else if ( numberStr.equals(VCFConstants.PER_GENOTYPE_COUNT) ) {
countType = VCFHeaderLineCount.G;
- } else if ( ((version == VCFHeaderVersion.VCF4_0 || version == VCFHeaderVersion.VCF4_1) &&
- numberStr.equals(VCFConstants.UNBOUNDED_ENCODING_v4)) ||
- ((version == VCFHeaderVersion.VCF3_2 || version == VCFHeaderVersion.VCF3_3) &&
- numberStr.equals(VCFConstants.UNBOUNDED_ENCODING_v3)) ) {
+ } else if ( (version.isAtLeastAsRecentAs(VCFHeaderVersion.VCF4_0) && numberStr.equals(VCFConstants.UNBOUNDED_ENCODING_v4)) ||
+ (! version.isAtLeastAsRecentAs(VCFHeaderVersion.VCF4_0) && numberStr.equals(VCFConstants.UNBOUNDED_ENCODING_v3)) ) {
countType = VCFHeaderLineCount.UNBOUNDED;
} else {
countType = VCFHeaderLineCount.INTEGER;
diff --git a/src/java/org/broadinstitute/variant/vcf/VCFHeaderLineTranslator.java b/src/java/org/broadinstitute/variant/vcf/VCFHeaderLineTranslator.java
index 3c2a35d..ab6ee8f 100644
--- a/src/java/org/broadinstitute/variant/vcf/VCFHeaderLineTranslator.java
+++ b/src/java/org/broadinstitute/variant/vcf/VCFHeaderLineTranslator.java
@@ -39,6 +39,7 @@ public class VCFHeaderLineTranslator {
mapping = new HashMap<VCFHeaderVersion,VCFLineParser>();
mapping.put(VCFHeaderVersion.VCF4_0,new VCF4Parser());
mapping.put(VCFHeaderVersion.VCF4_1,new VCF4Parser());
+ mapping.put(VCFHeaderVersion.VCF4_2,new VCF4Parser());
mapping.put(VCFHeaderVersion.VCF3_3,new VCF3Parser());
mapping.put(VCFHeaderVersion.VCF3_2,new VCF3Parser());
}
diff --git a/src/java/org/broadinstitute/variant/vcf/VCFHeaderVersion.java b/src/java/org/broadinstitute/variant/vcf/VCFHeaderVersion.java
index 35ca451..812b4fa 100644
--- a/src/java/org/broadinstitute/variant/vcf/VCFHeaderVersion.java
+++ b/src/java/org/broadinstitute/variant/vcf/VCFHeaderVersion.java
@@ -34,7 +34,8 @@ public enum VCFHeaderVersion {
VCF3_2("VCRv3.2","format"),
VCF3_3("VCFv3.3","fileformat"),
VCF4_0("VCFv4.0","fileformat"),
- VCF4_1("VCFv4.1","fileformat");
+ VCF4_1("VCFv4.1","fileformat"),
+ VCF4_2("VCFv4.2","fileformat");
private final String versionString;
private final String formatString;
@@ -105,6 +106,27 @@ public enum VCFHeaderVersion {
return s.trim();
}
+ /**
+ * Determines whether this version is at least as recent as a given version
+ *
+ * @param target the target version to compare against
+ * @return true if this version is at least as recent as the target version, false otherwise
+ */
+ public boolean isAtLeastAsRecentAs(final VCFHeaderVersion target) {
+ switch (target) {
+ case VCF4_2:
+ return this == VCF4_2;
+ case VCF4_1:
+ return this == VCF4_1 || this == VCF4_2;
+ case VCF4_0:
+ return this != VCF3_2 && this != VCF3_3;
+ case VCF3_3:
+ return this != VCF3_2;
+ case VCF3_2:
+ default:
+ return true;
+ }
+ }
public String getVersionString() {
return versionString;
diff --git a/src/tests/java/net/sf/picard/vcf/VcfFormatConverterTest.java b/src/tests/java/net/sf/picard/vcf/VcfFormatConverterTest.java
index 1dadb88..2300488 100644
--- a/src/tests/java/net/sf/picard/vcf/VcfFormatConverterTest.java
+++ b/src/tests/java/net/sf/picard/vcf/VcfFormatConverterTest.java
@@ -36,7 +36,8 @@ public class VcfFormatConverterTest {
private static final String TEST_DATA_PATH = "testdata/net/sf/picard/vcf/";
private static final String TEST_FILE_BASE = "vcfFormatTest";
- private static final String VCF = ".vcf";
+ private static final String VCF = ".vcf";
+ private static final String VCF_GZ = ".vcf.gz";
private static final String BCF = ".bcf";
private static final File TEST_VCF = new File(TEST_DATA_PATH, TEST_FILE_BASE + VCF);
@@ -49,7 +50,12 @@ public class VcfFormatConverterTest {
@Test
public void testVcfToBcf() {
- runBackAndForthTest(TEST_VCF, BCF);
+ runBackAndForthTest(TEST_VCF, BCF, VCF);
+ }
+
+ @Test
+ public void testVcfToVcfGz() {
+ runBackAndForthTest(TEST_VCF, VCF_GZ, VCF);
}
@Test
@@ -59,7 +65,7 @@ public class VcfFormatConverterTest {
@Test
public void testBcfToVcf() {
- runBackAndForthTest(TEST_BCF, VCF);
+ runBackAndForthTest(TEST_BCF, VCF, BCF);
}
private void runLikeTest(final File input, final String format) {
@@ -67,11 +73,11 @@ public class VcfFormatConverterTest {
compareFiles(input, outputFile);
}
- private void runBackAndForthTest(final File input, final String format) {
+ private void runBackAndForthTest(final File input, final String format, final String originalFormat) {
final String tempPrefix = "backAndForth";
final File backAndForth = convertFile(input, tempPrefix, format);
- final File backAndForthSeries2 = convertFile(backAndForth, tempPrefix, getOppositeFormat(format));
+ final File backAndForthSeries2 = convertFile(backAndForth, tempPrefix, originalFormat);
compareFiles(input, backAndForthSeries2);
}
@@ -80,15 +86,23 @@ public class VcfFormatConverterTest {
final File outputFile;
try {
outputFile = File.createTempFile(prefix, format);
- } catch (IOException ioe) {
+ } catch (final IOException ioe) {
throw new PicardException("Unable to create temp file!");
}
+ outputFile.deleteOnExit();
+ new File(outputFile.getAbsolutePath() + ".idx").deleteOnExit();
final VcfFormatConverter vcfFormatConverter = new VcfFormatConverter();
vcfFormatConverter.INPUT = input;
vcfFormatConverter.OUTPUT = outputFile;
+ if (VCF_GZ.equals(format)) {
+ vcfFormatConverter.CREATE_INDEX = false;
+ }
+ if (input.getName().endsWith(VCF_GZ)) {
+ vcfFormatConverter.REQUIRE_INDEX = false;
+ }
- vcfFormatConverter.instanceMain(new String[0]);
+ Assert.assertEquals(vcfFormatConverter.doWork(), 0);
return outputFile;
}
@@ -100,9 +114,4 @@ public class VcfFormatConverterTest {
Assert.assertEquals(file1.length(), file2.length());
}
- public static String getOppositeFormat(final String curFormat) {
- if (curFormat.equals(VCF)) return BCF;
- else if (curFormat.equals(BCF)) return VCF;
- else throw new RuntimeException();
- }
}
diff --git a/src/tests/java/org/broadinstitute/variant/variantcontext/writer/VCFWriterUnitTest.java b/src/tests/java/org/broadinstitute/variant/variantcontext/writer/VCFWriterUnitTest.java
index 7a1117d..e91fe79 100644
--- a/src/tests/java/org/broadinstitute/variant/variantcontext/writer/VCFWriterUnitTest.java
+++ b/src/tests/java/org/broadinstitute/variant/variantcontext/writer/VCFWriterUnitTest.java
@@ -184,7 +184,7 @@ public class VCFWriterUnitTest extends VariantBaseTest {
final VCFHeader header = createFakeHeader(metaData,Columns);
final EnumSet<Options> options = EnumSet.of(Options.ALLOW_MISSING_FIELDS_IN_HEADER,Options.INDEX_ON_THE_FLY);
- final File tempDir = TestUtil.getTempDirecory("VCFWriter", "StaleIndex");
+ final File tempDir = TestUtil.getTempDirectory("VCFWriter", "StaleIndex");
tempDir.deleteOnExit();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/picard-tools.git
More information about the debian-med-commit
mailing list