JAL-1269 refactored Annotate3d test and added additional ID test case
authorJim Procter <jprocter@compbio.dundee.ac.uk>
Sun, 26 May 2013 14:48:46 +0000 (15:48 +0100)
committerJim Procter <jprocter@compbio.dundee.ac.uk>
Sun, 26 May 2013 14:48:46 +0000 (15:48 +0100)
test/jalview/ext/paradise/TestAnnotate3D.java

index 702d9ad..896b60c 100644 (file)
@@ -24,34 +24,45 @@ public class TestAnnotate3D
 {
 
   @Test
-  public void testIdVsContent() throws Exception
+  public void test1GIDbyId() throws Exception
   {
-    Iterator<Reader> ids = Annotate3D
-            .getRNAMLForPDBId("2GIS");
+    // use same ID as standard tests given at https://bitbucket.org/fjossinet/pyrna-rest-clients
+    Iterator<Reader> ids = Annotate3D.getRNAMLForPDBId("1GID");
+    assertTrue("Didn't retrieve 1GID by id.", ids != null);
+    testRNAMLcontent(ids,null);
+  }
+
+  @Test
+  public void testIdVsContent2GIS() throws Exception
+  {
+    Iterator<Reader> ids = Annotate3D.getRNAMLForPDBId("2GIS");
     assertTrue("Didn't retrieve 2GIS by id.", ids != null);
-    Iterator<Reader> files = Annotate3D
-            .getRNAMLForPDBFileAsString(FileUtil.readFileToString(new File(
-                    "examples/2GIS.pdb")));
+    Iterator<Reader> files = Annotate3D.getRNAMLForPDBFileAsString(FileUtil
+            .readFileToString(new File("examples/2GIS.pdb")));
     assertTrue("Didn't retrieve using examples/2GIS.pdb.", files != null);
-    int i=0;
+    int i = 0;
     while (ids.hasNext() && files.hasNext())
     {
-      BufferedReader file=new BufferedReader(files.next()), id=new BufferedReader(ids.next());
-    String iline, fline;
-    do
-    {
-      iline = id.readLine();
-      fline = file.readLine();
-      if (iline != null)
-        System.out.println(iline);
-      if (fline != null)
-        System.out.println(fline);
-      // next assert fails for latest RNAview - because the XMLID entries change between file and ID based RNAML generation.
-      assertTrue("Results differ for ID and file upload based retrieval (chain entry "+(++i)+")",
-              ((iline == fline && iline == null) || (iline != null
-                      && fline != null && iline.equals(fline))));
+      BufferedReader file = new BufferedReader(files.next()), id = new BufferedReader(
+              ids.next());
+      String iline, fline;
+      do
+      {
+        iline = id.readLine();
+        fline = file.readLine();
+        if (iline != null)
+          System.out.println(iline);
+        if (fline != null)
+          System.out.println(fline);
+        // next assert fails for latest RNAview - because the XMLID entries
+        // change between file and ID based RNAML generation.
+        assertTrue(
+                "Results differ for ID and file upload based retrieval (chain entry "
+                        + (++i) + ")",
+                ((iline == fline && iline == null) || (iline != null
+                        && fline != null && iline.equals(fline))));
 
-    } while (iline != null);
+      } while (iline != null);
     }
   }
 
@@ -66,16 +77,22 @@ public class TestAnnotate3D
   {
     PDBfile pdbf = new PDBfile("examples/2GIS.pdb", FormatAdapter.FILE);
     Assert.assertTrue(pdbf.isValid());
-    StringBuffer sb = new StringBuffer();
     // Comment - should add new FileParse constructor like new FileParse(Reader
     // ..). for direct reading
     Iterator<Reader> readers = Annotate3D
             .getRNAMLForPDBFileAsString(FileUtil.readFileToString(new File(
                     "examples/2GIS.pdb")));
-    int r=0;
+    testRNAMLcontent(readers, pdbf);
+  }
+
+  private void testRNAMLcontent(Iterator<Reader> readers, PDBfile pdbf)
+          throws Exception
+  {
+    StringBuffer sb = new StringBuffer();
+    int r = 0;
     while (readers.hasNext())
     {
-      System.out.println("Testing RNAML input number "+(++r));
+      System.out.println("Testing RNAML input number " + (++r));
       BufferedReader br = new BufferedReader(readers.next());
       String line;
       while ((line = br.readLine()) != null)
@@ -85,29 +102,35 @@ public class TestAnnotate3D
       assertTrue("No data returned by Annotate3D", sb.length() > 0);
       AlignmentI al = new FormatAdapter().readFile(sb.toString(),
               FormatAdapter.PASTE, "RNAML");
-
+      if (al==null || al.getHeight()==0) {
+        System.out.println(sb.toString());
+      }
       assertTrue("No alignment returned.", al != null);
       assertTrue("No sequences in returned alignment.", al.getHeight() > 0);
-      for (SequenceI sq : al.getSequences())
+      if (pdbf != null)
       {
+        for (SequenceI sq : al.getSequences())
         {
-          SequenceI struseq = null;
-          String sq_ = new String(sq.getSequence()).toLowerCase();
-          for (SequenceI _struseq : pdbf.getSeqsAsArray())
           {
-            if (new String(_struseq.getSequence()).toLowerCase()
-                    .equals(sq_))
+            SequenceI struseq = null;
+            String sq_ = new String(sq.getSequence()).toLowerCase();
+            for (SequenceI _struseq : pdbf.getSeqsAsArray())
             {
-              struseq = _struseq;
-              break;
+              if (new String(_struseq.getSequence()).toLowerCase().equals(
+                      sq_))
+              {
+                struseq = _struseq;
+                break;
+              }
+            }
+            if (struseq == null)
+            {
+              Assert.fail("Couldn't find this sequence in original input:\n"
+                      + new FastaFile().print(new SequenceI[]
+                      { sq })
+                      + "\n\nOriginal input:\n"
+                      + new FastaFile().print(pdbf.getSeqsAsArray()) + "\n");
             }
-          }
-          if (struseq == null)
-          {
-            Assert.fail("Couldn't find this sequence in original input:\n"
-                    + new FastaFile().print(new SequenceI[]
-                    { sq }) + "\n\nOriginal input:\n"
-                    + new FastaFile().print(pdbf.getSeqsAsArray()) + "\n");
           }
         }
       }