/**
   * Selects the columns in the associated sequence group that correspond to the selected range in
   * the current chart.
   */
  protected void selectSitesFromAxesRange() {
    if (chart.isRangeSelected()) {
      double[] range = chart.getRangeSelection();
      int rangeStart = (int) Math.round(range[0]);
      int rangeEnd = (int) Math.round(range[1]);

      try {
        SGContentPanelDisplay sgDisplay = (SGContentPanelDisplay) source;
        sgDisplay.selectColumns(rangeStart, rangeEnd);
      } catch (ClassCastException ex) {
        //	apparently source wasn't an sgDisplay, not sure what should happen here
      }
    }
  }
  public void analyze(String name, Object data) {
    if (data.getClass() != SequenceGroup.class) {
      ErrorWindow.showErrorWindow(
          new IllegalArgumentException(
              "Got a incompatible data type for SequenceLineChart: " + data.getClass()));
      return;
    }

    SequenceGroup currentSG = (SequenceGroup) data;
    originalSG = currentSG;
    originalSG.addPartitionListener(this);
    originalSG.addSGChangeListener(this);
    sgSeriesMap.put((SequenceGroup) data, new ArrayList<AbstractSeries>());
    currentName = name;
    if (topLabel != null) topLabel.setText(currentName);
    else topLabel = new JLabel(currentName);

    topLabel.setFont(defaultFont);

    int maxLength = currentSG.getMaxSeqLength();

    // Guess some decent initial values for size of window and step
    int windowSize = Math.min(100, maxLength);
    int windowStep = maxLength > 50 ? 10 : 1;
    if (maxLength > 9999) {
      windowSize = 1000;
      windowStep = 100;
    }

    SpinnerModel sizeModel = new SpinnerNumberModel(windowSize, 1, maxLength, 1);
    SpinnerModel stepModel = new SpinnerNumberModel(windowStep, 1, maxLength / 2, 1);

    windowSizeSpinner.setModel(sizeModel);
    windowStepSpinner.setModel(stepModel);

    if (currentSG.getPartitionCount() < 2) {
      usePartitionsBox.setSelected(false);
      usePartitionsBox.setEnabled(false);
    } else {
      usePartitionsBox.setEnabled(true);
      usePartitionsBox.setSelected(true);
    }

    toggleCalculator(SGStatisticsRegistry.NUC_DIVERSITY);
    chart.repaint();
  }
Example #3
0
  /**
   * Retrieve a new window series, but only using those sites in the specified partition. This is
   * trickier than it should be. We only add a new value if TWO conditions are met: 1. The central
   * site is in the specified partition. 2. At least windowSize / 10 sites in the range are in the
   * partition
   *
   * @param windowSize The breadth of the window (in sites) over which to calculate a single value
   * @param stepSize The amount the window is moved each step
   * @param partitionIndex The partition to calculate the value for
   * @return
   */
  public ArrayList<Point2D> getWindowPointSeries(int windowSize, int stepSize, int partitionIndex) {
    ArrayList<Point2D> points = new ArrayList<Point2D>();

    for (int i = 0; i + windowSize < sg.getMaxSeqLength(); i += stepSize) {
      double xValue = i;
      double yValue = Double.NaN;
      int startSite = Math.max(0, i - windowSize / 2);
      if (sg.getPartitionNumForSite(i) == partitionIndex
          || sg.getPartitionNumForSite(i + 1) == partitionIndex
          || sg.getPartitionNumForSite(i + 2) == partitionIndex) {

        Double[] sumCount = getSumAndCount(startSite, windowSize, partitionIndex);
        if (sumCount[1] > ((double) windowSize / 10.0)) yValue = sumCount[0] / sumCount[1];
        else yValue = Double.NaN;
      }

      points.add(new Point2D.Double(xValue, yValue));
    }

    return points;
  }