Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Sequence.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file Sequence.hh
11 /// @brief class definition for a sequence
12 /// @author James Thompson
13 
14 #ifndef INCLUDED_core_sequence_Sequence_hh
15 #define INCLUDED_core_sequence_Sequence_hh
16 
17 // Unit headers
19 
20 // Project headers
21 #include <core/types.hh>
22 #include <core/pose/Pose.fwd.hh>
23 
24 // Utility headers
25 #include <utility/file/FileName.fwd.hh>
26 #include <utility/pointer/ReferenceCount.hh>
27 
28 // C++ headers
29 // AUTO-REMOVED #include <iostream>
30 
31 #include <string>
32 
33 #include <utility/vector1.hh>
34 
35 
36 namespace core {
37 namespace sequence {
38 
40 
41 public:
42 
43  /// @brief ctor
44  Sequence() : id_( "blank" ), start_( 1 ), gap_char_('-') {}
46  id_( id ),
47  start_( start ),
48  gap_char_('-')
49  {
50  sequence( seq );
51  }
52 
53  Sequence( core::pose::Pose const & pose );
54 
55  /// @brief copy constructor.
56  Sequence( Sequence const & src ) :
57  ReferenceCount()
58  {
59  *this = src;
60  }
61 
62 public: // virtual functions
63  /// @brief dtor
64  virtual ~Sequence();
65 
66  /// @brief Returns an owning pointer to a copy of this sequence.
67  virtual SequenceOP clone() const;
68 
69  /// @brief initializes this sequence object from a file.
70  virtual void read_from_file( utility::file::FileName const & /*fn*/ );
71 
72  /// @brief Returns the number of characters in this object.
73  virtual core::Size length() const;
74  /// @brief Inserts a character at the given position.
75 
76  virtual void insert_char( core::Size pos, char new_char );
77 
78  /// @brief Deletes the given position from the Sequence and shifts
79  /// everything else back by one.
80  virtual void delete_position( core::Size pos );
81 
82  virtual std::string to_string() const;
83 
84  virtual std::string type() const;
85 
86 public: // non-virtual functions
87 
88  /// @brief sets sequence to the given value.
90 
91  /// @brief sets id to the given value.
92  void id ( std::string new_id );
93 
94  /// @brief sets starting index to the given value.
95  void start ( core::Size new_start );
96 
97  /// @brief sets gap_char to the given value.
98  void gap_char( char gap_char );
99 
100  /// @brief Returns the number of characters in this object, ignoring gaps.
101  core::Size ungapped_length() const;
102 
103  /// @brief Returns the start of this object.
104  core::Size start() const;
105 
106  /// @brief Returns the id of this object.
107  std::string id() const;
108 
109  /// @brief Returns the character used to represent a gap for this object.
110  char gap_char() const;
111 
112  /// @brief Returns the string representing this sequence without gaps.
114 
115  /// @brief Returns the full sequence, which may include gaps.
116  std::string sequence() const;
117 
118  /// @brief assignment operator.
119  Sequence & operator = ( Sequence const & rhs ) {
120  if ( this == &rhs ) return *this;
121 
122  start_ = rhs.start();
123  id_ = rhs.id();
124  gap_char_ = rhs.gap_char();
125  seq_ = rhs.sequence();
126 
127  return *this;
128  }
129 
130  /// @brief Returns true if this Sequence object's id is lexicographically
131  /// less than the given Sequence object's id, returns false otherwise. Uses
132  /// C++ string < operator to compare this Sequence object's id() to the
133  /// given Sequence object's id().
134  inline bool operator < ( const Sequence & s ) const {
135  return id() < s.id();
136  }
137 
138  /// @brief Returns true if the given Sequence object is equal to this
139  /// Sequence object. Tests for string equality of id(), start(), and
140  /// sequence(), and returns false if any of these are not equal.
141  inline bool operator == ( const Sequence & s ) const {
142  return (
143  id() == s.id() &&
144  start() == s.start() &&
145  sequence() == s.sequence()
146  );
147  }
148 
149  /// @brief Returns the character at the given sequence position.
150  char operator[]( core::Size pos ) const;
151  char at( core::Size pos ) const;
152 
153 
154  /// @brief Inserts a gap at the given position, where insert_gap( 0 )
155  /// inserts the character at the beginning of the sequence, and
156  /// insert_gap( length() ) inserts the character at the end of the
157  /// sequence.
158  void insert_gap( core::Size pos );
159 
160  /// @brief Append a character
161  void append_char( char new_char );
162 
163  /// @brief Append a gap
164  void append_gap( );
165 
166  /// @brief Returns true if this position in the sequence represents a gap,
167  /// returns false otherwise.
168  bool is_gap( core::Size pos ) const;
169 
170  /// @brief Initializes the information in this sequence from the given
171  /// std::istream. The istream should yield three pieces of information in
172  /// the following order:
173  /// - id
174  /// - start
175  /// - sequence
176 
177  void read_data( std::istream & in );
178 
179  /// @brief Returns the index of the given sequence position, which is the
180  /// position in the sequence minus any gaps that occur earlier in the
181  /// sequence. For example, if the sequence is ---AT, resnum(5) will return 2.
182  /// Returns 0 for unaligned positions.
183  core::Size resnum( core::Size idx ) const;
184 
185  /// @brief Prints the information a given Sequence object to the given
186  /// std::ostream.
187  friend std::ostream & operator<<( std::ostream & out, const Sequence & seq );
188 
189  /// @brief Prints the information a given Sequence object to the given
190  /// std::ostream.
191  friend std::ostream & operator<<( std::istream & out, Sequence & seq );
192  friend std::istream & operator>>( std::istream & in, Sequence & seq );
193 
194 private:
197  char gap_char_;
198 
200 }; // class Sequence
201 
202 } // sequence
203 } // core
204 
205 #endif