예제 #1
0
  private void updateJmolDisplay() {

    if (jmol == null) return;

    int size = afpChain.getAlnLength();

    StringBuffer cmd = new StringBuffer("select ");

    int nrSelected = 0;
    try {

      for (int i = 0; i < size; i++) {
        if (selection.get(i)) {

          Atom a1 = DisplayAFP.getAtomForAligPos(afpChain, 0, i, ca1, false);
          Atom a2 = DisplayAFP.getAtomForAligPos(afpChain, 1, i, ca2, false);

          String select1 = "";

          if (a1 != null) select1 = JmolTools.getPdbInfo(a1);
          String select2 = "";
          if (a2 != null) select2 = JmolTools.getPdbInfo(a2);

          // nothing to display
          if (select1.equals("") && select2.equals("")) continue;

          if (nrSelected > 0) cmd.append(", ");

          cmd.append(select1);
          cmd.append(", ");
          cmd.append(select2);
          nrSelected++;
        }
      }

    } catch (StructureException e) {
      e.printStackTrace();
    }
    if (nrSelected == 0) cmd.append(" none;");
    else cmd.append("; set display selected;");

    jmol.evalString(cmd.toString());
  }
예제 #2
0
  public void paintComponent(Graphics g) {

    super.paintComponent(g);

    Graphics2D g2D = (Graphics2D) g;

    g2D.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // only draw within the ranges of the Clip
    // Rectangle drawHere = g2D.getClipBounds();

    // int startpos = coordManager.getSeqPos(0,drawHere.x);
    // int endpos   = coordManager.getSeqPos(0,drawHere.x+drawHere.width-2);

    char[] seq1 = afpChain.getAlnseq1();
    char[] seq2 = afpChain.getAlnseq2();
    char[] symb = afpChain.getAlnsymb();

    int startpos = 0;
    int endpos = afpChain.getAlnLength();

    String summary = afpChain.toString();
    g2D.drawString(summary, 20, coordManager.getSummaryPos());

    Color significantCol = Color.red;
    if (afpChain.isSignificantResult()) significantCol = Color.green;

    g2D.setPaint(significantCol);
    // draw a darker backgroun
    Rectangle sig = new Rectangle(10, 10, 10, 10);
    g2D.fill(sig);
    boolean isFATCAT = false;
    if (afpChain.getAlgorithmName().startsWith("jFatCat")) {
      isFATCAT = true;
    }
    for (int i = startpos; ((i <= endpos) && (i < afpChain.getAlnLength())); i++) {

      // TODO:
      // color amino acids by hydrophobicity
      char c1 = seq1[i];
      char c2 = seq2[i];
      boolean isGapped = false;
      g2D.setFont(seqFont);

      List<Integer> alignedPos = null;
      if (colorByAlignmentBlock) {
        alignedPos = DisplayAFP.getEQRAlignmentPos(afpChain);
      }
      if (isFATCAT) {
        char s = symb[i];
        if (s != ' ') {
          isGapped = false;
          g2D.setFont(eqFont);
        } else isGapped = true;
      } else {
        if (c1 != '-' && c2 != '-') {
          // no gap
          g2D.setFont(eqFont);
        } else {
          isGapped = true;
        }
      }

      Point p1 = coordManager.getPanelPos(0, i);
      int xpos1 = p1.x;
      int ypos1 = p1.y;
      Point p2 = coordManager.getPanelPos(1, i);
      int xpos2 = p2.x;
      int ypos2 = p2.y;
      int blockNum = afpChain.getBlockNum();
      if (!isGapped) {
        Color bg = Color.white;
        Color bg2 = Color.white;
        Color end1 = ColorUtils.rotateHue(ColorUtils.orange, (1.0f / 24.0f) * blockNum);
        Color end2 = ColorUtils.rotateHue(ColorUtils.cyan, (1.0f / 24.0f) * (blockNum + 1));

        if (colorByAlignmentBlock) {

          if (!alignedPos.contains(i)) {

            // unaligned!
            bg = Color.white;
            bg2 = Color.white;
          } else {

            int colorPos = 0;
            if (isFATCAT) {
              int block = 0;
              char s = symb[i];
              try {
                block = Integer.parseInt(s + "") - 1;
                bg = ColorUtils.getIntermediate(ColorUtils.orange, end1, blockNum, block);
                bg2 = ColorUtils.getIntermediate(ColorUtils.cyan, end2, blockNum, block);
                // bg = ColorUtils.rotateHue(ColorUtils.orange,  (1.0f  / 24.0f) * block  );
                // bg2 = ColorUtils.rotateHue(ColorUtils.cyan,  (1.0f  / 16.0f) * block );
              } catch (Exception e) {
              }

              if (colorPos > ColorUtils.colorWheel.length) {
                colorPos = ColorUtils.colorWheel.length % colorPos;
              }
            } else {
              colorPos = DisplayAFP.getBlockNrForAlignPos(afpChain, i);
              bg = ColorUtils.getIntermediate(ColorUtils.orange, end1, blockNum, colorPos);
              bg2 = ColorUtils.getIntermediate(ColorUtils.cyan, end2, blockNum, colorPos);
              // bg = ColorUtils.rotateHue(ColorUtils.orange,  (1.0f  / 24.0f) * colorPos );
              // bg2 = ColorUtils.rotateHue(ColorUtils.cyan,  (1.0f  / 16.0f) * colorPos);
            }
          }
        } else {

          bg = Color.LIGHT_GRAY;
          bg2 = Color.LIGHT_GRAY;
        }

        // draw a darker background
        g2D.setPaint(bg);
        Rectangle rec = new Rectangle(p1.x - 1, p1.y - 11, (p2.x - p1.x) + 12, (p2.y - p1.y) + 1);
        g2D.fill(rec);
        g2D.setPaint(bg2);
        Rectangle rec2 = new Rectangle(p1.x - 1, p1.y + 4, (p2.x - p1.x) + 12, (p2.y - p1.y) - 3);
        g2D.fill(rec2);

        // g2D.setPaint(Color.black);
        // g2D.draw(rec);
      }
      if (colorBySimilarity) {
        if (c1 == c2) {
          Color bg = Color.red;
          g2D.setPaint(bg);
          Rectangle rec =
              new Rectangle(p1.x - 1, p1.y - 11, (p2.x - p1.x) + 12, (p2.y - p1.y) + 12);
          g2D.fill(rec);
        } else if (AFPAlignmentDisplay.aaScore(c1, c2) > 0) {
          Color bg = Color.orange;
          g2D.setPaint(bg);
          Rectangle rec =
              new Rectangle(p1.x - 1, p1.y - 11, (p2.x - p1.x) + 12, (p2.y - p1.y) + 12);
          g2D.fill(rec);
        }
      }

      // if ( selectionStart != null && selectionEnd != null){
      //	if ( i >= selectionStart.getPos1() && i <= selectionEnd.getPos1()) {

      if (isSelected(i)) {
        // draw selection
        Color bg = Color.YELLOW;
        g2D.setPaint(bg);
        // draw a darker backgroun
        Rectangle rec = new Rectangle(p1.x - 1, p1.y - 11, (p2.x - p1.x) + 12, (p2.y - p1.y) + 12);
        g2D.fill(rec);
        //	}
      }

      // draw the AA sequence
      g2D.setColor(Color.black);
      g2D.drawString(c1 + "", xpos1, ypos1);
      g2D.drawString(c2 + "", xpos2, ypos2);

      // System.out.println(seq1[i] + " " + xpos1 + " " + ypos1 + " " + seq2[i] + xpos2 + " " +
      // ypos2);
    }

    int nrLines = (afpChain.getAlnLength() - 1) / AFPChainCoordManager.DEFAULT_LINE_LENGTH;

    for (int i = 0; i <= nrLines; i++) {

      try {
        // draw legend at i
        Point p1 = coordManager.getLegendPosition(i, 0);
        Point p2 = coordManager.getLegendPosition(i, 1);

        int aligPos = i * AFPChainCoordManager.DEFAULT_LINE_LENGTH;
        Atom a1 = DisplayAFP.getAtomForAligPos(afpChain, 0, aligPos, ca1, false);
        Atom a2 = DisplayAFP.getAtomForAligPos(afpChain, 1, aligPos, ca2, false);
        String label1 = JmolTools.getPdbInfo(a1, false);
        String label2 = JmolTools.getPdbInfo(a2, false);
        g2D.drawString(label1, p1.x, p1.y);
        g2D.drawString(label2, p2.x, p2.y);

        Point p3 = coordManager.getEndLegendPosition(i, 0);
        Point p4 = coordManager.getEndLegendPosition(i, 1);

        aligPos =
            i * AFPChainCoordManager.DEFAULT_LINE_LENGTH
                + AFPChainCoordManager.DEFAULT_LINE_LENGTH
                - 1;
        if (aligPos > afpChain.getAlnLength()) aligPos = afpChain.getAlnLength() - 1;
        Atom a3 = DisplayAFP.getAtomForAligPos(afpChain, 0, aligPos, ca1, true);
        Atom a4 = DisplayAFP.getAtomForAligPos(afpChain, 1, aligPos, ca2, true);

        String label3 = JmolTools.getPdbInfo(a3, false);
        String label4 = JmolTools.getPdbInfo(a4, false);

        g2D.drawString(label3, p3.x, p3.y);
        g2D.drawString(label4, p4.x, p4.y);

      } catch (StructureException e) {
        e.printStackTrace();
      }
    }
  }