From 6ec47c00025dbeb48dba5f5db77754ec50b7a6b5 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Fri, 30 Jun 2017 16:17:47 +0100 Subject: [PATCH] JAL-2505 correct handling of change of feature type --- src/jalview/appletgui/FeatureRenderer.java | 11 ++++---- src/jalview/datamodel/SequenceFeature.java | 22 ++++++++++++--- src/jalview/gui/FeatureRenderer.java | 4 +-- test/jalview/datamodel/SequenceFeatureTest.java | 33 ++++++++++++++++++++++- 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/jalview/appletgui/FeatureRenderer.java b/src/jalview/appletgui/FeatureRenderer.java index 435e78d..8721ff4 100644 --- a/src/jalview/appletgui/FeatureRenderer.java +++ b/src/jalview/appletgui/FeatureRenderer.java @@ -413,7 +413,8 @@ public class FeatureRenderer extends if (!colourPanel.isGcol) { // update colour - otherwise its already done. - setColour(sf.type, new FeatureColour(colourPanel.getBackground())); + setColour(enteredType, + new FeatureColour(colourPanel.getBackground())); } int newBegin = sf.begin; int newEnd = sf.end; @@ -431,14 +432,14 @@ public class FeatureRenderer extends * (to ensure integrity of SequenceFeatures data store) */ sequences.get(0).deleteFeature(sf); - SequenceFeature newSf = new SequenceFeature(sf, newBegin, newEnd, - enteredGroup, sf.getScore()); + SequenceFeature newSf = new SequenceFeature(sf, enteredType, + newBegin, newEnd, enteredGroup, sf.getScore()); newSf.setDescription(enteredDesc); ffile.parseDescriptionHTML(newSf, false); // amend features dialog only updates one sequence at a time sequences.get(0).addSequenceFeature(newSf); - boolean typeOrGroupChanged = (!featureType.equals(sf.type) || !featureGroup - .equals(sf.featureGroup)); + boolean typeOrGroupChanged = (!featureType.equals(newSf.getType()) || !featureGroup + .equals(newSf.getFeatureGroup())); ffile.parseDescriptionHTML(sf, false); if (typeOrGroupChanged) diff --git a/src/jalview/datamodel/SequenceFeature.java b/src/jalview/datamodel/SequenceFeature.java index 9a6cf2b..ba7412c 100755 --- a/src/jalview/datamodel/SequenceFeature.java +++ b/src/jalview/datamodel/SequenceFeature.java @@ -143,15 +143,16 @@ public class SequenceFeature implements FeatureLocationI * A copy constructor that allows the value of final fields to be 'modified' * * @param sf + * @param newType * @param newBegin * @param newEnd * @param newGroup * @param newScore */ - public SequenceFeature(SequenceFeature sf, int newBegin, int newEnd, - String newGroup, float newScore) + public SequenceFeature(SequenceFeature sf, String newType, int newBegin, + int newEnd, String newGroup, float newScore) { - this(sf.getType(), sf.getDescription(), newBegin, newEnd, newScore, + this(newType, sf.getDescription(), newBegin, newEnd, newScore, newGroup); if (sf.otherDetails != null) @@ -173,6 +174,21 @@ public class SequenceFeature implements FeatureLocationI } /** + * A copy constructor that allows the value of final fields to be 'modified' + * + * @param sf + * @param newBegin + * @param newEnd + * @param newGroup + * @param newScore + */ + public SequenceFeature(SequenceFeature sf, int newBegin, int newEnd, + String newGroup, float newScore) + { + this(sf, sf.getType(), newBegin, newEnd, newGroup, newScore); + } + + /** * Two features are considered equal if they have the same type, group, * description, start, end, phase, strand, and (if present) 'Name', ID' and * 'Parent' attributes. diff --git a/src/jalview/gui/FeatureRenderer.java b/src/jalview/gui/FeatureRenderer.java index ac56590..5c7bd4e 100644 --- a/src/jalview/gui/FeatureRenderer.java +++ b/src/jalview/gui/FeatureRenderer.java @@ -448,8 +448,8 @@ public class FeatureRenderer extends * (to ensure integrity of SequenceFeatures data store) */ sequences.get(0).deleteFeature(sf); - SequenceFeature newSf = new SequenceFeature(sf, newBegin, newEnd, - enteredGroup, sf.getScore()); + SequenceFeature newSf = new SequenceFeature(sf, enteredType, + newBegin, newEnd, enteredGroup, sf.getScore()); sf.setDescription(enteredDescription); ffile.parseDescriptionHTML(newSf, false); // amend features dialog only updates one sequence at a time diff --git a/test/jalview/datamodel/SequenceFeatureTest.java b/test/jalview/datamodel/SequenceFeatureTest.java index d105cc5..fbeb365 100644 --- a/test/jalview/datamodel/SequenceFeatureTest.java +++ b/test/jalview/datamodel/SequenceFeatureTest.java @@ -42,7 +42,7 @@ public class SequenceFeatureTest } @Test(groups = { "Functional" }) - public void testCopyConstructor() + public void testCopyConstructors() { SequenceFeature sf1 = new SequenceFeature("type", "desc", 22, 33, 12.5f, "group"); @@ -56,10 +56,41 @@ public class SequenceFeatureTest assertEquals("desc", sf2.getDescription()); assertEquals(22, sf2.getBegin()); assertEquals(33, sf2.getEnd()); + assertEquals(12.5f, sf2.getScore()); assertEquals("+", sf2.getValue("STRAND")); assertEquals("Testing", sf2.getValue("Note")); // shallow clone of otherDetails map - contains the same object values! assertSame(count, sf2.getValue("Count")); + + /* + * copy constructor modifying begin/end/group/score + */ + SequenceFeature sf3 = new SequenceFeature(sf1, 11, 14, "group2", 17.4f); + assertEquals("type", sf3.getType()); + assertEquals("desc", sf3.getDescription()); + assertEquals(11, sf3.getBegin()); + assertEquals(14, sf3.getEnd()); + assertEquals(17.4f, sf3.getScore()); + assertEquals("+", sf3.getValue("STRAND")); + assertEquals("Testing", sf3.getValue("Note")); + // shallow clone of otherDetails map - contains the same object values! + assertSame(count, sf3.getValue("Count")); + + /* + * copy constructor modifying type/begin/end/group/score + */ + SequenceFeature sf4 = new SequenceFeature(sf1, "Disulfide bond", 12, + 15, "group3", -9.1f); + assertEquals("Disulfide bond", sf4.getType()); + assertTrue(sf4.isContactFeature()); + assertEquals("desc", sf4.getDescription()); + assertEquals(12, sf4.getBegin()); + assertEquals(15, sf4.getEnd()); + assertEquals(-9.1f, sf4.getScore()); + assertEquals("+", sf4.getValue("STRAND")); + assertEquals("Testing", sf4.getValue("Note")); + // shallow clone of otherDetails map - contains the same object values! + assertSame(count, sf4.getValue("Count")); } /** -- 1.7.10.2