From: janengelhardt Date: Mon, 25 Jul 2011 10:58:33 +0000 (+0200) Subject: JAL-882; VARNA crashed when non-standard gaps where in structure; the X-Git-Tag: Jalview_2_9~576^2~21 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9a05eeccaf18e0c82cd183f0b84a8be42bf181c7;p=jalview.git JAL-882; VARNA crashed when non-standard gaps where in structure; the are now replaced with standard gaps before commiting to VARNA in AppVarna.java Change-Id: I36b523fb7f1063dc2fa5924cb4569f15e0067df2 --- diff --git a/src/jalview/gui/AnnotationPanel.java b/src/jalview/gui/AnnotationPanel.java index 60d3e06..32f9514 100755 --- a/src/jalview/gui/AnnotationPanel.java +++ b/src/jalview/gui/AnnotationPanel.java @@ -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! diff --git a/src/jalview/gui/AppVarna.java b/src/jalview/gui/AppVarna.java index 7617574..fe9292e 100644 --- a/src/jalview/gui/AppVarna.java +++ b/src/jalview/gui/AppVarna.java @@ -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 rnaList = new ArrayList(); 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) {