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

📄 sequencejpanel.java

📁 emboss的linux版本的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  /**  *  * Find all occurences of the pattern in the sequence between  * the start and stop positions. Returning all positions of these  * in a vector.  * @param istart	start search from  * @param istop	stop search from  * @param seqS		sequence string to search  * @return		vector of all positions which match   *  */  private Vector getPatternPositions(int istart, int istop,                                     String seqS)  {    Vector pvec = new Vector();    int patlen = pattern.length();    int pstart = istart-patlen;    int pstop  = istop+patlen;    if(pstart < 0)      pstart = 0;    if(pstop > seqLength)      pstop = seqLength;    int ipat;    while( (ipat = seqS.substring(pstart,pstop).indexOf(pattern)) > -1)    {      for(int i=0;i<patlen;i++)        pvec.add(new Integer(ipat+pstart+i));      pstart = ipat+pstart+1;    }//  System.out.println("Showing "+pattern+" :: "+ipat+pstart+" :: "+//                     "istart "+istart+" istop "+istop);    return pvec;  }  /**  *  * Find all occurences of the pattern in the sequence between  * the start and stop positions. Returning all positions of these  * in a vector.  * @param subseqStart	index of the start of the (sub)sequence  * @param subseq       sequence string to search  * @return             vector of all positions which match  *  */  private Vector getPatternPositions(int subseqStart,                                     String subseq)  {    subseq = subseq.toLowerCase();    Vector pvec = new Vector();    int patlen = pattern.length();    int pstart = 0;    int ipat;    while( (ipat = subseq.substring(pstart).indexOf(pattern)) > -1)    {      for(int i=0;i<patlen;i++)        pvec.add(new Integer(ipat+pstart+subseqStart+i));      pstart = ipat+pstart+1;    }//  System.out.println("Showing "+pattern+" :: "+ipat+pstart+" :: "+//                     "istart "+istart+" istop "+istop);    return pvec;  }  /**  *  * Set pattern to high light  * @param pattern	pattern to high light  *  */  protected void showPattern(String pattern)  {    highlightPattern = true;    this.pattern = pattern.toLowerCase();  }    /**  *  * Set prettyplot display  * @param prettyPlot	true if the prettyplot display is to  *			be used  */  public void setPrettyPlot(boolean prettyPlot)  {    this.prettyPlot = prettyPlot;  }   /**  *  * Determine if using prettyplot display  * @return  	true if the prettyplot display is to  *           	be used  */  public boolean isPrettyPlot()  {    return prettyPlot;  }  /**  *  * Determine the tool tip to display  * @param e	mouse event  * @return	tool tip  *  */  public String getToolTipText(MouseEvent e)  {    Point loc = e.getPoint();    int resPos = (int)(loc.x/resWidth);    if(resPos < 0)      return null;    if(resPos > seq.getSequence().length()-1)      return null;    String res = seq.getSequence().substring(resPos,resPos+1);    String ls = System.getProperty("line.separator");    if(seq.getID() != null)      return seq.getID()+"\nResidue: "+res+ls+           "Position: "+Integer.toString(resPos+1);    return seq.getName()+"\nResidue: "+res+ls+           "Position: "+Integer.toString(resPos+1);  }  /**  *  * Get the tool tip location  * @param e    mouse event  * @return     point on the display  *  */  public Point getToolTipLocation(MouseEvent e)  {    Point loc = e.getPoint();    int x = (int)((loc.x+resWidth)/resWidth)*resWidth;    int y = seqHeight-(resWidth/2);    return new Point(x,y);  }  /**  *  * Get a residue colour  * @param s	residue  * @return	colour of the residue s  *  */  private Color getColor(String s)  {    s = s.toUpperCase();    if(colorTable.containsKey(s))      return (Color)colorTable.get(s);           return getBackground();  }   /**  *  * Set a default colour scheme   *  */   public void setDefaultColorHashtable()  {    colorTable = new Hashtable();    colorTable.put("A",Color.green);    colorTable.put("T",Color.red);    colorTable.put("C",Color.blue);    colorTable.put("G",Color.white);  }  /**  *  * Set whether to draw boxes around residues  * @param drawBlackBox	true to draw boxes  *  */  public void setDrawBoxes(boolean drawBlackBox)  {    if(drawNumber)      return;    this.drawBlackBox = drawBlackBox;//  paintComponent(getGraphics());  }  /**  *  * Set whether to colour residues  * @param drawColorBox true to colour residues  *  */  public void setDrawColor(boolean drawColorBox)  {    if(drawNumber)      return;    this.drawColorBox = drawColorBox;//  paintComponent(getGraphics());  }  /**  *  * Set the font size and set the size  * @param size		font size  *  */  public void setFontSize(int size)  {    fontSize = size;    font = new Font("Monospaced",                      Font.PLAIN, fontSize);    FontMetrics metrics = getFontMetrics(font);    boundWidth = metrics.stringWidth("A");    resWidth = metrics.stringWidth("A")+boundWidth/2;    seqHeight = metrics.stringWidth("A")+boundWidth;    setPreferredSize(getPreferredSize());    repaint();//  paintComponent(getGraphics());  }   /**  *  * Get the width of a residue  * @return	residue width  *  */  public int getResidueWidth()  {    return resWidth;  }  /**  *  * Set the colour scheme   * @param colorHash	colour scheme to use  *  */  public void setColorScheme(Hashtable colorHash)  {    this.colorTable = colorHash;    setPrettyPlot(false);  }  /**  *  * Get the font size  * @return font size  *  */  public int getFontSize()  {    return fontSize;  }  /**  *  * Get the preferred size dimension  * @return 	preferred dimension for this component  *  */  public Dimension getPreferredSize()  {    return new Dimension(getSequenceWidth(),getSequenceHeight());  }  /**  *  * Re-size the sequence alignment panel if the width of   * this sequence pane increases  *  */  protected void viewPaneResize()  {    Dimension dpane = viewPane.getPreferredSize();    GraphicSequenceCollection gsc = (GraphicSequenceCollection)viewPane;        int xpane = (int)dpane.getWidth();    int xsize = gsc.getPanelWidth();    if(xsize > xpane)      viewPane.setPreferredSize(new Dimension(xsize,                              gsc.getPanelHeight()));    gsc.setJScrollPaneViewportView();  }  /**  *  * Get the sequence panel height  * @return 	sequence height  *  */  public int getSequenceHeight()  {    return seqHeight+ypad;  }  /**  *  * Get the sequence panel width  * @return     sequence width  *  */  public int getSequenceWidth()  {    return resWidth*seqLength;  }  /**  *  * Get the width of a residue  * @return 	residue width  *  */  public int getSequenceResidueWidth()  {    return resWidth;  }  /**  *  * Set the sequence length  * @param s	sequence length  *  */  public void setSequenceLength(int s)  {    seqLength = s;  }  /**  *  * Get the sequence name associated with this display  * @return	sequence name  *  */  public String getName()  {    return seq.getName();  }  /**  *  * Render the sequence name graphic  * @param g2d	graphic  *  */  public void getNamePrintGraphic(Graphics g2d)  {    if(seq == null)      return;    String name = seq.getName();    if(seq.getID() != null)      name = seq.getID();    g2d.setFont(font);    g2d.setColor(Color.black);    g2d.drawString(name,0,seqHeight-boundWidth2);  }   /**  *  * Render the sequence graphic  * @param g2d  	graphic  * @param MAXSEQNAME	maximum size for a sequence name  * @param istart	sequence start position for graphic  * @param istop	sequence stop position for graphic  *  */  public void getSequencePrintGraphic(Graphics g2d, int MAXSEQNAME,                                       int istart, int istop)   {    String sName = null;    String seqS  = null;     g2d.setFont(font);    if(drawSequence)    {      sName = seq.getName();      if(seq.getID() != null)        sName = seq.getID();      seqS  = seq.getSequence();      int seqLength = seq.getLength();      if(seqLength < istop)        istop = seqLength;    }    int boundWidth4 = boundWidth2/2;    boolean leftResidue = false;    FontMetrics metrics = getFontMetrics(font);    for(int i=istart;i<istop;i++)    {      int ipos = (i-istart)*(resWidth)+MAXSEQNAME;      if(drawColorBox)      {        g2d.setColor(getColor(seqS.substring(i,i+1)));        g2d.fillRect(ipos,0,resWidth,seqHeight);      }      g2d.setColor(Color.black);      if(drawBlackBox)        g2d.drawRect((i-istart)*(resWidth)+MAXSEQNAME,0,resWidth,seqHeight);      if(drawSequence)      {        String res = seqS.substring(i,i+1);        if(prettyPlot)          leftResidue = prettyDraw(i,ipos,istop,res,seqHeight,                                   resWidth,leftResidue,g2d);        g2d.drawString(res,                      ((i-istart)*resWidth)+boundWidth4+MAXSEQNAME,                      seqHeight-boundWidth2);            }      else if(drawNumber && (int)((i+1-istart)%interval) == 0)      {        String snum = Integer.toString(i+1);        int numWidth = metrics.stringWidth(snum);        g2d.drawString(snum,                     ((int)((i-istart+0.5)*resWidth)-(numWidth/2))+MAXSEQNAME,                     seqHeight-boundWidth2);      }    }  }   /**  *  * Override actionPerformed for popup menu actions  * @param e	action event  *   */  public void actionPerformed(ActionEvent e)  {    JMenuItem source = (JMenuItem)(e.getSource());    if(source.getText().startsWith("Delete "))    {      ((GraphicSequenceCollection)viewPane).deleteSequence(seq.getName());    }    else if(source.getText().startsWith("Reverse Complement"))    {      seq.reverseComplementSequence();      paintComponent(getGraphics());    }    else if(source.getText().startsWith("Reverse "))    {      seq.reverseSequence();      paintComponent(getGraphics());    }    else if(source.getText().startsWith("Complement "))    {      seq.complementSequence();      paintComponent(getGraphics());    }  }  /**  *  * Popup listener  *  */  class PopupListener extends MouseAdapter  {    public void mousePressed(MouseEvent e)    {      maybeShowPopup(e);    }    public void mouseReleased(MouseEvent e)    {      maybeShowPopup(e);    }    private void maybeShowPopup(MouseEvent e)    {      if(e.isPopupTrigger())        popup.show(e.getComponent(),                e.getX(), e.getY());    }  }}

⌨️ 快捷键说明

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