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

📄 graphicsequencecollection.java

📁 emboss的linux版本的源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
   // rescale consensus plot    if(pc != null)    {      SequenceJPanel sj = (SequenceJPanel)graphicSequence.get(0);      int interval = sj.getSequenceResidueWidth();      pc.setInterval(interval);      pc.setPlotSize();    }   //    Dimension dpane = getPanelSize();    setMinimumSize(dpane);    setPreferredSize(dpane);    setNamePanelWidth(getNameWidth());    setJScrollPaneViewportView();  }  /**  *  * Get the font size used to display the sequences in the  * editor  * return 	font size  *  */  public int getFontSize()  {    return ((SequenceJPanel)graphicSequence.get(0)).getFontSize();  }  /**  *  * Search sequences for a pattern and highlight matches. Set the  * viewport to that position.  *  * @param String pat pattern to match   * @param int oldResPosition if this is a repeat of a search  *        this is the position the old search finished at  * @param boolean wrapAround true if the search should wrap  *        around the sequences  * @return int the matching position found (or -1 if none found)  *  */  public int findPattern(String pat, int oldResPosition,                         boolean wrapAround)  {    int resWidth = ((SequenceJPanel)graphicSequence.get(0)).                                           getSequenceResidueWidth();    Rectangle r = getViewRect();    int ypos = r.y;    int xpos = r.x/resWidth;    int viewWidth = r.width/resWidth;    pat = pat.toLowerCase();            // highlight matching segments of seqs    Enumeration enumer = graphicSequence.elements();    while(enumer.hasMoreElements())    {      SequenceJPanel sjp = (SequenceJPanel)enumer.nextElement();      sjp.showPattern(pat);    }// move view to the next occurence of that pattern    if(oldResPosition > -1)      // possibly this as well: (&& xpos < oldResPosition)      xpos = oldResPosition;    int newResPos = searchSequences(xpos,pat);    if(newResPos > -1)    {      int mid = findMiddle(newResPos,viewWidth,pat);      jspSequence.getViewport().setViewPosition(                        new Point(mid*resWidth,ypos));//    System.out.println("xpos "+xpos+" newResPos "+newResPos+//                       " viewWidth "+viewWidth+" mid "+mid+//                       " oldResPosition "+oldResPosition);    }    else if(wrapAround)     // search from start of seqs    {//    JOptionPane.show      newResPos = searchSequences(0,pat);//    System.out.println("SEARCH FROM START OF SEQUENCE");      if(newResPos > -1)      {        int mid = findMiddle(newResPos,viewWidth,pat);        jspSequence.getViewport().setViewPosition(                         new Point(mid*resWidth,ypos));      }    }    else if(!wrapAround)      newResPos = oldResPosition;    return newResPos+1;  }  /**  *  * Search the sequences for the position in that matches  * the given pattern to search for.   *  * @param int startSearch position at which the search is started  * @param String pat is the pattern to search  * @return int position in a sequence that next matches the pattern  *         (or -1 if none found)  *  */  private int searchSequences(int startSearch, String pat)  {    int newResPos = 0;    int nfound = 0;    Enumeration enumer = seqs.elements();    while(enumer.hasMoreElements())    {      Sequence seq = (Sequence)enumer.nextElement();      int index = seq.getSequence().toLowerCase().indexOf(pat,startSearch);      if(index > -1)      {        if(nfound == 0 || index < newResPos)          newResPos = index;        nfound++;      }    }    if(nfound == 0)      return -1;    return newResPos;  }  /**  *  * Locate the center of a vieport view that contains the  * defined position to display  *  * @param int newResPos position in the sequence to display  * @param int viewWidth width of the viewport  * @param String pat matching pattern  * @return int position to set the viewport to so that the  *         pattern is displayed in the middle of it   *  */  private int findMiddle(int newResPos, int viewWidth, String pat)  {    int mid;    int viewWidth2 = viewWidth/2;    if(newResPos <= viewWidth2)      mid = 0;    else      mid = newResPos-viewWidth2+(pat.length()/2);    return mid;  }  /**   *  * Set the colour scheme to use  * @param colourTable	colour scheme as a hashtable  *  */  public void setColorScheme(Hashtable colourTable)  {    this.colorScheme  = colourTable;    this.drawColorBox = true;    Enumeration enumer = graphicSequence.elements();    while(enumer.hasMoreElements())    {      SequenceJPanel sjp = (SequenceJPanel)enumer.nextElement();      sjp.setColorScheme(colourTable);      sjp.setDrawColor(drawColorBox);    }  }   /**   *  * Display the sequences as per emboss prettyplot colours  * @param bpretty	true if displaying as prettyplot  *  */  public void setPrettyPlot(boolean bpretty, PrettyPlotJFrame prettyPlot)  {    this.prettyPlot = prettyPlot;    Enumeration enumer = graphicSequence.elements();    while(enumer.hasMoreElements())      ((SequenceJPanel)(enumer.nextElement())).setPrettyPlot(bpretty);  }   /**  *  * Force display in the viewport  *  */  public void setJScrollPaneViewportView()  {    jspSequence.setViewportView(this);  }  /**  *  * Get the number of pages to print the alignment in  * a given format  * @param format	format for printing  * @return		number of pages  *  */  public int getNumberPages(PageFormat format)  {    return getNumberPages(format,getResiduesPerLine(format));  }  /**  *  * Get the number of pages to print the alignment in  * a given format and with a given number of residues per line  * @param format         format for printing  * @param numResPerLine  number of residues per line  * @return               number of pages  *  */  public int getNumberPages(PageFormat format, int numResPerLine)  {    double pageHeight = format.getImageableHeight();    int residueWidth  = ((SequenceJPanel)graphicSequence.get(0)).getSequenceHeight();    int nblockPerPage = (int)(pageHeight/((graphicSequence.size()+2)*residueWidth));    int npage         = MAXSEQLENGTH/(nblockPerPage*numResPerLine)+1;    return npage;  }  /**  *  * Get the imageable size. This is for fitting the image  * to one page.  * @return               image size  *  */  public Dimension getImageableSize(int numResPerLine)  {    SequenceJPanel seq = (SequenceJPanel)graphicSequence.get(0);    int residueHeight = seq.getSequenceHeight();    int alignHeight   = (graphicSequence.size()+1)*residueHeight;    int nalign = Math.round(((float)MAXSEQLENGTH/                             (float)numResPerLine)+.5f)*alignHeight;//  System.out.println("nalign "+//                     Math.round(((float)MAXSEQLENGTH/(float)numResPerLine)+.5f)+//                     "  alignHeight "+alignHeight+"  nalign "+nalign+" //                     residueHeight "+residueHeight+ //                     "  graphicSequence.size()+1 "+(graphicSequence.size()+1));    int width  = (seq.getResidueWidth()*(numResPerLine+2))+getNameWidth();    return new Dimension(width,nalign);  }  /**  *  * Get the number residues per line  * @param format    	format for printing  * @return		number residues per line	  *  */  public int getResiduesPerLine(PageFormat format)  {    double pwidth = format.getImageableWidth()-(double)getNameWidth();//  int resWidth = ((SequenceJPanel)graphicSequence.get(0)).getSequenceHeight();    int resWidth = ((SequenceJPanel)graphicSequence.get(0)).getSequenceResidueWidth();    return (int)(pwidth/(double)resWidth);  }  /**  *  * Get the number residues per page  * @param format         format for printing  * @param numResPerLine  number residues per line          * @return 		  number residues per page  *  */  public int getResiduesPerPage(PageFormat format, int numResPerLine)  {    double pageHeight = format.getImageableHeight();    int residueWidth  = ((SequenceJPanel)graphicSequence.get(0)).getSequenceHeight();    int nblockPerPage = (int)(pageHeight/(residueWidth*(graphicSequence.size()+2)));    return nblockPerPage*numResPerLine;  }  /**  *  * Used to print the sequence alignment  * @param g		graphics  * @param format	page format  * @param pageIndex 	page number to print  * @throws PrinterException  *  */  public int print(Graphics g, PageFormat format, int pageIndex)                                              throws PrinterException  {    Graphics2D g2d = (Graphics2D) g.create();    drawSequences(g2d,format,pageIndex,numResiduePerLine);    return Printable.PAGE_EXISTS;  }  /**  *  * Set the number of residues per line to user setting  * @param numResiduePerLine 	number of residues per line  *  */  protected void setNumberOfResiduesPerLine(int numResiduePerLine)  {    this.numResiduePerLine = numResiduePerLine;  }  /**  *  * Draws the sequences for printing  * @param g2d		graphics  * @param format	page format  * @param pageIndex	page number to print  *  */  public void drawSequences(Graphics2D g2d, PageFormat format,                             int pageIndex)  {    int numResPerLine = getResiduesPerLine(format);    drawSequences(g2d,format,pageIndex,numResPerLine);  }  /**  *  * Draws the sequences for printing  * @param g2d          	graphics  * @param format       	page format  * @param pageIndex    	page number to print  * @param numResPerLine 	number of residues per line  */  public void drawSequences(Graphics2D g2d, PageFormat format,                             int pageIndex, int numResPerLine)  {    // move origin from the corner of the Paper to the corner of imageable area    g2d.translate(format.getImageableX(), format.getImageableY());    int resPerPage  = getResiduesPerPage(format,numResPerLine);    int istart = resPerPage*pageIndex;    int istop  = istart+resPerPage;    if(istop > MAXSEQLENGTH)      istop = MAXSEQLENGTH;//  System.out.println("pageIndex "+pageIndex+" numResPerLine "+numResPerLine);    for(int i=istart;i<istop;i+=numResPerLine)    {      Enumeration enumer = graphicSequence.elements();      SequenceJPanel gs = null;      int iend;      while(enumer.hasMoreElements())      {        iend = i+numResPerLine;        if(iend > istop)          iend = istop;        gs = (SequenceJPanel)(enumer.nextElement());        gs.getSequencePrintGraphic(g2d,getNameWidth(),i,iend);//                                 i+numResPerLine);        gs.getNamePrintGraphic(g2d);        g2d.translate(0,gs.getSequenceHeight());      }      g2d.translate(0,gs.getSequenceHeight());    }  }//scrollable interface methods  /**  *  * Override for scrollable interface   *  */  public Dimension getPreferredScrollableViewportSize()  {    return getPreferredSize();  }  /**  *  * Override for scrollable interface   *  */  public boolean getScrollableTracksViewportHeight()  {    return false;  }  /**  *  * Override for scrollable interface   *  */  public boolean getScrollableTracksViewportWidth()  {    return false;  }  /**  *  * Override for scrollable interface   *  */  public int getScrollableBlockIncrement(Rectangle r,                    int orientation, int direction)  {    return 60;  }  /**  *  * Override for scrollable interface   *  */  public int getScrollableUnitIncrement(Rectangle r,                    int orientation, int direction)  {    return 60;  }  public static void main(String args[])  {    Vector seqs = new Vector();    seqs.add(new Sequence("Seq1","ACCaaaaaaaaaaaaaaaaaaaaTAGAtTAT"+             "ACCaaaaaaaaaaaaaaaaaaaaTAGAtTAT"+             "ACCaaaaaaaaaaaaaaaaaaaaTAGAtTAT"));    seqs.add(new Sequence("Seq2","ACCaaaaaaaaaaaaaaaaaaaaTAGAtTAT"+             "ACCaaaaaaaaaaaaaaaaaaaaTAGAtTAT"+             "ACCaaaaaaaaaaaaaaaaaaaaTAGAtTAT"));    JScrollPane jspSequence = new JScrollPane();    GraphicSequenceCollection gsc = new GraphicSequenceCollection(                                          seqs,null,jspSequence,                                          true,true,true,false,null);    jspSequence.setViewportView(gsc);     JFrame f = new JFrame("Sequence Panel");    JPanel pane = (JPanel)f.getContentPane();    pane.add(jspSequence);    f.pack();    f.setVisible(true);  }  protected void drawNumber()  {    numberDraw = new SequenceJPanel(10,MAXSEQLENGTH);    graphicSequence.add(numberDraw);    Box XBox = new Box(BoxLayout.X_AXIS);    XBox.add(numberDraw);    XBox.add(Box.createHorizontalGlue());    seqBox.add(XBox);    setNumberSize();    SequenceNameJButton snjBlank =               new SequenceNameJButton(new Sequence(" "),0);    graphicName.add(snjBlank);    seqNameBox.add(snjBlank);  }  protected void addAnnotationSequence(Sequence s)  {    addSequence(s,true,0,getFontSize());  }}

⌨️ 快捷键说明

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