X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fdatamodel%2Ffeatures%2FSequenceFeaturesTest.java;h=56512cdc4ea65efab57839dfbe337fde15e3a996;hb=7dc7404ce7a339c600130e9828e3efc05b1e3270;hp=32987b0e5fc2258034331f9127d2966adafe87fb;hpb=a4f2a7f356b8edab17a9a5bb6f2e71a1419792a9;p=jalview.git diff --git a/test/jalview/datamodel/features/SequenceFeaturesTest.java b/test/jalview/datamodel/features/SequenceFeaturesTest.java index 32987b0..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 @@ -940,14 +939,14 @@ public class SequenceFeaturesTest assertFalse(iterator.hasNext()); /* - * two types specified - get sorted alphabetically + * two types specified - order is preserved */ types = sf.varargToTypes("Metal", "Cath"); iterator = types.iterator(); assertTrue(iterator.hasNext()); - assertSame(iterator.next(), featureStores.get("Cath")); - assertTrue(iterator.hasNext()); assertSame(iterator.next(), featureStores.get("Metal")); + assertTrue(iterator.hasNext()); + assertSame(iterator.next(), featureStores.get("Cath")); assertFalse(iterator.hasNext()); /* @@ -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") @@ -1161,7 +1177,7 @@ public class SequenceFeaturesTest public void testShiftFeatures() { SequenceFeatures store = new SequenceFeatures(); - assertFalse(store.shiftFeatures(1)); + assertFalse(store.shiftFeatures(0, 1)); SequenceFeature sf1 = new SequenceFeature("Cath", "", 2, 5, 0f, null); store.add(sf1); @@ -1179,7 +1195,7 @@ public class SequenceFeaturesTest /* * shift features right by 5 */ - assertTrue(store.shiftFeatures(5)); + assertTrue(store.shiftFeatures(0, 5)); // non-positional features untouched: List nonPos = store.getNonPositionalFeatures(); @@ -1208,7 +1224,7 @@ public class SequenceFeaturesTest * feature at [7-10] should be removed * feature at [13-19] should become [1-4] */ - assertTrue(store.shiftFeatures(-15)); + assertTrue(store.shiftFeatures(0, -15)); pos = store.getPositionalFeatures(); assertEquals(pos.size(), 2); SequenceFeatures.sortFeatures(pos, true); @@ -1218,6 +1234,35 @@ public class SequenceFeaturesTest assertEquals(pos.get(1).getBegin(), 13); assertEquals(pos.get(1).getEnd(), 22); assertEquals(pos.get(1).getType(), "Disulfide bond"); + + /* + * shift right by 4 from column 2 + * feature at [1-4] should be unchanged + * feature at [13-22] should become [17-26] + */ + assertTrue(store.shiftFeatures(2, 4)); + pos = store.getPositionalFeatures(); + assertEquals(pos.size(), 2); + SequenceFeatures.sortFeatures(pos, true); + assertEquals(pos.get(0).getBegin(), 1); + assertEquals(pos.get(0).getEnd(), 4); + assertEquals(pos.get(0).getType(), "Metal"); + assertEquals(pos.get(1).getBegin(), 17); + assertEquals(pos.get(1).getEnd(), 26); + assertEquals(pos.get(1).getType(), "Disulfide bond"); + + /* + * shift right from column 18 + * should be no updates + */ + SequenceFeature f1 = pos.get(0); + SequenceFeature f2 = pos.get(1); + assertFalse(store.shiftFeatures(18, 6)); + pos = store.getPositionalFeatures(); + assertEquals(pos.size(), 2); + SequenceFeatures.sortFeatures(pos, true); + assertSame(pos.get(0), f1); + assertSame(pos.get(1), f2); } @Test(groups = "Functional") @@ -1232,4 +1277,18 @@ public class SequenceFeaturesTest assertTrue(store.isOntologyTerm("junk", new String[] {})); assertTrue(store.isOntologyTerm("junk", (String[]) null)); } + + @Test(groups = "Functional") + public void testDeleteAll() + { + SequenceFeaturesI store = new SequenceFeatures(); + assertFalse(store.hasFeatures()); + store.deleteAll(); + assertFalse(store.hasFeatures()); + store.add(new SequenceFeature("Cath", "Desc", 12, 20, 0f, "Group")); + store.add(new SequenceFeature("Pfam", "Desc", 6, 12, 2f, "Group2")); + assertTrue(store.hasFeatures()); + store.deleteAll(); + assertFalse(store.hasFeatures()); + } }