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

📄 simpledp.java

📁 Sequence alignement using different algorithms
💻 JAVA
📖 第 1 页 / 共 4 页
字号:

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

      m_currentStep++;
   }

   protected void stepZero() {

      // just in case:
      m_dpTable.getCell(1, 1).clearColor();

      switch (m_currentPhase) {
         case PHASE_BACKTRACK:

            //m_currentPhase = 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_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_lDEqual.setText("D(S1,S2) = Min");
            m_l1Choiche.setText("D(S1-1, S2) + 1");
            m_l2Choiche.setText("D(S1, S2-1) + 1");
            m_l3Choiche.setText("D(S1 - 1, S2 - 1) + [1|0]");

            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 void stepEnd() {

      int i;
      int totSize = m_s1_size * m_s2_size;

      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());
      }
   }

   protected void algoClear() {

      int c, r;
      for (c = 0; c < m_dpTable.getHCellsCount(); ++c) {
         m_dpTable.getCell(c, 0).clearCell();
         m_dpTable.getCell(c, 1).clearCell();
      }

      for (r = 0; r < m_dpTable.getVCellsCount(); ++r) {
         m_dpTable.getCell(0, r).clearCell();
         m_dpTable.getCell(1, r).clearCell();
      }

      m_StringOne.setText(emptyStringMessage);
      m_StringTwo.setText(emptyStringMessage);
      m_gapOne.setText(emptyGapMessage);
      m_gapTwo.setText(emptyGapMessage);

      m_s1 = null;
      m_s2 = null;
      m_s1_size = 0;
      m_s2_size = 0;

      m_currentPhase = PHASE_CALC_GRID;
      stepZero(); // warning: do not put this after setGridSize!

      m_dpTable.clearGridRectangles();
      m_dpTable.clearInteractiveCells();
      m_dpTable.setGridSize(10, 6);  // TODO: make something for this

      m_gridScrollArea.doLayout();

      m_btnSetGapOne.setEnabled(false);
      m_btnSetGapTwo.setEnabled(false);
      m_btnNext.setEnabled(false);
      m_btnEnd.setEnabled(false);

      m_dpTable.repaint();
   }

   ////////////////////////////////////////////////////////////////////
   ///////// Listeners ////////////////////////////////////////////////
   ////////////////////////////////////////////////////////////////////

   protected class AliasingComboListener
       implements ItemListener {

      public void itemStateChanged(ItemEvent event) {
         Choice ch = (Choice) event.getSource();

         boolean currentAntiAlias = m_dpTable.getAntiAlias();
         boolean newAntiAlias = false;

         switch (ch.getSelectedIndex()) {
            // Anti alias ON
            case 0:
               newAntiAlias = true;
               break;

               // Anti alias OFF
            case 1:
               newAntiAlias = false;
               break;
         }

         if (newAntiAlias != currentAntiAlias) {
            m_dpTable.setAntiAlias(newAntiAlias);
            m_dpTable.paint(m_dpTable.getGraphics());
         }

      }
   }

   protected class ZoomComboListener
       implements ItemListener {

      public void itemStateChanged(ItemEvent event) {
         Choice cb = (Choice) event.getSource();

         double currentZoom = m_dpTable.getZoomLevel();
         double newZoom = 1.0;

         switch (cb.getSelectedIndex()) {
            // Zoom -2
            case 0:

               newZoom = 0.6;
               break;

               // Zoom -1
            case 1:

               newZoom = 0.8;
               break;

               // Zoom Normal
            case 2:

               newZoom = 1.0;
               break;

               // Zoom +1
            case 3:

               newZoom = 1.4;
               break;

               // Zoom +2
            case 4:

               newZoom = 1.8;
               break;

               // Zoom +3
            case 5:

               newZoom = 2.3;
               break;

         }

         if (newZoom != currentZoom) {
            m_dpTable.setZoomLevel(newZoom);
            m_dpTable.paint(m_dpTable.getGraphics());
            m_gridScrollArea.doLayout();
         }

      }
   }

   protected class MoveButtonListener
       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_btnBeginning) {
            stepZero();
         }
         else if (b == m_btnNext) {
            stepForward(true);
         }
         else if (b == m_btnPrev) {
            stepBackward();
         }
         else if (b == m_btnEnd) {
            stepEnd();
         }
         else if (b == m_btnClear) {
            algoClear();
         }
      } // end actionPerformed ---------------------------

   }

   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;

         if (b == m_btnSetOne) {
            title = "Setting string";
            message[0] = "Input the String S1 (i.e. GCCACCGT):";
            stringField = new JTextFieldUC();
            stringField.setText(m_defS1);
            stringField.selectAll();

            options = new String[2];
            options[0] = "Ok";
            options[1] = "Cancel";
         }
         else if (b == m_btnSetTwo) {
            title = "Setting string";
            message[0] = "Input the String S2 (i.e. TTTACGT):";
            stringField = new JTextFieldUC();
            stringField.setText(m_defS2);
            stringField.selectAll();

            options = new String[2];
            options[0] = "Ok";
            options[1] = "Cancel";
         }
         else if (b == m_btnSetGapOne ||
                  b == m_btnSetGapTwo) {
            title = "Setting gap penalty";
            message[0] = "Input the gap penalty sequence (i.e. 1,2,3,4):";
            stringField = new JTextFieldGaps();

            if (b == m_btnSetGapOne) {
               stringField.setText(m_gapOne.getText());
            }
            else {
               stringField.setText(m_gapTwo.getText());
            }

            options = new String[5];
            options[0] = "Ok";
            options[1] = "Increasing";
            options[2] = "All Zero";
            options[3] = "All k-value";
            options[4] = "Cancel";
         }
         else {
            return;
         }

         message[1] = stringField;

         //JOptionPane confirmPane = new JOptionPane();
         //confirmPane.setWantsInput(true);

// 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 (b == m_btnSetOne) {
            if (result == 0) {
               m_defS1 = stringField.getText();
               setString(m_defS1, STRING_ONE);
            }
         }
         else if (b == m_btnSetTwo) {
            if (result == 0) {
               m_defS2 = stringField.getText();
               setString(m_defS2, STRING_TWO);
            }
         }
         else if (b == m_btnSetGapOne ||
                  b == m_btnSetGapTwo) {

            int gapType;
            if (b == m_btnSetGapOne) {
               gapType = GAP_ONE;
            }
            else {
               gapType = GAP_TWO;
            }

            switch (result) {

               case 0: // OK
                  setGapSequence(stringField.getText(), gapType);
                  break;
               case 1: // Increasing
                  setGapSequence(getGapIncreasing(gapType), gapType);
                  break;
               case 2: // Zero Sequence
                  setGapSequence(getGapKSequence(gapType, 0), gapType);
                  break;
               case 3: // All k Sequence
                  String strKVal = JOptionPane.showInputDialog(null,
                      "Please enter the k-value:",
                      "0");

                  int kVal;

                  try {
                     kVal = Integer.parseInt(strKVal);
                  }
                  catch (NumberFormatException ex) {
                     kVal = 0;
                  }

                  setGapSequence(getGapKSequence(gapType, kVal), gapType);
                  break;
            }
         }
      }
   }

}

⌨️ 快捷键说明

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