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

📄 nussinov.java

📁 Sequence alignement using different algorithms
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
         alphabet += ((Character)it.next()).charValue();
      }

      return alphabet;
        }

   // Default TABLE scores
   protected void setDefaultScores() {

      m_scoreHash.clearScores();

      int i, j;
      char a, b;
      for (i = 0; i < m_alphabet.length(); ++i) {
         for (j = 0; j < i+1; ++j) {

            a = m_alphabet.charAt(j);
            b = m_alphabet.charAt(i);

            if ((a == 'G' && b =='C' ) || (a == 'C' && b =='G' ) || (a == 'A' && b =='U' ) || (a == 'U' && b =='A' )) {
               m_scoreHash.setScore(a, b, 1);
            }
            else {
               m_scoreHash.setScore(a, b, 0);
            }
         }
      }
   }

   // There are no GAP scores
   protected void setDefaultGap(int whichString) {
      return;
   }

   public void setCellScoresMatrix() {

      int r, c, sc;
      char cS1, cS2;

      // NOTE: S1 = vertical, S2 = horizontal
       ScoredCellElement tmpCell;

      for (r = 0; r < m_s1_size; ++r) {
         for (c = 0; c < m_s1_size; ++c) {

             cS1 = m_s1.charAt(c);
             cS2 = m_s1.charAt(r);

          tmpCell = (ScoredCellElement)m_dpTable.getCell(c + 1, r + 1);

          if ( r <  c + 2 ) {
                 tmpCell.setScoreVal(m_scoreHash.getScore(cS1, cS2));
             } else {
                 tmpCell.setColor(Color.BLACK);
             }
         }

     }
   }

   protected void stepFWDCalc(boolean showSteps) {

      if (m_currentStep == 0) {
         m_btnSetOne.setEnabled(false);
         m_btnSetTwo.setEnabled(false);
         m_btnSetGapOne.setEnabled(false);
         m_btnSetGapTwo.setEnabled(false);
         m_btnScoreTable.setEnabled(false);

         m_btnPrev.setEnabled(true);
         m_btnBeginning.setEnabled(true);
      }

      Point realD = getCoordsByStep(m_currentStep);

      Point D = new Point(realD.x , realD.y );

      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 bottomCell = m_dpTable.getCell(realD.x, realD.y + 1);
      CellElement bottomLeftCell = m_dpTable.getCell(realD.x - 1, realD.y + 1);

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

      int scoreCurrent = currentCell.getIntScoreVal();

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

         String DLeft = "D(" + (D.y ) + ", " + (D.x - 1) + ") = " +
             leftCell.getVal() ;
         String DBottom = "D(" + (D.y + 1  ) + ", " + (D.x ) + ") = " +
             bottomCell.getVal();

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

         m_lDEqual.setText(DEqual);
         m_l1Choiche.setText(DLeft);
         m_l2Choiche.setText(DBottom);
         m_l3Choiche.setText(DBottomLeft);
      }

      int bifur,maxbifur;
      maxbifur = 0;
      CellElement k1Cell,k2Cell;

      int fromLeftVal = leftCell.getIntVal() ;
      int fromBottomVal = bottomCell.getIntVal()  ;
      int fromBottomLeftVal = bottomLeftCell.getIntVal() + scoreCurrent;

      Vector bifurCellVector = new Vector();

      // i < k < j
      for (int k = D.y+1; k < D.x; k++) {

          k1Cell = m_dpTable.getCell(k,D.y);
          k2Cell = m_dpTable.getCell(D.x,k+1);

          bifur = k1Cell.getIntVal()+k2Cell.getIntVal();
          if (bifur > maxbifur) {
              maxbifur = bifur;
              bifurCellVector.clear();
          }
          if (bifur == maxbifur) {
              bifurCellVector.add(new NCellPair(k1Cell,k2Cell));
          }
      }

      int max = Math.max(fromLeftVal, Math.max(fromBottomVal, Math.max(fromBottomLeftVal,maxbifur)));

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

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

      }
      if (fromBottomVal == max) {
         m_l2Choiche.setBackground(Color.yellow);
         currentCell.addBottomPointer(bottomCell);
         highlightList.add(bottomCell);
      }
      if (fromBottomLeftVal == max) {
         m_l3Choiche.setBackground(Color.yellow);
         currentCell.addDiagPointer(bottomLeftCell);
         highlightList.add(bottomLeftCell);
      }

      if (maxbifur == max) {
          m_l4Choiche.setBackground(Color.yellow);
          ListIterator it = bifurCellVector.listIterator();
          NCellPair pair;

          while (it.hasNext()) {
              pair = (NCellPair)it.next();
              currentCell.addBifPointers(pair);
              highlightList.addAll(pair.getCellPair());
          }
      }

      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++;
   }

   protected void stepFWDBackTrack(boolean showSteps) {
       m_l1Choiche.setBackground(m_mainPane.getBackground());
       m_l2Choiche.setBackground(m_mainPane.getBackground());
       m_l3Choiche.setBackground(m_mainPane.getBackground());
       m_l4Choiche.setBackground(m_mainPane.getBackground());

       NussinovCellElement theOneBefore = null;

       if (!m_backTrackList.isEmpty()) {
           theOneBefore = (NussinovCellElement) m_backTrackList.getLast();
       }
       else {
           theOneBefore = null;
       }
        if (m_backtrackLastSel == null) {
           //user didn't select cell
           NussinovCellElement tmp = (NussinovCellElement) theOneBefore.getPointerWithPolicy(m_backtrackingPolicy);
           if (tmp==null) {
               NCellPair tmppair=theOneBefore.getFirstBifPointers();;
               m_backTrackList.add(tmppair.getCellOne());
               m_bifuratedCells.addLast(tmppair.getCellTwo());
           }
           else {
               m_backTrackList.add(tmp);
           }
       }
       else {
           // user did select cell!
           if (theOneBefore == null) {
               m_backTrackList.add(m_backtrackLastSel);
           }
           else {
               if (theOneBefore.isBifCell(m_backtrackLastSel)) { //user select a bif-cell pair
                   m_backTrackList.add(m_backtrackLastSel);
                   m_bifuratedCells.addLast(theOneBefore.getNextCellFromPair(
                           m_backtrackLastSel));
               } else {
                   m_backTrackList.add(m_backtrackLastSel);
               }
           }
       }

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

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


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

       CellElement leftCell = currentCell.getLeftPointer();
       CellElement BottomCell = currentCell.getBottomPointer();
       CellElement BottomLeftCell = currentCell.getDiagPointer();

       String DEqual = "D(" + (D.y) + ", " + (D.x) + ") = Select";
       String DLeft = "";
       String DBottom = "";
       String DBottomLeft = "";
       String DBifuricate = "";

       m_dpTable.clearInteractiveCells();

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

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

       if (BottomCell == null) {
           DBottom = "No Pointer";
       } else {
           DBottom = "D(" + BottomCell.getRow() + ", " + BottomCell.getColumn() +
                     ")";
           m_dpTable.addInteractiveCell(BottomCell);
           highlightList.add(BottomCell);
       }

       if (BottomLeftCell == null) {
           DBottomLeft = "No Pointer";
       } else {
           DBottomLeft = "D(" + BottomLeftCell.getRow() + ", " +
                         BottomLeftCell.getColumn() + ")";
           m_dpTable.addInteractiveCell(BottomLeftCell);
           highlightList.add(BottomLeftCell);
       }

       int n = 0;
       NCellPair cellPair;
       ListIterator a = currentCell.getBifPointers().listIterator();

        while (a.hasNext()) {
            cellPair = (NCellPair)a.next();
            n++;
            highlightList.addAll(cellPair.getCellPair());
            ((NTable)m_dpTable).addInteractiveCell(cellPair);
        }

        if (n==0) {
            DBifuricate = "No Pointers";
        }
        else {
            DBifuricate = n + " Pointer Pair" + (n>1?"s":"");
        }

        m_lDEqual.setText(DEqual);
        m_l1Choiche.setText(DLeft);
        m_l2Choiche.setText(DBottom);
        m_l3Choiche.setText(DBottomLeft);
        m_l4Choiche.setText(DBifuricate);

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

        currentCell.setColor(Color.green);

        if (currentCell.isEndCell() && m_bifuratedCells.isEmpty()) {
           m_btnNext.setEnabled(false);
           m_btnEnd.setEnabled(false);
           m_dpTable.clearAllArrows();
           m_dpTable.clearGridCircle();
        }
        else {
           m_btnNext.setEnabled(true);
           m_btnEnd.setEnabled(true);
        }

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

        if (currentCell.isEndCell() && !m_bifuratedCells.isEmpty()) {
            m_backtrackLastSel = (CellElement)this.m_bifuratedCells.removeLast();

⌨️ 快捷键说明

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