Beispiel #1
0
 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));
 }
Beispiel #2
0
  /**
   * Chromosome "0" is whole genome
   *
   * @param chromosomes list of chromosomes
   */
  void setChromosomes(List<Chromosome> chromosomes) {
    int[] chromosomeBoundaries = new int[chromosomes.size() - 1];
    long bound = 0;
    for (int i = 1; i < chromosomes.size(); i++) {
      Chromosome c = chromosomes.get(i);
      bound += (c.getLength() / 1000);
      chromosomeBoundaries[i - 1] = (int) bound;
    }
    heatmapPanel.setChromosomeBoundaries(chromosomeBoundaries);

    chrBox1.setModel(
        new DefaultComboBoxModel<Chromosome>(
            chromosomes.toArray(new Chromosome[chromosomes.size()])));
    chrBox2.setModel(
        new DefaultComboBoxModel<Chromosome>(
            chromosomes.toArray(new Chromosome[chromosomes.size()])));
  }
Beispiel #3
0
  public void unsafeRefreshChromosomes(SuperAdapter superAdapter) {

    if (chrBox1.getSelectedIndex() == 0 || chrBox2.getSelectedIndex() == 0) {
      chrBox1.setSelectedIndex(0);
      chrBox2.setSelectedIndex(0);
    }

    Chromosome chr1 = (Chromosome) chrBox1.getSelectedItem();
    Chromosome chr2 = (Chromosome) chrBox2.getSelectedItem();

    Chromosome chrX = chr1.getIndex() < chr2.getIndex() ? chr1 : chr2;
    Chromosome chrY = chr1.getIndex() < chr2.getIndex() ? chr2 : chr1;

    setNormalizationDisplayState(superAdapter.getHiC());

    superAdapter.unsafeUpdateHiCChromosomes(chrX, chrY);

    updateThumbnail(superAdapter.getHiC());
  }
Beispiel #4
0
  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());
    }
  }
Beispiel #5
0
  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);
  }
Beispiel #6
0
 private boolean isWholeGenome() {
   Chromosome chr1 = (Chromosome) chrBox1.getSelectedItem();
   Chromosome chr2 = (Chromosome) chrBox2.getSelectedItem();
   return chr1.getName().equals("All") || chr2.getName().equals("All");
 }
Beispiel #7
0
 private boolean isIntraChromosomal() {
   Chromosome chr1 = (Chromosome) chrBox1.getSelectedItem();
   Chromosome chr2 = (Chromosome) chrBox2.getSelectedItem();
   return chr1.getIndex() != chr2.getIndex();
 }
Beispiel #8
0
 /*
  * Only accessed from within another unsafe method in Heatmap Panel class,
  * which in turn is encapsulated (i.e. made safe)
  */
 public void unsafeSetSelectedChromosomes(
     SuperAdapter superAdapter, Chromosome xChrom, Chromosome yChrom) {
   chrBox1.setSelectedIndex(yChrom.getIndex());
   chrBox2.setSelectedIndex(xChrom.getIndex());
   unsafeRefreshChromosomes(superAdapter);
 }