From: gmungoc Date: Thu, 25 May 2017 08:30:53 +0000 (+0100) Subject: JAL-2490 test coverage of empty and null feature group in Jalview format X-Git-Tag: Release_2_10_3b1~234 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=7e2aa9039133d9e17aef05507fc652542d64a838;p=jalview.git JAL-2490 test coverage of empty and null feature group in Jalview format export --- diff --git a/src/jalview/io/FeaturesFile.java b/src/jalview/io/FeaturesFile.java index afc00ee..a3cab6b 100755 --- a/src/jalview/io/FeaturesFile.java +++ b/src/jalview/io/FeaturesFile.java @@ -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 sortedGroups = new ArrayList(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); diff --git a/test/jalview/io/FeaturesFileTest.java b/test/jalview/io/FeaturesFileTest.java index d59c6bb..b88c2ee 100644 --- a/test/jalview/io/FeaturesFileTest.java +++ b/test/jalview/io/FeaturesFileTest.java @@ -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" + "Pfam domainPfam_3_4\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); }