From: amwaterhouse Date: Fri, 4 Feb 2005 18:29:43 +0000 (+0000) Subject: SequenceFeature display added X-Git-Tag: Release_2_0~701 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=22be3f466cd70cb03d5eae619ede8589ae69716a;p=jalview.git SequenceFeature display added --- diff --git a/src/MCview/PDBfile.java b/src/MCview/PDBfile.java index ce98a06..7e46b2e 100755 --- a/src/MCview/PDBfile.java +++ b/src/MCview/PDBfile.java @@ -12,6 +12,15 @@ public class PDBfile extends jalview.io.FileParse { Vector lineArray = new Vector(); + public PDBfile(String [] lines) + { + for(int i=0; i")>-1) + { + sequence = align.findName( parseElement( result[r], "" )) ; + features = new Vector(); + type=""; start="0"; end="0"; description=""; status=""; pdb=""; + } + + if(sequence==null) + continue; + + if( result[r].indexOf("-1) + { + pdb = parseValue( result[r], "value=" ); + sequence.setPDBId(pdb); + } + + if(result[r].indexOf("feature type")>-1) + { + type = parseValue( result[r], "type=" ); + description = parseValue( result[r], "description=" ); + status = parseValue ( result[r], "status="); + + while( result[r].indexOf("")==-1) + { + r++; // + } + r++; + if(result[r].indexOf("begin")>-1) + { + start = parseValue( result[r], "position=" ); + end = parseValue( result[++r], "position=" ); + } + else + { + start = parseValue( result[r], "position=" ); + end = parseValue( result[r], "position=" ); + } + int sstart = Integer.parseInt(start); + int eend = Integer.parseInt(end); + + if(sstart>=sequence.getStart() && eend<=sequence.getEnd()) + { + SequenceFeature sf = new SequenceFeature(type, + sstart, + eend, + description, + status); + features.add(sf); + } + } + + if(result[r].indexOf("")>-1) + { + sequence.setSequenceFeatures( features ); + features = null; + sequence = null; + } + } + } + } + + static String parseValue(String line, String tag) + { + + int index = line.indexOf(tag)+tag.length()+1; + if(index==tag.length()) + return ""; + + return line.substring( index, line.indexOf("\"", index+1) ); + } + + + static String parseElement(String line, String tag) + { + int index = line.indexOf(tag)+tag.length(); + return line.substring( index, line.indexOf(" 0) { - color = Color.red; - } else { - color = Color.lightGray; - } - } - public String print() { - String tmp = new Format("%15s").form(type); - tmp = tmp + new Format("%6d").form(start); - tmp = tmp + new Format("%6d").form(end); - tmp = tmp + " " + description; - return tmp; - } - public void draw(Graphics g, int fstart, int fend, int x1, int y1, int width, int height) { - g.setColor(new Color((float)(Math.random()),(float)(Math.random()),(float)(Math.random()))); - - // int xstart = sequence.findIndex(start); - //int xend = sequence.findIndex(end); - int xstart = start; - int xend = end; - long tstart = System.currentTimeMillis(); - if (!(xend < fstart && xstart > fend)) { - - if (xstart > fstart) { - x1 = x1 + (xstart-fstart)*width; - fstart = xstart; - } - - if (xend < fend) { - fend = xend; - } - - for (int i = fstart; i <= fend; i++) { - char c = sequence.sequence.charAt(i); - if (!jalview.util.Comparison.isGap((c))) - g.fillRect(x1+(i-fstart)*width,y1,width,height); - else - g.drawString("-",x1+(i-fstart)*width,y1+height); - - } - - } - long tend = System.currentTimeMillis(); - System.out.println("Time = " + (tend-tstart) + "ms"); - - } - - public static void main(String[] args) { - SequenceFeature sf = new SequenceFeature(); - - System.out.println("Feature " + sf); - } - public static int CHAIN = 0; - public static int DOMAIN = 1; - public static int TRANSMEM = 2; - public static int SIGNAL = 3; - public static int HELIX = 4; - public static int TURN = 5; - public static int SHEET = 6; - public static int CARBOHYD = 7; - public static int ACT_SITE = 8; - public static int TRANSIT = 9; - public static int VARIANT = 10; - public static int BINDING = 11; + public String getStatus() + {return status;} + + +/* + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +*/ } diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index 2183131..75b17eb 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -36,6 +36,13 @@ public interface SequenceI { public void setColor(Color c); public Color getColor(); + + public Vector getSequenceFeatures(); + public void setSequenceFeatures(Vector v); + + public void setPDBId(String id); + public String getPDBId(); + } diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 2542216..1f6fabd 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -17,7 +17,6 @@ import jalview.datamodel.*; import jalview.analysis.*; import jalview.io.*; import jalview.ws.*; -import MCview.*; import java.awt.*; import java.awt.event.*; import java.awt.print.*; @@ -34,14 +33,13 @@ public class AlignFrame extends GAlignFrame { super(); + AlignmentUtil.addUniprotFeatures(al); + viewport = new AlignViewport(al,true,true,true,false); alignPanel = new AlignmentPanel(this, viewport); getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER); fontNameMenuItem.setText(viewport.getFont().getName()); fontSizeMenuItem.setText(viewport.getFont().getSize()+""); - - clustalColour.setSelected(true); - clustalColour_actionPerformed(null); } protected void saveAs_actionPerformed(ActionEvent e) @@ -431,9 +429,10 @@ public class AlignFrame extends GAlignFrame alignPanel.RefreshPanels(); } - public void secondaryStructure_actionPerformed(ActionEvent evt) + public void sequenceFeatures_actionPerformed(ActionEvent evt) { - alignPanel.setSecondaryStructureVisible(secondaryStructure.isSelected()); + viewport.showSequenceFeatures(sequenceFeatures.isSelected()); + alignPanel.RefreshPanels(); } public void consensusGraphMenuItem_actionPerformed(ActionEvent e) @@ -870,6 +869,8 @@ public class AlignFrame extends GAlignFrame if (alignment != null) { AlignFrame af = new AlignFrame(new Alignment(alignment)); + af.clustalColour.setSelected(true); + af.clustalColour_actionPerformed(null); Desktop.addInternalFrame(af, getTitle().concat(" - ClustalW Alignment"), 700, 500); // JBPNote - is there a new window geom. property ? } @@ -895,51 +896,13 @@ public class AlignFrame extends GAlignFrame g.setColor(Color.black); g.drawString("Clustal Alignment Web Service running", 30,30); } - - - } - - - public void pdbTest_actionPerformed(ActionEvent e) - { - String reply = - JOptionPane.showInternalInputDialog(this, "Enter pdb code", - "PDB test viewer", JOptionPane.QUESTION_MESSAGE); - - String url = "http://www.ebi.ac.uk/cgi-bin/pdbfetch?id=1a4u"; - if (reply.length()>1) - url = "http://www.ebi.ac.uk/cgi-bin/pdbfetch?id="+reply; - - try - { - PDBfile pdb = new PDBfile(url, - "URL"); - Sequence seq = (Sequence)viewport.getAlignment().getSequenceAt(0); - seq.setPDBfile(pdb); - ( (PDBChain) pdb.chains.elementAt(seq.maxchain)).isVisible = true; - ( (PDBChain) pdb.chains.elementAt(seq.maxchain)).sequence = seq; - // ( (PDBChain) pdb.chains.elementAt(seq.maxchain)).colourBySequence(); - - rotCanvas rc = new rotCanvas(pdb); - JInternalFrame frame = new JInternalFrame(); - frame.setContentPane(rc); - Desktop.addInternalFrame(frame, url, 400,400); - } - catch (Exception ex) - { - ex.printStackTrace(); - } - } public void doKeyPressed(KeyEvent evt) { - - System.out.println(evt.getKeyChar()); if(evt.isControlDown() && evt.getKeyChar()=='f') findMenuItem_actionPerformed(null); - } diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 1c6c453..7352495 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -21,6 +21,7 @@ public class AlignViewport boolean showBoxes=true; boolean wrapAlignment=false; boolean renderGaps = true; + boolean showSequenceFeatures = true; ColourSchemeI globalColourScheme = null; boolean conservationColourSelected = false; @@ -89,6 +90,10 @@ public class AlignViewport setFont( font ); } + public void showSequenceFeatures(boolean b) + { + showSequenceFeatures = b; + } public String getVisibleConsensus() { diff --git a/src/jalview/gui/DrawableSequence.java b/src/jalview/gui/DrawableSequence.java index 32e8d1c..dc6ff1e 100755 --- a/src/jalview/gui/DrawableSequence.java +++ b/src/jalview/gui/DrawableSequence.java @@ -3,6 +3,7 @@ package jalview.gui; import jalview.datamodel.*; import jalview.schemes.*; import java.awt.*; +import java.util.*; public class DrawableSequence implements SequenceI { protected boolean fastDraw = true; @@ -12,6 +13,19 @@ public class DrawableSequence implements SequenceI { ColourSchemeI cs = null; + public Vector sequenceFeatures = new Vector(); + public void setSequenceFeatures(Vector v) + { sequenceFeatures = v; } + public Vector getSequenceFeatures() + {return sequenceFeatures; } + + String pdbId; + public void setPDBId(String id) + { pdbId = id; } + public String getPDBId() + { return pdbId; } + + public DrawableSequence(SequenceI s) { this.sequence = s; diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java new file mode 100755 index 0000000..6e38f1b --- /dev/null +++ b/src/jalview/gui/FeatureRenderer.java @@ -0,0 +1,71 @@ +package jalview.gui; + +import jalview.datamodel.*; +import jalview.schemes.*; +import java.awt.*; +import java.util.*; + +public class FeatureRenderer implements RendererI +{ + AlignViewport av; + + SequenceGroup currentSequenceGroup = null; + SequenceGroup [] allGroups = null; + Color resBoxColour; + Graphics graphics; + + public FeatureRenderer(AlignViewport av) + { + this.av = av; + } + + + public void drawSequence(Graphics g,SequenceI seq,SequenceGroup [] sg, int start, int end, int x1, int y1, int width, int height, Vector pid, int seqnum) + { + Vector features = seq.getSequenceFeatures(); + Enumeration e = features.elements(); + while( e.hasMoreElements() ) + { + SequenceFeature sf = (SequenceFeature)e.nextElement(); + int fstart = seq.findIndex(sf.getStart())-1; + int fend = seq.findIndex(sf.getEnd())-1; + + if( (fstart>=start&&fstart<=end) || (fend>=start&&fend<=end)) + { + if(fstart==fend) + { + g.setColor(Color.red); + g.fillRoundRect( (fstart - start) * width, y1, width, height, 4,4); + g.setColor(Color.white); + + char s = seq.getSequence().charAt(fstart); + FontMetrics fm = g.getFontMetrics(); + int charOffset = (width - fm.charWidth(s))/2; + int pady = height/5; + g.drawString(String.valueOf(s), charOffset + x1 + width * (fstart - start), y1 + height - pady); + + } + else + { + for (int i = fstart; i <= fend; i++) + { + g.setColor(Color.blue); + g.fillRect( (i-start) * width, y1, width, height); + + g.setColor(Color.white); + char s = seq.getSequence().charAt(i); + FontMetrics fm = g.getFontMetrics(); + int charOffset = (width - fm.charWidth(s)) / 2; + int pady = height / 5; + g.drawString(String.valueOf(s), + charOffset + x1 + width * (i-start), + y1 + height - pady); + + } + } + } + + } + } + +} diff --git a/src/jalview/gui/IdPanel.java b/src/jalview/gui/IdPanel.java index 0e528a2..3e8af17 100755 --- a/src/jalview/gui/IdPanel.java +++ b/src/jalview/gui/IdPanel.java @@ -122,7 +122,7 @@ public class IdPanel extends JPanel implements MouseListener, MouseMotionListene if (javax.swing.SwingUtilities.isRightMouseButton(e)) { jalview.gui.PopupMenu pop = new jalview.gui.PopupMenu(alignPanel, - av.getAlignment().getSequenceAt(seq)); + (Sequence)av.getAlignment().getSequenceAt(seq)); pop.show(this, e.getX(), y); return; } diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 4ad7090..2bdaf37 100755 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -5,7 +5,8 @@ import jalview.analysis.*; import jalview.schemes.*; import javax.swing.*; import java.awt.event.*; - +import jalview.io.*; +import MCview.*; public class PopupMenu extends JPopupMenu { @@ -39,10 +40,11 @@ public class PopupMenu extends JPopupMenu JMenu residueMenu = new JMenu(); JMenuItem annotateResidue = new JMenuItem(); - SequenceI sequence; + Sequence sequence; JMenuItem unGroupMenuItem = new JMenuItem(); + JMenuItem pdbMenuItem = new JMenuItem(); - public PopupMenu(AlignmentPanel ap, SequenceI seq) + public PopupMenu(AlignmentPanel ap, Sequence seq) { /////////////////////////////////////////////////////////// // If this is activated from the sequence panel, the user may want to @@ -189,6 +191,14 @@ public class PopupMenu extends JPopupMenu unGroupMenuItem_actionPerformed(e); } }); + pdbMenuItem.setText("View PDB structure"); + pdbMenuItem.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + pdbMenuItem_actionPerformed(e); + } + }); add(groupMenu); this.add(sequenceMenu); this.add(residueMenu); @@ -220,6 +230,7 @@ public class PopupMenu extends JPopupMenu defineMenu.add(conservationMenuItem); sequenceMenu.add(sequenceName); + sequenceMenu.add(pdbMenuItem); residueMenu.add(annotateResidue); noColourmenuItem.setText("None"); @@ -597,4 +608,33 @@ public class PopupMenu extends JPopupMenu ap.av.setRubberbandGroup(null); ap.RefreshPanels(); } + + void pdbMenuItem_actionPerformed(ActionEvent e) + { + if(sequence.getPDBId()==null) + return; + + try + { + EBIFetchClient ebi = new EBIFetchClient(); + String[] result = ebi.fetchData("pdb:" + sequence.getPDBId(), null, null); + + PDBfile pdb = new PDBfile(result); + sequence.setPDBfile(pdb); + + ( (PDBChain) pdb.chains.elementAt(sequence.maxchain)).isVisible = true; + ( (PDBChain) pdb.chains.elementAt(sequence.maxchain)).sequence = sequence; + // ( (PDBChain)pdb.chains.elementAt(sequence.maxchain)).colourBySequence(); + + rotCanvas rc = new rotCanvas(pdb); + JInternalFrame frame = new JInternalFrame(); + frame.setContentPane(rc); + Desktop.addInternalFrame(frame,sequence.getName()+" "+ sequence.getPDBId(), 400, 400); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + } diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 3c9bf51db..c33f3ed 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -10,6 +10,7 @@ import jalview.analysis.*; public class SeqCanvas extends JPanel { + FeatureRenderer fr; Image img; Graphics gg; int imgWidth; @@ -30,6 +31,7 @@ public class SeqCanvas extends JPanel public SeqCanvas(AlignViewport av) { this.av = av; + fr = new FeatureRenderer(av); setLayout(new BorderLayout()); PaintRefresher.Register(this); @@ -176,6 +178,17 @@ public class SeqCanvas extends JPanel offset + AlignmentUtil.getPixelHeight(starty, i, av.getCharHeight()), charWidth,charHeight,null, i); + if(av.showSequenceFeatures) + { + fr.drawSequence(g, nextSeq, groups, x1, x2, + (x1 - startx) * charWidth, + offset + + AlignmentUtil.getPixelHeight(starty, i, av.getCharHeight()), + charWidth, charHeight, null, i); + } + + + if( group!=null ) { diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index aa4a456..cc16a26 100755 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -4,6 +4,7 @@ import java.awt.*; import java.awt.event.*; import jalview.datamodel.*; import javax.swing.*; +import java.util.*; import jalview.schemes.*; import jalview.analysis.*; @@ -168,17 +169,40 @@ public class SeqPanel extends JPanel if(seq>=av.getAlignment().getHeight()) return; - Object obj = ResidueProperties.aa2Triplet.get( av.getAlignment().getSequenceAt(seq).getCharAt(res)+"" ) ; + SequenceI sequence = av.getAlignment().getSequenceAt(seq); + Object obj = ResidueProperties.aa2Triplet.get( sequence.getCharAt(res)+"" ) ; String aa = ""; if(obj!=null) aa = obj.toString(); - StringBuffer text = new StringBuffer("Sequence " +(seq+1)+" ID: "+av.getAlignment().getSequenceAt(seq).getName()); + StringBuffer text = new StringBuffer("Sequence " +(seq+1)+" ID: "+sequence.getName()); if(aa!="") text.append(" Residue: "+aa+" ("+ av.getAlignment().getSequenceAt(seq).findPosition(res)+")"); ap.alignFrame.statusBar.setText(text.toString()); + if(av.showSequenceFeatures) + { + Vector features = sequence.getSequenceFeatures(); + Enumeration e = features.elements(); + StringBuffer sbuffer = new StringBuffer(); + + this.setToolTipText(null); + while (e.hasMoreElements()) + { + SequenceFeature sf = (SequenceFeature) e.nextElement(); + if (sf.getStart() <= sequence.findPosition(res) && + sf.getEnd() >= sequence.findPosition(res)) + { + sbuffer.append(sf.getType() + " " + sf.getDescription()); + ToolTipManager.sharedInstance().registerComponent(this); + this.setToolTipText(sbuffer.toString()); + } + + } + } + + } public void doMouseDragged(MouseEvent evt) { diff --git a/src/jalview/jbgui/GAlignFrame.java b/src/jalview/jbgui/GAlignFrame.java index ab133fe..764f5cf 100755 --- a/src/jalview/jbgui/GAlignFrame.java +++ b/src/jalview/jbgui/GAlignFrame.java @@ -80,7 +80,7 @@ public class GAlignFrame extends JInternalFrame JMenuItem findMenuItem = new JMenuItem(); JMenu searchMenu = new JMenu(); protected JCheckBoxMenuItem abovePIDThreshold = new JCheckBoxMenuItem(); - protected JCheckBoxMenuItem secondaryStructure = new JCheckBoxMenuItem(); + protected JCheckBoxMenuItem sequenceFeatures = new JCheckBoxMenuItem(); protected JRadioButtonMenuItem nucleotideColour = new JRadioButtonMenuItem(); JMenuItem deleteGroups = new JMenuItem(); public GAlignFrame() @@ -593,14 +593,13 @@ public class GAlignFrame extends JInternalFrame abovePIDThreshold_actionPerformed(e); } }); - secondaryStructure.setEnabled(false); - secondaryStructure.setSelected(true); - secondaryStructure.setText("Secondary Structure"); - secondaryStructure.addActionListener(new ActionListener() + sequenceFeatures.setSelected(true); + sequenceFeatures.setText("Sequence Features"); + sequenceFeatures.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { - secondaryStructure_actionPerformed(actionEvent); + sequenceFeatures_actionPerformed(actionEvent); } }); nucleotideColour.setText("Nucleotide colours"); @@ -661,7 +660,7 @@ public class GAlignFrame extends JInternalFrame viewMenu.add(renderGapsMenuItem); viewMenu.add(consensusGraphMenuItem); viewMenu.add(overviewMenuItem); - viewMenu.add(secondaryStructure); + viewMenu.add(sequenceFeatures); colourMenu.add(noColourmenuItem); colourMenu.add(clustalColour); colourMenu.add(zappoColour); @@ -993,7 +992,7 @@ public class GAlignFrame extends JInternalFrame } - public void secondaryStructure_actionPerformed(ActionEvent actionEvent) + public void sequenceFeatures_actionPerformed(ActionEvent actionEvent) { }