Annotations.Graph can be bargraph, linegraph
authoramwaterhouse <Andrew Waterhouse>
Thu, 22 Dec 2005 15:57:25 +0000 (15:57 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 22 Dec 2005 15:57:25 +0000 (15:57 +0000)
src/jalview/gui/AlignViewport.java
src/jalview/gui/AnnotationLabels.java
src/jalview/gui/AnnotationPanel.java
src/jalview/gui/Jalview2XML.java
src/jalview/ws/JPredClient.java

index 7f86753..44330fa 100755 (executable)
@@ -264,7 +264,7 @@ public class AlignViewport
                                                  ConsPercGaps + "% gaps",\r
                                                  annotations, 0f, // cons.qualityRange[0].floatValue(),\r
                                                  11f, // cons.qualityRange[1].floatValue()\r
-                                                 1);\r
+                                                 AlignmentAnnotation.BAR_GRAPH);\r
 \r
           if (showConservation)\r
           {\r
@@ -276,7 +276,7 @@ public class AlignViewport
                                             qannotations,\r
                                             cons.qualityRange[0].floatValue(),\r
                                             cons.qualityRange[1].floatValue(),\r
-                                            1);\r
+                                            AlignmentAnnotation.BAR_GRAPH);\r
 \r
           if (showQuality)\r
           {\r
@@ -360,7 +360,7 @@ public class AlignViewport
         if (consensus == null)\r
         {\r
           consensus = new AlignmentAnnotation("Consensus", "PID",\r
-                                              annotations, 0f, 100f, 1);\r
+                                              annotations, 0f, 100f,AlignmentAnnotation.BAR_GRAPH);\r
 \r
           if (showIdentity)\r
           {\r
index 5ae610f..560c983 100755 (executable)
@@ -405,14 +405,14 @@ public class AnnotationLabels extends JPanel implements MouseListener,
 \r
                 x = width - fm.stringWidth(aa[i].label) - 3;\r
 \r
-                if (aa[i].isGraph)\r
+                if (aa[i].graph>0)\r
                 {\r
                     y += (aa[i].height / 3);\r
                 }\r
 \r
                 g.drawString(aa[i].label, x, y);\r
 \r
-                if (aa[i].isGraph)\r
+                if (aa[i].graph>0)\r
                 {\r
                     y += ((2 * aa[i].height) / 3);\r
                 }\r
index d97c80f..8f72f71 100755 (executable)
@@ -123,7 +123,7 @@ public class AnnotationPanel extends JPanel implements MouseListener,
                     aa[i].height += 16;\r
                 }\r
 \r
-                if (aa[i].isGraph)\r
+                if (aa[i].graph>0)\r
                 {\r
                     aa[i].height += GRAPH_HEIGHT;\r
                 }\r
@@ -657,7 +657,7 @@ public class AnnotationPanel extends JPanel implements MouseListener,
             }\r
 \r
 \r
-            if (row.isGraph)\r
+            if (row.graph>0)\r
             {\r
                 // this is so that we draw the characters below the graph\r
                 y += row.height;\r
@@ -719,7 +719,7 @@ public class AnnotationPanel extends JPanel implements MouseListener,
                                 0))) / 2;\r
                     g.setColor(row.annotations[j].colour);\r
 \r
-                    if (j == 0 || row.isGraph)\r
+                    if (j == 0 || row.graph>0)\r
                     {\r
                         g.drawString(row.annotations[j].displayCharacter, x+charOffset,\r
                             y + iconOffset + 3);\r
@@ -784,33 +784,19 @@ public class AnnotationPanel extends JPanel implements MouseListener,
                     }\r
                 }\r
 \r
-                if (validRes && row.isGraph)\r
+                if (validRes && row.graph>0)\r
                 {\r
-                    g.setColor(new Color(0, 0, 180));\r
+                    ///g.setColor(new Color(0, 0, 180));\r
 \r
-                    int height = (int) ((row.annotations[j].value / row.graphMax) * GRAPH_HEIGHT);\r
+                    if(row.graph== AlignmentAnnotation.LINE_GRAPH )\r
+                        drawLineGraph(g, row, j, j+1, x, y);\r
+                    else if(row.graph == AlignmentAnnotation.BAR_GRAPH )\r
+                       drawBarGraph(g, row, j, j+1, x, y);\r
 \r
-                    if (row.windowLength > 1)\r
-                    {\r
-                        int total = 0;\r
-\r
-                        for (int i2 = j - (row.windowLength / 2);\r
-                                i2 < (j + (row.windowLength / 2)); i2++)\r
-                        {\r
-                            if ((i2 < 0) || (i2 >= av.alignment.getWidth()))\r
-                            {\r
-                                continue;\r
-                            }\r
-\r
-                            total += row.annotations[i2].value;\r
-                        }\r
-\r
-                        total /= row.windowLength;\r
-                        height = (int) ((total / row.graphMax) * GRAPH_HEIGHT);\r
-                    }\r
+                    //int height = (int) ((row.annotations[j].value / row.graphMax) * GRAPH_HEIGHT);\r
 \r
-                    g.setColor(row.annotations[j].colour);\r
-                    g.fillRect(x, y - height, av.charWidth, height);\r
+                   // g.setColor(row.annotations[j].colour);\r
+                   // g.fillRect(x, y - height, av.charWidth, height);\r
                 }\r
             }\r
 \r
