コード例 #1
0
  /**
   * common initialization routine for multiple constructors
   *
   * @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.
   * @param allowCompressed if false, we won't compress the output, even if the stub requests it.
   *     Critical for creating temp. output files that will be subsequently merged, as these do not
   *     support compressed output
   * @return A VCF writer for use with this class
   */
  private VariantContextWriter vcfWriterToFile(
      final VariantContextWriterStub stub,
      final File file,
      final boolean indexOnTheFly,
      final boolean allowCompressed) {
    try {
      // we cannot merge compressed outputs, so don't compress if allowCompressed is false,
      // which is the case when we have a temporary output file for later merging
      if (allowCompressed && stub.isCompressed()) stream = new BlockCompressedOutputStream(file);
      else
        stream = new PrintStream(new BufferedOutputStream(new FileOutputStream(file), BUFFER_SIZE));
    } catch (IOException ex) {
      throw new UserException.CouldNotCreateOutputFile(
          file, "Unable to open target output stream", ex);
    }

    // The GATK/Tribble can't currently index block-compressed files on the fly.  Disable OTF
    // indexing even if the user explicitly asked for it.
    EnumSet<Options> options = stub.getWriterOptions(indexOnTheFly);
    VariantContextWriter writer =
        VariantContextWriterFactory.create(
            file, this.stream, stub.getMasterSequenceDictionary(), options);

    // if the stub says to test BCF, create a secondary writer to BCF and an 2 way out writer to
    // send to both
    // TODO -- remove me when argument generateShadowBCF is removed
    if (stub.alsoWriteBCFForTest() && !VariantContextWriterFactory.isBCFOutput(file, options)) {
      final File bcfFile = BCF2Utils.shadowBCF(file);
      if (bcfFile != null) {
        VariantContextWriter bcfWriter =
            VariantContextWriterFactory.create(
                bcfFile, stub.getMasterSequenceDictionary(), options);
        writer = new TestWriter(writer, bcfWriter);
      }
    }

    return writer;
  }
コード例 #2
0
 /**
  * Constructs an object which will write directly into the output file provided by the stub.
  * Intentionally delaying the writing of the header -- this should be filled in by the walker.
  *
  * <p>Respecs the isCompressed() request in stub, so if isCompressed() is true then this will
  * create a storage output that dumps output to a BlockCompressedOutputStream.
  *
  * @param stub Stub to use when constructing the output file.
  */
 public VariantContextWriterStorage(VariantContextWriterStub stub) {
   if (stub.getOutputFile() != null) {
     this.file = stub.getOutputFile();
     writer = vcfWriterToFile(stub, stub.getOutputFile(), true, true);
   } else if (stub.getOutputStream() != null) {
     this.file = null;
     this.stream = stub.getOutputStream();
     writer =
         VariantContextWriterFactory.create(
             stream, stub.getMasterSequenceDictionary(), stub.getWriterOptions(false));
   } else
     throw new ReviewedStingException(
         "Unable to create target to which to write; storage was provided with neither a file nor a stream.");
 }