From bb4e715f6a6681100b7b43562211cf690118ee8a Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 2 Jul 2019 09:06:28 +0100 Subject: [PATCH] JAL-3178 output nonpositional features in 'not positional' groups --- src/jalview/io/FeaturesFile.java | 17 ++++++++++++++++- test/jalview/io/FeaturesFileTest.java | 14 +++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/jalview/io/FeaturesFile.java b/src/jalview/io/FeaturesFile.java index 70f2ac7..75fdc4c 100755 --- a/src/jalview/io/FeaturesFile.java +++ b/src/jalview/io/FeaturesFile.java @@ -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 featureGroups = fr.getFeatureGroups(); + /* + * get all positional feature groups + */ + Set 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 nonPosGroups = seq.getFeatures().getFeatureGroups(false); + featureGroups.addAll(nonPosGroups); + } /* * sort groups alphabetically, and ensure that features with a diff --git a/test/jalview/io/FeaturesFileTest.java b/test/jalview/io/FeaturesFileTest.java index 77c18db..e47bd43 100644 --- a/test/jalview/io/FeaturesFileTest.java +++ b/test/jalview/io/FeaturesFileTest.java @@ -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" + "Pfam domainPfam_3_4\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" -- 1.7.10.2