public void setSelectedChromosomesNoRefresh( Chromosome xChrom, Chromosome yChrom, Context xContext, Context yContext) { chrBox1.setSelectedIndex(yChrom.getIndex()); chrBox2.setSelectedIndex(xChrom.getIndex()); rulerPanelX.setContext(xContext, HiCRulerPanel.Orientation.HORIZONTAL); rulerPanelY.setContext(yContext, HiCRulerPanel.Orientation.VERTICAL); resolutionSlider.setEnabled(!xChrom.getName().equals(Globals.CHR_ALL)); }
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()); } }
private void parsePositionText() { // Expected format 1: <chr>:<start>-<end>:<resolution> // Expected format 2: <chr>:<midpt>:<resolution> String delimiters = "\\s+|:\\s*|\\-\\s*"; String dashDelimiters = "\\s+|\\-\\s*"; String[] leftChrTokens = positionChrLeft.getText().split(delimiters); String[] topChrTokens = positionChrTop.getText().split(delimiters); String[] leftDashChrTokens = positionChrLeft.getText().split(dashDelimiters); String[] topDashChrTokens = positionChrTop.getText().split(dashDelimiters); if (topChrTokens.length == 1 || leftChrTokens.length == 1) { parseGenePositionText(); return; } // Read Chromosomes: HashMap<String, Chromosome> chromosomeMap = new HashMap<String, Chromosome>(); for (Chromosome c : hic.getDataset().getChromosomes()) { chromosomeMap.put(c.getName().toLowerCase(), c); chromosomeMap.put("chr" + c.getName().toLowerCase(), c); if (c.getName().equals("MT")) chromosomeMap.put("chrm", c); } Chromosome topChr = chromosomeMap.get(topChrTokens[0].toLowerCase()); if (topChr == null) { positionChrTop.setBackground(Color.yellow); log.error("Cannot find " + topChrTokens[0] + " in dataset's chromosome list"); return; } Chromosome leftChr = chromosomeMap.get(leftChrTokens[0].toLowerCase()); if (leftChr == null) { positionChrLeft.setBackground(Color.yellow); log.error("Cannot find " + leftChrTokens[0] + " in dataset's chromosome list"); return; } // chrPositions {start, end, outBin, estimatedOutBinSize} int[] topChrPositions; try { topChrPositions = extractParametersFromTokens(topChrTokens, topDashChrTokens, positionChrTop); } catch (Exception e) { return; } int[] leftChrPositions; try { leftChrPositions = extractParametersFromTokens(leftChrTokens, leftDashChrTokens, positionChrLeft); } catch (Exception e) { return; } // Read resolution: int outBinSize = 0; HiC.Unit resolutionUnits = HiC.Unit.BP; int estimatedOutBinSize = Math.max(topChrPositions[3], leftChrPositions[3]); if (topChrTokens.length > 3 || (topDashChrTokens.length == 1 && topChrTokens.length > 2)) { try { int[] resolutionParameters = extractResolutionParametersFromTokens(topChrTokens, topDashChrTokens, positionChrTop); outBinSize = resolutionParameters[0]; if (resolutionParameters[1] < 0) { resolutionUnits = HiC.Unit.FRAG; } } catch (Exception e) { return; } } else if (leftChrTokens.length > 3 || (leftDashChrTokens.length == 1 && leftChrTokens.length > 2)) { try { int[] resolutionParameters = extractResolutionParametersFromTokens( leftChrTokens, leftDashChrTokens, positionChrLeft); outBinSize = resolutionParameters[0]; if (resolutionParameters[1] < 0) { resolutionUnits = HiC.Unit.FRAG; } } catch (Exception e) { return; } } else if (estimatedOutBinSize > 0) { outBinSize = estimatedOutBinSize; } else if (hic.getZoom().getBinSize() != 0) { // no resolution specified, not at whole genome view outBinSize = hic.validateBinSize(String.valueOf(hic.getZoom().getBinSize())); if (outBinSize != Integer.MIN_VALUE) { resolutionUnits = hic.getZoom().getUnit(); } } positionChrTop.setBackground(Color.white); positionChrLeft.setBackground(Color.white); if (outBinSize == Integer.MIN_VALUE) { outBinSize = 250000; // If bin size is not valid, set to max bin size } hic.setLocation( topChr.getName(), leftChr.getName(), resolutionUnits, outBinSize, Math.max(topChrPositions[2], 0), Math.max(leftChrPositions[2], 0), hic.getScaleFactor(), HiC.ZoomCallType.STANDARD, "Goto", true); }
private boolean isWholeGenome() { Chromosome chr1 = (Chromosome) chrBox1.getSelectedItem(); Chromosome chr2 = (Chromosome) chrBox2.getSelectedItem(); return chr1.getName().equals("All") || chr2.getName().equals("All"); }