-
- public RNA trimRNA(RNA rna){
- ShiftList offset=new ShiftList();
- RNA rnaTrim = new RNA("trim_"+rna.getName());
- try {
- rnaTrim.setRNA(rna.getSeq(),replaceOddGaps(rna.getStructDBN()));
- } catch (ExceptionUnmatchedClosingParentheses e2) {
- e2.printStackTrace();
- } catch (ExceptionFileFormatOrSyntax e3) {
- e3.printStackTrace();
- }
-
- StringBuffer seq=new StringBuffer(rnaTrim.getSeq());
- StringBuffer struc=new StringBuffer(rnaTrim.getStructDBN());
- int ofstart=-1,sleng=rnaTrim.getSeq().length();
- for(int i=0;i<sleng;i++){
- //TODO: Jalview utility for gap detection java.utils.isGap()
- //TODO: Switch to jalview rna datamodel
- if(jalview.util.Comparison.isGap(seq.charAt(i))){
- if (ofstart==-1)
- {
- ofstart=i;
- }
- if(!rnaTrim.findPair(i).isEmpty()){
- int m=rnaTrim.findPair(i).get(1);
- int l=rnaTrim.findPair(i).get(0);
-
- struc.replace(m, m+1, "*");
- struc.replace(l, l+1, "*");
- }else{
- struc.replace(i, i+1, "*");
- }
- } else {
- if (ofstart>-1)
- {
- offset.addShift(ofstart, ofstart-i);
- ofstart=-1;
- }
- }
- }
- // final gap
- if (ofstart>-1)
- {
- offset.addShift(ofstart, ofstart-sleng);
- ofstart=-1;
- }
- String newSeq=rnaTrim.getSeq().replace("-", "");
- rnaTrim.getSeq().replace(".", "");
- String newStruc=struc.toString().replace("*", "");
-
- try {
- rnaTrim.setRNA(newSeq,newStruc);
- registerOffset(rnaTrim,offset);
- } catch (ExceptionUnmatchedClosingParentheses e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ExceptionFileFormatOrSyntax e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return rnaTrim;
+
+ /**
+ * Constructs a split pane with an empty selection list and display panel, and
+ * adds it to the desktop
+ */
+ public void initVarna()
+ {
+ VARNAPanel varnaPanel = vab.get_varnaPanel();
+ setBackground(Color.white);
+ split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true,
+ vab.getListPanel(), varnaPanel);
+ getContentPane().setLayout(new BorderLayout());
+ getContentPane().add(split, BorderLayout.CENTER);
+
+ varnaPanel.addSelectionListener(this);
+ jalview.gui.Desktop.addInternalFrame(this, "", getBounds().width,
+ getBounds().height);
+ this.pack();
+ showPanel(true);
+ }
+
+ /**
+ * Constructs a new RNA model from the given one, without gaps. Also
+ * calculates and saves a 'shift list'
+ *
+ * @param rna
+ * @param name
+ * @return
+ */
+ public RNA trimRNA(RNA rna, String name)
+ {
+ ShiftList offset = new ShiftList();
+
+ RNA rnaTrim = new RNA(name);
+ try
+ {
+ String structDBN = rna.getStructDBN(true);
+ rnaTrim.setRNA(rna.getSeq(), replaceOddGaps(structDBN));
+ } catch (ExceptionUnmatchedClosingParentheses e2)
+ {
+ e2.printStackTrace();
+ } catch (ExceptionFileFormatOrSyntax e3)
+ {
+ e3.printStackTrace();
+ }
+
+ String seq = rnaTrim.getSeq();
+ StringBuilder struc = new StringBuilder(256);
+ struc.append(rnaTrim.getStructDBN(true));
+ int ofstart = -1;
+ int sleng = seq.length();
+
+ for (int i = 0; i < sleng; i++)
+ {
+ if (Comparison.isGap(seq.charAt(i)))
+ {
+ if (ofstart == -1)
+ {
+ ofstart = i;
+ }
+ /*
+ * mark base or base & pair in the structure with *
+ */
+ if (!rnaTrim.findPair(i).isEmpty())
+ {
+ int m = rnaTrim.findPair(i).get(1);
+ int l = rnaTrim.findPair(i).get(0);
+
+ struc.replace(m, m + 1, "*");
+ struc.replace(l, l + 1, "*");
+ }
+ else
+ {
+ struc.replace(i, i + 1, "*");
+ }
+ }
+ else
+ {
+ if (ofstart > -1)
+ {
+ offset.addShift(offset.shift(ofstart), ofstart - i);
+ ofstart = -1;
+ }
+ }
+ }
+ // final gap
+ if (ofstart > -1)
+ {
+ offset.addShift(offset.shift(ofstart), ofstart - sleng);
+ ofstart = -1;
+ }
+
+ /*
+ * remove the marked gaps from the structure
+ */
+ String newStruc = struc.toString().replace("*", "");
+
+ /*
+ * remove gaps from the sequence
+ */
+ String newSeq = AlignSeq.extractGaps(Comparison.GapChars, seq);
+
+ try
+ {
+ rnaTrim.setRNA(newSeq, newStruc);
+ registerOffset(rnaTrim, offset);
+ } catch (ExceptionUnmatchedClosingParentheses e)
+ {
+ e.printStackTrace();
+ } catch (ExceptionFileFormatOrSyntax e)
+ {
+ e.printStackTrace();
+ }
+ return rnaTrim;