JAL-882; VARNA crashed when non-standard gaps where in structure; the
authorjanengelhardt <engelhardt87@googlemail.com>
Mon, 25 Jul 2011 10:58:33 +0000 (12:58 +0200)
committerjanengelhardt <engelhardt87@googlemail.com>
Mon, 25 Jul 2011 12:59:28 +0000 (14:59 +0200)
are now replaced with standard gaps before commiting to VARNA in
AppVarna.java

Change-Id: I36b523fb7f1063dc2fa5924cb4569f15e0067df2

src/jalview/gui/AnnotationPanel.java
src/jalview/gui/AppVarna.java

index 60d3e06..32f9514 100755 (executable)
@@ -93,6 +93,10 @@ public class AnnotationPanel extends JPanel implements MouseListener,
   boolean mouseDragging = false;
 
   boolean MAC = false;
+  
+  //for editing cursor
+  int cursorX = 0;
+  int cursorY = 0;
 
   /**
    * Creates a new AnnotationPanel object.
@@ -454,15 +458,22 @@ public class AnnotationPanel extends JPanel implements MouseListener,
       }
 
       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);
-      item = new JMenuItem(STEM);
-      item.addActionListener(this);
-      pop.add(item);
+      JMenuItem item;
+      /*
+       * Just display the needed structure options
+       */
+      if(av.alignment.isNucleotide()==true){
+         item = new JMenuItem(STEM);
+         item.addActionListener(this);
+         pop.add(item); 
+      }else{
+         item = new JMenuItem(HELIX);
+         item.addActionListener(this);
+         pop.add(item);
+         item = new JMenuItem(SHEET);
+         item.addActionListener(this);
+         pop.add(item);          
+      }
       item = new JMenuItem(LABEL);
       item.addActionListener(this);
       pop.add(item);
@@ -655,7 +666,35 @@ public class AnnotationPanel extends JPanel implements MouseListener,
    */
   public void mouseClicked(MouseEvent evt)
   {
+         if(activeRow !=-1){
+           AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation();              
+           AlignmentAnnotation anot = aa[activeRow];
+           
+           if(anot.description.equals("secondary structure")){
+               System.out.println(anot.description+" "+anot.getRNAStruc());       
+           }
+         }
   }
+         
+         public void drawCursor(Graphics graphics, SequenceI seq, int res, int x1, int y1)
+         {
+           int pady = av.charHeight / 5;
+           int charOffset = 0;
+           graphics.setColor(Color.black);
+           graphics.fillRect(x1, y1, av.charWidth, av.charHeight);
+
+           if (av.validCharWidth)
+           {
+             graphics.setColor(Color.white);
+
+             char s = seq.getCharAt(res);
+
+             charOffset = (av.charWidth - fm.charWidth(s)) / 2;
+             graphics.drawString(String.valueOf(s), charOffset + x1,
+                     (y1 + av.charHeight) - pady);
+           }
+
+         }
 
   /**
    * DOCUMENT ME!
index 7617574..fe9292e 100644 (file)
@@ -18,6 +18,8 @@
 package jalview.gui;
 
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.awt.*;
 
 import javax.swing.*;
@@ -61,11 +63,13 @@ public class AppVarna extends JInternalFrame implements InterfaceVARNAListener,S
          initVarna();
   }*/
   
+  
   public AppVarna(String seq,String struc,String name,AlignmentPanel ap){
          ArrayList<RNA> rnaList = new ArrayList<RNA>();
          RNA rna1 = new RNA(name);
          try {
-                 rna1.setRNA(seq,struc);
+                 rna1.setRNA(seq,replaceOddGaps(struc));
          } catch (ExceptionUnmatchedClosingParentheses e2) {
                e2.printStackTrace();
          } catch (ExceptionFileFormatOrSyntax e3) {
@@ -99,10 +103,19 @@ public class AppVarna extends JInternalFrame implements InterfaceVARNAListener,S
          showPanel(true);
   }
   
+  public String replaceOddGaps(String oldStr){
+         String patternStr = "[^([{<>}])]";
+      String replacementStr = ".";
+      Pattern pattern = Pattern.compile(patternStr);
+      Matcher matcher = pattern.matcher(oldStr);
+      String newStr=matcher.replaceAll(replacementStr);
+         return newStr;
+  }
+  
   public RNA trimRNA(RNA rna){
          RNA rnaTrim = new RNA("trim_"+rna.getName());
          try {
-                 rnaTrim.setRNA(rna.getSeq(),rna.getStructDBN());
+                 rnaTrim.setRNA(rna.getSeq(),replaceOddGaps(rna.getStructDBN()));
          } catch (ExceptionUnmatchedClosingParentheses e2) {
                e2.printStackTrace();
          } catch (ExceptionFileFormatOrSyntax e3) {