示例#1
0
 /** Invoked by the framework when this viewer is selected. */
 public void onSelected(IFramework framework) {
   geneClusterCB.removeAllItems();
   for (int i = 0; i < framework.getClusterRepository(0).size(); i++) {
     if (framework.getClusterRepository(0).getCluster(i + 1) == null) break;
     Cluster cluster = framework.getClusterRepository(0).getCluster(i + 1);
     geneClusterCB.addItem(
         "Cluster #: " + cluster.getSerialNumber() + ", " + cluster.getClusterLabel());
   }
 }
示例#2
0
  private void populateGeneListComboBoxes() {
    geneClusterCB = new JComboBox();
    geneClusterCB.removeAllItems();
    for (int i = 0; i < framework.getClusterRepository(0).size(); i++) {
      if (framework.getClusterRepository(0).getCluster(i + 1) == null) break;
      Cluster cluster = framework.getClusterRepository(0).getCluster(i + 1);
      geneClusterCB.addItem(
          "Cluster #: " + cluster.getSerialNumber() + ", " + cluster.getClusterLabel());
    }
    geneClusterCB.setVisible(false);
    geneClusterCB.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {

            repaint();
          }
        });
    geneAnnotationCB = new JComboBox(framework.getData().getAllFilledAnnotationFields());
    geneAnnotationCB.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (chartTypeCB.getSelectedIndex() > 1) // this method only applies for single gene
            return;
            geneCB.removeAllItems();
            int selected = Math.max(geneAnnotationCB.getSelectedIndex(), 0);
            int numGenes =
                framework
                    .getData()
                    .getAnnotationList(framework.getData().getAllFilledAnnotationFields()[selected])
                    .length;
            StringExt[] stringext = new StringExt[numGenes];
            String[] geneNames =
                framework
                    .getData()
                    .getAnnotationList(
                        framework.getData().getAllFilledAnnotationFields()[selected]);
            for (int i = 0; i < numGenes; i++) stringext[i] = new StringExt(geneNames[i]);

            DefaultComboBoxModel cbm = new DefaultComboBoxModel(stringext);
            geneCB.setModel(cbm);
          }
        });
    geneCB =
        new JComboBox(
            framework
                .getData()
                .getAnnotationList(framework.getData().getAllFilledAnnotationFields()[0]));
    geneCB.setMaximumSize(new Dimension(150, geneCB.getHeight()));
    geneCB.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            repaint();
          }
        });
  }
