JAL-2490 test coverage of empty and null feature group in Jalview format
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 25 May 2017 08:30:53 +0000 (09:30 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 25 May 2017 08:30:53 +0000 (09:30 +0100)
export

src/jalview/io/FeaturesFile.java
test/jalview/io/FeaturesFileTest.java

index afc00ee..a3cab6b 100755 (executable)
@@ -542,12 +542,15 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
             .toArray(new String[visible.keySet().size()]);
 
     /*
-     * sort groups alphabetically, and ensure that null group is output last
+     * sort groups alphabetically, and ensure that features with a
+     * null or empty group are output after those in named groups
      */
     List<String> sortedGroups = new ArrayList<String>(visibleFeatureGroups);
     sortedGroups.remove(null);
+    sortedGroups.remove("");
     Collections.sort(sortedGroups);
     sortedGroups.add(null);
+    sortedGroups.add("");
 
     boolean foundSome = false;
 
@@ -570,7 +573,8 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
 
     for (String group : sortedGroups)
     {
-      if (group != null)
+      boolean isNamedGroup = (group != null && !"".equals(group));
+      if (isNamedGroup)
       {
         out.append(newline);
         out.append("STARTGROUP").append(TAB);
@@ -598,7 +602,7 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
         }
       }
 
-      if (group != null)
+      if (isNamedGroup)
       {
         out.append("ENDGROUP").append(TAB);
         out.append(group);
index d59c6bb..b88c2ee 100644 (file)
@@ -420,6 +420,21 @@ public class FeaturesFileTest
     featuresFile.parse(al.getDataset(), colours, false);
 
     /*
+     * add positional and non-positional features with null and
+     * empty feature group to check handled correctly
+     */
+    SequenceI seq = al.getSequenceAt(1); // FER_CAPAN
+    seq.addSequenceFeature(new SequenceFeature("Pfam", "desc1", 0, 0, 1.3f,
+            null));
+    seq.addSequenceFeature(new SequenceFeature("Pfam", "desc2", 4, 9,
+            Float.NaN, null));
+    seq = al.getSequenceAt(2); // FER1_SOLLC
+    seq.addSequenceFeature(new SequenceFeature("Pfam", "desc3", 0, 0,
+            Float.NaN, ""));
+    seq.addSequenceFeature(new SequenceFeature("Pfam", "desc4", 5, 8,
+            -2.6f, ""));
+
+    /*
      * first with no features displayed, exclude non-positional features
      */
     FeatureRenderer fr = af.alignPanel.getFeatureRenderer();
@@ -437,7 +452,10 @@ public class FeaturesFileTest
     visibleGroups.add("uniprot");
     exported = featuresFile.printJalviewFormat(al.getSequencesArray(),
             visible, visibleGroups, true);
-    expected = "Cath\tFER_CAPAA\t-1\t0\t0\tDomain\t0.0\n\nSTARTGROUP\tuniprot\nENDGROUP\tuniprot\n";
+    expected = "Cath\tFER_CAPAA\t-1\t0\t0\tDomain\t0.0\n"
+            + "desc1\tFER_CAPAN\t-1\t0\t0\tPfam\t1.3\n"
+            + "desc3\tFER1_SOLLC\t-1\t0\t0\tPfam\n" // NaN is not output
+            + "\nSTARTGROUP\tuniprot\nENDGROUP\tuniprot\n";
     assertEquals(expected, exported);
 
     /*
@@ -473,7 +491,11 @@ public class FeaturesFileTest
             + "Turn\tFER_CAPAA\t-1\t36\t38\tGAMMA-TURN\t0.0\n"
             + "Iron\tFER_CAPAA\t-1\t39\t39\tMETAL\t0.0\n"
             + "<html>Pfam domain<a href=\"http://pfam.xfam.org/family/PF00111\">Pfam_3_4</a></html>\tFER_CAPAA\t-1\t20\t20\tPfam\t0.0\n"
-            + "ENDGROUP\tuniprot\n";
+            + "ENDGROUP\tuniprot\n"
+            // null / empty group features output after features in named
+            // groups:
+            + "desc2\tFER_CAPAN\t-1\t4\t9\tPfam\n"
+            + "desc4\tFER1_SOLLC\t-1\t5\t8\tPfam\t-2.6\n";
     assertEquals(expected, exported);
   }