Esempio 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();
    }
  }
Esempio n. 2
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
    };
  }
Esempio n. 3
0
  /**
   * Center the bins in view at the current resolution.
   *
   * @param binX center X
   * @param binY center Y
   */
  public void center(double binX, double binY) {

    double w = superAdapter.getHeatmapPanel().getWidth() / getScaleFactor(); // view width in bins
    int newOriginX = (int) (binX - w / 2);

    double h = superAdapter.getHeatmapPanel().getHeight() / getScaleFactor(); // view height in bins
    int newOriginY = (int) (binY - h / 2);
    moveTo(newOriginX, newOriginY);
  }
Esempio n. 4
0
 private boolean safeActuallySetZoomAndLocation(
     final String chrXName,
     final String chrYName,
     final HiCZoom newZoom,
     final int genomeX,
     final int genomeY,
     final double scaleFactor,
     final boolean resetZoom,
     final ZoomCallType zoomCallType,
     String message,
     final boolean allowLocationBroadcast) {
   final boolean[] returnVal = new boolean[1];
   superAdapter.executeLongRunningTask(
       new Runnable() {
         @Override
         public void run() {
           returnVal[0] =
               unsafeActuallySetZoomAndLocation(
                   chrXName,
                   chrYName,
                   newZoom,
                   genomeX,
                   genomeY,
                   scaleFactor,
                   resetZoom,
                   zoomCallType,
                   allowLocationBroadcast);
         }
       },
       message);
   return returnVal[0];
 }
Esempio n. 5
0
 private void safeSave1DTrackToWigFile(
     final Chromosome chromosomeForPosition,
     final File outputWigFile,
     final int binStartPosition) {
   superAdapter
       .getMainWindow()
       .executeLongRunningTask(
           new Runnable() {
             @Override
             public void run() {
               try {
                 PrintWriter printWriter = new PrintWriter(outputWigFile);
                 unsafeSave1DTrackToWigFile(chromosomeForPosition, printWriter, binStartPosition);
                 printWriter.close();
                 if (outputWigFile.exists() && outputWigFile.length() > 0) {
                   // TODO this still doesn't add to the resource tree / load annotation dialog box
                   // superAdapter.getTrackLoadAction();
                   // getResourceTree().add1DCustomTrack(outputWigFile);
                   HiC.this.loadTrack(outputWigFile.getAbsolutePath());
                   LoadAction loadAction = superAdapter.getTrackLoadAction();
                   loadAction.checkBoxesForReload(outputWigFile.getName());
                 }
               } catch (Exception e) {
                 System.err.println("Unable to generate and save 1D HiC track");
               }
             }
           },
           "Saving_1D_track_as_wig");
 }
Esempio n. 6
0
 // TODO zgire - why iterate through tracksToRemove if you end up calling clearFeatures() at the
 // end?
 public void clearTracksForReloadState() {
   ArrayList<HiCTrack> tracksToRemove = new ArrayList<HiCTrack>(trackManager.getLoadedTracks());
   for (HiCTrack trackToRemove : tracksToRemove) {
     if (trackToRemove.getName().equals(eigString)) {
       eigenvectorTrack = null;
     } else if (trackToRemove.getName().equals(ctrlEigString)) {
       controlEigenvectorTrack = null;
     } else {
       trackManager.removeTrack(trackToRemove);
     }
   }
   clearFeatures();
   superAdapter.updateTrackPanel();
 }
Esempio n. 7
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();
    }
  }
