protected String statsSummary() { final BlockStats stats = getBlockStats(false); return String.format("%12d blocks (%12d empty (%.2f%%))", stats.total, stats.empty, (100.0 * stats.empty) / stats.total); }
@Override public List<Block> getBlocks(final String chr, final int start, final int end) { return getChrIndex(chr).getBlocks(start, end); }
@Override public boolean isCurrentVersion() { if (!super.isCurrentVersion()) return false; // todo fixme nasty hack to determine if this is an old style V3 linear index (without nFeaturesPerBin) for (final htsjdk.tribble.index.ChrIndex chrIndex : chrIndices.values()) if (((ChrIndex) chrIndex).OLD_V3_INDEX) return false; return true; }
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(); }
@Override public void write(final Path idxPath) throws IOException { try(final LittleEndianOutputStream idxStream = new LittleEndianOutputStream(new BufferedOutputStream(Files.newOutputStream(idxPath)))) { write(idxStream); } }
@Override public void write(final LittleEndianOutputStream stream) throws IOException { writeHeader(stream); //# of chromosomes stream.writeInt(chrIndices.size()); for (final ChrIndex chrIdx : chrIndices.values()) { chrIdx.write(stream); } }
/** * write the header to the target output stream * * @param dos the little endian output stream * @throws IOException an exception when we can't write to the file */ private void writeHeader(final LittleEndianOutputStream dos) throws IOException { dos.writeInt(MAGIC_NUMBER); dos.writeInt(getType()); dos.writeInt(version); dos.writeString(indexedPath.toUri().toString()); dos.writeLong(indexedFileSize); dos.writeLong(indexedFileTS); dos.writeString(indexedFileMD5); dos.writeInt(flags); // Properties (Version 3 and later) dos.writeInt(properties.size()); for (final Map.Entry<String, String> prop : properties.entrySet()) { dos.writeString(prop.getKey()); dos.writeString(prop.getValue()); } }
/** * read the header from the input stream * * @param dis the little endian input stream * @throws IOException if we fail to read from the file at any point */ private void readHeader(final LittleEndianInputStream dis) throws IOException { version = dis.readInt(); indexedFile = new File(dis.readString()); indexedFileSize = dis.readLong(); indexedFileTS = dis.readLong(); indexedFileMD5 = dis.readString(); flags = dis.readInt(); if (version < 3 && (flags & SEQUENCE_DICTIONARY_FLAG) == SEQUENCE_DICTIONARY_FLAG) { readSequenceDictionary(dis); } if (version >= 3) { int nProperties = dis.readInt(); while (nProperties-- > 0) { final String key = dis.readString(); final String value = dis.readString(); properties.put(key, value); } } }
/** * Gets the indexed file. * @throws UnsupportedOperationException if the path cannot be represented as a file. * @deprecated on 03/2017. Use {@link #getIndexedPath()} instead. */ @Deprecated public File getIndexedFile() { return getIndexedPath().toFile(); }
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(); }
@Override public void writeBasedOnFeaturePath(final Path featurePath) throws IOException { if (!Files.isRegularFile(featurePath)) { throw new IOException("Cannot write based on a non-regular file: " + featurePath.toUri()); } write(Tribble.indexPath(featurePath)); }
@Override public void write(final LittleEndianOutputStream stream) throws IOException { writeHeader(stream); //# of chromosomes stream.writeInt(chrIndices.size()); for (final ChrIndex chrIdx : chrIndices.values()) { chrIdx.write(stream); } }
/** * write the header to the target output stream * * @param dos the little endian output stream * @throws IOException an exception when we can't write to the file */ private void writeHeader(final LittleEndianOutputStream dos) throws IOException { dos.writeInt(MAGIC_NUMBER); dos.writeInt(getType()); dos.writeInt(version); dos.writeString(indexedPath.toUri().toString()); dos.writeLong(indexedFileSize); dos.writeLong(indexedFileTS); dos.writeString(indexedFileMD5); dos.writeInt(flags); // Properties (Version 3 and later) dos.writeInt(properties.size()); for (final Map.Entry<String, String> prop : properties.entrySet()) { dos.writeString(prop.getKey()); dos.writeString(prop.getValue()); } }
/** * read the header from the input stream * * @param dis the little endian input stream * @throws IOException if we fail to read from the file at any point */ private void readHeader(final LittleEndianInputStream dis) throws IOException { version = dis.readInt(); indexedPath = IOUtil.getPath(dis.readString()); indexedFileSize = dis.readLong(); indexedFileTS = dis.readLong(); indexedFileMD5 = dis.readString(); flags = dis.readInt(); if (version < 3 && (flags & SEQUENCE_DICTIONARY_FLAG) == SEQUENCE_DICTIONARY_FLAG) { readSequenceDictionary(dis); } if (version >= 3) { int nProperties = dis.readInt(); while (nProperties-- > 0) { final String key = dis.readString(); final String value = dis.readString(); properties.put(key, value); } } }
/** * Gets the indexed file. * @throws UnsupportedOperationException if the path cannot be represented as a file. * @deprecated on 03/2017. Use {@link #getIndexedPath()} instead. */ @Deprecated public File getIndexedFile() { return getIndexedPath().toFile(); }
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(); }
protected String statsSummary() { final BlockStats stats = getBlockStats(false); return String.format("%12d blocks (%12d empty (%.2f%%))", stats.total, stats.empty, (100.0 * stats.empty) / stats.total); }
@Override public List<Block> getBlocks(final String chr, final int start, final int end) { return getChrIndex(chr).getBlocks(start, end); }
@Override public void write(final Path idxPath) throws IOException { try(final LittleEndianOutputStream idxStream = new LittleEndianOutputStream(new BufferedOutputStream(Files.newOutputStream(idxPath)))) { write(idxStream); } }
public void write(final LittleEndianOutputStream stream) throws IOException { writeHeader(stream); //# of chromosomes stream.writeInt(chrIndices.size()); for (final ChrIndex chrIdx : chrIndices.values()) { chrIdx.write(stream); } }