From 10b40b4ec840e5076c95109b0ea518928385821c Mon Sep 17 00:00:00 2001 From: gmungoc Date: Tue, 19 May 2020 18:27:40 +0100 Subject: [PATCH] JAL-3621 corrected sequence feature sort and test --- .../datamodel/features/SequenceFeatures.java | 3 +- .../datamodel/features/SequenceFeaturesTest.java | 38 ++++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/jalview/datamodel/features/SequenceFeatures.java b/src/jalview/datamodel/features/SequenceFeatures.java index 70485b6..8ac4991 100644 --- a/src/jalview/datamodel/features/SequenceFeatures.java +++ b/src/jalview/datamodel/features/SequenceFeatures.java @@ -414,7 +414,8 @@ public class SequenceFeatures implements SequenceFeaturesI final boolean forwardStrand) { Collections.sort(features, - forwardStrand ? IntervalI.COMPARE_BEGIN_ASC_END_ASC + forwardStrand + ? IntervalI.COMPARE_BEGIN_ASC_END_DESC : IntervalI.COMPARE_END_DESC); } diff --git a/test/jalview/datamodel/features/SequenceFeaturesTest.java b/test/jalview/datamodel/features/SequenceFeaturesTest.java index 4198a37..56512cd 100644 --- a/test/jalview/datamodel/features/SequenceFeaturesTest.java +++ b/test/jalview/datamodel/features/SequenceFeaturesTest.java @@ -5,8 +5,6 @@ import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertSame; import static org.testng.Assert.assertTrue; -import jalview.datamodel.SequenceFeature; - import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -15,6 +13,7 @@ import java.util.Set; import org.testng.annotations.Test; +import jalview.datamodel.SequenceFeature; import junit.extensions.PA; public class SequenceFeaturesTest @@ -1052,7 +1051,8 @@ public class SequenceFeaturesTest public void testSortFeatures() { List sfs = new ArrayList<>(); - SequenceFeature sf1 = new SequenceFeature("Pfam", "desc", 30, 80, + SequenceFeature sf1 = new SequenceFeature("Pfam", "desc", 30, + 60, Float.NaN, null); sfs.add(sf1); SequenceFeature sf2 = new SequenceFeature("Rfam", "desc", 40, 50, @@ -1061,18 +1061,34 @@ public class SequenceFeaturesTest SequenceFeature sf3 = new SequenceFeature("Rfam", "desc", 50, 60, Float.NaN, null); sfs.add(sf3); + SequenceFeature sf4 = new SequenceFeature("Xfam", "desc", 30, + 80, + Float.NaN, null); + sfs.add(sf4); + SequenceFeature sf5 = new SequenceFeature("Xfam", "desc", 30, + 90, + Float.NaN, null); + sfs.add(sf5); - // sort by end position descending + /* + * sort by end position descending, order unchanged if matched + */ SequenceFeatures.sortFeatures(sfs, false); - assertSame(sfs.get(0), sf1); - assertSame(sfs.get(1), sf3); - assertSame(sfs.get(2), sf2); + assertSame(sfs.get(0), sf5); // end 90 + assertSame(sfs.get(1), sf4); // end 80 + assertSame(sfs.get(2), sf1); // end 60, start 50 + assertSame(sfs.get(3), sf3); // end 60, start 30 + assertSame(sfs.get(4), sf2); // end 50 - // sort by start position ascending + /* + * resort {5, 4, 1, 3, 2} by start position ascending, end descending + */ SequenceFeatures.sortFeatures(sfs, true); - assertSame(sfs.get(0), sf1); - assertSame(sfs.get(1), sf2); - assertSame(sfs.get(2), sf3); + assertSame(sfs.get(0), sf5); // start 30, end 90 + assertSame(sfs.get(1), sf4); // start 30, end 80 + assertSame(sfs.get(2), sf1); // start 30, end 60 + assertSame(sfs.get(3), sf2); // start 40 + assertSame(sfs.get(4), sf3); // start 50 } @Test(groups = "Functional") -- 1.7.10.2