From c59fb56cb143b05c5643a71f5b39996ac1cd2fef Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Fri, 1 Apr 2005 16:46:10 +0000 Subject: [PATCH] Alignment Annotation added --- src/jalview/datamodel/Alignment.java | 47 +++ src/jalview/datamodel/AlignmentAnnotation.java | 62 +++ src/jalview/datamodel/AlignmentI.java | 8 +- src/jalview/datamodel/Annotation.java | 21 + src/jalview/gui/AlignFrame.java | 41 +- src/jalview/gui/AlignViewport.java | 124 ++++-- src/jalview/gui/AlignmentPanel.java | 102 +++-- src/jalview/gui/AnnotationLabels.java | 213 ++++++++++ src/jalview/gui/AnnotationPanel.java | 523 ++++++++++++++++++++++++ src/jalview/gui/ColumnSelection.java | 3 +- src/jalview/gui/ScorePanel.java | 104 ----- src/jalview/gui/SecondaryStructurePanel.java | 194 --------- src/jalview/jbgui/GAlignFrame.java | 31 +- src/jalview/jbgui/GAlignmentPanel.java | 53 ++- 14 files changed, 1096 insertions(+), 430 deletions(-) create mode 100755 src/jalview/datamodel/AlignmentAnnotation.java create mode 100755 src/jalview/datamodel/Annotation.java create mode 100755 src/jalview/gui/AnnotationLabels.java create mode 100755 src/jalview/gui/AnnotationPanel.java delete mode 100755 src/jalview/gui/ScorePanel.java delete mode 100755 src/jalview/gui/SecondaryStructurePanel.java diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 5adb70d..10e2766 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -13,6 +13,9 @@ public class Alignment implements AlignmentI protected Vector groups = new Vector(); protected ArrayList superGroup = new ArrayList(); protected char gapCharacter = '-'; + public AlignmentAnnotation [] annotations; + public Conservation conservation; + public boolean featuresAdded = false; /** Make an alignment from an array of Sequences. @@ -504,8 +507,52 @@ public class Alignment implements AlignmentI return false; return true; + } + + public void deleteAnnotation(AlignmentAnnotation aa) + { + int aSize = 1; + if(annotations!=null) + aSize = annotations.length; + + AlignmentAnnotation [] temp = new AlignmentAnnotation [aSize-1]; + + int tIndex = 0; + for (int i = 0; i < aSize; i++) + { + if(annotations[i]==aa) + continue; + + + temp[tIndex] = annotations[i]; + tIndex++; + } + + annotations = temp; + } + + public void addAnnotation(AlignmentAnnotation aa) + { + int aSize = 1; + if(annotations!=null) + aSize = annotations.length+1; + + AlignmentAnnotation [] temp = new AlignmentAnnotation [aSize]; + int i=0; + if (aSize > 1) + for (i = 0; i < aSize-1; i++) + temp[i] = annotations[i]; + + temp[i] = aa; + + annotations = temp; } + public AlignmentAnnotation[] getAlignmentAnnotation() + { + return annotations; + } + } diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java new file mode 100755 index 0000000..43ebf38 --- /dev/null +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -0,0 +1,62 @@ +package jalview.datamodel; + +public class AlignmentAnnotation +{ + public String label; + public String description; + public Annotation [] annotations; + public boolean isGraph = false; + public float graphMin, graphMax; + public int windowLength; + + // Graphical hints and tips + public boolean editable = false; + public boolean hasIcons; // + public boolean hasText; + public boolean visible = true; + public int height=0; + + public AlignmentAnnotation(String label, String description, Annotation [] annotations) + { + // always editable? + editable = true; + this.label = label; + this.description = description; + this.annotations = annotations; + for(int i=0; i0) + hasText = true; + } + } + + public AlignmentAnnotation(String label, String description, Annotation [] annotations, float min, float max, int winLength) + { + // graphs are not editable + this.label = label; + this.description = description; + this.annotations = annotations; + isGraph = true; + graphMin = min; + graphMax = max; + windowLength = winLength; + for(int i=0; i0) + hasText = true; + } + + + } + +} diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index 182b687..b46a1a7 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -1,6 +1,5 @@ package jalview.datamodel; -import jalview.jbgui.*; import java.util.*; /** Data structure to hold and manipulate a multiple sequence alignment @@ -63,10 +62,15 @@ public interface AlignmentI { public void sortByPID(SequenceI s) ; public void sortByID() ; + //Annotations + public void addAnnotation(AlignmentAnnotation aa); + public void deleteAnnotation(AlignmentAnnotation aa); + public AlignmentAnnotation [] getAlignmentAnnotation(); + public void setGapCharacter(char gc); public char getGapCharacter(); - public Vector getAAFrequency(); + public Vector getAAFrequency(); } diff --git a/src/jalview/datamodel/Annotation.java b/src/jalview/datamodel/Annotation.java new file mode 100755 index 0000000..6179cfa --- /dev/null +++ b/src/jalview/datamodel/Annotation.java @@ -0,0 +1,21 @@ +package jalview.datamodel; +import java.awt.*; + +public class Annotation +{ + public String displayCharacter=""; + public String description=""; // currently used as mouse over + public char secondaryStructure=' '; // recognises H and E + public float value; + + // add visual cues here + public Color colour = Color.black; + + public Annotation(String displayChar, String desc, char ss, float val) + { + displayCharacter = displayChar; + description = desc; + secondaryStructure = ss; + value = val; + } +} diff --git a/src/jalview/gui/AlignFrame.java b/src/jalview/gui/AlignFrame.java index 00961d6..8c7c9be 100755 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@ -32,7 +32,6 @@ public class AlignFrame extends GAlignFrame final AlignViewport viewport; public AlignFrame(AlignmentI al) { - super(); viewport = new AlignViewport(al,true,true,false); String fontName = jalview.bin.Cache.getProperty("FONT_NAME"); @@ -45,6 +44,15 @@ public class AlignFrame extends GAlignFrame alignPanel = new AlignmentPanel(this, viewport); getContentPane().add(alignPanel, java.awt.BorderLayout.CENTER); + // add conservation graph to alignment + viewport.updateConservation(); + viewport.updateConsensus(); + + alignPanel.annotationPanel.adjustPanelHeight(); + alignPanel.annotationSpaceFillerHolder.setPreferredSize(alignPanel.annotationPanel.getPreferredSize()); + alignPanel.annotationScroller.setPreferredSize(alignPanel.annotationPanel.getPreferredSize()); + + addInternalFrameListener(new InternalFrameAdapter() { public void internalFrameActivated(InternalFrameEvent evt) @@ -227,6 +235,8 @@ public class AlignFrame extends GAlignFrame seq = (SequenceI[]) history[1]; viewport.setAlignment( new Alignment(seq) ); updateEditMenuBar(); + viewport.updateConsensus(); + alignPanel.RefreshPanels(); alignPanel.RefreshPanels(); } @@ -339,12 +349,14 @@ public class AlignFrame extends GAlignFrame int newHeight = newSeqs.length * af.viewport.getCharHeight() + 200; if (newHeight > 500) newHeight = 500; - Desktop.addInternalFrame(af, "Copied sequences", 700, newHeight); + Desktop.addInternalFrame(af, "Copied sequences", 700, 500); } else { viewport.setEndSeq(viewport.alignment.getHeight()); viewport.alignment.getWidth(); + viewport.updateConservation(); + viewport.updateConsensus(); alignPanel.RefreshPanels(); } @@ -386,6 +398,8 @@ public class AlignFrame extends GAlignFrame { this.setClosed(true); }catch(Exception ex){} + viewport.updateConservation(); + viewport.updateConsensus(); alignPanel.RefreshPanels(); } @@ -398,6 +412,8 @@ public class AlignFrame extends GAlignFrame SequenceI[] seq = (SequenceI[]) history[1]; viewport.setAlignment( new Alignment(seq) ); updateEditMenuBar(); + viewport.updateConsensus(); + alignPanel.RefreshPanels(); alignPanel.RefreshPanels(); } @@ -508,6 +524,8 @@ public class AlignFrame extends GAlignFrame { addHistoryItem("delete gapped columns"); viewport.getAlignment().removeGaps(); + viewport.updateConservation(); + viewport.updateConsensus(); alignPanel.RefreshPanels(); } @@ -528,7 +546,8 @@ public class AlignFrame extends GAlignFrame jSize--; } } - + viewport.updateConservation(); + viewport.updateConsensus(); alignPanel.RefreshPanels(); } @@ -616,9 +635,9 @@ public class AlignFrame extends GAlignFrame alignPanel.RefreshPanels(); } - public void consensusGraphMenuItem_actionPerformed(ActionEvent e) + public void annotationPanelMenuItem_actionPerformed(ActionEvent e) { - alignPanel.setGraphPanelVisible( consensusGraphMenuItem.isSelected() ); + alignPanel.setAnnotationVisible( annotationPanelMenuItem.isSelected() ); } public void overviewMenuItem_actionPerformed(ActionEvent e) @@ -1109,11 +1128,13 @@ if ( viewport.getConservationSelected() ) g.drawString("Clustal Alignment Web Service running", 30,30); } } - public void jpredMenuItem_actionPerformed(ActionEvent e) - { - // JInternalFrame frame = new JInternalFrame(); -// JPredClient ct = new JPredClient((SequenceI) - /// viewport.getAlignment().getSequences().elementAt(0)); + protected void jpred_actionPerformed(ActionEvent e) +{ + + + JInternalFrame frame = new JInternalFrame(); + JPredClient ct = new JPredClient((SequenceI) + viewport.getAlignment().getSequences().elementAt(0)); } protected void LoadtreeMenuItem_actionPerformed(ActionEvent e) { diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 71427ca..19a206d 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -1,7 +1,7 @@ package jalview.gui; import java.awt.*; -import jalview.io.*; +import jalview.analysis.*; import jalview.analysis.NJTree; import jalview.datamodel.*; import jalview.schemes.*; @@ -42,7 +42,6 @@ public class AlignViewport ColumnSelection colSel = new ColumnSelection(); - String visibleConsensus; int threshold; int increment; @@ -50,32 +49,20 @@ public class AlignViewport NJTree currentTree = null; - public AlignViewport(AlignmentI da, + public AlignViewport(AlignmentI al, boolean showText, boolean showBoxes, boolean wrapAlignment) { - this(0,da.getWidth()-1,0,da.getHeight()-1, - showText, - showBoxes, - wrapAlignment); - - setAlignment(da); - } - public AlignViewport(int startRes, int endRes, - int startSeq, int endSeq, - boolean showText, - boolean showBoxes, - boolean wrapAlignment) { - - this.startRes = startRes; - this.endRes = endRes; - this.startSeq = startSeq; - this.endSeq = endSeq; - this.showText = showText; - this.showBoxes = showBoxes; + this.startRes = 0; + this.endRes = al.getWidth()-1; + this.startSeq = 0; + this.endSeq = al.getHeight()-1; + this.showText = showText; + this.showBoxes = showBoxes; this.wrapAlignment = wrapAlignment; + setAlignment(al); setFont( font ); } @@ -84,31 +71,112 @@ public class AlignViewport showSequenceFeatures = b; } + AlignmentAnnotation consensus; + AlignmentAnnotation conservation; + public void updateConservation() + { + Annotation [] annotations = new Annotation[alignment.getWidth()]; + + Conservation cons = new jalview.analysis.Conservation("All", + jalview.schemes.ResidueProperties.propHash, 3, + alignment.getSequences(), 0, + alignment.getWidth()); + cons.calculate(); + cons.verdict(false, 100); + + String sequence = cons.getConsSequence().getSequence(); + for (int i = 0; i < alignment.getWidth(); i++) + { + int value = 0; + try + { + value = Integer.parseInt(sequence.charAt(i) + ""); + } + catch (Exception ex) + { + if (sequence.charAt(i) == '*') value = 10; + } + + annotations[i] = new Annotation(sequence.charAt(i) + "", + "Conservation graph", ' ', value); + } + + if(conservation==null) + { + conservation = new AlignmentAnnotation("Conservation", + "Conservation of total alignment", + annotations, 0, 10, 1); + alignment.addAnnotation(conservation); + } + else + conservation.annotations = annotations; + + } + + public void updateConsensus() + { + Annotation [] annotations = new Annotation[alignment.getWidth()]; + + Vector cons = alignment.getAAFrequency(); + Hashtable hash = null; + for (int i = 0; i < alignment.getWidth(); i++) + { + hash = (Hashtable) cons.elementAt(i); + float value = Float.parseFloat(hash.get("maxCount").toString()); + value /= Float.parseFloat(hash.get("size").toString()); + + value *= 100; + String maxRes = hash.get("maxResidue")+" "; + String mouseOver = hash.get("maxResidue")+" "; + if(maxRes.length()>2) + { + mouseOver = "["+maxRes+"] "; + maxRes = "+ "; + } + + mouseOver += value+"%"; + annotations[i] = new Annotation(maxRes, mouseOver, ' ', value); + + } + + if(consensus==null) + { + consensus = new AlignmentAnnotation("% Identity", + "PID", annotations, 0f, 100f, 1); + alignment.addAnnotation(consensus); + } + else + consensus.annotations = annotations; + + } + public String getVisibleConsensus() { return visibleConsensus; } - Vector consensus = new Vector(); + String visibleConsensus; + Vector consensusV = new Vector(); public Vector getConsensus(boolean recalculate) { - if(recalculate || consensus.size()<1) + if(recalculate || consensusV.size()<1) { - consensus = alignment.getAAFrequency(); + consensusV = alignment.getAAFrequency(); StringBuffer sb = new StringBuffer(); Hashtable hash = null; - for (int i = 0; i < consensus.size(); i++) + for (int i = 0; i < consensusV.size(); i++) { - hash = (Hashtable) consensus.elementAt(i); + hash = (Hashtable) consensusV.elementAt(i); sb.append(hash.get("maxResidue").toString().charAt(0)); } visibleConsensus = sb.toString(); } - return consensus; + return consensusV; } + public SequenceGroup getSelectionGroup() { return selectionGroup; diff --git a/src/jalview/gui/AlignmentPanel.java b/src/jalview/gui/AlignmentPanel.java index d8131b4..248fb3d 100755 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@ -22,10 +22,10 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene SeqPanel seqPanel; IdPanel idPanel; IdwidthAdjuster idwidthAdjuster; - SecondaryStructurePanel ssPanel; public AlignFrame alignFrame; ScalePanel scalePanel; - ScorePanel scorePanel; + AnnotationPanel annotationPanel; + AnnotationLabels alabels; public AlignmentPanel(AlignFrame af, final AlignViewport av) { @@ -35,22 +35,25 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene idPanel = new IdPanel (av, this); scalePanel = new ScalePanel(av, this); - scorePanel = new ScorePanel(av); - ssPanel = new SecondaryStructurePanel(av); - - secondaryPanelHolder.add(ssPanel, BorderLayout.CENTER); idPanelHolder.add(idPanel, BorderLayout.CENTER); idwidthAdjuster = new IdwidthAdjuster(this); idSpaceFillerPanel1.add(idwidthAdjuster, BorderLayout.CENTER); + annotationPanel = new AnnotationPanel(this); + alabels = new AnnotationLabels(this); + + annotationSpaceFillerHolder.setPreferredSize(annotationPanel.getPreferredSize()); + annotationScroller.setPreferredSize(annotationPanel.getPreferredSize()); + annotationScroller.setViewportView(annotationPanel); + annotationSpaceFillerHolder.add(alabels, BorderLayout.CENTER); + Dimension d = calculateIdWidth(); d.setSize( d.width+4, d.height); idPanel.idCanvas.setPreferredSize( d ); hscrollFillerPanel.setPreferredSize( d ); scalePanelHolder.add(scalePanel, BorderLayout.CENTER); - scorePanelHolder.add(scorePanel, BorderLayout.CENTER); seqPanelHolder.add(seqPanel, BorderLayout.CENTER); @@ -63,7 +66,6 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene Dimension d = calculateIdWidth(); d.setSize( d.width+4, d.height); idPanel.idCanvas.setPreferredSize( d ); - hscrollFillerPanel.setPreferredSize( d ); RefreshPanels(); } }); @@ -92,15 +94,19 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene RefreshPanels(); break; case KeyEvent.VK_X: + if(evt.isControlDown()) alignFrame.cut_actionPerformed(null); break; case KeyEvent.VK_C: + if(evt.isControlDown()) alignFrame.copy_actionPerformed(null); break; case KeyEvent.VK_V: + if(evt.isControlDown()) alignFrame.paste(true); break; case KeyEvent.VK_A: + if(evt.isControlDown()) alignFrame.selectAllSequenceMenuItem_actionPerformed(null); break; case KeyEvent.VK_DOWN: @@ -110,6 +116,7 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene alignFrame.moveSelectedSequences(true); break; case KeyEvent.VK_F: + if(evt.isControlDown()) alignFrame.findMenuItem_actionPerformed(null); break; } @@ -176,32 +183,28 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene } - public void setGraphPanelVisible(boolean b) + public void setAnnotationVisible(boolean b) { - idSpaceFillerPanel.setVisible(b); - scorePanelHolder.setVisible(b); + annotationSpaceFillerHolder.setVisible(b); + annotationScroller.setVisible(b); + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + RefreshPanels(); + } + }); - RefreshPanels(); - // bit annoying to call this twice, can you do better? - RefreshPanels(); } - public void setSecondaryStructureVisible(boolean b) - { - secondaryPanelHolder.setVisible(b); - RefreshPanels(); - } public void setWrapAlignment(boolean wrap) { - scorePanelHolder.setVisible(!wrap); scalePanelHolder.setVisible(!wrap); - secondaryPanelHolder.setVisible(!wrap); - hscroll.setVisible(!wrap); - idwidthAdjuster.setVisible(!wrap); - idSpaceFillerPanel.setVisible(!wrap); + annotationScroller.setVisible(!wrap); + annotationSpaceFillerHolder.setVisible(!wrap); idSpaceFillerPanel1.setVisible(!wrap); RefreshPanels(); @@ -232,35 +235,31 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene RefreshPanels(); } + public void RefreshPanels() { + requestFocus(); + invalidate(); + + Dimension d = idPanel.idCanvas.getPreferredSize(); + idPanelHolder.setPreferredSize(d); + hscrollFillerPanel.setPreferredSize(new Dimension(d.width, 12)); - requestFocus(); - invalidate(); - idPanelHolder.setPreferredSize(idPanel.idCanvas.getPreferredSize()); - if(idPanel.idCanvas.getPreferredSize()!=null) - hscrollFillerPanel.setPreferredSize(new Dimension(idPanel.idCanvas.getPreferredSize().width, 12)); - idSpaceFillerPanel1.setPreferredSize(new Dimension(500, - av.charHeight / 2 + 12)); - scalePanelHolder.setPreferredSize(new Dimension(500, - av.charHeight / 2 + 12)); - - if (av.getWrapAlignment()) - { - int max = av.alignment.getWidth() / - (seqPanel.seqCanvas.getWidth() / av.charWidth)+1 ; - - vscroll.setValues(0, 1, 0, max); - } - else - { - av.getConsensus(true); - if (overviewPanel != null) - overviewPanel.updateOverviewImage(); - setScrollValues(av.getStartRes(), av.getStartSeq()); - } - - repaint(); + if (av.getWrapAlignment()) + { + int max = av.alignment.getWidth() / + (seqPanel.seqCanvas.getWidth() / av.charWidth) + 1; + vscroll.setValues(0, 1, 0, max); + } + else + { + if (overviewPanel != null) + overviewPanel.updateOverviewImage(); + setScrollValues(av.getStartRes(), av.getStartSeq()); + } + + validate(); + repaint(); } int hextent = 0; @@ -329,8 +328,6 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene hscroll.setValues(x,hextent,0,av.getAlignment().getWidth()); vscroll.setValues(y,vextent,0,av.getAlignment().getHeight() ); - repaint(); - } @@ -363,6 +360,7 @@ public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListene overviewPanel.setBoxPosition(); repaint(); + } public int print(Graphics pg, PageFormat pf, int pi) throws PrinterException diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java new file mode 100755 index 0000000..c600b82 --- /dev/null +++ b/src/jalview/gui/AnnotationLabels.java @@ -0,0 +1,213 @@ + +package jalview.gui; + +import javax.swing.*; +import java.awt.event.*; +import java.awt.*; +import java.awt.image.*; +import jalview.datamodel.*; + +public class AnnotationLabels extends JPanel implements MouseListener, MouseMotionListener, ActionListener +{ + boolean active = false; + Image image; + AlignmentPanel ap ; + boolean resizing = false; + int oldY, mouseX; + static String ADDNEW = "Add new row"; + static String HIDE = "Hide this row"; + static String DELETE = "Delete this row"; + static String SHOWALL="Show all hidden rows"; + int selectedRow = 0; + int scrollOffset = 0; + + public AnnotationLabels(AlignmentPanel ap) + { + this.ap = ap; + + java.net.URL url = getClass().getResource("/images/idwidth.gif"); + Image temp = null; + if (url != null) + temp = java.awt.Toolkit.getDefaultToolkit().createImage(url); + + try + { + MediaTracker mt = new MediaTracker(this); + mt.addImage(temp, 0); + mt.waitForID(0); + } + catch (Exception ex) {} + + BufferedImage bi = new BufferedImage(temp.getHeight(this), temp.getWidth(this), + BufferedImage.TYPE_INT_RGB); + Graphics2D g = (Graphics2D) bi.getGraphics(); + g.rotate(Math.toRadians(90)); + g.drawImage(temp, 0, -bi.getWidth(this), this); + image = (Image) bi; + + addMouseListener(this); + addMouseMotionListener(this); + } + + public void setScrollOffset(int y) + { + scrollOffset = y; + repaint(); + } + + public void actionPerformed(ActionEvent evt) + { + AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation(); + + if(evt.getActionCommand().equals(ADDNEW)) + { + String label = JOptionPane.showInputDialog(this, "Label for annotation"); + if(label==null) + label = ""; + ap.av.alignment.addAnnotation(new AlignmentAnnotation + (label, + "New description", + new Annotation[ap.av.alignment.getWidth()])); + } + else if(evt.getActionCommand().equals(HIDE)) + { + aa[selectedRow].visible = false; + } + else if(evt.getActionCommand().equals(DELETE)) + { + ap.av.alignment.deleteAnnotation(aa[selectedRow]); + } + else if(evt.getActionCommand().equals(SHOWALL)) + { + for(int i=0; i20) + { + ap.annotationScroller.setPreferredSize(new Dimension(d.width,d.height - dif)); + d = ap.annotationSpaceFillerHolder.getPreferredSize(); + ap.annotationSpaceFillerHolder.setPreferredSize(new Dimension(d.width,d.height - dif)); + ap.RefreshPanels(); + } + ap.addNotify(); + } + + public void mouseMoved(MouseEvent evt) {} + public void mouseClicked(MouseEvent evt) {} + + public void paintComponent(Graphics g1) + { + Graphics2D g = (Graphics2D)g1; + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); + + FontMetrics fm = g.getFontMetrics(g.getFont()); + + g.setColor(Color.white); + g.fillRect(0,0, getWidth(), getHeight()); + + g.translate(0, scrollOffset); + g.setColor(Color.black); + + AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation(); + int y = g.getFont().getSize(); + int x = 0; + + if(aa!=null) + for(int i=0; i0 && !aa[activeRow].hasText) + aa[activeRow].hasText = true; + + for(int i=0; i0 && !aa[activeRow].hasText) + aa[activeRow].hasText = true; + + for(int i=0; i-1 && aa[row].annotations[res]!=null) + this.setToolTipText(aa[row].annotations[res].description); + + } + public void mouseClicked(MouseEvent evt) {} + + + public void paintComponent(Graphics g) + { + if(bi==null + || bi.getWidth()!=ap.annotationPanel.getWidth() + || bi.getHeight()!=ap.annotationPanel.getHeight()) + { + bi = new BufferedImage(ap.annotationPanel.getWidth(), + ap.annotationPanel.getHeight(), + BufferedImage.TYPE_INT_RGB); + } + + drawComponent( (Graphics2D)bi.getGraphics() ); + g.drawImage( bi, 0, 0, this); + } + + public void drawComponent(Graphics2D g) + { + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); + FontMetrics fm = g.getFontMetrics(); + g.setFont(av.getFont()); + g.setColor(Color.white); + g.fillRect(0,0,getWidth(),getHeight()); + + if(av.alignment.getAlignmentAnnotation()==null || av.alignment.getAlignmentAnnotation().length<1) + { + g.setColor(Color.black); + g.drawString("Alignment has no annotations",20,15); + return; + } + + AlignmentAnnotation [] aa = av.alignment.getAlignmentAnnotation(); + + int j, x=0, y=0; + char [] lastSS = new char[aa.length]; + int [] lastSSX= new int[aa.length] ; + int iconOffset = av.charHeight/2; + boolean validRes = false; + //\u03B2 \u03B1 + for(int i=0; i0) + { + int charOffset = (av.charWidth - + fm.charWidth(row.annotations[j].displayCharacter. + charAt(0))) / 2; + g.setColor( row.annotations[j].colour); + if(j==0) + { + if (row.annotations[0].secondaryStructure == 'H' + || row.annotations[0].secondaryStructure == 'E') + g.drawString(row.annotations[j].displayCharacter, x, + y + iconOffset + 2); + } + else if( (row.annotations[j].secondaryStructure=='H' + || row.annotations[j].secondaryStructure=='E') && + (row.annotations[j-1]==null || + row.annotations[j].secondaryStructure!=row.annotations[j-1].secondaryStructure)) + + g.drawString(row.annotations[j].displayCharacter, x, y + iconOffset + 2); + + if(!row.hasIcons) + g.drawString(row.annotations[j].displayCharacter, x + charOffset, + y + iconOffset + 2); + } + + if(row.hasIcons) + if(!validRes || row.annotations[j].secondaryStructure!=lastSS[i]) + { + switch (lastSS[i]) + { + case 'H': + g.setColor(HELIX_COLOUR); + g.fillRoundRect(lastSSX[i], y+4 + iconOffset, x-lastSSX[i], 7, 8, 8); + break; + case 'E': + g.setColor(SHEET_COLOUR); + g.fillRect(lastSSX[i], y + 4 + iconOffset, x-lastSSX[i]-4, 7); + g.fillPolygon(new int[] {x - 4, x- 4, x } + , new int[]{y+ iconOffset, y + 14+ iconOffset, y + 8+ iconOffset}, 3); + break; + case 'C': + break; + default : + g.setColor(Color.gray); + g.fillRect(lastSSX[i], y+6+ iconOffset, x-lastSSX[i], 2); + break; + } + + if(validRes) + lastSS[i] = row.annotations[j].secondaryStructure; + else + lastSS[i] = ' '; + lastSSX[i] = x; + } + + if (validRes && row.isGraph) + { + g.setColor(new Color(0,0,180)); + int height = (int)((row.annotations[j].value / row.graphMax)*50); + + if(row.windowLength>1) + { + int total =0; + for(int i2=j- (row.windowLength/2); i2=av.alignment.getWidth()) + continue; + + total += row.annotations[i2].value; + } + + total/=row.windowLength; + height = (int)( (total / row.graphMax) *50); + + } + + g.fillRect(x, y-height, av.charWidth, height ); + } + + + } + + x+=av.charWidth; + + if(row.hasIcons) + switch (lastSS[i]) + { + case 'H': + g.setColor(HELIX_COLOUR); + g.fillRoundRect(lastSSX[i], y+4+ iconOffset, x - lastSSX[i], 7, 8, 8); + break; + case 'E': + g.setColor(SHEET_COLOUR); + g.fillRect(lastSSX[i], y + 4+ iconOffset, x - lastSSX[i] - 4, 7); + g.fillPolygon(new int[] + {x - 4, x - 4, x} + , new int[] + {y + iconOffset, y + 14+ iconOffset, y + 7+ iconOffset} + , 3); + break; + case 'C': + break; + default: + g.setColor(Color.gray); + g.fillRect(lastSSX[i], y+6+ iconOffset, x-lastSSX[i], 2); + break; + + } + + if(row.isGraph && row.hasText) + y+=av.charHeight; + if(!row.isGraph) + y+=aa[i].height; + } + } + + // used by overview window + public void drawGraph(Graphics g, AlignmentAnnotation aa,int width, int y) + { + g.setColor(Color.white); + g.fillRect(0,0,width, y); + g.setColor(new Color(0,0,180)); + int x = 0; + for(int j=0; j= start) { + if (temp >= start) selected.setElementAt(new Integer(temp-change),i); - } } } } diff --git a/src/jalview/gui/ScorePanel.java b/src/jalview/gui/ScorePanel.java deleted file mode 100755 index e6ba4b3..0000000 --- a/src/jalview/gui/ScorePanel.java +++ /dev/null @@ -1,104 +0,0 @@ -package jalview.gui; - -import jalview.jbgui.*; -import java.util.*; -import javax.swing.*; -import java.awt.*; -import java.awt.event.*; - -public class ScorePanel extends JPanel -{ - AlignViewport av; - - public ScorePanel(AlignViewport a) - { - av = a; - setPreferredSize(new Dimension(500,80)); - addMouseMotionListener(new MouseMotionAdapter() - { public void mouseMoved(MouseEvent evt) - { - doMouseMoved(evt); - } - }); - - ToolTipManager.sharedInstance().registerComponent(this); - } - - public void doMouseMoved(MouseEvent evt) - { - Vector freq = av.getConsensus(false); - - int col = (int)(evt.getX()/av.charWidth) +av.getStartRes(); - - if(col >= av.getEndRes() || col >= freq.size()) - return; - - Hashtable hash = (Hashtable) freq.elementAt( col ); - - String characters = hash.get("maxResidue").toString(); - - if (characters.length()>1) - this.setToolTipText(characters); - else - this.setToolTipText(null); - } - - - - public void paintComponent(Graphics g) - { - setPreferredSize(new Dimension( this.getWidth(), 80)); - drawScorePanel(g, getWidth(), av.getStartRes(), av.getChunkWidth()); - } - - public void drawScorePanel(Graphics g, int width, int startRes, int length) - { - g.setColor(Color.white); - g.fillRect(0, 0,width, 80); - g.setColor(Color.blue); - g.setFont(av.getFont()); - - Vector freq = av.getConsensus(false); - - int value, charOffset; - String characters; - char character; - - - int i=0, iSize = length; - if(iSize > freq.size()) - iSize=freq.size(); - - for (i = 0; i < iSize; i++) - { - g.setColor(Color.blue); - - Hashtable hash = (Hashtable) freq.elementAt(i+startRes); - if(hash.containsKey("maxResidue")) - characters = hash.get("maxResidue").toString(); - else - characters="@"; - character = characters.charAt(0); - value = Integer.parseInt(hash.get("maxCount").toString()); - - if (characters.length() > 1) - character = '+'; - - charOffset = (int) (av.charWidth - - g.getFontMetrics().charWidth(character)) / 2; - g.drawString(character + "", charOffset + (int) (i * av.charWidth), - 60 + (int) av.charWidth); - - value = (int) ( (float) value / - Float.parseFloat(hash.get("size").toString()) * 55); - - if ( !jalview.util.Comparison.isGap(character)) - g.fillRect( (int) (i * av.charWidth), - 60 - value, - (int) av.charWidth, - value - ); - } - } - -} diff --git a/src/jalview/gui/SecondaryStructurePanel.java b/src/jalview/gui/SecondaryStructurePanel.java deleted file mode 100755 index 1c8bd36..0000000 --- a/src/jalview/gui/SecondaryStructurePanel.java +++ /dev/null @@ -1,194 +0,0 @@ -package jalview.gui; - -import javax.swing.JPanel; -import java.awt.event.*; -import java.awt.*; -import java.util.*; -import javax.swing.*; -import jalview.datamodel.*; - -public class SecondaryStructurePanel extends JPanel implements ActionListener -{ - AlignViewport av; - Vector structures; - - SecondaryStructure amend; - - public SecondaryStructurePanel(AlignViewport av) - { - this.av = av; - structures = new Vector(); - setPreferredSize(new Dimension(500,30)); - - addMouseListener(new MouseAdapter() - { - public void mousePressed(MouseEvent evt) - { doMousePressed(evt); } - public void mouseReleased(MouseEvent evt) - { doMouseReleased(evt); } - }); - addMouseMotionListener(new MouseMotionAdapter() - { - public void mouseDragged(MouseEvent evt) - { doMouseDragged(evt); } - }); - } - - int startRes = 0; - int endRes = 0; - boolean amendStart = false; - boolean amendEnd = false; - - public void doMousePressed(MouseEvent evt) - { - amend = null; - amendStart =false; - amendEnd = false; - - startRes = evt.getX() / av.getCharWidth() + av.getStartRes(); - for(int i=0; i=ss.start && startRes<=ss.end) - { - amend = ss; - if(startRes==ss.start) - amendStart = true; - - if(startRes==ss.end) - amendEnd = true; - - if(evt.getClickCount()==2) - { - String label = JOptionPane.showInputDialog(this, "Amend label", "Amend label", JOptionPane.QUESTION_MESSAGE ); - if(label==null) - label = ""; - ss.label = label; - } - break; - } - } - repaint(); - - } - - public void doMouseReleased(MouseEvent evt) - { - endRes = evt.getX() / av.getCharWidth() + av.getStartRes(); - - if(amend!=null) - { - if(amendStart) - amend.start = endRes; - if(amendEnd) - amend.end = endRes; - - amend=null; - repaint(); - return; - } - - endRes = evt.getX() / av.getCharWidth() + av.getStartRes(); - - JPopupMenu pop = new JPopupMenu("Structure type"); - JMenuItem item = new JMenuItem("Helix"); - item.addActionListener(this); - pop.add(item); - item = new JMenuItem("Sheet"); - item.addActionListener(this); - pop.add(item); - pop.show(this, evt.getX(), evt.getY()); - - } - - public void actionPerformed(ActionEvent evt) - { - - int type = 0; - if(evt.getActionCommand().equals("Helix")) - type = SecondaryStructure.HELIX; - else if(evt.getActionCommand().equals("Sheet")) - type = SecondaryStructure.SHEET; - - String label = JOptionPane.showInputDialog(this, "Enter a label for the structure?", "Enter label", JOptionPane.QUESTION_MESSAGE ); - if(label==null) - label = ""; - - SecondaryStructure ss = new SecondaryStructure(startRes, endRes, type, label); - structures.add(ss); - repaint(); - - } - - public void doMouseDragged(MouseEvent evt) - { - paintNow(getGraphics()); - } - - void paintNow(Graphics g) - { - g.setColor(Color.white); - g.setFont(new Font("Verdana", Font.PLAIN, 10)); - g.fillRect(0,0,getWidth(),getHeight()); - for(int i=0; i