if (chrPos == null) {
return new ArrayList<Peak>();
} else {
List<Peak> peaks = new ArrayList<Peak>(10000);
LittleEndianInputStream reader = null;
SeekableStream ss = null;
try {
ss = IGVSeekableStreamFactory.getInstance().getStreamFor(path);
int bufferSize = 512000;
long contentLength = ss.length();
if(contentLength > 0) {
bufferSize = (int) Math.min(contentLength, bufferSize);
}
IGVSeekableBufferedStream bufferedStream = new IGVSeekableBufferedStream(ss, bufferSize);
bufferedStream.seek(chrPos);
reader = new LittleEndianInputStream(bufferedStream);
int nBytes = reader.readInt();
byte[] compressedBytes = new byte[nBytes];
bufferedStream.readFully(compressedBytes);
byte[] bytes = compressionUtils.decompress(compressedBytes);
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
reader = new LittleEndianInputStream(bis);
String chrRecorded = reader.readString();
if (!chrRecorded.equals(chr)) {
throw new RuntimeException("Error paring peak file: " + path +
"<br>Expected: " + chr + " found: " + chrRecorded);
}
int nDataPoints = reader.readInt();
for (int n = 0; n < nDataPoints; n++) {
int start = reader.readInt();
int end = reader.readInt();
float combinedScore = reader.readFloat();
float[] timePointScores = new float[nTimePoints];
for (int i = 0; i < nTimePoints; i++) {
timePointScores[i] = reader.readFloat();
}
peaks.add(new Peak(chr, start, end, "", combinedScore, timePointScores));
}
return peaks;
} finally {
if (ss != null) ss.close();
}
}
}