JAL-2110 additional tests for setDatasetSequence, javadoc for isProtein
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 3 Oct 2016 15:10:21 +0000 (16:10 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Mon, 3 Oct 2016 15:10:21 +0000 (16:10 +0100)
src/jalview/datamodel/Sequence.java
src/jalview/datamodel/SequenceI.java
test/jalview/datamodel/SequenceTest.java

index 29d114d..68c8c50 100755 (executable)
@@ -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;
   };
index a29e2ba..49ddf86 100755 (executable)
@@ -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();
 
index 0c401e2..25804bc 100644 (file)
@@ -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);
+  }
 }