disulfide bond exceptions
authoramwaterhouse <Andrew Waterhouse>
Tue, 1 Nov 2005 15:34:35 +0000 (15:34 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 1 Nov 2005 15:34:35 +0000 (15:34 +0000)
src/jalview/gui/FeatureRenderer.java
src/jalview/gui/IdPanel.java
src/jalview/gui/SeqPanel.java

index 372ecd7..829bafb 100755 (executable)
@@ -39,6 +39,8 @@ public class FeatureRenderer
     Color resBoxColour;\r
     Graphics graphics;\r
     float transparency = 1.0f;\r
+    FontMetrics fm;\r
+    int charOffset;\r
 \r
     // The following vector holds the features which are\r
     // to be added, in the correct order or rendering\r
@@ -75,6 +77,8 @@ public class FeatureRenderer
       if (seq.getDatasetSequence().getSequenceFeatures() == null)\r
         return;\r
 \r
+      fm = g.getFontMetrics();\r
+\r
       if (transparency != 1)\r
       {\r
         Graphics2D g2 = (Graphics2D) g;\r
@@ -83,88 +87,52 @@ public class FeatureRenderer
                 AlphaComposite.SRC_OVER, transparency));\r
       }\r
 \r
-      Enumeration e, e2;\r
       String type;\r
       SequenceFeature sf;\r
-      if (featuresDisplayed != null)\r
-      {\r
-           e = featuresDisplayed.elements();\r
-           while(e.hasMoreElements())\r
-           {\r
-             type = e.nextElement().toString();\r
-             e2 = seq.getDatasetSequence().getSequenceFeatures().elements();\r
-             while(e2.hasMoreElements())\r
-             {\r
-               sf = (SequenceFeature) e2.nextElement();\r
-               if(!type.equals(sf.getType() ) )\r
-                  continue;\r
-\r
-               if (sf.getBegin() > seq.getEnd())\r
-                  continue;\r
-\r
-               renderFeature(g,seq,\r
-                         seq.findIndex(sf.getBegin()) - 1,\r
-                         seq.findIndex(sf.getEnd()) - 1,\r
-                         type,start,end,x1,y1,width,height);\r
-             }\r
-           }\r
-      }\r
-      else\r
+      if (featuresDisplayed == null || featuresDisplayed.size()==0)\r
+        findAllFeatures();\r
+\r
+      Enumeration e = featuresDisplayed.elements(), e2;\r
+\r
+      // Loop through each visible feature\r
+      while (e.hasMoreElements())\r
       {\r
-        e = seq.getDatasetSequence().getSequenceFeatures().elements();\r
-        while (e.hasMoreElements())\r
+\r
+        type = e.nextElement().toString();\r
+        e2 = seq.getDatasetSequence().getSequenceFeatures().elements();\r
+        // loop through all features in sequence to find\r
+        // current feature to render\r
+          while (e2.hasMoreElements())\r
         {\r
-          sf = (SequenceFeature) e.nextElement();\r
-          type = sf.getType();\r
+\r
+          sf = (SequenceFeature) e2.nextElement();\r
+          if (!type.equals(sf.getType()))\r
+            continue;\r
 \r
           if (sf.getBegin() > seq.getEnd())\r
-          {\r
             continue;\r
-          }\r
 \r
-          renderFeature(g,seq,\r
-                        seq.findIndex(sf.getBegin()) - 1,\r
-                        seq.findIndex(sf.getEnd()) - 1,\r
-                        type,start,end,x1,y1,width,height);\r
+          if (type.equals("disulfide bond"))\r
+          {\r
+\r
+            renderFeature(g, seq,\r
+                          seq.findIndex(sf.getBegin()) - 1,\r
+                          seq.findIndex(sf.getBegin()) - 1,\r
+                          type, start, end, x1, y1, width, height);\r
+            renderFeature(g, seq,\r
+                          seq.findIndex(sf.getEnd()) - 1,\r
+                          seq.findIndex(sf.getEnd()) - 1,\r
+                          type, start, end, x1, y1, width, height);\r
 \r
+          }\r
+          else\r
+            renderFeature(g, seq,\r
+                          seq.findIndex(sf.getBegin()) - 1,\r
+                          seq.findIndex(sf.getEnd()) - 1,\r
+                          type, start, end, x1, y1, width, height);\r
         }\r
       }\r
 \r
