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:
hanna 2009-10-14 21:45:35 +00:00
parent e740e7a7ce
commit 316b30ee56
4 changed files with 30 additions and 15 deletions

View File

@ -2,7 +2,6 @@ package org.broadinstitute.sting.alignment.bwa.bwt;
import org.broadinstitute.sting.alignment.bwa.packing.PackUtils;
import org.broadinstitute.sting.utils.StingException;
import org.broadinstitute.sting.utils.Pair;
/**
* Represents the Burrows-Wheeler Transform of a reference sequence.

View File

@ -17,7 +17,7 @@ public class BWTReader {
/**
* Input stream from which to read BWT data.
*/
private InputStream inputStream;
private FileInputStream inputStream;
/**
* Create a new BWT reader.
@ -25,7 +25,7 @@ public class BWTReader {
*/
public BWTReader( File inputFile ) {
try {
this.inputStream = new BufferedInputStream(new FileInputStream(inputFile));
this.inputStream = new FileInputStream(inputFile);
}
catch( FileNotFoundException ex ) {
throw new StingException("Unable to open input file", ex);

View File

@ -17,7 +17,7 @@ public class SuffixArrayReader {
/**
* Input stream from which to read suffix array data.
*/
private InputStream inputStream;
private FileInputStream inputStream;
/**
* BWT to use to fill in missing data.
@ -31,7 +31,7 @@ public class SuffixArrayReader {
*/
public SuffixArrayReader(File inputFile, BWT bwt) {
try {
this.inputStream = new BufferedInputStream(new FileInputStream(inputFile));
this.inputStream = new FileInputStream(inputFile);
this.bwt = bwt;
}
catch( FileNotFoundException ex ) {
@ -57,7 +57,7 @@ public class SuffixArrayReader {
intPackedInputStream.read(occurrences);
// Throw away the suffix array size in bytes and use the occurrences table directly.
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);
}
catch( IOException ex ) {

View File

@ -3,6 +3,7 @@ package org.broadinstitute.sting.alignment.bwa.packing;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.channels.FileChannel;
/**
* Read a set of integers packed into
@ -14,12 +15,22 @@ public class IntPackedInputStream {
/**
* 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.
*/
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.
@ -36,9 +47,10 @@ public class IntPackedInputStream {
* @param inputStream Input stream from which to read ints.
* @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.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.
*/
public void read( int[] data, int offset, int length ) throws IOException {
for(int i = offset; i < offset+length; i++) {
targetInputStream.read(buffer.array());
data[i] = buffer.getInt();
buffer.rewind();
}
ByteBuffer readBuffer = ByteBuffer.allocate(bytesPerInteger*length).order(byteOrder);
targetInputChannel.read(readBuffer,targetInputChannel.position());
readBuffer.flip();
targetInputChannel.position(targetInputChannel.position()+readBuffer.remaining());
int i = 0;
while(i < length)
data[offset+i++] = readBuffer.getInt();
}
/**