Esempio n. 8
0
  public void centerFragment(int fragmentX, int fragmentY) {
    if (currentZoom != null) {

      MatrixZoomData zd = getMatrix().getZoomData(currentZoom);
      HiCGridAxis xAxis = zd.getXGridAxis();
      HiCGridAxis yAxis = zd.getYGridAxis();
      int binX;
      int binY;
      try {
        binX = xAxis.getBinNumberForFragment(fragmentX);
        //noinspection SuspiciousNameCombination
        binY = yAxis.getBinNumberForFragment(fragmentY);
        center(binX, binY);
      } catch (RuntimeException error) {
        superAdapter.launchGenericMessageDialog(
            error.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
      }
    }
  }
Esempio n. 9
0
  public GoToPanel(SuperAdapter superAdapter) {
    super();
    this.hic = superAdapter.getHiC();
    this.superAdapter = superAdapter;

    JLabel goLabel = new JLabel("Goto");
    goLabel.setHorizontalAlignment(SwingConstants.CENTER);

    JPanel goLabelPanel = new JPanel();
    goLabelPanel.setBackground(HiCGlobals.backgroundColor);
    goLabelPanel.setLayout(new BorderLayout());
    goLabelPanel.add(goLabel, BorderLayout.CENTER);

    positionChrTop = initializeGoToTextField();
    positionChrLeft = initializeGoToTextField();

    JPanel goPositionPanel = new JPanel();
    goPositionPanel.setLayout(new BorderLayout());
    goPositionPanel.add(positionChrTop, BorderLayout.PAGE_START);
    goPositionPanel.add(positionChrLeft, BorderLayout.PAGE_END);

    goButton = new JideButton();
    goButton.setEnabled(false);
    goButton.setIcon(
        new ImageIcon(getClass().getResource("/toolbarButtonGraphics/general/Refresh24.gif")));
    goButton.addActionListener(this);

    JPanel goButtonPanel = new JPanel();
    goButtonPanel.setBackground(new Color(238, 238, 238));
    goButtonPanel.setLayout(new BoxLayout(goButtonPanel, BoxLayout.X_AXIS));
    goButtonPanel.add(goPositionPanel, BorderLayout.PAGE_START);
    goButtonPanel.add(goButton);

    setBackground(new Color(238, 238, 238));
    setBorder(LineBorder.createGrayLineBorder());
    setLayout(new BorderLayout());
    add(goLabelPanel, BorderLayout.PAGE_START);
    add(goButtonPanel);
    setMinimumSize(new Dimension(100, 70));
    setPreferredSize(new Dimension(120, 70));
    setMaximumSize(new Dimension(200, 70));
  }
Esempio n. 10
0
 private void initializeGeneHashMap(String genomeID) {
   if (genomeID.equals("hg19")
       || genomeID.equals("hg38")
       || genomeID.equals("mm9")
       || genomeID.equals("mm10")) {
     final String gID = genomeID;
     Runnable runnable =
         new Runnable() {
           @Override
           public void run() {
             unsafeInitializeGeneHashMap(gID);
           }
         };
     superAdapter.executeLongRunningTask(runnable, "Initialize Gene Hash Map");
   } else {
     MessageUtils.showErrorMessage("Cannot find genes for " + genomeID, null);
     positionChrTop.setBackground(Color.yellow);
     geneLocationHashMap = null;
   }
 }
Esempio n. 11
0
  private void extractGeneLocation() {
    GeneLocation location1 = geneLocationHashMap.get(positionChrTop.getText().trim().toLowerCase());
    GeneLocation location2 =
        geneLocationHashMap.get(positionChrLeft.getText().trim().toLowerCase());
    if (location1 == null) {
      positionChrTop.setBackground(Color.yellow);
      MessageUtils.showMessage(
          "Gene location map doesn't contain " + positionChrTop.getText().trim());
      return;
    }
    if (location2 == null) {
      positionChrLeft.setBackground(Color.yellow);
      MessageUtils.showMessage(
          "Gene location map doesn't contain " + positionChrLeft.getText().trim());
      return;
    }

    List<Integer> bpResolutions = Ints.asList(HiCGlobals.bpBinSizes);
    int geneZoomResolution = hic.getZoom().getBinSize();
    if (!bpResolutions.contains(geneZoomResolution)) {
      geneZoomResolution = Collections.min(bpResolutions);
    }

    hic.setLocation(
        location1.chromosome,
        location2.chromosome,
        HiC.Unit.BP,
        geneZoomResolution,
        location1.centerPosition,
        location2.centerPosition,
        hic.getScaleFactor(),
        HiC.ZoomCallType.STANDARD,
        "Gene Goto",
        true);

    superAdapter.setNormalizationDisplayState();
  }
Esempio n. 12
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;
  }
Esempio n. 13
0
 public boolean isResolutionLocked() {
   return superAdapter.isResolutionLocked()
       ||
       // pearson can't zoom in
       (isInPearsonsMode() && currentZoom.getBinSize() == HiCGlobals.MAX_PEARSON_ZOOM);
 }