JAL-1028 JAL-1142 refactor test to allow reuse of secondary structure validation...
authorj.procter@dundee.ac.uk <jprocter@jims-mbp-2.dyn.lifesci.dundee.ac.uk>
Fri, 18 Jul 2014 11:00:44 +0000 (12:00 +0100)
committerj.procter@dundee.ac.uk <jprocter@jims-mbp-2.dyn.lifesci.dundee.ac.uk>
Fri, 18 Jul 2014 11:00:44 +0000 (12:00 +0100)
test/jalview/ext/jmol/PDBFileWithJmolTest.java

index 900e47c..ef14287 100644 (file)
@@ -27,6 +27,9 @@ import java.util.Vector;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+import jalview.io.AppletFormatAdapter;
+import jalview.io.FileLoader;
 
 import org.junit.Test;
 
@@ -36,32 +39,63 @@ import org.junit.Test;
  */
 public class PDBFileWithJmolTest
 {
+  String[] testFile = new String[]
+  { "./examples/1GAQ.txt" }; // , "./examples/DNMT1_MOUSE.pdb" };
 
   @Test
-  public void test() throws Exception
+   public void testAlignmentLoader() throws Exception
+   {
+    for (String f:testFile) {
+      FileLoader fl = new jalview.io.FileLoader(false);
+      AlignFrame af = fl.LoadFileWaitTillLoaded(f, AppletFormatAdapter.FILE);
+      validateSecStrRows(af.getViewport().getAlignment());
+    }
+   }
+  @Test
+  public void testFileParser() throws Exception
+  {
+    for (String pdbStr : testFile)
+    {
+      PDBFileWithJmol jtest = new PDBFileWithJmol(pdbStr,
+              jalview.io.AppletFormatAdapter.FILE);
+      Vector<SequenceI> seqs = jtest.getSeqs();
+
+      assertTrue(
+              "No sequences extracted from testfile\n"
+                      + (jtest.hasWarningMessage() ? jtest.getWarningMessage()
+                              : "(No warnings raised)"), seqs != null
+                      && seqs.size() > 0);
+      for (SequenceI sq : seqs)
+      {
+        AlignmentI al = new Alignment(new SequenceI[]
+        { sq });
+        validateSecStrRows(al);
+      }
+    }
+  }
+
+  private void validateSecStrRows(AlignmentI al)
   {
-    PDBFileWithJmol jtest = new PDBFileWithJmol("./examples/1GAQ.txt",
-            jalview.io.AppletFormatAdapter.FILE);
-    Vector<SequenceI> seqs = jtest.getSeqs();
 
-    assertTrue(
-            "No sequences extracted from testfile\n"
-                    + (jtest.hasWarningMessage() ? jtest.getWarningMessage()
-                            : "(No warnings raised)"),
-            seqs != null && seqs.size() > 0);
-    for (SequenceI sq : seqs)
+    if (!al.isNucleotide())
     {
-      AlignmentI al = new Alignment(new SequenceI[]
-      { sq });
-      if (!al.isNucleotide())
+      for (SequenceI asq : al.getSequences())
       {
+        SequenceI sq = asq;
+        while (sq.getDatasetSequence()!=null && sq.getAnnotation()==null)
+        {
+          sq = asq.getDatasetSequence();
+        }
         assertTrue(
                 "No secondary structure assigned for protein sequence.",
                 sq.getAnnotation() != null
                         && sq.getAnnotation().length >= 1
                         && sq.getAnnotation()[0].hasIcons);
+        assertTrue(
+                "Secondary structure not associated for sequence "
+                        + sq.getName(),
+                sq.getAnnotation()[0].sequenceRef == sq);
       }
     }
   }
-
 }