/** * Alternative to other one with similar name * * @param directory directory containing SDF * @param indexFile index file * @param loadNames should we load names * @param loadFullNames should we load full names * @param region region to restrict to * @throws IOException IO exception occurs */ CompressedMemorySequencesReader2( File directory, IndexFile indexFile, boolean loadNames, boolean loadFullNames, LongRange region) throws IOException { mIndexFile = indexFile; mRegion = SequencesReaderFactory.resolveRange(indexFile, region); mStart = mRegion.getStart(); mEnd = mRegion.getEnd(); mNumberSequences = mEnd - mStart; mData = DataInMemory.loadDelayQuality( directory, indexFile, DataFileIndex.loadSequenceDataFileIndex(indexFile.dataIndexVersion(), directory), mStart, mEnd); if (mNumberSequences > Integer.MAX_VALUE) { throw new IllegalArgumentException( "Too many sequences in region: " + region + ", maximum is: " + Integer.MAX_VALUE); } mDirectory = directory; if (loadNames && mIndexFile.hasNames()) { loadNames(); loadNameSuffixes(loadFullNames, mIndexFile.hasSequenceNameSuffixes()); } final StringBuilder sb = new StringBuilder("CMSR2 statistics"); sb.append(LS); this.infoString(sb); Diagnostic.userLog(sb.toString()); }
@Override public int read(long sequenceIndex, byte[] dataOut) throws IllegalArgumentException, IOException { if (sequenceIndex >= mNumberSequences) { throw new IllegalArgumentException( "Invalid sequence index: " + sequenceIndex + ", maximum is: " + mNumberSequences); } return mData.readSequence((int) sequenceIndex, dataOut, 0, Integer.MAX_VALUE); }
@Override public int readQuality(long sequenceIndex, byte[] dest, int start, int length) throws IllegalArgumentException, IOException { if (sequenceIndex >= mNumberSequences) { throw new IllegalArgumentException( "Invalid sequence index: " + sequenceIndex + ", maximum is: " + mNumberSequences); } return mData.readQuality((int) sequenceIndex, dest, start, length); }
@Override public int[] sequenceLengths(long start, long end) { if (start >= mNumberSequences) { throw new IllegalArgumentException( "Invalid sequence index: " + start + ", maximum is: " + mNumberSequences); } if (end > mNumberSequences) { throw new IllegalArgumentException( "Invalid sequence index: " + end + ", maximum is: " + mNumberSequences); } return mData.sequenceLengths((int) start, (int) end); }
void infoString(final StringBuilder sb) { sb.append("Memory Usage: ").append(mNumberSequences).append(" sequences").append(LS); long totalBytes = mData.infoString(sb); if (mNames != null) { sb.append("\t\t") .append(StringUtils.commas(mNames.bytes())) .append("\t") .append(StringUtils.commas(mNames.length())) .append("\tNames") .append(LS); totalBytes += mNames.bytes(); } if (mNameSuffixes != null) { sb.append("\t\t") .append(StringUtils.commas(mNameSuffixes.bytes())) .append("\t") .append(StringUtils.commas(mNameSuffixes.length())) .append("\tSuffixes") .append(LS); totalBytes += mNameSuffixes.bytes(); } sb.append("\t\t").append(StringUtils.commas(totalBytes)).append("\t\tTotal bytes").append(LS); }
void initQuality() throws IOException { mData.initQuality(); }
@Override public byte sequenceDataChecksum(long sequenceIndex) throws IOException { return mData.sequenceChecksum((int) sequenceIndex); }
@Override public int length(long sequenceIndex) { return mData.length((int) sequenceIndex); }