@Override public void read(final LittleEndianInputStream dis) throws IOException { name = dis.readString(); binWidth = dis.readInt(); final int nBins = dis.readInt(); longestFeature = dis.readInt(); //largestBlockSize = dis.readInt(); // largestBlockSize and totalBlockSize are old V3 index values. largest block size should be 0 for // all newer V3 block. This is a nasty hack that should be removed when we go to V4 (XML!) indices OLD_V3_INDEX = dis.readInt() > 0; nFeatures = dis.readInt(); // note the code below accounts for > 60% of the total time to read an index blocks = new ArrayList<Block>(nBins); long pos = dis.readLong(); for (int binNumber = 0; binNumber < nBins; binNumber++) { final long nextPos = dis.readLong(); final long size = nextPos - pos; blocks.add(new Block(pos, size)); pos = nextPos; } }
/** * Keep reading until the input buffer is filled. */ private void readFully(byte b[]) throws IOException { int len = b.length; if (len < 0) throw new IndexOutOfBoundsException(); int n = 0; while (n < len) { int count = read(b, n, len - n); if (count < 0) throw new EOFException(); n += count; } }
/** * */ public long readLong() throws IOException { readFully(buffer); long byte1 = (long) buffer[0]; long byte2 = (long) buffer[1]; long byte3 = (long) buffer[2]; long byte4 = (long) buffer[3]; long byte5 = (long) buffer[4]; long byte6 = (long) buffer[5]; long byte7 = (long) buffer[6]; long byte8 = (long) buffer[7]; return (byte8 << 56) + ((byte7 << 56) >>> 8) + ((byte6 << 56) >>> 16) + ((byte5 << 56) >>> 24) + ((byte4 << 56) >>> 32) + ((byte3 << 56) >>> 40) + ((byte2 << 56) >>> 48) + ((byte1 << 56) >>> 56); }
/** * Kept to maintain backward compatibility with pre version 3 indexes. The sequence dictionary is no longer * used, use getSequenceNames() instead. * * @param dis * @throws IOException */ private void readSequenceDictionary(final LittleEndianInputStream dis) throws IOException { final int size = dis.readInt(); if (size < 0) throw new IllegalStateException("Size of the sequence dictionary entries is negative"); for (int x = 0; x < size; x++) { dis.readString(); dis.readInt(); } }
private LinearIndex loadLinearIndex(final int referenceSequenceIndex, final LittleEndianInputStream dis) throws IOException { final int numElements = dis.readInt(); final long[] elements = new long[numElements]; for (int i = 0; i < numElements; ++i) { elements[i] = dis.readLong(); } return new LinearIndex(referenceSequenceIndex, 0, elements); }
@Test public void testRead() throws Exception { LittleEndianInputStream lis = new LittleEndianInputStream(new BufferedInputStream(new FileInputStream("les_test.bin"))); assertEquals("Binary test file", lis.readString()); assertEquals(Float.MAX_VALUE, lis.readFloat()); assertEquals(Byte.MAX_VALUE, lis.readByte()); assertEquals(Short.MAX_VALUE, lis.readShort()); assertEquals(Integer.MAX_VALUE, lis.readInt()); assertEquals(Long.MAX_VALUE, lis.readLong()); assertEquals(Double.MAX_VALUE, lis.readDouble()); lis.close(); }
LittleEndianInputStream parser = new LittleEndianInputStream(new BufferedInputStream(ParsingUtils.openInputStream(indexURL))); int magic = parser.readInt(); int nref = parser.readInt(); int format = parser.readInt(); int col_seq = parser.readInt(); int col_beg = parser.readInt(); int col_end = parser.readInt(); int meta = parser.readInt(); int skip = parser.readInt(); int l_nm = parser.readInt(); String seq_name = parser.readString(); int nbin = parser.readInt(); int binNumber = parser.readInt(); int nchnk = parser.readInt(); // # of chunks for this bin long n_maped = parser.readLong(); long nUnmapped = parser.readLong(); int nchnk = parser.readInt(); // # of chunks for this bin int nintv = parser.readInt(); for (int i = 0; i < nintv; i++) {
private TabixIndex(final InputStream inputStream, final boolean closeInputStream) throws IOException { final LittleEndianInputStream dis = new LittleEndianInputStream(inputStream); if (dis.readInt() != MAGIC_NUMBER) { throw new TribbleException(String.format("Unexpected magic number 0x%x", MAGIC_NUMBER)); final int numSequences = dis.readInt(); indices = new BinningIndexContent[numSequences]; formatSpec = new TabixFormat(); formatSpec.flags = dis.readInt(); formatSpec.sequenceColumn = dis.readInt(); formatSpec.startPositionColumn = dis.readInt(); formatSpec.endPositionColumn = dis.readInt(); formatSpec.metaCharacter = (char) dis.readInt(); formatSpec.numHeaderLinesToSkip = dis.readInt(); final int nameBlockSize = dis.readInt(); final byte[] nameBlock = new byte[nameBlockSize]; if (dis.read(nameBlock) != nameBlockSize) throw new EOFException("Premature end of file reading Tabix header"); final List<String> sequenceNames = new ArrayList<String>(numSequences); int startPos = 0;
public final float readFloat() throws IOException { return Float.intBitsToFloat(this.readInt()); }
final LittleEndianInputStream dis = new LittleEndianInputStream(is); final int magicNumber; final int type; magicNumber = dis.readInt(); type = dis.readInt(); is.reset();
public void read(final LittleEndianInputStream dis) throws IOException { try { readHeader(dis); int nChromosomes = dis.readInt(); chrIndices = new LinkedHashMap<String, ChrIndex>(nChromosomes); while (nChromosomes-- > 0) { final ChrIndex chrIdx = (ChrIndex) getChrIndexClass().newInstance(); chrIdx.read(dis); chrIndices.put(chrIdx.getName(), chrIdx); } } catch (final InstantiationException e) { throw new TribbleException.UnableToCreateCorrectIndexType("Unable to create class " + getChrIndexClass(), e); } catch (final IllegalAccessException e) { throw new TribbleException.UnableToCreateCorrectIndexType("Unable to create class " + getChrIndexClass(), e); } finally { dis.close(); } //printIndexInfo(); }
public final double readDouble() throws IOException { return Double.longBitsToDouble(this.readLong()); }
/** * Load from file. * @param inputStream This method assumes that the input stream is already buffered as appropriate. */ public LinearIndex(final InputStream inputStream) throws IOException { final LittleEndianInputStream dis = new LittleEndianInputStream(inputStream); validateIndexHeader(INDEX_TYPE, dis); read(dis); }
try { if (bufferedInputStream != null) bufferedInputStream.close(); if (dis != null) dis.close();
private TabixIndex(final InputStream inputStream, final boolean closeInputStream) throws IOException { final LittleEndianInputStream dis = new LittleEndianInputStream(inputStream); if (dis.readInt() != MAGIC_NUMBER) { throw new TribbleException(String.format("Unexpected magic number 0x%x", MAGIC_NUMBER)); final int numSequences = dis.readInt(); indices = new BinningIndexContent[numSequences]; formatSpec = new TabixFormat(); formatSpec.flags = dis.readInt(); formatSpec.sequenceColumn = dis.readInt(); formatSpec.startPositionColumn = dis.readInt(); formatSpec.endPositionColumn = dis.readInt(); formatSpec.metaCharacter = (char) dis.readInt(); formatSpec.numHeaderLinesToSkip = dis.readInt(); final int nameBlockSize = dis.readInt(); final byte[] nameBlock = new byte[nameBlockSize]; if (dis.read(nameBlock) != nameBlockSize) throw new EOFException("Premature end of file reading Tabix header"); final List<String> sequenceNames = new ArrayList<String>(numSequences); int startPos = 0;
private LinearIndex loadLinearIndex(final int referenceSequenceIndex, final LittleEndianInputStream dis) throws IOException { final int numElements = dis.readInt(); final long[] elements = new long[numElements]; for (int i = 0; i < numElements; ++i) { elements[i] = dis.readLong(); } return new LinearIndex(referenceSequenceIndex, 0, elements); }
public final float readFloat() throws IOException { return Float.intBitsToFloat(this.readInt()); }
/** * Kept to maintain backward compatibility with pre version 3 indexes. The sequence dictionary is no longer * used, use getSequenceNames() instead. * * @param dis * @throws IOException */ private void readSequenceDictionary(final LittleEndianInputStream dis) throws IOException { final int size = dis.readInt(); if (size < 0) throw new IllegalStateException("Size of the sequence dictionary entries is negative"); for (int x = 0; x < size; x++) { dis.readString(); dis.readInt(); } }
final LittleEndianInputStream dis = new LittleEndianInputStream(is); final int magicNumber; final int type; magicNumber = dis.readInt(); type = dis.readInt(); is.reset();
public void read(final LittleEndianInputStream dis) throws IOException { try { readHeader(dis); int nChromosomes = dis.readInt(); chrIndices = new LinkedHashMap<String, ChrIndex>(nChromosomes); while (nChromosomes-- > 0) { final ChrIndex chrIdx = (ChrIndex) getChrIndexClass().newInstance(); chrIdx.read(dis); chrIndices.put(chrIdx.getName(), chrIdx); } } catch (final InstantiationException e) { throw new TribbleException.UnableToCreateCorrectIndexType("Unable to create class " + getChrIndexClass(), e); } catch (final IllegalAccessException e) { throw new TribbleException.UnableToCreateCorrectIndexType("Unable to create class " + getChrIndexClass(), e); } finally { dis.close(); } //printIndexInfo(); }