-   /*       while (e.hasMoreElements())\r
-        {\r
-            SequenceFeature sf=null;\r
-            if(featuresDisplayed!=null)\r
-            {\r
-              e2 = seq.getDatasetSequence().getSequenceFeatures().elements();\r
-              type = e.nextElement().toString();\r
-              while(e2.hasMoreElements())\r
-              {\r
-                sf = (SequenceFeature) e2.nextElement();\r
-                if(sf.getType().equals(type))\r
-                  break;\r
-                else\r
-                  sf = null;\r
-              }\r
-            }\r
-            else\r
-            {\r
-              sf = (SequenceFeature) e.nextElement();\r
-              type = sf.getType();\r
-            }\r
-\r
-            if(sf==null)\r
-              continue;\r
-\r
-\r
-            if (sf.getBegin() > seq.getEnd())\r
-            {\r
-                continue;\r
-            }\r
-\r
-            int fstart = seq.findIndex(sf.getBegin()) - 1;\r
-            int fend = seq.findIndex(sf.getEnd()) - 1;\r
-*/\r
-\r
         if(transparency!=1.0f)\r
         {\r
           Graphics2D g2 = (Graphics2D) g;\r
@@ -174,9 +142,11 @@ public class FeatureRenderer
         }\r
     }\r
 \r
+\r
     void renderFeature(Graphics g, SequenceI seq,\r
                        int fstart, int fend, String type, int start, int end, int x1, int y1, int width, int height)\r
     {\r
+\r
       if (((fstart <= end) && (fend >= start)))\r
       {\r
           if (fstart < start)\r
@@ -186,48 +156,53 @@ public class FeatureRenderer
 \r
           if (fend >= end)\r
           {\r
-              fend = end;\r
+            fend = end;\r
           }\r
-\r
-          if (fstart == fend)\r
+          for (int i = fstart; i <= fend; i++)\r
           {\r
-              g.setColor(getColour(type));\r
-              g.fillRoundRect((fstart - start) * width, y1, width,\r
-                  height, 4, 4);\r
-              g.setColor(Color.white);\r
-\r
-              char s = seq.getSequence().charAt(fstart);\r
-              FontMetrics fm = g.getFontMetrics();\r
-              int charOffset = (width - fm.charWidth(s)) / 2;\r
-              int pady = height / 5;\r
-              g.drawString(String.valueOf(s),\r
-                  charOffset + x1 + (width * (fstart - start)),\r
-                  (y1 + height) - pady);\r
+            char s = seq.getSequence().charAt(i);\r
+\r
+            if (jalview.util.Comparison.isGap(s))\r
+            {\r
+              continue;\r
+            }\r
+\r
+            g.setColor(getColour(type));\r
+\r
+            g.fillRect( (i - start) * width, y1, width, height);\r
+\r
+            g.setColor(Color.white);\r
+\r
+            charOffset = (width - fm.charWidth(s)) / 2;\r
+            g.drawString(String.valueOf(s),\r
+                         charOffset + x1 + (width * (i - start)),\r
+                         (y1 + height) - height/5);//pady = height / 5;\r
           }\r
-          else\r
+        }\r
+    }\r
+\r
+    void findAllFeatures()\r
+    {\r
+      Vector features = new Vector();\r
+      SequenceFeature sf;\r
+      featuresDisplayed = new Vector();\r
+      Enumeration e;\r
+      for (int i = 0; i < av.alignment.getHeight(); i++)\r
+      {\r
+        features = av.alignment.getSequenceAt(i).getDatasetSequence().\r
+            getSequenceFeatures();\r
+        if (features == null)\r
+          continue;\r
+\r
+        e = features.elements();\r
+        while (e.hasMoreElements())\r
+        {\r
+          sf = (SequenceFeature) e.nextElement();\r
+          if (!featuresDisplayed.contains(sf.getType()))\r
           {\r
-              for (int i = fstart; i <= fend; i++)\r
-              {\r
-                  char s = seq.getSequence().charAt(i);\r
-\r
-                  if (jalview.util.Comparison.isGap(s))\r
-                  {\r
-                      continue;\r
-                  }\r
-\r
-                  g.setColor(getColour(type));\r
-                  g.fillRect((i - start) * width, y1, width, height);\r
-\r
-                  g.setColor(Color.white);\r
-\r
-                  FontMetrics fm = g.getFontMetrics();\r
-                  int charOffset = (width - fm.charWidth(s)) / 2;\r
-                  int pady = height / 5;\r
-                  g.drawString(String.valueOf(s),\r
-                      charOffset + x1 + (width * (i - start)),\r
-                      (y1 + height) - pady);\r
-              }\r
+            featuresDisplayed.addElement(sf.getType());\r
           }\r
+        }\r
       }\r
     }\r
 \r
@@ -276,7 +251,7 @@ public class FeatureRenderer
       featureColours.put("coiled-coil region", new Color(215, 115, 0));\r
       featureColours.put("compositionally biased region", new Color(205, 125, 0));\r
       featureColours.put("cross-link", new Color(195, 135, 0));\r
