/** * Transform the string to a valid output format. * If none, VCF by default. * * @param outputFormatStr Output format as String * @param output Output file * @return Valid VariantOutputFormat * @throws IllegalArgumentException if the outputFormatStr is not valid */ public static VariantOutputFormat toOutputFormat(String outputFormatStr, String output) { if (!StringUtils.isEmpty(outputFormatStr)) { outputFormatStr = outputFormatStr.replace('.', '_'); return VariantOutputFormat.valueOf(outputFormatStr.toUpperCase()); } else if (isStandardOutput(output)) { return VCF; } else { return VCF_GZ; } }
public static OutputStream getOutputStream(String output, VariantOutputFormat outputFormat) throws IOException { boolean gzip = outputFormat.isGzip(); // output format has priority over output name OutputStream outputStream; if (isStandardOutput(output)) { // Unclosable OutputStream outputStream = new UnclosableOutputStream(System.out); } else { outputStream = new FileOutputStream(output); logger.debug("writing to %s", output); } // If compressed a GZip output stream is used if (gzip && outputFormat != VariantOutputFormat.AVRO_GZ) { outputStream = new GZIPOutputStream(outputStream); } else { outputStream = new BufferedOutputStream(outputStream); } logger.debug("using {} output stream", gzip ? "gzipped" : "plain"); return outputStream; }
public static String checkOutput(@Nullable String output, VariantOutputFormat outputFormat) throws IOException { if (isStandardOutput(output)) {
/** * Exports the result of the given query and the associated metadata. * @param outputFileUri Optional output file. If null or empty, will print into the Standard output. Won't export any metadata. * @param outputFormat Variant Output format. * @param query Query with the variants to export * @param queryOptions Query options * @throws IOException If there is any IO error * @throws StorageEngineException If there is any error exporting variants */ public void export(@Nullable URI outputFileUri, VariantOutputFormat outputFormat, Query query, QueryOptions queryOptions) throws IOException, StorageEngineException { String outputFile = null; if (outputFileUri != null) { outputFile = outputFileUri.getPath(); } outputFile = VariantWriterFactory.checkOutput(outputFile, outputFormat); try (OutputStream os = VariantWriterFactory.getOutputStream(outputFile, outputFormat)) { boolean logProgress = !VariantWriterFactory.isStandardOutput(outputFile); exportData(os, outputFormat, query, queryOptions, logProgress); } if (metadataFactory != null && !VariantWriterFactory.isStandardOutput(outputFile)) { VariantMetadata metadata = metadataFactory.makeVariantMetadata(query, queryOptions); writeMetadata(metadata, outputFile + METADATA_FILE_EXTENSION); } }
URI outputFile = null; final Path outdir; if (!VariantWriterFactory.isStandardOutput(outputStr)) { URI outdirUri = null; try {