JAL-1645 source formatting and organise imports
[jalview.git] / test / jalview / io / StockholmFileTest.java
index 8fece9d..e889837 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  */
 package jalview.io;
 
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import jalview.datamodel.Alignment;
+import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertNotNull;
+import static org.testng.AssertJUnit.assertTrue;
+
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
@@ -34,7 +35,7 @@ import java.util.BitSet;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.junit.Test;
+import org.testng.annotations.Test;
 
 public class StockholmFileTest
 {
@@ -42,13 +43,13 @@ public class StockholmFileTest
   static String PfamFile = "examples/PF00111_seed.stk",
           RfamFile = "examples/RF00031_folded.stk";
 
-  @Test
+  @Test(groups = { "Functional" })
   public void pfamFileIO() throws Exception
   {
-    testFileIOwithFormat(new File(PfamFile), "STH");
+    testFileIOwithFormat(new File(PfamFile), "STH", -1, 0);
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void pfamFileDataExtraction() throws Exception
   {
     AppletFormatAdapter af = new AppletFormatAdapter();
@@ -57,9 +58,9 @@ public class StockholmFileTest
     int numpdb = 0;
     for (SequenceI sq : al.getSequences())
     {
-      if (sq.getPDBId() != null)
+      if (sq.getAllPDBEntries() != null)
       {
-        numpdb += sq.getPDBId().size();
+        numpdb += sq.getAllPDBEntries().size();
       }
     }
     assertTrue(
@@ -67,10 +68,10 @@ public class StockholmFileTest
             numpdb > 0);
   }
 
-  @Test
+  @Test(groups = { "Functional" })
   public void rfamFileIO() throws Exception
   {
-    testFileIOwithFormat(new File(RfamFile), "STH");
+    testFileIOwithFormat(new File(RfamFile), "STH", 2, 1);
   }
 
   /**
@@ -83,7 +84,9 @@ public class StockholmFileTest
    *          - label for IO class used to write and read back in the data from
    *          f
    */
-  public static void testFileIOwithFormat(File f, String ioformat)
+
+  public static void testFileIOwithFormat(File f, String ioformat,
+          int naliannot, int nminseqann)
   {
     System.out.println("Reading file: " + f);
     String ff = f.getPath();
@@ -91,7 +94,7 @@ public class StockholmFileTest
     {
       AppletFormatAdapter rf = new AppletFormatAdapter();
 
-      Alignment al = rf.readFile(ff, AppletFormatAdapter.FILE,
+      AlignmentI al = rf.readFile(ff, AppletFormatAdapter.FILE,
               new IdentifyFile().Identify(ff, AppletFormatAdapter.FILE));
 
       assertNotNull("Couldn't read supplied alignment data.", al);
@@ -105,7 +108,7 @@ public class StockholmFileTest
       System.out.println("Output file in '" + ioformat + "':\n"
               + outputfile + "\n<<EOF\n");
       // test for consistency in io
-      Alignment al_input = new AppletFormatAdapter().readFile(outputfile,
+      AlignmentI al_input = new AppletFormatAdapter().readFile(outputfile,
               AppletFormatAdapter.PASTE, ioformat);
       assertNotNull("Couldn't parse reimported alignment data.", al_input);
 
@@ -117,7 +120,29 @@ public class StockholmFileTest
               "Identify routine could not recognise output generated by '"
                       + ioformat + "' writer",
               ioformat.equals(identifyoutput));
-      testAlignmentEquivalence(al, al_input);
+      testAlignmentEquivalence(al, al_input, false);
+      int numaliannot = 0, numsqswithali = 0;
+      for (AlignmentAnnotation ala : al_input.getAlignmentAnnotation())
+      {
+        if (ala.sequenceRef == null)
+        {
+          numaliannot++;
+        }
+        else
+        {
+          numsqswithali++;
+        }
+      }
+      if (naliannot > -1)
+      {
+        assertEquals("Number of alignment annotations", naliannot,
+                numaliannot);
+      }
+
+      assertTrue(
+              "Number of sequence associated annotations wasn't at least "
+                      + nminseqann, numsqswithali >= nminseqann);
+
     } catch (Exception e)
     {
       e.printStackTrace();
@@ -133,9 +158,11 @@ public class StockholmFileTest
    * @param al_input
    *          'secondary' or generated alignment from some datapreserving
    *          transformation
+   * @param ignoreFeatures
+   *          when true, differences in seuqence feature annotation are ignored.
    */
   public static void testAlignmentEquivalence(AlignmentI al,
-          AlignmentI al_input)
+          AlignmentI al_input, boolean ignoreFeatures)
   {
     assertNotNull("Original alignment was null", al);
     assertNotNull("Generated alignment was null", al_input);
@@ -237,9 +264,11 @@ public class StockholmFileTest
                   + " are not equal", ss_original.equals(ss_new));
 
           assertTrue(
-                  "Sequence Features were not equivalent",
-                  (seq_original[i].getSequenceFeatures() == null && seq_new[in]
-                          .getSequenceFeatures() == null)
+                  "Sequence Features were not equivalent"
+                          + (ignoreFeatures ? " ignoring." : ""),
+                  ignoreFeatures
+                          || (seq_original[i].getSequenceFeatures() == null && seq_new[in]
+                                  .getSequenceFeatures() == null)
                           || (seq_original[i].getSequenceFeatures() != null && seq_new[in]
                                   .getSequenceFeatures() != null));
           // compare sequence features
@@ -322,9 +351,11 @@ public class StockholmFileTest
                 an_new.displayCharacter.trim())
                 || !("" + an_or.secondaryStructure).trim().equals(
                         ("" + an_new.secondaryStructure).trim())
-                || (an_or.description != an_new.description && (an_or.description == null
-                        || an_new.description == null || !an_or.description
-                          .equals(an_new.description))))
+                || (an_or.description != an_new.description && !((an_or.description == null && an_new.description
+                        .trim().length() == 0)
+                        || (an_new.description == null && an_or.description
+                                .trim().length() == 0) || an_or.description
+                        .trim().equals(an_new.description.trim()))))
         {
           System.err.println("Annotation Element Mismatch\nElement " + i
                   + " in original: " + annot_or.annotations[i].toString()