Merge branch 'bug/JAL-1775' into develop
authorJim Procter <jprocter@issues.jalview.org>
Mon, 15 Jun 2015 14:24:38 +0000 (15:24 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Mon, 15 Jun 2015 14:24:38 +0000 (15:24 +0100)
src/jalview/io/FileLoader.java
test/jalview/ws/jabaws/RNAStructExportImport.java

index e27c666..0cd2987 100755 (executable)
  */
 package jalview.io;
 
-import java.util.StringTokenizer;
-import java.util.Vector;
-
-import javax.swing.JOptionPane;
-import javax.swing.SwingUtilities;
-
 import jalview.api.ComplexAlignFile;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.ColumnSelection;
@@ -39,6 +33,12 @@ import jalview.schemes.ColourSchemeI;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.MessageManager;
 
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
+
 public class FileLoader implements Runnable
 {
   String file;
@@ -317,6 +317,7 @@ public class FileLoader implements Runnable
 
         if ((al != null) && (al.getHeight() > 0))
         {
+          // construct and register dataset sequences
           for (SequenceI sq : al.getSequences())
           {
             while (sq.getDatasetSequence() != null)
@@ -327,21 +328,23 @@ public class FileLoader implements Runnable
             {
               for (PDBEntry pdbe : sq.getPDBId())
               {
+                // register PDB entries with desktop's structure selection
+                // manager
                 StructureSelectionManager.getStructureSelectionManager(
                         Desktop.instance).registerPDBEntry(pdbe);
               }
             }
           }
+
           if (viewport != null)
           {
+            // append to existing alignment
             viewport.addAlignment(al, title);
           }
           else
           {
-            if (!protocol.equals(AppletFormatAdapter.PASTE))
-            {
-              alignFrame.setFileName(file, format);
-            }
+            // otherwise construct the alignFrame
+
             if (source instanceof ComplexAlignFile)
             {
               ColumnSelection colSel = ((ComplexAlignFile) source)
@@ -353,8 +356,7 @@ public class FileLoader implements Runnable
               ColourSchemeI cs = ((ComplexAlignFile) source)
                       .getColourScheme();
               alignFrame = new AlignFrame(al, hiddenSeqs, colSel,
-                      AlignFrame.DEFAULT_WIDTH,
-                      AlignFrame.DEFAULT_HEIGHT);
+                      AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
 
               alignFrame.getViewport().setShowSequenceFeatures(
                       showSeqFeatures);
@@ -365,29 +367,34 @@ public class FileLoader implements Runnable
               alignFrame = new AlignFrame(al, AlignFrame.DEFAULT_WIDTH,
                       AlignFrame.DEFAULT_HEIGHT);
             }
+          }
+          // add metadata and update ui
+          if (!protocol.equals(AppletFormatAdapter.PASTE))
+          {
+            alignFrame.setFileName(file, format);
+          }
 
-            alignFrame.statusBar.setText(MessageManager.formatMessage(
-                    "label.successfully_loaded_file", new String[]
-                    { title }));
+          alignFrame.statusBar.setText(MessageManager.formatMessage(
+                  "label.successfully_loaded_file", new String[]
+                  { title }));
 
-            if (raiseGUI)
-            {
-              // add the window to the GUI
-              // note - this actually should happen regardless of raiseGUI
-              // status in Jalview 3
-              // TODO: define 'virtual desktop' for benefit of headless scripts
-              // that perform queries to find the 'current working alignment'
-              Desktop.addInternalFrame(alignFrame, title,
-                      AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
-            }
+          if (raiseGUI)
+          {
+            // add the window to the GUI
+            // note - this actually should happen regardless of raiseGUI
+            // status in Jalview 3
+            // TODO: define 'virtual desktop' for benefit of headless scripts
+            // that perform queries to find the 'current working alignment'
+            Desktop.addInternalFrame(alignFrame, title,
+                    AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT);
+          }
 
-            try
-            {
-              alignFrame.setMaximum(jalview.bin.Cache.getDefault(
-                      "SHOW_FULLSCREEN", false));
-            } catch (java.beans.PropertyVetoException ex)
-            {
-            }
+          try
+          {
+            alignFrame.setMaximum(jalview.bin.Cache.getDefault(
+                    "SHOW_FULLSCREEN", false));
+          } catch (java.beans.PropertyVetoException ex)
+          {
           }
         }
         else
index 36b3196..665d9c8 100644 (file)
@@ -23,6 +23,17 @@ package jalview.ws.jabaws;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.gui.Jalview2XML;
+import jalview.io.AnnotationFile;
+import jalview.io.FormatAdapter;
+import jalview.io.StockholmFileTest;
+import jalview.ws.jws2.Jws2Discoverer;
+import jalview.ws.jws2.RNAalifoldClient;
+import jalview.ws.jws2.SequenceAnnotationWSClient;
+import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.params.AutoCalcSetting;
 
 import java.awt.Component;
 import java.util.ArrayList;
@@ -32,25 +43,15 @@ import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 
 import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import compbio.metadata.WrongParameterException;
 
-import jalview.datamodel.AlignmentI;
-import jalview.gui.Jalview2XML;
-import jalview.io.AnnotationFile;
-import jalview.io.FormatAdapter;
-import jalview.io.StockholmFileTest;
-import jalview.ws.jws2.Jws2Discoverer;
-import jalview.ws.jws2.RNAalifoldClient;
-import jalview.ws.jws2.SequenceAnnotationWSClient;
-import jalview.ws.jws2.jabaws2.Jws2Instance;
-import jalview.ws.params.AutoCalcSetting;
-
 public class RNAStructExportImport
 {
-  public static String testseqs = "examples/unfolded_RF00031.aln";
+  public static String testseqs = "examples/RF00031_folded.stk";
 
   public static Jws2Discoverer disc;
 
@@ -89,6 +90,22 @@ public class RNAStructExportImport
 
     assertNotNull("Couldn't load test data ('" + testseqs + "')", af);
 
+    // remove any existing annotation
+    List<AlignmentAnnotation> aal = new ArrayList<AlignmentAnnotation>();
+    for (AlignmentAnnotation rna : af.getViewport().getAlignment()
+            .getAlignmentAnnotation())
+    {
+      if (rna.isRNA())
+      {
+        aal.add(rna);
+      }
+    }
+    for (AlignmentAnnotation rna : aal)
+    {
+      af.getViewport().getAlignment().deleteAnnotation(rna);
+    }
+    af.getViewport().alignmentChanged(af.alignPanel); // why is af.alignPanel
+                                                      // public?
   }
 
   @AfterClass
@@ -102,6 +119,38 @@ public class RNAStructExportImport
   }
 
   @Test
+  public void testRNAAliFoldValidStructure()
+  {
+
+    alifoldClient = new RNAalifoldClient(rnaalifoldws, af, null, null);
+
+    af.getViewport().getCalcManager().startWorker(alifoldClient);
+
+    do
+    {
+      try
+      {
+        Thread.sleep(50);
+      } catch (InterruptedException x)
+      {
+      }
+      ;
+    } while (af.getViewport().getCalcManager().isWorking());
+
+    AlignmentI orig_alig = af.getViewport().getAlignment();
+    for (AlignmentAnnotation aa:orig_alig.getAlignmentAnnotation())
+    {
+      if (alifoldClient.involves(aa))
+      {
+        if (aa.isRNA())
+        {
+          Assert.assertTrue("Did not create valid structure from RNAALiFold prediction", aa.isValidStruc());
+        }
+      }
+    }
+  }
+
+  @Test
   public void testRNAStructExport()
   {