From: Jim Procter Date: Thu, 23 Jun 2016 13:01:36 +0000 (+0100) Subject: JAL-2110 SequenceI.isProtein method X-Git-Tag: Release_2_10_0~140^2~5^2~47 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=63c08febd1f76249b308628611857b9698baaf8d;p=jalview.git JAL-2110 SequenceI.isProtein method --- diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 151d8c4..31ffdfd 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -1086,6 +1086,25 @@ public class Sequence extends ASequence implements SequenceI return new Sequence(this); } + private boolean _isNa; + + private long _seqhash = 0; + + @Override + public boolean isProtein() + { + if (datasetSequence != null) + { + return datasetSequence.isProtein(); + } + if (_seqhash != sequence.hashCode()) + { + _seqhash = sequence.hashCode(); + _isNa=jalview.util.Comparison.isNucleotide(new SequenceI[] { this }); + } + return !_isNa; + }; + /* * (non-Javadoc) * diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index 69eb1d4..355e271 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -219,6 +219,12 @@ public interface SequenceI extends ASequenceI public int[] findPositionMap(); /** + * + * @return true if sequence is composed of amino acid characters + */ + public boolean isProtein(); + + /** * Delete a range of aligned sequence columns, creating a new dataset sequence * if necessary and adjusting start and end positions accordingly. * diff --git a/test/jalview/datamodel/SequenceTest.java b/test/jalview/datamodel/SequenceTest.java index 17dfcdc..5c5c5c3 100644 --- a/test/jalview/datamodel/SequenceTest.java +++ b/test/jalview/datamodel/SequenceTest.java @@ -65,6 +65,20 @@ public class SequenceTest assertEquals("Gap interval 2 end wrong", 8, gapInt.get(1)[1]); } + @Test(groups = ("Functional")) + public void testIsProtein() + { + // test Protein + assertTrue(new Sequence("prot","ASDFASDFASDF").isProtein()); + // test DNA + assertFalse(new Sequence("prot","ACGTACGTACGT").isProtein()); + // test RNA + SequenceI sq = new Sequence("prot","ACGUACGUACGU"); + assertFalse(sq.isProtein()); + // change sequence, should trigger an update of cached result + sq.setSequence("ASDFASDFADSF"); + assertTrue(sq.isProtein()); + } @Test(groups = { "Functional" }) public void testGetAnnotation() { @@ -388,6 +402,20 @@ public class SequenceTest } /** + * test createDatasetSequence behaves to doc + */ + @Test(groups = { "Functional" }) + public void testCreateDatasetSequence() + { + SequenceI sq = new Sequence("my","ASDASD"); + assertNull(sq.getDatasetSequence()); + SequenceI rds = sq.createDatasetSequence(); + assertNotNull(rds); + assertNull(rds.getDatasetSequence()); + assertEquals(sq.getDatasetSequence(), rds); + } + + /** * Test for deriveSequence applied to a sequence with a dataset */ @Test(groups = { "Functional" })