From: Diane Trout Date: Fri, 15 Sep 2006 00:48:10 +0000 (+0000) Subject: report our "start/stop" location on a subsequence X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=commitdiff_plain;h=300dcbd19171a4bfd300afb3cc8344f20825c139 report our "start/stop" location on a subsequence this should be useful for trying to use sequences as a replacement for the annotation class. of course ticket:129 is a problem. I need to figure out how to get the start/stop coordinates to be relative to the immediate parent, not relative to the base sequence. (Or perhaps i should be able to retrieve both versions) --- diff --git a/alg/sequence.cpp b/alg/sequence.cpp index f1c7a71..0be6659 100644 --- a/alg/sequence.cpp +++ b/alg/sequence.cpp @@ -653,6 +653,16 @@ bool Sequence::empty() const return (seq_count == 0) ? true : false; } +Sequence::size_type Sequence::start() const +{ + return seq_start; +} + +Sequence::size_type Sequence::stop() const +{ + return seq_start + seq_count; +} + Sequence::size_type Sequence::size() const { return seq_count; diff --git a/alg/sequence.hpp b/alg/sequence.hpp index 6ad8320..4a99e70 100644 --- a/alg/sequence.hpp +++ b/alg/sequence.hpp @@ -157,6 +157,10 @@ public: size_type size() const; //! alias for size (used by string) size_type length() const; + //! start position relative to "base" sequence + size_type start() const; + //! one past the last position relative to "base" sequence + size_type stop() const; //! return a subsequence, copying over any appropriate annotation Sequence subseq(int start=0, int count = std::string::npos) const; diff --git a/alg/test/test_sequence.cpp b/alg/test/test_sequence.cpp index c6a4ca6..e8b35ad 100644 --- a/alg/test/test_sequence.cpp +++ b/alg/test/test_sequence.cpp @@ -93,6 +93,36 @@ BOOST_AUTO_TEST_CASE( subseq_names ) BOOST_CHECK_EQUAL(s2.get_fasta_header(), s1.get_fasta_header()); } +BOOST_AUTO_TEST_CASE( sequence_start_stop ) +{ + Sequence s1; + BOOST_CHECK_EQUAL( s1.start(), 0 ); + BOOST_CHECK_EQUAL( s1.stop(), 0 ); + + std::string seq_string("AAGGCCTT"); + Sequence s2(seq_string); + BOOST_CHECK_EQUAL( s2.start(), 0 ); + BOOST_CHECK_EQUAL( s2.stop(), seq_string.size() ); + + std::string s3seq_string = seq_string.substr(2,3); + Sequence s3 = s2.subseq(2,3); + BOOST_CHECK_EQUAL( s3.start(), 2); + BOOST_CHECK_EQUAL( s3.stop(), 2+3); + BOOST_CHECK_EQUAL( s3.size(), 3); + BOOST_CHECK_EQUAL( s3, s3seq_string); + + // FIXME: updated for ticket:129 + // once I have a solution for ticket:129 the commented + // out version should work. + //std::string s4seq_string = s3seq_string.substr(1,1); + std::string s4seq_string = seq_string.substr(1,1); + Sequence s4 = s2.subseq(1,1); + BOOST_CHECK_EQUAL( s4.start(), 1 ); + BOOST_CHECK_EQUAL( s4.stop(), 1+1); + BOOST_CHECK_EQUAL( s4.size(), 1); + BOOST_CHECK_EQUAL( s4, s4seq_string); +} + //! Can we load data from a file BOOST_AUTO_TEST_CASE( sequence_load ) {