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

📄 graphicsequencecollection.java

📁 emboss的linux版本的源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/***************************************************************** This program is free software; you can redistribute it and/or* modify it under the terms of the GNU General Public License* as published by the Free Software Foundation; either version 2* of the License, or (at your option) any later version.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the* GNU General Public License for more details.** You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.**  @author: Copyright (C) Tim Carver****************************************************************/package org.emboss.jemboss.editor;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.awt.print.*;import java.util.*;import java.io.File;import org.emboss.jemboss.gui.form.MultiLineToolTipUI;/***  * This class can be used to get a grapical representation* of a collection of sequences.**/public class GraphicSequenceCollection extends JPanel                                       implements Printable, Scrollable{  /** Vector of sequences removed from panel */  private Vector removedSeqs = new Vector();  /** Vector containing Sequence objects     */  protected Vector seqs;               /** Vector containing graphical sequences  */  protected Vector graphicSequence;    /** Vector containing graphical names of sequences */  protected Vector graphicName;        /** Colour scheme to use                   */  protected Hashtable colorScheme;     /** Consensus plot  */  private PlotConsensus pc = null;   private int hgt;  private int len;  /** longest sequence length */   protected int MAXSEQLENGTH = 0;  /** number of residues on each line for print */  private int numResiduePerLine = 0;     /** panel for sequence numbers */  protected SequenceJPanel numberDraw;  /** sequence scrollpane */  protected JScrollPane jspSequence;   /** sequence name panel */   private JPanel seqNamePanel;  /** container for sequences */  protected Box seqBox;  /** container for sequence names */  protected Box seqNameBox;  /** container for consensus plot */  private Box plotconsSeqBox = null;  /** draw the sequence */  protected boolean drawSequence;  /** draw black square around residues */  protected boolean drawBlackBox;  /** colour residues   */  protected boolean drawColorBox;  /** draw sequence position number */  protected boolean drawNumber;  /** draw as per prettplot */  private boolean prettPlot = false;  /** gap between sequences and consensus plot */  private int plotConStrut = 20;  /** pretty plot values */  private PrettyPlotJFrame prettyPlot;  /** scoring matrix */  private Matrix mat;  /**  *  * @param seqs		vector of sequences  * @param colorScheme	sequence colour scheme  * @param jspSequence 	sequence scrollpane  * @param drawSequence true to draw the sequence  * @param drawBlackBox true to draw black square around residues  * @param drawColorBox true to colour residues  * @param drawNumber   true to draw sequence position number  * @param statusField	status field in the editor  *  */  public GraphicSequenceCollection(Vector seqs, Hashtable colorScheme,                         JScrollPane jspSequence,                         boolean drawSequence, boolean drawBlackBox,                         boolean drawColorBox, boolean drawNumber,                         JTextField statusField)  {    super(new BorderLayout());    this.seqs = seqs;    this.colorScheme = colorScheme;    this.jspSequence = jspSequence;    this.drawSequence = drawSequence;    this.drawBlackBox = drawBlackBox;    this.drawColorBox = drawColorBox;    this.drawNumber = drawNumber;    jspSequence.getViewport().setBackground(Color.white);    setBackground(Color.white);    MultiLineToolTipUI.initialize();    graphicSequence = new Vector();    graphicName = new Vector();// find maximum seq length    setMaxSeqLength();    Box centerBox = new Box(BoxLayout.Y_AXIS);    seqBox = new Box(BoxLayout.Y_AXIS);    centerBox.add(seqBox);    Box westBox = new Box(BoxLayout.Y_AXIS);    seqNameBox = new Box(BoxLayout.Y_AXIS);    westBox.add(seqNameBox);    seqNamePanel = new JPanel(new BorderLayout());    seqNamePanel.add(westBox,BorderLayout.CENTER);    seqNamePanel.setBackground(Color.white);    jspSequence.setRowHeaderView(seqNamePanel);// draw residue/base numbering    if(drawNumber)      drawNumber();// draw names and sequences     Enumeration enumer = seqs.elements();    while(enumer.hasMoreElements())      addSequence((Sequence)enumer.nextElement(),false,0,0);    westBox.add(Box.createVerticalGlue());    centerBox.add(Box.createVerticalGlue());    plotconsSeqBox = new Box(BoxLayout.Y_AXIS);    centerBox.add(plotconsSeqBox);    add(centerBox,BorderLayout.CENTER);        int xfill = getNameWidth();    seqNamePanel.setPreferredSize(new Dimension(xfill,2000));  }   /**  *  * @param seqs         vector of sequences  * @param jspSequence  sequence scrollpane  * @param drawSequence true to draw the sequence  * @param drawBlackBox true to draw black square around residues  * @param drawColorBox true to colour residues  * @param drawNumber   true to draw sequence position number  * @param statusField  status field in the editor  *  */  public GraphicSequenceCollection(Vector seqs, JScrollPane jspSequence,                         boolean drawSequence, boolean drawBlackBox,                         boolean drawColorBox, boolean drawNumber,                         JTextField statusField)  {    this(seqs,null,jspSequence,drawSequence,         drawBlackBox,drawColorBox,drawNumber,statusField);  }  /**  *  * Get the vector of Sequences  * @return 	vector of Sequences  *  */  protected Vector getSequenceCollection()  {    return seqs;  }  /**  *  * Get the consensus sequence  * @return     consensus sequence  *  */  protected Sequence getConsensusSequence()  {    Enumeration enumer = seqs.elements();    while(enumer.hasMoreElements())    {      Sequence s = (Sequence)enumer.nextElement();      String name = s.getName();      if(name.equals("Consensus"))        return s;    }    return null;  }  /**  *  * Get the number of sequences  * @return     vector of Sequences  *  */  protected int getNumberSequences()  {    return seqs.size();  }  /**  *  * Get the position of the sequence JViewPort   * @return 	position of the sequence JViewPort  *  */  protected Point getViewPosition()   {    return jspSequence.getViewport().getViewPosition();  }  /**  *  * Get the Rectangle being displayed by the sequence JViewPort  * @return     rectangle being displayed by the sequence JViewPort  *  */  protected Rectangle getViewRect()  {    Rectangle r = jspSequence.getViewport().getViewRect();// adjustment for the sequence names on the west//  r.x = r.x - westBox.getWidth();//  if(r.x < 0)//    r.x = 0;    return r;  }  /**  *  * Calculate and display the consensus plot  * @param File matrix - scoring matrix  * @param int wsize window size to average scores over  *  */  protected void showConsensusPlot(File matrix, int wsize)  {    deleteConsensusPlot();    SequenceJPanel sj = (SequenceJPanel)graphicSequence.get(0);    int interval = sj.getSequenceResidueWidth();    pc =  new PlotConsensus(matrix,seqs,wsize,interval,this);    pc.setBackground(Color.white);        Box XBox = new Box(BoxLayout.X_AXIS);    XBox.add(pc);    XBox.add(Box.createHorizontalGlue());    plotconsSeqBox.add(Box.createVerticalStrut(plotConStrut));    plotconsSeqBox.add(XBox);    plotconsSeqBox.add(Box.createVerticalGlue());    Dimension dpane = getPanelSize();    setMinimumSize(dpane);    setPreferredSize(dpane);    setJScrollPaneViewportView();  }  /**  *  * Calculate and display the consensus plot  * @param File matrix - scoring matrix  * @param int wsize window size to average scores over  *  */  protected void showConsensusPlot(Matrix mat, int wsize)  {    deleteConsensusPlot();    SequenceJPanel sj = (SequenceJPanel)graphicSequence.get(0);    int interval = sj.getSequenceResidueWidth();    pc =  new PlotConsensus(mat,seqs,wsize,interval,this);    pc.setBackground(Color.white);       Box XBox = new Box(BoxLayout.X_AXIS);    XBox.add(pc);    XBox.add(Box.createHorizontalGlue());    plotconsSeqBox.add(Box.createVerticalStrut(20));    plotconsSeqBox.add(XBox);    plotconsSeqBox.add(Box.createVerticalGlue());    Dimension dpane = getPanelSize();    setMinimumSize(dpane);    setPreferredSize(dpane);    setJScrollPaneViewportView();  }  /**  *  * Remove the consensus plot from the sequence editor  *  */  protected void deleteConsensusPlot()  {    plotconsSeqBox.removeAll();  }  /**  *  * Set the longest sequence length  * @param max 	longest sequence length  *  */  protected void setMaxSequenceLength(int max)  {    if(max > MAXSEQLENGTH)      MAXSEQLENGTH = max;  }  /**  *  * Calculate the longest sequence length  *  */  protected void setMaxSeqLength()  {    MAXSEQLENGTH = 0;    Enumeration enumer = seqs.elements();    while(enumer.hasMoreElements())    {      Sequence seq = (Sequence)(enumer.nextElement());      if(seq.getSequence().length()>MAXSEQLENGTH)        MAXSEQLENGTH = seq.getSequence().length();    }  }  /**  *  * Get the longest sequence length  * @return 	longest sequence length  *  */  public int getMaxSeqLength()  {    return MAXSEQLENGTH;  }  /**  *  * Lock/group the sequences  * @param 	true to lock sequences  *  */  protected void setSequenceLock(boolean llock)  {    Enumeration enumer = graphicName.elements();    if(!llock)    {      while(enumer.hasMoreElements())        ((SequenceNameJButton)enumer.nextElement()).setSelected(false);       enumer = graphicSequence.elements();      while(enumer.hasMoreElements())        ((SequenceJPanel)enumer.nextElement()).detachAll();               return;    }    int i = 0;    Vector selected = new Vector();    while(enumer.hasMoreElements())    {      SequenceNameJButton sbutt = (SequenceNameJButton)enumer.nextElement();      if(sbutt.isSelected())        selected.add((SequenceJPanel)graphicSequence.get(i));      i++;    }    // group sequences    for(i=0;i<selected.size();i++)    {      SequenceJPanel si = (SequenceJPanel)selected.get(i);      for(int j=0;j<selected.size();j++)        if(i!=j)          ((SequenceJPanel)selected.get(j)).attach(si);    }  }  /**  *  * Set the size of the sequence number panel  *  */  protected void setNumberSize()  {    Dimension actual = numberDraw.getMaximumSize();    int slen = numberDraw.getResidueWidth()*(int)(MAXSEQLENGTH*1.5);    numberDraw.setMaximumSize(new Dimension(slen,(int)actual.getHeight()));  }  protected void setMatrix(Matrix mat)  {    this.mat = mat;  }  /**  *  * Determine the colour of a residue at a given position. If  * the residues at that position in all the sequences are identical  * then return red otherwise return black.  * @param s		residue at position pos  * @param pos		residue position  * @param seqName	sequence name  * @return 	red if all identical otherwise return black  *  */  protected Color getColor(String s, int pos, String seqName)  {    if(s.equals("-") || s.equals("."))      return Color.black;    int identical = 1;    int nseqs = 0;    Enumeration enumer = seqs.elements();    while(enumer.hasMoreElements())    {      nseqs++;      Sequence seq = (Sequence)(enumer.nextElement());      if(!seqName.equals(seq.getName()))      {        SequenceJPanel seqPanel = (SequenceJPanel)graphicSequence.get(nseqs);        if(pos < seq.getLength() && seqPanel.isPrettyPlot())          if(seq.getResidue(pos).equalsIgnoreCase(s))            identical++;      }    }      if(identical >= prettyPlot.getMinimumIdentity(nseqs))      return prettyPlot.getIDColour();    else if(mat != null)    {      double threshold = prettyPlot.getMatchThreshold();      int m1 = mat.getMatrixIndex(s);      int matrix[][] = mat.getMatrix();      float matching = 0.f;      nseqs = 0;      enumer = seqs.elements();      while(enumer.hasMoreElements())      {        nseqs++;        Sequence seq = (Sequence)(enumer.nextElement());        SequenceJPanel seqPanel = (SequenceJPanel)graphicSequence.get(nseqs);//      if(!seqName.equals(seq.getName()))//      {          if(pos < seq.getLength() && seqPanel.isPrettyPlot())          {            int m2 = mat.getMatrixIndex(seq.getResidue(pos));            if(m1 >= 0 && m2 >= 0 && matrix[m1][m2]>0)              matching += seq.getWeight();          }//      }      }      if(matching >= threshold)        return prettyPlot.getMatchColour(); 

⌨️ 快捷键说明

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