@@ -851,38 +837,73 @@ public class AnnotationPanel extends JPanel implements MouseListener,
                 }\r
             }\r
 \r
-            if (row.isGraph && row.hasText)\r
+            if (row.graph>0 && row.hasText)\r
             {\r
                 y += av.charHeight;\r
             }\r
 \r
-            if (!row.isGraph)\r
+            if (row.graph==0)\r
             {\r
                 y += aa[i].height;\r
             }\r
         }\r
     }\r
 \r
-    // used by overview window\r
-    public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes)\r
+    public void drawLineGraph(Graphics g, AlignmentAnnotation aa, int sRes, int eRes, int x, int y)\r
     {\r
-        g.setColor(Color.white);\r
-        g.fillRect(0, 0, width, y);\r
-        g.setColor(new Color(0, 0, 180));\r
+      g.setColor(new Color(0, 0, 0));\r
+      if(sRes==0)\r
+        sRes++;\r
 \r
+      int y1=y, y2=y;\r
+      for (int j = sRes; j < eRes; j++)\r
+      {\r
+          if(aa.annotations[j-1]!=null)\r
+            y1 = y - (int) ((aa.annotations[j-1].value / aa.graphMax) * GRAPH_HEIGHT);\r
 \r
-        int x = 0, height;\r
+          if(aa.annotations[j]!=null)\r
+          y2 = y - (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);\r
 \r
-        for (int j = sRes; j < eRes; j++)\r
-        {\r
-            g.setColor(new Color(0, 0, 180));\r
+          g.drawLine(x-av.charWidth/2, y1, x+av.charWidth/2, y2);\r
+\r
+          x += av.charWidth;\r
+        }\r
+    }\r
 \r
-            height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);\r
-            if(height>y)\r
-              height = y;\r
+    public void drawBarGraph(Graphics g, AlignmentAnnotation aa, int sRes, int eRes, int x, int y)\r
+    {\r
+      g.setColor(new Color(0, 0, 180));\r
+      int j, height=0;\r
+      for (j = sRes; j < eRes; j++)\r
+      {\r
+          g.setColor(aa.annotations[j].colour);\r
+          height = (int) ((aa.annotations[j].value / aa.graphMax) * GRAPH_HEIGHT);\r
 \r
-            g.fillRect(x, y - height, av.charWidth, height);\r
-            x += av.charWidth;\r
+          g.fillRect(x, y - height, av.charWidth, height);\r
+          x += av.charWidth;\r
         }\r
     }\r
+\r
+    // used by overview window\r
+    public void drawGraph(Graphics g, AlignmentAnnotation aa, int width, int y, int sRes, int eRes)\r
+    {\r
+      g.setColor(Color.white);\r
+      g.fillRect(0, 0, width, y);\r
+      g.setColor(new Color(0, 0, 180));\r
+\r
+      int x = 0, height;\r
+\r
+      for (int j = sRes; j < eRes; j++)\r
+      {\r
+          g.setColor(new Color(0, 0, 180));\r
+\r
+          height = (int) ((aa.annotations[j].value / aa.graphMax) * y);\r
+          if(height>y)\r
+            height = y;\r
+\r
+          g.fillRect(x, y - height, av.charWidth, height);\r
+          x += av.charWidth;\r
+      }\r
+    }\r
+\r
 }\r
index c06e805..8406299 100755 (executable)
@@ -308,7 +308,9 @@ public class Jalview2XML
 \r
                 Annotation an = new Annotation();\r
                 an.setDescription(aa[i].description);\r
-                an.setGraph(aa[i].isGraph);\r
+                if(aa[i].graph>0)\r
+                  an.setGraph(true);\r
+\r
                 an.setLabel(aa[i].label);\r
 \r
                 AnnotationElement ae;\r
@@ -717,7 +719,8 @@ public class Jalview2XML
                 if (an[i].getGraph())\r
                 {\r
                     jaa = new jalview.datamodel.AlignmentAnnotation(an[i].getLabel(),\r
-                            an[i].getDescription(), anot, 0, 0, 1);\r
+                            an[i].getDescription(), anot, 0, 0,\r
+                            jalview.datamodel.AlignmentAnnotation.BAR_GRAPH);\r
                 }\r
                 else\r
                 {\r
index a17ccbb..798259a 100755 (executable)
@@ -503,7 +503,8 @@ public class JPredClient
             {\r
               annot = new AlignmentAnnotation(preds[i].getName(),\r
                                               "JNet Output", annotations, 0f,\r
-                                              10f, 1);\r
+                                              10f,\r
+                                              AlignmentAnnotation.BAR_GRAPH);\r
             }\r
             else\r
             {\r