diff --git a/uk/ac/sanger/artemis/editor/DBViewer.java b/uk/ac/sanger/artemis/editor/DBViewer.java index 4ee2df49b46c1b5efd418a29367e332f2e69899d..18a4ce0aec1a4f370929af51a253de360b459fa2 100644 --- a/uk/ac/sanger/artemis/editor/DBViewer.java +++ b/uk/ac/sanger/artemis/editor/DBViewer.java @@ -25,19 +25,79 @@ package uk.ac.sanger.artemis.editor; import java.awt.*; +import java.awt.event.*; import javax.swing.*; import java.util.Vector; import java.util.Enumeration; -public class DBViewer extends JPanel +public class DBViewer extends ScrollPanel { - Vector hitInfoCollection = null; + /** collection of hits */ + private Vector hitInfoCollection = null; + /** query length */ + private int qlen; + /** viewer boundary */ + private int bound = 10; + /** y displacement for each hit */ + private int ydisp = 5; + /** maximum hit score */ + private float max_score = 0; + /** colour the hits by score or by evalue */ + private boolean colourByScore = false; + /** popup menu */ + private JPopupMenu popup; + /** number height */ + private int hgtNumber; public DBViewer(FastaTextPane fastaPane) { super(); hitInfoCollection = fastaPane.getHitCollection(); + qlen = fastaPane.getQueryLength(); + + Dimension d = new Dimension(500, + (hitInfoCollection.size()*ydisp)+(6*bound)); + setPreferredSize(d); + setToolTipText(""); //enable tooltip display + + Enumeration enumHits = hitInfoCollection.elements(); + while(enumHits.hasMoreElements()) + { + HitInfo hit = (HitInfo)enumHits.nextElement(); + float score = Float.parseFloat(hit.getScore()); + if(score > max_score) + max_score = score; + } + + // Popup menu + addMouseListener(new PopupListener()); + popup = new JPopupMenu(); + + JRadioButtonMenuItem colourScore = new JRadioButtonMenuItem("Colour by Score"); + colourScore.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + setColourByScore(true); + } + }); + popup.add(colourScore); + + JRadioButtonMenuItem colourEval = new JRadioButtonMenuItem("Colour by E-value"); + colourEval.setSelected(true); + colourEval.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + setColourByScore(false); + } + }); + popup.add(colourEval); + + ButtonGroup butt = new ButtonGroup(); + butt.add(colourScore); + butt.add(colourEval); } /** @@ -50,34 +110,118 @@ public class DBViewer extends JPanel { // let UI delegate paint first (incl. background filling) super.paintComponent(g); - + + FontMetrics metrics = g.getFontMetrics(); + hgtNumber = metrics.getAscent(); + +// Dimension d = new Dimension(500, +// (hitInfoCollection.size()*ydisp)+(4*bound)+hgtNumber); +// setPreferredSize(d); + Graphics2D g2 = (Graphics2D)g; - int bound = 10; - int width = getWidth()-(2*bound); + int width = (int)getPreferredSize().getWidth()-(2*bound); g2.setColor(Color.black); g2.setStroke(new BasicStroke(3.f)); - g2.drawLine(bound,bound,bound+width,bound); + g2.drawLine(bound,bound+hgtNumber,bound+width,bound+hgtNumber); - int ydisp = bound+5; + g2.setStroke(new BasicStroke(1.f)); + g2.drawLine(bound,bound+hgtNumber,bound,bound+hgtNumber-6); + g2.drawString("0",bound,hgtNumber+3); + +// draw hits + int ypos = bound+ydisp+hgtNumber; Enumeration enumHits = hitInfoCollection.elements(); while(enumHits.hasMoreElements()) { - ydisp += 5; + ypos += ydisp; HitInfo hit = (HitInfo)enumHits.nextElement(); - g2.setColor(Color.red); + if(colourByScore) + { + float score = Float.parseFloat(hit.getScore()); + if(score > max_score/2) + g2.setColor(Color.red); + else if(score > max_score/4) + g2.setColor(Color.blue); + else + g2.setColor(Color.cyan); + } + else + { + double evalue = Double.parseDouble(hit.getEValue()); + if(evalue < 0.005) + g2.setColor(Color.red); + else if(evalue < 0.) + g2.setColor(Color.blue); + else + g2.setColor(Color.cyan); + } + g2.setStroke(new BasicStroke(1.f)); - float hit_unit = (float)width/(float)hit.getQueryLength(); + float hit_unit = (float)width/(float)qlen; int start = (int)(bound+(hit_unit*hit.getQueryStart())); int end = (int)(bound+(hit_unit*hit.getQueryEnd())); - g2.drawLine(start,bound+ydisp,end,bound+ydisp); + g2.drawLine(start,bound+ypos,end,bound+ypos); - System.out.println(hit.getID()+" "+hit.getQueryStart()+" -> "+hit.getQueryEnd()+ - " start "+start+" end "+end+" width "+width); +// System.out.println(hit.getID()+" "+hit.getQueryStart()+" -> "+hit.getQueryEnd()+ +// " start "+start+" end "+end+" width "+width); // ", E = "+hit.getEValue()+" Length = "+hit.getQueryLength()); } + + } + + protected void setColourByScore(boolean colourByScore) + { + this.colourByScore = colourByScore; + repaint(); + } + + /** + * + * Popup menu 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()); + } + } + + + /** + * + * Determine the tool tip to display + * @param e mouse event + * @return tool tip + * + */ + public String getToolTipText(MouseEvent e) + { + Point loc = e.getPoint(); + int seqPos = (int)((loc.y-bound-ydisp-bound-ydisp-hgtNumber)/ydisp); + + if(seqPos >= 0 && seqPos<=hitInfoCollection.size()) + { + HitInfo hit = (HitInfo)hitInfoCollection.get(seqPos); + return hit.getID(); + } + return null; } } diff --git a/uk/ac/sanger/artemis/editor/DataViewInternalFrame.java b/uk/ac/sanger/artemis/editor/DataViewInternalFrame.java index 665a1953f8665178f070b578c0fe4b4f76aae28d..0befa1815678dde659ff12f88e4fcea6c94febe8 100644 --- a/uk/ac/sanger/artemis/editor/DataViewInternalFrame.java +++ b/uk/ac/sanger/artemis/editor/DataViewInternalFrame.java @@ -70,7 +70,7 @@ public class DataViewInternalFrame extends JInternalFrame true);//iconifiable DBViewer dbview = new DBViewer(fastaPane); JScrollPane dbviewScroll = new JScrollPane(dbview); - dbviewScroll.setPreferredSize(new Dimension(500,200)); + dbviewScroll.setPreferredSize(new Dimension(500,300)); jif.getContentPane().add(dbviewScroll); jif.setLocation(0,0); jif.setSize(500,300); diff --git a/uk/ac/sanger/artemis/editor/FastaTextPane.java b/uk/ac/sanger/artemis/editor/FastaTextPane.java index 38c48a37aba1c584254dffb7cad42a0aefd2c71d..28d8747571e03656594c8e8866b9aaab2dcbac21 100644 --- a/uk/ac/sanger/artemis/editor/FastaTextPane.java +++ b/uk/ac/sanger/artemis/editor/FastaTextPane.java @@ -48,6 +48,7 @@ public class FastaTextPane extends JScrollPane private JTextArea textArea; private Vector hitInfoCollection = null; private String format = null; + private int qlen; public FastaTextPane(String dataFile) { @@ -155,7 +156,6 @@ public class FastaTextPane extends JScrollPane streamReader = new InputStreamReader(getInputStream(dataFile)); buffReader = new BufferedReader(streamReader); - String qlen = null; String line = null; int textPosition = 0; int len = 0; @@ -200,9 +200,6 @@ public class FastaTextPane extends JScrollPane hit = getHitInfo(currentID,hitInfoCollection); hit.setStartPosition(textPosition); - if(qlen != null) - hit.setQueryLength(Integer.parseInt(qlen)); - String going = ""; ind = line.indexOf("GO:"); if(ind > -1) @@ -284,7 +281,7 @@ public class FastaTextPane extends JScrollPane else ind2 = line.indexOf("("); - qlen = line.substring(ind2+1,ind1).trim(); + qlen = Integer.parseInt(line.substring(ind2+1,ind1).trim()); } textPosition += len; @@ -415,6 +412,17 @@ public class FastaTextPane extends JScrollPane return sbuff; } + /** + * + * Get the query sequence length. + * @return query sequence length. + * + */ + protected int getQueryLength() + { + return qlen; + } + protected Vector getHitCollection() { return hitInfoCollection; diff --git a/uk/ac/sanger/artemis/editor/HitInfo.java b/uk/ac/sanger/artemis/editor/HitInfo.java index c8f84a56cb226cc50739df2a96dc2950ae0f8995..80703f047ca47284f3b6f1d00f5f2f8106e0cf6f 100644 --- a/uk/ac/sanger/artemis/editor/HitInfo.java +++ b/uk/ac/sanger/artemis/editor/HitInfo.java @@ -49,8 +49,6 @@ public class HitInfo private String desc = null; /** Sequence length */ private String length = null; - /** Query length */ - private int queryLength = 0; /** */ private String opt = null; @@ -245,28 +243,6 @@ public class HitInfo this.endPosition = endPosition; } - /** - * - * Set the query sequence length. - * @param queryLength query sequence length. - * - */ - protected void setQueryLength(int queryLength) - { - this.queryLength = queryLength; - } - - /** - * - * Get the query sequence length. - * @return query sequence length. - * - */ - protected int getQueryLength() - { - return queryLength; - } - /** *