JAL-3178 output nonpositional features in 'not positional' groups bug/JAL-3178nonposFeatureExport_take2
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 2 Jul 2019 08:06:28 +0000 (09:06 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 2 Jul 2019 08:06:28 +0000 (09:06 +0100)
src/jalview/io/FeaturesFile.java
test/jalview/io/FeaturesFileTest.java

index 70f2ac7..75fdc4c 100755 (executable)
@@ -49,9 +49,11 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Set;
 
 /**
  * Parses and writes features files, which may be in Jalview, GFF2 or GFF3
@@ -679,7 +681,20 @@ public class FeaturesFile extends AlignFile implements FeaturesSourceI
           FeatureRenderer fr, String[] featureTypes,
           SequenceI[] sequences, boolean includeNonPositional)
   {
-    List<String> featureGroups = fr.getFeatureGroups();
+    /*
+     * get all positional feature groups
+     */
+    Set<String> featureGroups = new HashSet<>(fr.getFeatureGroups());
+
+    /*
+     * add non-positional feature groups, just in case any are not
+     * also positional feature groups
+     */
+    for (SequenceI seq : sequences)
+    {
+      Set<String> nonPosGroups = seq.getFeatures().getFeatureGroups(false);
+      featureGroups.addAll(nonPosGroups);
+    }
 
     /*
      * sort groups alphabetically, and ensure that features with a
index 77c18db..e47bd43 100644 (file)
@@ -451,7 +451,9 @@ public class FeaturesFileTest
             + "Iron\tFER_CAPAA\t-1\t39\t39\tMETAL\n"
             + "Turn\tFER_CAPAA\t-1\t36\t38\tGAMMA-TURN\n"
             + "<html>Pfam domain<a href=\"http://pfam.xfam.org/family/PF00111\">Pfam_3_4</a></html>\tFER_CAPAA\t-1\t20\t20\tPfam\n"
-            + "ENDGROUP\tuniprot\n";
+            + "ENDGROUP\tuniprot\n" + "STARTGROUP\tfoobar\n"
+            + "Foo\tFER_CAPAN\t-1\t0\t0\tBar\n" // non-positional feature
+            + "ENDGROUP\tfoobar\n";
     FeaturesFile featuresFile = new FeaturesFile(features,
             DataSourceType.PASTE);
     featuresFile.parse(al.getDataset(), colours, false);
@@ -486,7 +488,9 @@ public class FeaturesFileTest
     fr.setGroupVisibility("uniprot", true);
     exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
             true);
-    expected = "\nSTARTGROUP\tuniprot\n"
+    expected = "\nSTARTGROUP\tfoobar\n"
+            + "Foo\tFER_CAPAN\t-1\t0\t0\tBar\t0.0\n"
+            + "ENDGROUP\tfoobar\n" + "\nSTARTGROUP\tuniprot\n"
             + "Cath\tFER_CAPAA\t-1\t0\t0\tDomain\t0.0\n"
             + "ENDGROUP\tuniprot\n\n"
             + "desc1\tFER_CAPAN\t-1\t0\t0\tPfam\t1.3\n\n"
@@ -543,12 +547,16 @@ public class FeaturesFileTest
     assertEquals(expected, exported);
 
     /*
-     * include non-positional (overrides group not shown)
+     * include non-positional (overrides group not shown);
+     * uniprot non-positional (but not positional) 
+     * features should be exported
      */
     exported = featuresFile.printJalviewFormat(al.getSequencesArray(), fr,
             true);
     expected = "METAL\tcc9900\n" + "Pfam\tff0000\n"
             + "GAMMA-TURN\tscore|ff0000|00ffff|noValueMin|20.0|95.0|below|66.0\n"
+            + "\nSTARTGROUP\tfoobar\n"
+            + "Foo\tFER_CAPAN\t-1\t0\t0\tBar\t0.0\n" + "ENDGROUP\tfoobar\n"
             + "\nSTARTGROUP\tuniprot\n"
             + "Cath\tFER_CAPAA\t-1\t0\t0\tDomain\t0.0\n"
             + "ENDGROUP\tuniprot\n"