From e6d61197e68bbdb7d0be88f66ce08edf1a295d5f Mon Sep 17 00:00:00 2001 From: hanna Date: Fri, 22 Oct 2010 17:40:37 +0000 Subject: [PATCH] Disable OTF indexing when writing indices for temporary VCFs when running with -nt option. When last I checked in, Ryan was seeing a ~25% speedup per shard by not indexing. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4556 348d0f76-0448-11de-a6fe-93d51630548a --- .../gatk/io/storage/VCFWriterStorage.java | 42 ++++++------------- 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/java/src/org/broadinstitute/sting/gatk/io/storage/VCFWriterStorage.java b/java/src/org/broadinstitute/sting/gatk/io/storage/VCFWriterStorage.java index 183597069..3dd6fbf5b 100644 --- a/java/src/org/broadinstitute/sting/gatk/io/storage/VCFWriterStorage.java +++ b/java/src/org/broadinstitute/sting/gatk/io/storage/VCFWriterStorage.java @@ -32,7 +32,7 @@ public class VCFWriterStorage implements Storage, VCFWriter { public VCFWriterStorage( VCFWriterStub stub ) { if ( stub.getFile() != null ) { this.file = stub.getFile(); - writer = VCFWriterToFile(stub, stub.getFile()); + writer = vcfWriterToFile(stub,stub.getFile(),true); } else if ( stub.getOutputStream() != null ) { this.file = null; @@ -45,11 +45,12 @@ public class VCFWriterStorage implements Storage, VCFWriter { /** * common initialization routine for multiple constructors - * @param stub - * @param file + * @param stub Stub to use when constructing the output file. + * @param file Target file into which to write VCF records. + * @param indexOnTheFly true to index the file on the fly. NOTE: will be forced to false for compressed files. * @return A VCF writer for use with this class */ - private StandardVCFWriter VCFWriterToFile(VCFWriterStub stub, File file) { + private StandardVCFWriter vcfWriterToFile(VCFWriterStub stub, File file, boolean indexOnTheFly) { try { if ( stub.isCompressed() ) stream = new BlockCompressedOutputStream(file); @@ -60,18 +61,19 @@ public class VCFWriterStorage implements Storage, VCFWriter { throw new UserException.CouldNotCreateOutputFile(file, "Unable to open target output stream", ex); } - return new StandardVCFWriter(file, this.stream, ! stub.isCompressed()); + // The GATK/Tribble can't currently index block-compressed files on the fly. Disable OTF indexing even if the user explicitly asked for it. + return new StandardVCFWriter(file, this.stream, indexOnTheFly && !stub.isCompressed()); } /** * Constructs an object which will redirect into a different file. * @param stub Stub to use when synthesizing file / header info. - * @param file File into which to direct the output data. + * @param tempFile File into which to direct the output data. */ - public VCFWriterStorage(VCFWriterStub stub, File file) { - this.file = file; - this.writer = VCFWriterToFile(stub, file); + public VCFWriterStorage(VCFWriterStub stub, File tempFile) { + this.file = tempFile; + this.writer = vcfWriterToFile(stub, file, false); writer.writeHeader(stub.getVCFHeader()); } @@ -95,30 +97,10 @@ public class VCFWriterStorage implements Storage, VCFWriter { writer.close(); } - /** - * Merges the stream backing up this temporary storage into the target. - * @param target Target stream for the temporary storage. May not be null. - */ -// public void mergeInto(VCFWriterStorage target) { -// PrintStream formattingTarget = new PrintStream(target.stream); -// try { -// BufferedReader reader = new BufferedReader(new FileReader(file)); -// String line = reader.readLine(); -// while ( line != null ) { -// if (!VCFHeaderLine.isHeaderLine(line)) -// formattingTarget.printf("%s%n",line); -// line = reader.readLine(); -// } -// -// reader.close(); -// } catch (IOException e) { -// throw new UserException.CouldNotReadInputFile(file, "Error reading file in VCFWriterStorage: ", e); -// } -// } public void mergeInto(VCFWriterStorage target) { try { //System.out.printf("merging %s%n", file); - BasicFeatureSource source = BasicFeatureSource.getFeatureSource(file.getAbsolutePath(), new VCFCodec()); + BasicFeatureSource source = BasicFeatureSource.getFeatureSource(file.getAbsolutePath(), new VCFCodec(), false); for ( VariantContext vc : source.iterator() ) { target.writer.add(vc, vc.getReferenceBaseForIndel());