⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smithwaterman.java

📁 Sequence alignement using different algorithms
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     Point D = new Point(realD.x - 1, realD.y - 1);

     m_l1Choiche.setBackground(SystemColor.control);
     m_l2Choiche.setBackground(SystemColor.control);
     m_l3Choiche.setBackground(SystemColor.control);
     m_l4Choiche.setBackground(SystemColor.control);

     CellElement leftCell = m_dpTable.getCell(realD.x - 1, realD.y);
     CellElement topCell = m_dpTable.getCell(realD.x, realD.y - 1);
     CellElement topLeftCell = m_dpTable.getCell(realD.x - 1, realD.y - 1);

     ScoredCellElement currentCell = (ScoredCellElement)m_dpTable.getCell(realD.x, realD.y);

//      char cS1, cS2;
//      cS1 = m_s1.charAt(realD.y - 2);
//      cS2 = m_s2.charAt(realD.x - 2);

     ScoredCellElement gapLeftCell = (ScoredCellElement)m_dpTable.getCell(1, realD.y);
     ScoredCellElement gapTopCell = (ScoredCellElement)m_dpTable.getCell(realD.x, 1);

     int scoreCurrent = Integer.parseInt(currentCell.getScoreVal());
     int scoreGapLeft = Integer.parseInt(gapLeftCell.getScoreVal());
     int scoreGapTop = Integer.parseInt(gapTopCell.getScoreVal());

     if (showSteps) {
        String DEqual = "D(" + (D.y) + ", " + (D.x) + ")= Max";

        String DLeft = "D(" + (D.y - 1) + ", " + (D.x) + ") + sc.= " +
            leftCell.getVal() + " + " + scoreGapLeft + " = " + (leftCell.getIntVal() + scoreGapLeft);
        String DTop = "D(" + (D.y) + ", " + (D.x - 1) + ") + sc.= " +
            topCell.getVal() + " + " + scoreGapTop + " = " + (topCell.getIntVal() + scoreGapTop);

        String DTopLeft = "D(" + (D.y - 1) + ", " + (D.x - 1) + ") + sc.= " +
            topLeftCell.getVal() + " + " + scoreCurrent + " = " +
            (topLeftCell.getIntVal() + scoreCurrent);

        m_lDEqual.setText(DEqual);
        m_l1Choiche.setText(DLeft);
        m_l2Choiche.setText(DTop);
        m_l3Choiche.setText(DTopLeft);
     }

     int fromLeftVal = leftCell.getIntVal() + scoreGapLeft;
     int fromTopVal = topCell.getIntVal() + scoreGapTop;
     int fromTopLeftVal = topLeftCell.getIntVal() + scoreCurrent;
     int zero = 0;

     int max = Math.max(
                        Math.max(fromLeftVal,
                                 Math.max(fromTopVal, fromTopLeftVal)), 0);

     // Init choosen array
     LinkedList highlightList = new LinkedList();

     if (fromLeftVal == max) {
        m_l1Choiche.setBackground(Color.yellow);
        currentCell.addLeftPointer(leftCell);
        highlightList.add(leftCell);
        highlightList.add(gapLeftCell);

     }
     if (fromTopVal == max) {
        m_l2Choiche.setBackground(Color.yellow);
        currentCell.addTopPointer(topCell);
        highlightList.add(topCell);
        highlightList.add(gapTopCell);
     }
     if (fromTopLeftVal == max) {
        m_l3Choiche.setBackground(Color.yellow);
        currentCell.addDiagPointer(topLeftCell);
        highlightList.add(topLeftCell);
     }
     if (max == 0) {
        m_l4Choiche.setBackground(Color.yellow);
     }

     currentCell.setIntVal(max);

     if (showSteps) {
        m_dpTable.setSideHighlight(currentCell, new Color(0, 255, 255));

        m_dpTable.setTriArrows(currentCell, true);
        m_dpTable.setMultipleCellHighlight(highlightList);
        m_dpTable.paint(m_dpTable.getGraphics());
     }

     m_currentStep++;
  }

  /**
   * Ovveride of stepFWDBackTrack: we need to change the behaviour
   * when in the local search it finds a zero.
   * @param showSteps
   */
  protected void stepFWDBackTrack(boolean showSteps) {

     // Global alignment: start from D(m,n)

     // TODO: Not very elegant. To be changed!
     CellElement theOneBefore = null;
     if (!m_backTrackList.isEmpty()) {
        theOneBefore = (CellElement) m_backTrackList.getLast();
     }

     if (m_backtrackLastSel == null) {
        // Policy for automatic pointer selection!!
        m_backTrackList.add(theOneBefore.getPointerWithPolicy(
            m_backtrackingPolicy));
     }
     else {
        m_backTrackList.add(m_backtrackLastSel);
     }

     CellElement currentCell = (CellElement) m_backTrackList.getLast();

     if (m_backTrackList.size() > 1) {
        setResultString(theOneBefore, currentCell);
     }

     Point D = new Point(currentCell.getColumn() - 1, currentCell.getRow() - 1);

     m_l1Choiche.setBackground(m_mainPane.getBackground());
     m_l2Choiche.setBackground(m_mainPane.getBackground());
     m_l3Choiche.setBackground(m_mainPane.getBackground());
     m_l4Choiche.setBackground(m_mainPane.getBackground());

     CellElement leftCell = currentCell.getLeftPointer();
     CellElement topCell = currentCell.getTopPointer();
     CellElement topLeftCell = currentCell.getDiagPointer();

     String DEqual = "D(" + (D.y) + ", " + (D.x) + ") = Select";
     String DLeft = "";
     String DTop = "";
     String DTopLeft = "";

     m_dpTable.clearInteractiveCells();

     // Init choosen array
     LinkedList highlightList = new LinkedList();

     if (leftCell == null) {
        DLeft = "No Pointer";
     }
     else {
        DLeft = "D(" + (leftCell.getRow() - 1) + ", " +
            (leftCell.getColumn() - 1) + ")";
        m_dpTable.addInteractiveCell(leftCell);
        highlightList.add(leftCell);
     }

     if (topCell == null) {
        DTop = "No Pointer";
     }
     else {
        DTop = "D(" + (topCell.getRow() - 1) + ", " +
            (topCell.getColumn() - 1) + ")";
        m_dpTable.addInteractiveCell(topCell);
        highlightList.add(topCell);
     }

     if (topLeftCell == null) {
        DTopLeft = "No Pointer";
     }
     else {
        DTopLeft = "D(" + (topLeftCell.getRow() - 1) + ", " +
            (topLeftCell.getColumn() - 1) + ")";
        m_dpTable.addInteractiveCell(topLeftCell);
        highlightList.add(topLeftCell);
     }

     m_lDEqual.setText(DEqual);
     m_l1Choiche.setText(DLeft);
     m_l2Choiche.setText(DTop);
     m_l3Choiche.setText(DTopLeft);

     m_dpTable.setTriArrows(currentCell, false);
     m_dpTable.setMultipleCellHighlight(highlightList);

     currentCell.setColor(Color.green);

     if (currentCell.getIntVal() == 0) {

        m_btnNext.setEnabled(false);
        m_btnEnd.setEnabled(false);
        m_dpTable.clearAllArrows();
        m_dpTable.clearGridCircle();

        m_dpTable.clearInteractiveCells();
        m_dpTable.clearDPHighlights();
     }
     else {
        // TODO: Not elegant. To be changed
        m_btnNext.setEnabled(true);
        m_btnEnd.setEnabled(true);
     }

     if (showSteps) {
        m_dpTable.paint(m_dpTable.getGraphics());
     }

     m_backtrackLastSel = null;
  }

  protected void stepZero() {

     switch (m_currentPhase) {
        case PHASE_SELECT_LOCAL:
           stepBackward();
           break;

        case PHASE_BACKTRACK:
           super.stepZero();
           m_lDEqual.setText("D(x, x) = Select");
           m_l1Choiche.setText("No Pointer");
           m_l2Choiche.setText("No Pointer");
           m_l3Choiche.setText("No Pointer");
           break;

        case PHASE_CALC_GRID:
           super.stepZero();
           this.putFourDrawablePanel();

           break;
     }
     m_l4Choiche.setBackground(m_mainPane.getBackground());
 }

  protected void stepEnd() {
     switch (m_currentPhase) {
        case PHASE_SELECT_LOCAL:
           stepForward(true);
           break;

        default:
           super.stepEnd();
     }
  }

  protected void findMaxValues() {

     m_dpTable.clearInteractiveCells();

     int c, r;
     CellElement tmpCell;

     int max = Integer.MIN_VALUE;
     LinkedList maxEls = new LinkedList();

     for (r = 2; r < m_dpTable.getVCellsCount(); ++r) {
        for (c = 2; c < m_dpTable.getHCellsCount(); ++c) {

           tmpCell = m_dpTable.getCell(c, r);

           if (tmpCell.getIntVal() > max) {
              maxEls.clear();
              maxEls.add(tmpCell);
              max = tmpCell.getIntVal();
           }
           else if (tmpCell.getIntVal() == max) {
              maxEls.add(tmpCell);
           }

        }
     }

     Iterator lIt = maxEls.iterator();

     while (lIt.hasNext()) {
        tmpCell = (CellElement)lIt.next();
        // highlight of the starting local point
        tmpCell.setHLColor(Color.blue);
        m_dpTable.addInteractiveCell(tmpCell);
     }

     // Selects by default the last max element:
     m_backtrackLastSel = (CellElement)maxEls.getLast();

     m_dpTable.paint(m_dpTable.getGraphics());
  }

  public void onInteractPress(CellElement cellPressed) {

     if (m_currentPhase == PHASE_SELECT_LOCAL) {
        this.initBackward();
     }

     super.onInteractPress(cellPressed);

  }

  protected void initBackward() {

     m_currentPhase = PHASE_BACKTRACK;
     setInfoMessage("Backtracking Pointers. Policy used: " +
                    CellElement.getPolicyName(
                    m_backtrackingPolicy) + ".");

    // Erase the highlights of the starting local point
     m_dpTable.clearHighlightColors();

     // reset result string
     for (int i = 0; i < 3; i++) {
        m_resLine[i] = "";
     }
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -