report our "start/stop" location on a subsequence
authorDiane Trout <diane@caltech.edu>
Fri, 15 Sep 2006 00:48:10 +0000 (00:48 +0000)
committerDiane Trout <diane@caltech.edu>
Fri, 15 Sep 2006 00:48:10 +0000 (00:48 +0000)
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)

alg/sequence.cpp
alg/sequence.hpp
alg/test/test_sequence.cpp

index f1c7a7132ab75d6cd0cc12a9ec5974cc764d0d29..0be66593c303e6191a7eea87ddd6272472a11445 100644 (file)
@@ -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;
index 6ad83206b994f9b8e51d3da2b30063984b3a5055..4a99e708be9e0767ef76e0af2e05f8aed4be44db 100644 (file)
@@ -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;
index c6a4ca6346afdefec6eedf926b22e31c00dc4e2e..e8b35ad823d4e3ca96542db6ff0f1a2cce65bcd2 100644 (file)
@@ -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 )
 {