Skip to content

Commit

Permalink
Merge pull request #641 from samtools/ak_split_asyncFlags
Browse files Browse the repository at this point in the history
split async flags for read and write
  • Loading branch information
akiezun authored Jun 21, 2016
2 parents dbee9ac + f5eb97d commit 2e26fe8
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 43 deletions.
37 changes: 13 additions & 24 deletions src/main/java/htsjdk/samtools/Defaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,20 @@ public class Defaults {
/** Should MD5 files be created when writing out SAM and BAM files? Default = false. */
public static final boolean CREATE_MD5;

/** Should asynchronous I/O be used where supported throughout all of htsjdk (one thread per file).
* Note: this option takes precedence over {@link #USE_ASYNC_IO_FOR_SAMTOOLS} and {@link #USE_ASYNC_IO_FOR_TRIBBLE}.
/** Should asynchronous read I/O be used where supported by the samtools package (one thread per file).
* Default = false.
*/
public static final boolean USE_ASYNC_IO;
public static final boolean USE_ASYNC_IO_READ_FOR_SAMTOOLS;

/** Should asynchronous I/O be used where supported by the samtools package (one thread per file).
* Note: The {@link #USE_ASYNC_IO} option takes precedence over this option.
/** Should asynchronous write I/O be used where supported by the samtools package (one thread per file).
* Default = false.
*/
public static final boolean USE_ASYNC_IO_FOR_SAMTOOLS;
public static final boolean USE_ASYNC_IO_WRITE_FOR_SAMTOOLS;

/** Should asynchronous I/O be used where supported by the tribble package (one thread per file).
* Note: performance may depend on the characteristics of the input file (eg number of samples in the VCF) and should be tested on a case-by-case basis.
* In particular, asynchronous reading of VCF files with few samples is known to perform worse than synchronous reading.
* Note: The {@link #USE_ASYNC_IO} option takes precedence over this option.
/** Should asynchronous write I/O be used where supported by the tribble package (one thread per file).
* Default = false.
*/
public static final boolean USE_ASYNC_IO_FOR_TRIBBLE;
public static final boolean USE_ASYNC_IO_WRITE_FOR_TRIBBLE;

/** Compresion level to be used for writing BAM and other block-compressed outputs. Default = 5. */
public static final int COMPRESSION_LEVEL;
Expand Down Expand Up @@ -93,15 +88,9 @@ public class Defaults {
static {
CREATE_INDEX = getBooleanProperty("create_index", false);
CREATE_MD5 = getBooleanProperty("create_md5", false);
if (hasProperty("use_async_io")){
USE_ASYNC_IO = getBooleanProperty("use_async_io", false);
USE_ASYNC_IO_FOR_SAMTOOLS = USE_ASYNC_IO;
USE_ASYNC_IO_FOR_TRIBBLE = USE_ASYNC_IO;
} else {
USE_ASYNC_IO = false;
USE_ASYNC_IO_FOR_SAMTOOLS = getBooleanProperty("use_async_io_samtools", false);
USE_ASYNC_IO_FOR_TRIBBLE = getBooleanProperty("use_async_io_tribble", false);
}
USE_ASYNC_IO_READ_FOR_SAMTOOLS = getBooleanProperty("use_async_io_read_samtools", false);
USE_ASYNC_IO_WRITE_FOR_SAMTOOLS = getBooleanProperty("use_async_io_write_samtools", false);
USE_ASYNC_IO_WRITE_FOR_TRIBBLE = getBooleanProperty("use_async_io_write_tribble", false);
COMPRESSION_LEVEL = getIntProperty("compression_level", 5);
BUFFER_SIZE = getIntProperty("buffer_size", 1024 * 128);
if (BUFFER_SIZE == 0) {
Expand All @@ -126,9 +115,9 @@ public static SortedMap<String, Object> allDefaults(){
final SortedMap<String, Object> result = new TreeMap<>();
result.put("CREATE_INDEX", CREATE_INDEX);
result.put("CREATE_MD5", CREATE_MD5);
result.put("USE_ASYNC_IO", USE_ASYNC_IO);
result.put("USE_ASYNC_IO_FOR_SAMTOOLS", USE_ASYNC_IO_FOR_SAMTOOLS);
result.put("USE_ASYNC_IO_FOR_TRIBBLE", USE_ASYNC_IO_FOR_TRIBBLE);
result.put("USE_ASYNC_IO_READ_FOR_SAMTOOLS", USE_ASYNC_IO_READ_FOR_SAMTOOLS);
result.put("USE_ASYNC_IO_WRITE_FOR_SAMTOOLS", USE_ASYNC_IO_WRITE_FOR_SAMTOOLS);
result.put("USE_ASYNC_IO_WRITE_FOR_TRIBBLE", USE_ASYNC_IO_WRITE_FOR_TRIBBLE);
result.put("COMPRESSION_LEVEL", COMPRESSION_LEVEL);
result.put("BUFFER_SIZE", BUFFER_SIZE);
result.put("NON_ZERO_BUFFER_SIZE", NON_ZERO_BUFFER_SIZE);
Expand Down Expand Up @@ -176,7 +165,7 @@ private static int getIntProperty(final String name, final int def) {
return Integer.parseInt(value);
}

/** Gets a File system property, prefixed with "samdjk." using the default if the property does not exist. */
/** Gets a File system property, prefixed with "samjdk." using the default if the property does not exist. */
private static File getFileProperty(final String name, final String def) {
final String value = getStringProperty(name, def);
// TODO: assert that it is readable
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/htsjdk/samtools/SAMFileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static SAMSequenceDictionary getSequenceDictionary(final File dictionaryF
private BAMIndex mIndex = null;
private SAMRecordFactory samRecordFactory = new DefaultSAMRecordFactory();
private ReaderImplementation mReader = null;
private boolean useAsyncIO = Defaults.USE_ASYNC_IO_FOR_SAMTOOLS;
private boolean useAsyncIO = Defaults.USE_ASYNC_IO_READ_FOR_SAMTOOLS;

private File samFile = null;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/htsjdk/samtools/SAMFileWriterFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class SAMFileWriterFactory implements Cloneable {
private boolean createIndex = defaultCreateIndexWhileWriting;
private static boolean defaultCreateMd5File = Defaults.CREATE_MD5;
private boolean createMd5File = defaultCreateMd5File;
private boolean useAsyncIo = Defaults.USE_ASYNC_IO_FOR_SAMTOOLS;
private boolean useAsyncIo = Defaults.USE_ASYNC_IO_WRITE_FOR_SAMTOOLS;
private int asyncOutputBufferSize = AsyncSAMFileWriter.DEFAULT_QUEUE_SIZE;
private int bufferSize = Defaults.BUFFER_SIZE;
private File tmpDir;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/htsjdk/samtools/SamReaderFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private static class SamReaderFactoryImpl extends SamReaderFactory {
private final static Log LOG = Log.getInstance(SamReaderFactory.class);
private final EnumSet<Option> enabledOptions;
private ValidationStringency validationStringency;
private boolean asynchronousIO = Defaults.USE_ASYNC_IO_FOR_SAMTOOLS;
private boolean asynchronousIO = Defaults.USE_ASYNC_IO_READ_FOR_SAMTOOLS;
private SAMRecordFactory samRecordFactory;
private CustomReaderFactory customReaderFactory;
private CRAMReferenceSource referenceSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author Tim Fennell
*/
public class FastqWriterFactory {
boolean useAsyncIo = Defaults.USE_ASYNC_IO_FOR_SAMTOOLS;
boolean useAsyncIo = Defaults.USE_ASYNC_IO_WRITE_FOR_SAMTOOLS;
boolean createMd5 = Defaults.CREATE_MD5;

/** Sets whether or not to use async io (i.e. a dedicated thread per writer. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public enum OutputType {
* Default constructor. Adds <code>USE_ASYNC_IO</code> to the Options if it is present in Defaults.
*/
public VariantContextWriterBuilder() {
if (Defaults.USE_ASYNC_IO_FOR_TRIBBLE) {
if (Defaults.USE_ASYNC_IO_WRITE_FOR_TRIBBLE) {
options.add(Options.USE_ASYNC_IO);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class VariantContextWriterFactory {
public static final EnumSet<Options> NO_OPTIONS = EnumSet.noneOf(Options.class);

static {
if (Defaults.USE_ASYNC_IO_FOR_TRIBBLE) {
if (Defaults.USE_ASYNC_IO_WRITE_FOR_TRIBBLE) {
DEFAULT_OPTIONS.add(Options.USE_ASYNC_IO);
}
}
Expand Down
14 changes: 2 additions & 12 deletions src/test/java/htsjdk/samtools/SAMFileWriterFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,11 @@
import htsjdk.samtools.cram.build.CramIO;
import htsjdk.samtools.cram.ref.ReferenceSource;
import htsjdk.samtools.util.IOUtil;
import htsjdk.variant.variantcontext.writer.AsyncVariantContextWriter;
import htsjdk.variant.variantcontext.writer.Options;
import htsjdk.variant.variantcontext.writer.VariantContextWriter;
import htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.*;

public class SAMFileWriterFactoryTest {

Expand Down Expand Up @@ -306,7 +296,7 @@ public void testAsync() throws IOException {
final File referenceFile = new File(TEST_DATA_DIR, "hg19mini.fasta");

SAMFileWriter writer = builder.makeWriter(header, false, outputFile, referenceFile);
Assert.assertEquals(writer instanceof AsyncSAMFileWriter, Defaults.USE_ASYNC_IO_FOR_SAMTOOLS, "testAsync default");
Assert.assertEquals(writer instanceof AsyncSAMFileWriter, Defaults.USE_ASYNC_IO_WRITE_FOR_SAMTOOLS, "testAsync default");

writer = builder.setUseAsyncIo(true).makeWriter(header, false, outputFile, referenceFile);
Assert.assertTrue(writer instanceof AsyncSAMFileWriter, "testAsync option=set");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public void testAsync() {
.setOutputFile(vcf);

VariantContextWriter writer = builder.build();
Assert.assertEquals(writer instanceof AsyncVariantContextWriter, Defaults.USE_ASYNC_IO_FOR_TRIBBLE, "testAsync default");
Assert.assertEquals(writer instanceof AsyncVariantContextWriter, Defaults.USE_ASYNC_IO_WRITE_FOR_TRIBBLE, "testAsync default");

writer = builder.setOption(Options.USE_ASYNC_IO).build();
Assert.assertTrue(writer instanceof AsyncVariantContextWriter, "testAsync option=set");
Expand Down

0 comments on commit 2e26fe8

Please sign in to comment.