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

📄 nussinov.java

📁 Sequence alignement using different algorithms
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }
        else {
            m_backtrackLastSel = null;
        }
   }

   protected void stepZero() {

   switch (m_currentPhase) {
      case PHASE_BACKTRACK:
         ListIterator lIt = m_backTrackList.listIterator();
         while (lIt.hasNext()) {
            m_backtrackLastSel = (CellElement) lIt.next();
            lIt.remove();
            m_backtrackLastSel.clearColor();
         }

         m_backTrackList.add(m_backtrackLastSel);

         m_dpTable.clearDPHighlights();
         m_dpTable.clearAllArrows();
         m_btnNext.setEnabled(true);
         m_btnEnd.setEnabled(true);

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

         stepBackward();
         break;

      case PHASE_CALC_GRID:
         m_btnScoreTable.setEnabled(true);
         m_currentStep = 0;

         m_dpTable.clearDPTableContent();
         m_dpTable.clearDPHighlights();

         m_dpTable.clearAllArrows();
         m_dpTable.clearGridCircle();

         m_backTrackList.clear();

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

         m_lDEqual.setText("D(i,j)= Max");
         m_l1Choiche.setText("D(i + 1, j)");
         m_l2Choiche.setText("D(i, j - 1)");
         m_l3Choiche.setText("D(i + 1, j - 1) + score");
         m_l4Choiche.setText("Max[D(i,k)+ D(k + 1,j)] (i<k<j)");

         setInfoMessage("Waiting..");

         m_btnPrev.setEnabled(false);
         m_btnBeginning.setEnabled(false);

         m_btnSetOne.setEnabled(true);
         m_btnSetTwo.setEnabled(true);
         m_btnSetGapOne.setEnabled(true);
         m_btnSetGapTwo.setEnabled(true);

         m_currentPhase = PHASE_CALC_GRID;
         m_bottomResultArea.setText("");

         m_dpTable.paint(m_dpTable.getGraphics());

         break;
   }

}

   protected class ScoreButtonListener
           implements ActionListener {

      public void actionPerformed(ActionEvent event) {
         // Perform the action indicated by a mouse click on a button.

         Object b = event.getSource(); // Get the component that was
         // clicked.

         if (b == m_btnScoreTable) {
            //String alphabet = "AGUC";
            ScoreDialog a = new ScoreDialog(m_alphabet, m_scoreHash);
            a.show();

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

   protected class SetButtonListener
           implements ActionListener {

        public void actionPerformed(ActionEvent event) {
           // Perform the action indicated by a mouse click on a button.

           Object b = event.getSource(); // Get the component that was clicked.

           Object[] message = new Object[2];
           String title;
           JTextField stringField;

           String[] options;


           title = "Setting string";
           message[0] = "Input the String S1 (i.e. GGGAAAUCC):";

           stringField = new JTextFieldUC();
           stringField.setText(m_defS1);
           stringField.selectAll();

           options = new String[2];
           options[0] = "Ok";
           options[1] = "Cancel";

           message[1] = stringField;

// Options
           int result = JOptionPane.showOptionDialog(
               new JPanel(), // the parent that the dialog blocks
               message, // the dialog message array
               title, // the title of the dialog window
               JOptionPane.DEFAULT_OPTION, // option type
               JOptionPane.QUESTION_MESSAGE, // message type
               null, // optional icon, use null to use the default icon
               options, // options string array, will be made into buttons
               message[0] // option that should be made into a default button
               );

            if (result == 0) {
                m_defS1 = stringField.getText();
                m_defS2 = m_defS1;
                setString(m_defS1, STRING_ONE);
                setString(m_defS2, STRING_TWO);
            }

        }
     }

  protected void stepForward(boolean showSteps) {
        m_movement = FORWARDS;
        int l  = m_dpTable.getHCellsCount() -1;

        switch (m_currentPhase) {

           case PHASE_CALC_GRID:

              if (m_currentStep >=
                  ((l*l - l) / 2) )  {

                 // Entering backtrack phase
                 m_currentPhase = PHASE_BACKTRACK;

                 m_backtrackLastSel = m_dpTable.getCell( l,1 );
                 m_bifuratedCells.clear();
                 m_backTrackList.clear();

                 m_dpTable.clearDPHighlights();
                 m_dpTable.clearAllArrows();

                 // reset result string
                 initResultString();


                 m_bottomResultArea.setText(m_resLine[0] + "\n" +
                                m_resLine[1] + "\n");

                 setInfoMessage("Backtracking Pointers. Policy used: " +
                                 CellElement.getPolicyName(
                                 m_backtrackingPolicy) + ".");
                 stepFWDBackTrack(showSteps);
              }
              else {
                 setInfoMessage("Calculating DP Table. Step: " +
                                m_currentStep);
                 stepFWDCalc(showSteps);
              }

              break;

           case PHASE_BACKTRACK:

              stepFWDBackTrack(showSteps);
              break;
        }

     }

     protected void initResultString() {
         m_resLine[0] = this.m_s1;

         StringBuffer s=new StringBuffer();
         for (int i=0 ; i < m_s1.length(); i++){
             s.append('.');
         }

         m_resLine[1] = s.toString();
         m_resLine[2] = "";
         this.m_bottomResultArea.setText(m_resLine[0] + '\n' + m_resLine[1] + '\n' );

     }

     protected void setResultString(ScoredCellElement prevCell,
                               ScoredCellElement selectedBackTrackingCell) {

    StringBuffer sb = new StringBuffer(m_resLine[1]);

    if (m_movement==FORWARDS) {
         if (prevCell.getDiagPointer() == selectedBackTrackingCell &&
             Integer.parseInt(prevCell.getScoreVal())>0 ) {

             sb.setCharAt(prevCell.getColumn()-1, ')');
             sb.setCharAt(prevCell.getRow()-1, '(');
         }
         m_resLine[1] = sb.toString();
     } else {
            sb.setCharAt(selectedBackTrackingCell.getColumn()-1, '.');
            sb.setCharAt(selectedBackTrackingCell.getRow()-1, '.');
            m_resLine[1] = sb.toString();
        }

         m_bottomResultArea.setText(m_resLine[0] + "\n" +
                                    m_resLine[1] + "\n");
  }

     protected void stepEnd() {

           int i;
           int totSize = (m_s1_size * m_s1_size - m_s1_size) /2 ;
           m_dpTable.clearDPHighlights();
           m_dpTable.clearAllArrows();
           m_dpTable.clearGridCircle();

           switch (m_currentPhase) {

              case PHASE_CALC_GRID:
                 for (i = m_currentStep; i < totSize; ++i) {
                    stepForward(false);
                 }

                 stepForward(true);
                 break;

              case PHASE_BACKTRACK:

                 while (m_btnEnd.isEnabled()) {
                    stepForward(false);
                 }
                 m_dpTable.paint(m_dpTable.getGraphics());
           }
        }

     // our steps are diagonal
     protected Point getCoordsByStep(int step) {
           Point ret = new Point();

           int i = m_s1_size - 1;
           int n = 1;

           while (step - i  >= 0) {
               step-=i;
               n ++;
               i --;
           }

           ret.x = step + n + 1;
           ret.y = step + 1;

           return ret;
   }

   protected void stepBackward() {

         CellElement currentCell;
         m_movement = BACKWARDS;
         switch (m_currentPhase) {

            case PHASE_CALC_GRID:
                super.stepBackward();
                break;
            case PHASE_BACKTRACK:
               currentCell = (CellElement) m_backTrackList.getLast();
               currentCell.clearColor();

               if (m_backTrackList.size() <= 1) {
                  m_currentStep--;
                  m_currentPhase = PHASE_CALC_GRID;
                  m_backTrackList.clear();
                  m_dpTable.clearInteractiveCells();
                  stepForward(true);
               }
               else {

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

                  if (m_backTrackList.size() == 0) {
                     m_backtrackLastSel = m_dpTable.getLastCell();
                     m_bottomResultArea.setText("");
                  }
                  else {
                     m_backtrackLastSel = (CellElement) m_backTrackList.getLast();
                     m_backTrackList.removeLast();
                  }

                  stepFWDBackTrack(true);
               }

               break;
         }

      }


}

⌨️ 快捷键说明

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