示例#3
0
  public void paint(Graphics g) {
    super.paint(g);
    if (clusterCount == 0) return;
    boolean ismultigene = !isSingleGene;
    Graphics2D g2 = (Graphics2D) g;
    multigeneCount = 1;
    Cluster cluster = null;
    if (ismultigene) {
      try {
        if (!inAnalysis) {
          int begin = geneClusterCB.getSelectedItem().toString().indexOf(":");
          int end = geneClusterCB.getSelectedItem().toString().indexOf(",");
          sn = geneClusterCB.getSelectedItem().toString().substring(begin + 2, end);
          cluster = framework.getClusterRepository(0).getCluster(Integer.parseInt(sn));
          geneIndices = cluster.getIndices();
        }
      } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Gene Cluster Problem");
        return;
      }
      if (geneIndices == null || geneIndices.length < 1) return;

      if (aggregateGeneCluster) multigeneCount = 1;
      else multigeneCount = geneIndices.length;
    }
    int chartTop = chartTopHeight;

    lowerOutliers = new float[multigeneCount][][];
    upperOutliers = new float[multigeneCount][][];
    expressionSDs = new float[multigeneCount][];
    expressionAverages = new float[multigeneCount][];
    expressionMedian = new float[multigeneCount][];
    expressionQ1 = new float[multigeneCount][];
    expressionQ3 = new float[multigeneCount][];
    expressionIQR = new float[multigeneCount][];
    expressionLowerWhisker = new float[multigeneCount][];
    expressionUpperWhisker = new float[multigeneCount][];
    chartTitles = new String[multigeneCount];
    int maxString = 0;
    for (int i = 0; i < clusterNames.length; i++) {
      maxString = Math.max(maxString, g.getFontMetrics().stringWidth(clusterNames[i]));
    }
    chartGap = maxString + 50;

    // for only drawing the visible area- dramatic speed improvements
    Rectangle bounds = g.getClipBounds();
    int indexBegin = (int) Math.max(-3 + bounds.y / (chartHeight + chartGap), 0f);
    int indexEnd =
        (int) Math.min(multigeneCount, 3 + (bounds.y + bounds.height) / (chartHeight + chartGap));

    for (int multigeneIndex = indexBegin; multigeneIndex < indexEnd; multigeneIndex++) {
      if (ismultigene) {
        if (aggregateGeneCluster) {
          getChartData(geneIndices, multigeneIndex);
          if (inAnalysis) chartTitles[multigeneIndex] = geneClusterLabel;
          else chartTitles[multigeneIndex] = cluster.getClusterLabel();
        } else {
          getChartData(geneIndices[multigeneIndex], multigeneIndex);
          chartTitles[multigeneIndex] =
              framework.getData()
                  .getElementAnnotation(
                      geneIndices[multigeneIndex], framework.getData().getFieldNames()[0])[0];
        }
      } else {
        getChartData(geneCB.getSelectedIndex(), multigeneIndex);
        chartTitles[multigeneIndex] = geneCB.getSelectedItem().toString();
      }
      float maxHeight = 0;
      float minHeight = Float.POSITIVE_INFINITY;
      for (int i = 0; i < clusterCount; i++) {
        if (this.isBoxPlot) {
          for (int j = 0; j < this.upperOutliers[multigeneIndex][i].length; j++) {
            maxHeight = Math.max(upperOutliers[multigeneIndex][i][j], maxHeight);
          }
          maxHeight = Math.max(expressionUpperWhisker[multigeneIndex][i], maxHeight);
        } else {
          maxHeight =
              Math.max(
                  expressionAverages[multigeneIndex][i] + this.expressionSDs[multigeneIndex][i],
                  maxHeight);
        }
      }

      for (int i = 0; i < clusterCount; i++) {
        if (this.isBoxPlot) {
          for (int j = 0; j < this.lowerOutliers[multigeneIndex][i].length; j++) {
            minHeight = Math.min(lowerOutliers[multigeneIndex][i][j], minHeight);
          }
          minHeight = Math.min(expressionLowerWhisker[multigeneIndex][i], minHeight);
        } else minHeight = 0f; // Math.min(expressionAverages[i], minHeight);
      }
      maxHeight++;
      float topgridline;
      float bottomgridline;
      if (this.autoScale) {
        topgridline = (int) maxHeight + (int) maxHeight % 2;
        bottomgridline = (int) minHeight - (int) minHeight % 2 - 2;
        if (!isBoxPlot) bottomgridline = 0f;
        fixedTop = topgridline;
        fixedBottom = bottomgridline;
      } else {
        topgridline = fixedTop;
        bottomgridline = fixedBottom;
        if (!isBoxPlot) bottomgridline = 0f;
      }

      float gridrange = topgridline - bottomgridline;
      // draw everything
      // grid
      g2.setColor(Color.black);
      g2.drawLine(
          chartleft - 5,
          chartHeight + chartTop,
          chartleft + clusterCount * chartIncrement,
          chartHeight + chartTop); // horizontal line bottom
      g2.drawLine(chartleft, chartTop, chartleft, chartHeight + chartTop + 5); // vertical line left
      g2.setColor(Color.gray);
      g2.drawLine(chartleft - 7, chartTop, chartleft, chartTop); // horizontal line ticktop
      g2.drawLine(
          chartleft - 5,
          chartTop + chartHeight / 4,
          chartleft,
          chartTop + chartHeight / 4); // horizontal line tick75%
      g2.drawLine(
          chartleft - 7,
          chartTop + chartHeight / 2,
          chartleft,
          chartTop + chartHeight / 2); // horizontal line tickMid
      g2.drawLine(
          chartleft - 5,
          chartTop + 3 * chartHeight / 4,
          chartleft,
          chartTop + 3 * chartHeight / 4); // horizontal line tick25%
      if (showGridlines) {
        g2.setColor(Color.gray);
        g2.drawLine(
            chartleft,
            chartTop,
            chartleft + chartIncrement * clusterCount,
            chartTop); // horizontal line grid
        g2.drawLine(
            chartleft,
            chartTop + chartHeight / 4,
            chartleft + chartIncrement * clusterCount,
            chartTop + chartHeight / 4); // horizontal line grid
        g2.drawLine(
            chartleft,
            chartTop + chartHeight / 2,
            chartleft + chartIncrement * clusterCount,
            chartTop + chartHeight / 2); // horizontal line grid
        g2.drawLine(
            chartleft,
            chartTop + 3 * chartHeight / 4,
            chartleft + chartIncrement * clusterCount,
            chartTop + 3 * chartHeight / 4); // horizontal line grid
      }

      g2.setColor(Color.black);
      g2.drawString(
          Float.toString(bottomgridline + gridrange),
          chartleft - 40,
          chartTop + 3); // vertical axis label
      g2.drawString(
          Float.toString(bottomgridline + gridrange * 3f / 4f),
          chartleft - 40,
          (chartTop + 3) + chartHeight / 4); // vertical axis label
      g2.drawString(
          Float.toString(bottomgridline + gridrange / 2f),
          chartleft - 40,
          (chartTop + 3) + chartHeight / 2); // vertical axis label
      g2.drawString(
          Float.toString(bottomgridline + gridrange / 4f),
          chartleft - 40,
          (chartTop + 3) + (3 * chartHeight / 4)); // vertical axis label	
      g2.drawString(
          Float.toString(bottomgridline),
          chartleft - 40,
          (chartTop + 3) + (chartHeight)); // vertical axis label	

      Font font = g2.getFont();
      g2.setFont(new Font("Helvetica", Font.BOLD, 16));
      g2.drawString(
          chartTitles[multigeneIndex],
          chartleft + chartIncrement / 2,
          chartTop - 15); // Gene/group Name label
      g2.setFont(font);

      g2.rotate(-Math.PI / 2);
      g2.drawString(
          "Expression", -((chartTop + 3) + 2 * chartHeight / 3), (chartleft - 60)); // y-axis Label
      g2.rotate(Math.PI / 2);

      for (int i = 0; i < this.clusterCount; i++) {
        int xorigin = (int) ((.25f + (float) i) * chartIncrement) + chartleft;
        int yorigin = chartHeight + chartTop;
        int barWidth = chartIncrement / 2;

        int barHeight =
            (int) ((expressionAverages[multigeneIndex][i]) * ((float) chartHeight) / gridrange);
        int errorBarHeight =
            (int) (expressionSDs[multigeneIndex][i] * ((float) chartHeight) / gridrange);

        int boxBottom =
            (int)
                ((-bottomgridline + expressionQ1[multigeneIndex][i])
                    * ((float) chartHeight)
                    / gridrange);
        int boxTop =
            (int)
                ((-bottomgridline + expressionQ3[multigeneIndex][i])
                    * ((float) chartHeight)
                    / gridrange);
        int boxMedian =
            (int)
                ((-bottomgridline + expressionMedian[multigeneIndex][i])
                    * ((float) chartHeight)
                    / gridrange);
        int boxLowerWhisker =
            (int)
                ((-bottomgridline + expressionLowerWhisker[multigeneIndex][i])
                    * ((float) chartHeight)
                    / gridrange);
        int boxUpperWhisker =
            (int)
                ((-bottomgridline + expressionUpperWhisker[multigeneIndex][i])
                    * ((float) chartHeight)
                    / gridrange);

        g2.setColor(Color.gray);
        g2.drawLine(
            xorigin + 3 * barWidth / 2,
            yorigin,
            xorigin + 3 * barWidth / 2,
            yorigin + 5); // vertical tickmark
        g2.setColor(Color.black);
        g2.rotate(-Math.PI / 2);
        g2.drawString(
            clusterNames[i],
            -(yorigin + 5) - g.getFontMetrics().stringWidth(clusterNames[i]),
            (xorigin + barWidth / 2)); // cluster names
        g2.rotate(Math.PI / 2);

        if (!isBoxPlot) { // bar graph
          g2.setColor(clusterColors[i]);
          g2.fillRect(xorigin, yorigin - barHeight, barWidth, barHeight); // box
          g2.setColor(Color.black);
          g2.drawRect(xorigin, yorigin - barHeight, barWidth, barHeight); // box outline
          g2.drawLine(
              xorigin + barWidth / 2,
              yorigin - barHeight - errorBarHeight,
              xorigin + barWidth / 2,
              yorigin - barHeight); // vertical errorbar
          g2.drawLine(
              xorigin + barWidth / 4,
              yorigin - barHeight - errorBarHeight,
              xorigin + 3 * barWidth / 4,
              yorigin - barHeight - errorBarHeight); // horizontal error bar

        } else if (isBoxPlot) { // box plot
          g2.setColor(clusterColors[i]);
          g2.fillRect(xorigin, yorigin - boxTop, barWidth, boxTop - boxBottom); // box
          g2.setColor(Color.black);
          g2.drawRect(xorigin, yorigin - boxTop, barWidth, boxTop - boxBottom); // box	outline
          g2.drawLine(
              xorigin, yorigin - boxMedian, xorigin + barWidth, yorigin - boxMedian); // median line
          g2.drawLine(
              xorigin + barWidth / 2,
              yorigin - boxTop,
              xorigin + barWidth / 2,
              yorigin - boxUpperWhisker); // vertical whisker upper
          g2.drawLine(
              xorigin + barWidth / 2,
              yorigin - boxBottom,
              xorigin + barWidth / 2,
              yorigin - boxLowerWhisker); // vertical whisker lower
          g2.drawLine(
              xorigin + barWidth / 4,
              yorigin - boxUpperWhisker,
              xorigin + 3 * barWidth / 4,
              yorigin - boxUpperWhisker); // horizontal whisker upper
          g2.drawLine(
              xorigin + barWidth / 4,
              yorigin - boxLowerWhisker,
              xorigin + 3 * barWidth / 4,
              yorigin - boxLowerWhisker); // horizontal whisker lower

          // draw outliers
          int circleWidth = 6;
          for (int j = 0; j < upperOutliers[multigeneIndex][i].length; j++) {
            g2.drawOval(
                xorigin + barWidth / 2 - circleWidth / 2,
                yorigin
                    - (int)
                        ((float) ((-bottomgridline + upperOutliers[multigeneIndex][i][j]))
                            * ((float) chartHeight)
                            / gridrange)
                    - circleWidth / 2,
                circleWidth,
                circleWidth);
          }
          for (int j = 0; j < lowerOutliers[multigeneIndex][i].length; j++) {
            g2.drawOval(
                xorigin + barWidth / 2 - circleWidth / 2,
                yorigin
                    - (int)
                        ((float) ((-bottomgridline + lowerOutliers[multigeneIndex][i][j]))
                            * ((float) chartHeight)
                            / gridrange)
                    - circleWidth / 2,
                circleWidth,
                circleWidth);
          }

        } else {
          System.out.println("unknown chart type");
        }
      }

      chartTop =
          chartTopHeight
              + (multigeneIndex + 1) * (chartHeight + chartGap); // moves top down for next graph
    }
    jScrollBar.setUnitIncrement(chartHeight + chartGap);
    int viewerHeight = chartTopHeight + (multigeneCount) * (chartHeight + chartGap);
    this.setSize(new Dimension(this.getWidth(), viewerHeight));
    this.setPreferredSize(new Dimension(this.getWidth(), viewerHeight));
  }