+ * @param selectedIndex
+ */
+ public void setInitialSelection(final int selectedIndex)
+ {
+ /*
+ * empirically it needs a second for Varna/AWT to finish loading/drawing
+ * models for this to work; SwingUtilities.invokeLater _not_ a solution;
+ * explanation and/or better solution welcome!
+ */
+ synchronized (this)
+ {
+ try
+ {
+ wait(1000);
+ } catch (InterruptedException e)
+ {
+ // meh
+ }
+ }
+ vab.setSelectedIndex(selectedIndex);
+ }
+
+ /**
+ * Add a model with associated Varna session file
+ *
+ * @param rna
+ * @param modelName
+ */
+ public RNA addModelSession(RnaModel model, String modelName,
+ String sessionFile)
+ {
+ if (!model.ann.isValidStruc())
+ {
+ throw new IllegalArgumentException(
+ "Invalid RNA structure annotation");
+ }
+
+ try
+ {
+ FullBackup fromSession = vab.vp.loadSession(sessionFile);
+ vab.addStructure(fromSession.rna, fromSession.config);
+ RNA rna = fromSession.rna;
+ // copy the model, but now including the RNA object
+ RnaModel newModel = new RnaModel(model.title, model.ann, model.seq,
+ rna, model.gapped);
+ if (!model.gapped)
+ {
+ registerOffset(rna, buildOffset(model.seq));
+ }
+ models.put(rna, newModel);
+ // capture rna selection state when saved
+ selectionHighlighter = new VarnaHighlighter(rna);
+ return fromSession.rna;
+ } catch (ExceptionLoadingFailed e)
+ {
+ System.err
+ .println("Error restoring Varna session: " + e.getMessage());
+ return null;
+ }
+ }
+
+ /**
+ * Replace everything except RNA secondary structure characters with a period
+ *
+ * @param s
+ * @return