Enable on the fly indexing of BCF2
This commit is contained in:
parent
81ab0dd051
commit
27b51d4dea
|
|
@ -43,11 +43,11 @@ import java.io.*;
|
||||||
* this class writes VCF files
|
* this class writes VCF files
|
||||||
*/
|
*/
|
||||||
public abstract class IndexingVCFWriter implements VCFWriter {
|
public abstract class IndexingVCFWriter implements VCFWriter {
|
||||||
final private String name;
|
private final String name;
|
||||||
private final SAMSequenceDictionary refDict;
|
private final SAMSequenceDictionary refDict;
|
||||||
|
|
||||||
private OutputStream outputStream;
|
private OutputStream outputStream;
|
||||||
private PositionalStream positionalStream = null;
|
private PositionalOutputStream positionalOutputStream = null;
|
||||||
private DynamicIndexCreator indexer = null;
|
private DynamicIndexCreator indexer = null;
|
||||||
private LittleEndianOutputStream idxStream = null;
|
private LittleEndianOutputStream idxStream = null;
|
||||||
|
|
||||||
|
|
@ -65,13 +65,13 @@ public abstract class IndexingVCFWriter implements VCFWriter {
|
||||||
//System.out.println("Creating index on the fly for " + location);
|
//System.out.println("Creating index on the fly for " + location);
|
||||||
indexer = new DynamicIndexCreator(IndexFactory.IndexBalanceApproach.FOR_SEEK_TIME);
|
indexer = new DynamicIndexCreator(IndexFactory.IndexBalanceApproach.FOR_SEEK_TIME);
|
||||||
indexer.initialize(location, indexer.defaultBinSize());
|
indexer.initialize(location, indexer.defaultBinSize());
|
||||||
positionalStream = new PositionalStream(output);
|
positionalOutputStream = new PositionalOutputStream(output);
|
||||||
outputStream = positionalStream;
|
outputStream = positionalOutputStream;
|
||||||
} catch ( IOException ex ) {
|
} catch ( IOException ex ) {
|
||||||
// No matter what we keep going, since we don't care if we can't create the index file
|
// No matter what we keep going, since we don't care if we can't create the index file
|
||||||
idxStream = null;
|
idxStream = null;
|
||||||
indexer = null;
|
indexer = null;
|
||||||
positionalStream = null;
|
positionalOutputStream = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +95,7 @@ public abstract class IndexingVCFWriter implements VCFWriter {
|
||||||
// try to close the index stream (keep it separate to help debugging efforts)
|
// try to close the index stream (keep it separate to help debugging efforts)
|
||||||
if ( indexer != null ) {
|
if ( indexer != null ) {
|
||||||
try {
|
try {
|
||||||
Index index = indexer.finalizeIndex(positionalStream.getPosition());
|
Index index = indexer.finalizeIndex(positionalOutputStream.getPosition());
|
||||||
IndexDictionaryUtils.setIndexSequenceDictionary(index, refDict);
|
IndexDictionaryUtils.setIndexSequenceDictionary(index, refDict);
|
||||||
index.write(idxStream);
|
index.write(idxStream);
|
||||||
idxStream.close();
|
idxStream.close();
|
||||||
|
|
@ -113,7 +113,7 @@ public abstract class IndexingVCFWriter implements VCFWriter {
|
||||||
public void add(VariantContext vc) {
|
public void add(VariantContext vc) {
|
||||||
// if we are doing on the fly indexing, add the record ***before*** we write any bytes
|
// if we are doing on the fly indexing, add the record ***before*** we write any bytes
|
||||||
if ( indexer != null )
|
if ( indexer != null )
|
||||||
indexer.addFeature(vc, positionalStream.getPosition());
|
indexer.addFeature(vc, positionalOutputStream.getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -141,30 +141,27 @@ public abstract class IndexingVCFWriter implements VCFWriter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class PositionalStream extends OutputStream {
|
final class PositionalOutputStream extends OutputStream {
|
||||||
OutputStream out = null;
|
private final OutputStream out;
|
||||||
private long position = 0;
|
private long position = 0;
|
||||||
|
|
||||||
public PositionalStream(OutputStream out) {
|
public PositionalOutputStream(final OutputStream out) {
|
||||||
this.out = out;
|
this.out = out;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(final byte[] bytes) throws IOException {
|
public final void write(final byte[] bytes) throws IOException {
|
||||||
write(bytes, 0, bytes.length);
|
write(bytes, 0, bytes.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(final byte[] bytes, int startIndex, int numBytes) throws IOException {
|
public final void write(final byte[] bytes, final int startIndex, final int numBytes) throws IOException {
|
||||||
//System.out.println("write: " + bytes + " " + numBytes);
|
|
||||||
position += numBytes;
|
position += numBytes;
|
||||||
out.write(bytes, startIndex, numBytes);
|
out.write(bytes, startIndex, numBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(int c) throws IOException {
|
public final void write(int c) throws IOException {
|
||||||
System.out.println("write byte: " + c);
|
|
||||||
//System.out.printf("Position %d for %c\n", position, (char)c);
|
|
||||||
position++;
|
position++;
|
||||||
out.write(c);
|
out.write(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getPosition() { return position; }
|
public final long getPosition() { return position; }
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue