From bc02849268c0a7ffda386ec00658b3411029b5e5 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 3 Oct 2016 16:10:21 +0100 Subject: [PATCH] JAL-2110 additional tests for setDatasetSequence, javadoc for isProtein --- src/jalview/datamodel/Sequence.java | 11 ++++++++--- src/jalview/datamodel/SequenceI.java | 5 ++++- test/jalview/datamodel/SequenceTest.java | 20 +++++++++++++++++++- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 29d114d..68c8c50 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -22,6 +22,7 @@ package jalview.datamodel; import jalview.analysis.AlignSeq; import jalview.api.DBRefEntryI; +import jalview.util.Comparison; import jalview.util.DBRefUtils; import jalview.util.MapList; import jalview.util.StringUtils; @@ -1013,12 +1014,12 @@ public class Sequence extends ASequence implements SequenceI { if (seq == this) { - throw new Error( + throw new IllegalArgumentException( "Implementation Error: self reference passed to SequenceI.setDatasetSequence"); } if (seq != null && seq.getDatasetSequence() != null) { - throw new Error( + throw new IllegalArgumentException( "Implementation error: cascading dataset sequences are not allowed."); } datasetSequence = seq; @@ -1117,6 +1118,10 @@ public class Sequence extends ASequence implements SequenceI private long _seqhash = 0; + /** + * Answers false if the sequence is more than 85% nucleotide (ACGTU), else + * true + */ @Override public boolean isProtein() { @@ -1127,7 +1132,7 @@ public class Sequence extends ASequence implements SequenceI if (_seqhash != sequence.hashCode()) { _seqhash = sequence.hashCode(); - _isNa=jalview.util.Comparison.isNucleotide(new SequenceI[] { this }); + _isNa = Comparison.isNucleotide(this); } return !_isNa; }; diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index a29e2ba..49ddf86 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -217,8 +217,11 @@ public interface SequenceI extends ASequenceI public int[] findPositionMap(); /** + * Answers true if the sequence is composed of amino acid characters. Note + * that implementations may use heuristic methods which are not guaranteed to + * give the biologically 'right' answer. * - * @return true if sequence is composed of amino acid characters + * @return */ public boolean isProtein(); diff --git a/test/jalview/datamodel/SequenceTest.java b/test/jalview/datamodel/SequenceTest.java index 0c401e2..25804bc 100644 --- a/test/jalview/datamodel/SequenceTest.java +++ b/test/jalview/datamodel/SequenceTest.java @@ -370,7 +370,7 @@ public class SequenceTest { sq.getDatasetSequence().setDatasetSequence(sq); // loop! Assert.fail("Expected Error to be raised when calling setDatasetSequence with self reference"); - } catch (Error e) + } catch (IllegalArgumentException e) { // TODO Jalview error/exception class for raising implementation errors assertTrue(e.getMessage().toLowerCase() @@ -980,4 +980,22 @@ public class SequenceTest assertEquals(4, seq.getAllPDBEntries().size()); assertSame(pdbe5, seq.getAllPDBEntries().get(3)); } + + @Test( + groups = { "Functional" }, + expectedExceptions = { IllegalArgumentException.class }) + public void testSetDatasetSequence_toSelf() + { + seq.setDatasetSequence(seq); + } + + @Test( + groups = { "Functional" }, + expectedExceptions = { IllegalArgumentException.class }) + public void testSetDatasetSequence_cascading() + { + SequenceI seq2 = new Sequence("Seq2", "xyz"); + seq2.createDatasetSequence(); + seq.setDatasetSequence(seq2); + } } -- 1.7.10.2