/** * Called from alt-drag zoom * * @param xBP0 * @param yBP0 * @param targetBinSize */ public void zoomToDrawnBox(final int xBP0, final int yBP0, final double targetBinSize) { HiCZoom newZoom = currentZoom; if (!isResolutionLocked()) { List<HiCZoom> zoomList = currentZoom.getUnit() == HiC.Unit.BP ? dataset.getBpZooms() : dataset.getFragZooms(); for (int i = zoomList.size() - 1; i >= 0; i--) { if (zoomList.get(i).getBinSize() >= targetBinSize) { newZoom = zoomList.get(i); break; } } // this addresses draw box to zoom when down from low res pearsons // it can't zoom all the way in, but can zoom in a little more up to 500K if (isInPearsonsMode() && newZoom.getBinSize() < HiCGlobals.MAX_PEARSON_ZOOM) { for (int i = zoomList.size() - 1; i >= 0; i--) { if (zoomList.get(i).getBinSize() >= HiCGlobals.MAX_PEARSON_ZOOM) { newZoom = zoomList.get(i); break; } } } } safeActuallySetZoomAndLocation( newZoom, xBP0, yBP0, newZoom.getBinSize() / targetBinSize, false, ZoomCallType.DRAG, "DragZoom", true); }
public double[] getEigenvector(final int chrIdx, final int n, boolean isControl) { if (isControl) { if (controlDataset == null) return null; Chromosome chr = chromosomes.get(chrIdx); return controlDataset.getEigenvector(chr, currentZoom, n, normalizationType); } else { if (dataset == null) return null; Chromosome chr = chromosomes.get(chrIdx); return dataset.getEigenvector(chr, currentZoom, n, normalizationType); } }
private void unsafeSave1DTrackToWigFile( Chromosome chromosomeForPosition, PrintWriter printWriter, int binStartPosition) throws IOException { int resolution = getZoom().getBinSize(); for (Chromosome chromosome : chromosomes) { if (chromosome.getName().equals(Globals.CHR_ALL)) continue; Matrix matrix = null; if (displayOption == MatrixType.OBSERVED) { matrix = dataset.getMatrix(chromosomeForPosition, chromosome); } else if (displayOption == MatrixType.CONTROL) { matrix = controlDataset.getMatrix(chromosomeForPosition, chromosome); } if (matrix == null) continue; MatrixZoomData zd = matrix.getZoomData(currentZoom); printWriter.println( "fixedStep chrom=chr" + chromosome.getName().replace("chr", "") + " start=1 step=" + resolution + " span=" + resolution); int[] regionIndices; if (chromosomeForPosition.getIndex() < chromosome.getIndex()) { regionIndices = new int[] {binStartPosition, binStartPosition, 0, chromosome.getLength()}; } else { regionIndices = new int[] {0, chromosome.getLength(), binStartPosition, binStartPosition}; } zd.dump1DTrackFromCrossHairAsWig( printWriter, chromosomeForPosition, binStartPosition, chromosomeForPosition.getIndex() == chromosome.getIndex(), regionIndices, normalizationType, displayOption, getExpectedValues()); } }
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()); }
/** * ************************************************************* 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; }
public NormalizationVector getNormalizationVector(int chrIdx) { if (dataset == null) return null; return dataset.getNormalizationVector(chrIdx, currentZoom, normalizationType); }
public ExpectedValueFunction getExpectedValues() { if (dataset == null) return null; return dataset.getExpectedValues(currentZoom, normalizationType); }
public Matrix getControlMatrix() { if (controlDataset == null || xContext == null || currentZoom == null) return null; return controlDataset.getMatrix(xContext.getChromosome(), yContext.getChromosome()); }