From dd6a434e05eef33808d4cda23dd2c6f8d10a4630 Mon Sep 17 00:00:00 2001 From: amwaterhouse Date: Thu, 22 Dec 2005 15:57:25 +0000 Subject: [PATCH] Annotations.Graph can be bargraph, linegraph --- src/jalview/gui/AlignViewport.java | 6 +- src/jalview/gui/AnnotationLabels.java | 4 +- src/jalview/gui/AnnotationPanel.java | 105 ++++++++++++++++++++------------- src/jalview/gui/Jalview2XML.java | 7 ++- src/jalview/ws/JPredClient.java | 3 +- 5 files changed, 75 insertions(+), 50 deletions(-) diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 7f86753..44330fa 100755 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -264,7 +264,7 @@ public class AlignViewport ConsPercGaps + "% gaps", annotations, 0f, // cons.qualityRange[0].floatValue(), 11f, // cons.qualityRange[1].floatValue() - 1); + AlignmentAnnotation.BAR_GRAPH); if (showConservation) { @@ -276,7 +276,7 @@ public class AlignViewport qannotations, cons.qualityRange[0].floatValue(), cons.qualityRange[1].floatValue(), - 1); + AlignmentAnnotation.BAR_GRAPH); if (showQuality) { @@ -360,7 +360,7 @@ public class AlignViewport if (consensus == null) { consensus = new AlignmentAnnotation("Consensus", "PID", - annotations, 0f, 100f, 1); + annotations, 0f, 100f,AlignmentAnnotation.BAR_GRAPH); if (showIdentity) { diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index 5ae610f..560c983 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -405,14 +405,14 @@ public class AnnotationLabels extends JPanel implements MouseListener, x = width - fm.stringWidth(aa[i].label) - 3; - if (aa[i].isGraph) + if (aa[i].graph>0) { y += (aa[i].height / 3); } g.drawString(aa[i].label, x, y); - if (aa[i].isGraph) + if (aa[i].graph>0) { y += ((2 * aa[i].height) / 3); } diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index d97c80f..8f72f71 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -123,7 +123,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, aa[i].height += 16; } - if (aa[i].isGraph) + if (aa[i].graph>0) { aa[i].height += GRAPH_HEIGHT; } @@ -657,7 +657,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, } - if (row.isGraph) + if (row.graph>0) { // this is so that we draw the characters below the graph y += row.height; @@ -719,7 +719,7 @@ public class AnnotationPanel extends JPanel implements MouseListener, 0))) / 2; g.setColor(row.annotations[j].colour); - if (j == 0 || row.isGraph) + if (j == 0 || row.graph>0) { g.drawString(row.annotations[j].displayCharacter, x+charOffset, y + iconOffset + 3); @@ -784,33 +784,19 @@ public class AnnotationPanel extends JPanel implements MouseListener, } } - if (validRes && row.isGraph) + if (validRes && row.graph>0) { - g.setColor(new Color(0, 0, 180)); + ///g.setColor(new Color(0, 0, 180)); - int height = (int) ((row.annotations[j].value / row.graphMax) * GRAPH_HEIGHT); + if(row.graph== AlignmentAnnotation.LINE_GRAPH ) + drawLineGraph(g, row, j, j+1, x, y); + else if(row.graph == AlignmentAnnotation.BAR_GRAPH ) + drawBarGraph(g, row, j, j+1, x, y); - if (row.windowLength > 1) - { - int total = 0; - - for (int i2 = j - (row.windowLength / 2); - i2 < (j + (row.windowLength / 2)); i2++) - { - if ((i2 < 0) || (i2 >= av.alignment.getWidth())) - { - continue; - } - - total += row.annotations[i2].value; - } - - total /= row.windowLength; - height = (int) ((total / row.graphMax) * GRAPH_HEIGHT); - } + //int height = (int) ((row.annotations[j].value / row.graphMax) * GRAPH_HEIGHT); - g.setColor(row.annotations[j].colour); - g.fillRect(x, y - height, av.charWidth, height); + // g.setColor(row.annotations[j].colour); + // g.fillRect(x, y - height, av.charWidth, height); } } @@ -851,38 +837,73 @@ public class AnnotationPanel extends JPanel implements MouseListener, } } - if (row.isGraph && row.hasText) + if (row.graph>0 && row.hasText) { y += av.charHeight; } - if (!row.isGraph) + if (row.graph==0) { y += aa[i].height; } } } - // used by overview window - public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes) + public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes, int eRes, int x, int y) { - g.setColor(Color.white); - g.fillRect(0, 0, width, y); - g.setColor(new Color(0, 0, 180)); + g.setColor(new Color(0, 0, 0)); + if(sRes==0) + sRes++; + int y1=y, y2=y; + for (int j = sRes; j < eRes; j++) + { + if(aa.annotations[j-1]!=null) + y1 = y - (int) ((aa.annotations[j-1].value / aa.graphMax) * GRAPH_HEIGHT); - int x = 0, height; + if(aa.annotations[j]!=null) + y2 = y - (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT); - for (int j = sRes; j < eRes; j++) - { - g.setColor(new Color(0, 0, 180)); + g.drawLine(x-av.charWidth/2, y1, x+av.charWidth/2, y2); + + x += av.charWidth; + } + } - height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT); - if(height>y) - height = y; + public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes, int eRes, int x, int y) + { + g.setColor(new Color(0, 0, 180)); + int j, height=0; + for (j = sRes; j < eRes; j++) + { + g.setColor(aa.annotations[j].colour); + height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT); - g.fillRect(x, y - height, av.charWidth, height); - x += av.charWidth; + g.fillRect(x, y - height, av.charWidth, height); + x += av.charWidth; } } + + // used by overview window + public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes) + { + g.setColor(Color.white); + g.fillRect(0, 0, width, y); + g.setColor(new Color(0, 0, 180)); + + int x = 0, height; + + for (int j = sRes; j < eRes; j++) + { + g.setColor(new Color(0, 0, 180)); + + height = (int) ((aa.annotations[j].value / aa.graphMax) * y); + if(height>y) + height = y; + + g.fillRect(x, y - height, av.charWidth, height); + x += av.charWidth; + } + } + } diff --git a/src/jalview/gui/Jalview2XML.java b/src/jalview/gui/Jalview2XML.java index c06e805..8406299 100755 --- a/src/jalview/gui/Jalview2XML.java +++ b/src/jalview/gui/Jalview2XML.java @@ -308,7 +308,9 @@ public class Jalview2XML Annotation an = new Annotation(); an.setDescription(aa[i].description); - an.setGraph(aa[i].isGraph); + if(aa[i].graph>0) + an.setGraph(true); + an.setLabel(aa[i].label); AnnotationElement ae; @@ -717,7 +719,8 @@ public class Jalview2XML if (an[i].getGraph()) { jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(), - an[i].getDescription(), anot, 0, 0, 1); + an[i].getDescription(), anot, 0, 0, + jalview.datamodel.AlignmentAnnotation.BAR_GRAPH); } else { diff --git a/src/jalview/ws/JPredClient.java b/src/jalview/ws/JPredClient.java index a17ccbb..798259a 100755 --- a/src/jalview/ws/JPredClient.java +++ b/src/jalview/ws/JPredClient.java @@ -503,7 +503,8 @@ public class JPredClient { annot = new AlignmentAnnotation(preds[i].getName(), "JNet Output", annotations, 0f, - 10f, 1); + 10f, + AlignmentAnnotation.BAR_GRAPH); } else { -- 1.7.10.2