예제 #1
0
  /**
   * Move to the specified origin (in bins)
   *
   * @param newBinX new location X
   * @param newBinY new location Y
   */
  private void moveTo(double newBinX, double newBinY) {
    try {
      MatrixZoomData zd = getZd();

      final double wBins = (superAdapter.getHeatmapPanel().getWidth() / getScaleFactor());
      double maxX = zd.getXGridAxis().getBinCount() - wBins;

      final double hBins = (superAdapter.getHeatmapPanel().getHeight() / getScaleFactor());
      double maxY = zd.getYGridAxis().getBinCount() - hBins;

      double x = Math.max(0, Math.min(maxX, newBinX));
      double y = Math.max(0, Math.min(maxY, newBinY));

      xContext.setBinOrigin(x);
      yContext.setBinOrigin(y);

      superAdapter.repaint();
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (linkedMode) {
      broadcastLocation();
    }
  }
예제 #2
0
  /**
   * ************************************************************* Official Method for setting the
   * zoom and location for heatmap DO NOT IMPLEMENT A NEW FUNCTION Make the necessary
   * customizations, then call this function
   * *************************************************************
   *
   * @param newZoom
   * @param genomeX
   * @param genomeY
   * @param scaleFactor (pass -1 if scaleFactor should be calculated)
   * @return
   */
  public boolean unsafeActuallySetZoomAndLocation(
      String chrXName,
      String chrYName,
      HiCZoom newZoom,
      int genomeX,
      int genomeY,
      double scaleFactor,
      boolean resetZoom,
      ZoomCallType zoomCallType,
      boolean allowLocationBroadcast) {

    if (dataset == null) return false; // No data in view

    // Check this zoom operation is possible, if not, fail it here:
    //        if (superAdapter.testNewZoom(newZoom))
    //        {
    //            return false;
    //        }

    // String chr1OriginalName = xContext.getChromosome().getName();
    // String chr2OriginalName = yContext.getChromosome().getName();
    if (chrXName.length() > 0 && chrYName.length() > 0) {
      setChromosomesFromBroadcast(chrXName, chrYName);
      // We might end with All->All view, make sure normalization state is updates accordingly...
      superAdapter.getMainViewPanel().setNormalizationDisplayState(superAdapter.getHiC());
    }

    if (newZoom == null) {
      System.err.println("Invalid zoom " + newZoom);
    }

    Chromosome chr1 = xContext.getChromosome();
    Chromosome chr2 = yContext.getChromosome();
    final Matrix matrix = dataset.getMatrix(chr1, chr2);

    if (matrix == null) {
      superAdapter.launchGenericMessageDialog(
          "Sorry, this region is not available", "Matrix unavailable", JOptionPane.WARNING_MESSAGE);
      return false;
    }

    MatrixZoomData newZD = matrix.getZoomData(newZoom);
    if (HiCFileTools.isAllChromosome(chr1)) {
      newZD = matrix.getFirstZoomData(Unit.BP);
    }

    if (newZD == null) {
      superAdapter.launchGenericMessageDialog(
          "Sorry, this zoom is not available", "Zoom unavailable", JOptionPane.WARNING_MESSAGE);
      return false;
    }

    /* TODO Undo Zoom implementation mss2 _UZI
    if(currentZoom != null) {
        tempZoomState = new ZoomState(chr1OriginalName, chr2OriginalName, currentZoom.clone(), (int) xContext.getBinOrigin(),
                (int) yContext.getBinOrigin(), getScaleFactor(), resetZoom, ZoomCallType.GOTO);
    }
    */

    currentZoom = newZoom;
    xContext.setZoom(currentZoom);
    yContext.setZoom(currentZoom);

    if (scaleFactor > 0) {
      setScaleFactor(scaleFactor);
    } else {
      int maxBinCount =
          Math.max(newZD.getXGridAxis().getBinCount(), newZD.getYGridAxis().getBinCount());
      double defaultScaleFactor =
          Math.max(
              1.0, (double) superAdapter.getHeatmapPanel().getMinimumDimension() / maxBinCount);
      setScaleFactor(defaultScaleFactor);
    }

    int binX = newZD.getXGridAxis().getBinNumberForGenomicPosition(genomeX);
    int binY = newZD.getYGridAxis().getBinNumberForGenomicPosition(genomeY);
    switch (zoomCallType) {
      case INITIAL:
      case STANDARD:
        center(binX, binY);
        break;
      case DRAG:
        xContext.setBinOrigin(binX);
        yContext.setBinOrigin(binY);
        break;
      case DIRECT:
        xContext.setBinOrigin(genomeX);
        yContext.setBinOrigin(genomeY);
        break;
    }

    // Notify HeatmapPanel render that zoom has changed. Render should update zoom slider once with
    // previous range values

    setZoomChanged();
    if (resetZoom) {
      superAdapter.updateAndResetZoom(newZoom);
    } else {
      superAdapter.updateZoom(newZoom);
    }
    superAdapter.refresh();

    if (linkedMode && allowLocationBroadcast) {
      broadcastLocation();
    }
    /*
    TODO Undo Zoom implementation mss2 _UZI
    if(zoomCallType == ZoomCallType.INITIAL || tempZoomState == null || chrXName.equals(Globals.CHR_ALL) || chrYName.equals(Globals.CHR_ALL)
            || tempZoomState.chr1Name.equals(Globals.CHR_ALL) || tempZoomState.chr2Name.equals(Globals.CHR_ALL)){
        canRedoZoomChange = false;
        canUndoZoomChange = false;
    }
    else {
        // defauts for a normal zoom operation
        canRedoZoomChange = false;
        canUndoZoomChange = true;
        previousZoomState = tempZoomState;
    }
    */

    return true;
  }
예제 #3
0
 public void setScaleFactor(double scaleFactor) {
   this.scaleFactor = Math.max(Math.min(50, scaleFactor), 1e-10);
 }