/** * Get the level which is best for displaying the given range. * * @param levels list of levels to be checked * @param r the range to be displayed * @return */ private Level getBestLevel(List<Level> levels, Range r) { for (int i = levels.size() - 1; i > 0; i--) { Level lev = levels.get(i); if (r.getLength() > lev.resolution * ContinuousFormatterHelper.NOTIONAL_SCREEN_SIZE / 2) { return lev; } } return levels.get(0); }
/** * Get the records representing the data to be displayed for the given range. * * @param ref e.g. "chr1" * @param r the range of bases to be displayed * @param ignored historical only; no longer used * @return List of records to be displayed for the given range * @throws IOException */ @Override public List<GenericContinuousRecord> getRecords( String ref, RangeAdapter r, Resolution ignored, RecordFilterAdapter filt) throws IOException { List<GenericContinuousRecord> data = new ArrayList<GenericContinuousRecord>(); if (!savantFile.containsDataForReference(ref)) { ref = MiscUtils.homogenizeSequence(ref); if (!savantFile.containsDataForReference(ref)) { return data; } } Level lev = getBestLevel(refnameToLevelsIndex.get(ref), (Range) r); LOG.debug( "Chose " + lev.resolution + " as the best for range (" + r.getFrom() + "-" + r.getTo() + ")"); int rangeEnd = r.getTo() + 1; long seekPos = lev.offset + (r.getFrom() - 1) / lev.resolution * recordSize; if (savantFile.seek(ref, seekPos) >= 0) { LOG.debug("Sought to " + seekPos + " to find data for " + r.getFrom()); for (int pos = r.getFrom(); pos <= rangeEnd; pos += lev.resolution) { data.add(GenericContinuousRecord.valueOf(ref, pos, savantFile.readFloat())); if (savantFile.getFilePointer() >= savantFile.getHeaderOffset() + savantFile.getReferenceOffset(ref) + lev.offset + lev.size) { // We've read all the data available for this level. The rest of the // range will have no data. LOG.debug( "File position " + savantFile.getFilePointer() + " was past end of level (" + (savantFile.getHeaderOffset() + savantFile.getReferenceOffset(ref) + lev.offset + lev.size) + ")."); break; } } } return data; }