On the road to human: make sure the suffix array will fit in a Java array.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1846 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
e740e7a7ce
commit
316b30ee56
|
|
@ -2,7 +2,6 @@ package org.broadinstitute.sting.alignment.bwa.bwt;
|
||||||
|
|
||||||
import org.broadinstitute.sting.alignment.bwa.packing.PackUtils;
|
import org.broadinstitute.sting.alignment.bwa.packing.PackUtils;
|
||||||
import org.broadinstitute.sting.utils.StingException;
|
import org.broadinstitute.sting.utils.StingException;
|
||||||
import org.broadinstitute.sting.utils.Pair;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the Burrows-Wheeler Transform of a reference sequence.
|
* Represents the Burrows-Wheeler Transform of a reference sequence.
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ public class BWTReader {
|
||||||
/**
|
/**
|
||||||
* Input stream from which to read BWT data.
|
* Input stream from which to read BWT data.
|
||||||
*/
|
*/
|
||||||
private InputStream inputStream;
|
private FileInputStream inputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new BWT reader.
|
* Create a new BWT reader.
|
||||||
|
|
@ -25,7 +25,7 @@ public class BWTReader {
|
||||||
*/
|
*/
|
||||||
public BWTReader( File inputFile ) {
|
public BWTReader( File inputFile ) {
|
||||||
try {
|
try {
|
||||||
this.inputStream = new BufferedInputStream(new FileInputStream(inputFile));
|
this.inputStream = new FileInputStream(inputFile);
|
||||||
}
|
}
|
||||||
catch( FileNotFoundException ex ) {
|
catch( FileNotFoundException ex ) {
|
||||||
throw new StingException("Unable to open input file", ex);
|
throw new StingException("Unable to open input file", ex);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ public class SuffixArrayReader {
|
||||||
/**
|
/**
|
||||||
* Input stream from which to read suffix array data.
|
* Input stream from which to read suffix array data.
|
||||||
*/
|
*/
|
||||||
private InputStream inputStream;
|
private FileInputStream inputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BWT to use to fill in missing data.
|
* BWT to use to fill in missing data.
|
||||||
|
|
@ -31,7 +31,7 @@ public class SuffixArrayReader {
|
||||||
*/
|
*/
|
||||||
public SuffixArrayReader(File inputFile, BWT bwt) {
|
public SuffixArrayReader(File inputFile, BWT bwt) {
|
||||||
try {
|
try {
|
||||||
this.inputStream = new BufferedInputStream(new FileInputStream(inputFile));
|
this.inputStream = new FileInputStream(inputFile);
|
||||||
this.bwt = bwt;
|
this.bwt = bwt;
|
||||||
}
|
}
|
||||||
catch( FileNotFoundException ex ) {
|
catch( FileNotFoundException ex ) {
|
||||||
|
|
@ -57,7 +57,7 @@ public class SuffixArrayReader {
|
||||||
intPackedInputStream.read(occurrences);
|
intPackedInputStream.read(occurrences);
|
||||||
// Throw away the suffix array size in bytes and use the occurrences table directly.
|
// Throw away the suffix array size in bytes and use the occurrences table directly.
|
||||||
suffixArrayInterval = intPackedInputStream.read();
|
suffixArrayInterval = intPackedInputStream.read();
|
||||||
suffixArray = new int[occurrences[occurrences.length-1]+1/suffixArrayInterval];
|
suffixArray = new int[(occurrences[occurrences.length-1]+suffixArrayInterval-1)/suffixArrayInterval];
|
||||||
intPackedInputStream.read(suffixArray);
|
intPackedInputStream.read(suffixArray);
|
||||||
}
|
}
|
||||||
catch( IOException ex ) {
|
catch( IOException ex ) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package org.broadinstitute.sting.alignment.bwa.packing;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read a set of integers packed into
|
* Read a set of integers packed into
|
||||||
|
|
@ -14,12 +15,22 @@ public class IntPackedInputStream {
|
||||||
/**
|
/**
|
||||||
* Ultimate target for the occurrence array.
|
* Ultimate target for the occurrence array.
|
||||||
*/
|
*/
|
||||||
private final InputStream targetInputStream;
|
private final FileInputStream targetInputStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Target channel from which to pull file data.
|
||||||
|
*/
|
||||||
|
private final FileChannel targetInputChannel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The byte order in which integer input data appears.
|
* The byte order in which integer input data appears.
|
||||||
*/
|
*/
|
||||||
private final ByteBuffer buffer;
|
private final ByteOrder byteOrder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How many bytes are required to store an integer?
|
||||||
|
*/
|
||||||
|
private final int bytesPerInteger = PackUtils.bitsInType(Integer.class)/PackUtils.BITS_PER_BYTE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new PackedIntInputStream, writing to the given target file.
|
* Create a new PackedIntInputStream, writing to the given target file.
|
||||||
|
|
@ -36,9 +47,10 @@ public class IntPackedInputStream {
|
||||||
* @param inputStream Input stream from which to read ints.
|
* @param inputStream Input stream from which to read ints.
|
||||||
* @param byteOrder Endianness to use when writing a list of integers.
|
* @param byteOrder Endianness to use when writing a list of integers.
|
||||||
*/
|
*/
|
||||||
public IntPackedInputStream(InputStream inputStream, ByteOrder byteOrder) {
|
public IntPackedInputStream(FileInputStream inputStream, ByteOrder byteOrder) {
|
||||||
this.targetInputStream = inputStream;
|
this.targetInputStream = inputStream;
|
||||||
this.buffer = ByteBuffer.allocate(PackUtils.bitsInType(Integer.class)/ PackUtils.BITS_PER_BYTE).order(byteOrder);
|
this.targetInputChannel = inputStream.getChannel();
|
||||||
|
this.byteOrder = byteOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -69,11 +81,15 @@ public class IntPackedInputStream {
|
||||||
* @throws IOException if an I/O error occurs.
|
* @throws IOException if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
public void read( int[] data, int offset, int length ) throws IOException {
|
public void read( int[] data, int offset, int length ) throws IOException {
|
||||||
for(int i = offset; i < offset+length; i++) {
|
ByteBuffer readBuffer = ByteBuffer.allocate(bytesPerInteger*length).order(byteOrder);
|
||||||
targetInputStream.read(buffer.array());
|
|
||||||
data[i] = buffer.getInt();
|
targetInputChannel.read(readBuffer,targetInputChannel.position());
|
||||||
buffer.rewind();
|
readBuffer.flip();
|
||||||
}
|
targetInputChannel.position(targetInputChannel.position()+readBuffer.remaining());
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while(i < length)
|
||||||
|
data[offset+i++] = readBuffer.getInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue