+ }
+
+ /**
+ * Appends output of visible sequence features within feature groups to the
+ * output buffer. Groups other than the null or empty group are sandwiched by
+ * STARTGROUP and ENDGROUP lines. Answers the number of features written.
+ *
+ * @param out
+ * @param fr
+ * @param featureTypes
+ * @param sequences
+ * @param includeNonPositional
+ * @return
+ */
+ private int outputFeaturesByGroup(StringBuilder out,
+ FeatureRenderer fr, String[] featureTypes,
+ SequenceI[] sequences, boolean includeNonPositional)
+ {
+ List<String> featureGroups = fr.getFeatureGroups();
+
+ /*
+ * 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<>(featureGroups);
+ sortedGroups.remove(null);
+ sortedGroups.remove("");
+ Collections.sort(sortedGroups);
+ sortedGroups.add(null);
+ sortedGroups.add("");
+
+ int count = 0;
+ List<String> visibleGroups = fr.getDisplayedFeatureGroups();
+
+ /*
+ * loop over all groups (may be visible or not);
+ * non-positional features are output even if group is not visible
+ */
+ for (String group : sortedGroups)