-      featureColours.put("disulfide bond", new Color(185, 145, 0));\r
+      featureColours.put("disulfide bond", new Color(230,230,0));\r
       featureColours.put("DNA-binding region", new Color(175, 155, 0));\r
       featureColours.put("domain", new Color(165, 165, 0));\r
       featureColours.put("glycosylation site", new Color(155, 175, 0));\r
@@ -288,8 +263,7 @@ public class FeatureRenderer
       featureColours.put("mutagenesis site", new Color(95, 235, 45));\r
       featureColours.put("non-consecutive residues", new Color(85, 245, 55));\r
       featureColours.put("non-terminal residue", new Color(75, 255, 65));\r
-      featureColours.put("nucleotide phosphate-binding region",\r
-                         new Color(65, 245, 75));\r
+      featureColours.put("nucleotide phosphate-binding region",new Color(65, 245, 75));\r
       featureColours.put("peptide", new Color(55, 235, 85));\r
       featureColours.put("propeptide", new Color(45, 225, 95));\r
       featureColours.put("region of interest", new Color(35, 215, 105));\r
index 011502b..7c70c01 100755 (executable)
@@ -59,6 +59,7 @@ public class IdPanel extends JPanel implements MouseListener,
         add(idCanvas, BorderLayout.CENTER);\r
         addMouseListener(this);\r
         addMouseMotionListener(this);\r
+        ToolTipManager.sharedInstance().registerComponent(this);\r
     }\r
 \r
     /**\r
@@ -68,6 +69,28 @@ public class IdPanel extends JPanel implements MouseListener,
      */\r
     public void mouseMoved(MouseEvent e)\r
     {\r
+      int y = e.getY();\r
+\r
+      if (av.getWrapAlignment())\r
+      {\r
+        y = getWrappedY(y);\r
+      }\r
+\r
+      int seq = av.getIndex(y);\r
+      if(seq!=-1)\r
+      {\r
+        StringBuffer tip = new StringBuffer("<html>");\r
+        tip.append(av.alignment.getSequenceAt(seq).getDisplayId(true, true));\r
+        if (av.alignment.getSequenceAt(seq).getDescription() != null)\r
+        {\r
+          tip.append("<br><i>");\r
+          tip.append(av.alignment.getSequenceAt(seq).getDescription());\r
+          tip.append("</i>");\r
+        }\r
+        tip.append("</html>");\r
+        setToolTipText(tip.toString());\r
+      }\r
+\r
     }\r
 \r
     int getWrappedY(int y)\r
@@ -124,7 +147,7 @@ public class IdPanel extends JPanel implements MouseListener,
      */\r
     public void mouseClicked(MouseEvent e)\r
     {\r
-        if (e.getClickCount() < 2)\r
+      if (e.getClickCount() < 2)\r
         return;\r
 \r
       java.util.Vector links = Preferences.sequenceURLLinks;\r
index 600da64..491b667 100755 (executable)
@@ -402,16 +402,29 @@ public class SeqPanel extends JPanel
                 if ( (sf.getBegin() <= sequence.findPosition(res)) &&\r
                     (sf.getEnd() >= sequence.findPosition(res)))\r
                 {\r
-                  if (sbuffer.length() > 6)\r
-                    sbuffer.append("<br>");\r
-\r
-                  sbuffer.append(sf.getType());\r
-                  if (sf.getDescription() != null)\r
-                    sbuffer.append(" " + sf.getDescription());\r
-\r
-                  if (sf.getStatus() != null)\r
+                  if (sf.getType().equals("disulfide bond"))\r
                   {\r
-                    sbuffer.append(" (" + sf.getStatus() + ")");\r
+                    if (sf.getBegin() == sequence.findPosition(res)\r
+                        || sf.getEnd() == sequence.findPosition(res))\r
+                    {\r
+                      if (sbuffer.length() > 6)\r
+                        sbuffer.append("<br>");\r
+                      sbuffer.append("disulfide bond " + sf.getBegin() + ":" +\r
+                                     sf.getEnd());\r
+                    }\r
+                  }\r
+                  else\r
+                  {\r
+                    if (sbuffer.length() > 6)\r
+                      sbuffer.append("<br>");\r
+                    sbuffer.append(sf.getType());\r
+                    if (sf.getDescription() != null)\r
+                      sbuffer.append(" " + sf.getDescription());\r
+\r
+                    if (sf.getStatus() != null)\r
+                    {\r
+                      sbuffer.append(" (" + sf.getStatus() + ")");\r
+                    }\r
                   }\r
                 }\r
 \r