コード例 #1
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;
  }
コード例 #2
0
 @Override
 public void close() {
   try {
     if (savantFile != null) savantFile.close();
   } catch (IOException ignore) {
   }
 }
コード例 #3
0
 @Override
 public URI getURI() {
   return savantFile.getURI();
 }
コード例 #4
0
 @Override
 public Set<String> getReferenceNames() {
   return savantFile.getReferenceMap().keySet();
 }