Ejemplo n.º 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();
    }
  }
Ejemplo n.º 2
0
 public Matrix getMatrix() {
   if (dataset == null) {
     // System.err.println("Dataset is null");
     return null;
   } else if (xContext == null) {
     // System.err.println("xContext is null");
     return null;
   } else if (yContext == null) {
     // System.err.println("yContext is null");
     return null;
   }
   return dataset.getMatrix(xContext.getChromosome(), yContext.getChromosome());
 }
Ejemplo n.º 3
0
  public int[] getCurrentRegionWindowGenomicPositions() {

    // address int overflow or exceeding bound issues
    int xEndEdge =
        xContext.getGenomicPositionOrigin()
            + (int)
                ((double) getZoom().getBinSize()
                    * superAdapter.getHeatmapPanel().getWidth()
                    / getScaleFactor());
    if (xEndEdge < 0 || xEndEdge > xContext.getChromosome().getLength()) {
      xEndEdge = xContext.getChromosome().getLength();
    }

    int yEndEdge =
        yContext.getGenomicPositionOrigin()
            + (int)
                ((double) getZoom().getBinSize()
                    * superAdapter.getHeatmapPanel().getHeight()
                    / getScaleFactor());
    if (yEndEdge < 0 || yEndEdge > yContext.getChromosome().getLength()) {
      yEndEdge = yContext.getChromosome().getLength();
    }

    return new int[] {
      xContext.getGenomicPositionOrigin(), xEndEdge, yContext.getGenomicPositionOrigin(), yEndEdge
    };
  }
Ejemplo n.º 4
0
  public String getDefaultLocationDescription() {

    String xChr = xContext.getChromosome().getName();
    String yChr = yContext.getChromosome().getName();

    if (!(xChr.toLowerCase().contains("chr"))) xChr = "chr" + xChr;
    if (!(yChr.toLowerCase().contains("chr"))) yChr = "chr" + yChr;

    return xChr
        + "@"
        + (long) (xContext.getBinOrigin() * currentZoom.getBinSize())
        + "_"
        + yChr
        + "@"
        + (long) (yContext.getBinOrigin() * currentZoom.getBinSize());
  }
Ejemplo n.º 5
0
  private void setChromosomesFromBroadcast(String chrXName, String chrYName) {
    if (!chrXName.equals(xContext.getChromosome().getName())
        || !chrYName.equals(yContext.getChromosome().getName())) {
      Chromosome chrX = HiCFileTools.getChromosomeNamed(chrXName, chromosomes);
      Chromosome chrY = HiCFileTools.getChromosomeNamed(chrYName, chromosomes);

      if (chrX == null || chrY == null) {
        // log.info("Most probably origin is a different species saved location or sync/link between
        // two different species maps.");
        return;
      }

      this.xContext = new Context(chrX);
      this.yContext = new Context(chrY);
      superAdapter.setSelectedChromosomesNoRefresh(chrX, chrY);
      refreshEigenvectorTrackIfExists();
    }
  }
Ejemplo n.º 6
0
  public String getLocationDescription() {
    String xChr = xContext.getChromosome().getName();
    String yChr = yContext.getChromosome().getName();

    if (!(xChr.toLowerCase().contains("chr"))) xChr = "chr" + xChr;
    if (!(yChr.toLowerCase().contains("chr"))) yChr = "chr" + yChr;

    return "setlocation "
        + xChr
        + " "
        + yChr
        + " "
        + currentZoom.getUnit().toString()
        + " "
        + currentZoom.getBinSize()
        + " "
        + xContext.getBinOrigin()
        + " "
        + yContext.getBinOrigin()
        + " "
        + getScaleFactor();
  }
Ejemplo n.º 7
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;
  }
Ejemplo n.º 8
0
 /**
  * Move by the specified delta (in bins)
  *
  * @param dxBins -- delta x in bins
  * @param dyBins -- delta y in bins
  */
 public void moveBy(double dxBins, double dyBins) {
   final double newX = xContext.getBinOrigin() + dxBins;
   final double newY = yContext.getBinOrigin() + dyBins;
   moveTo(newX, newY);
 }
Ejemplo n.º 9
0
 public boolean isWholeGenome() {
   return xContext != null && HiCFileTools.isAllChromosome(xContext.getChromosome());
 }
Ejemplo n.º 10
0
 public Matrix getControlMatrix() {
   if (controlDataset == null || xContext == null || currentZoom == null) return null;
   return controlDataset.getMatrix(xContext.getChromosome(), yContext.getChromosome());
 }