Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SequenceAlignment.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 SequenceAlignment.hh
11 /// @brief class definition for a multiple sequence alignment
12 /// @author James Thompson
13 
14 #ifndef INCLUDED_core_sequence_SequenceAlignment_hh
15 #define INCLUDED_core_sequence_SequenceAlignment_hh
16 
17 // C/C++ headers
18 // AUTO-REMOVED #include <functional>
19 // AUTO-REMOVED #include <iostream>
20 #include <map>
21 #include <string>
22 
23 // External headers
24 #include <boost/functional/hash.hpp>
25 
26 // Utility headers
27 #include <utility/vector1_bool.hh>
28 #include <utility/pointer/ReferenceCount.hh>
29 
30 // Project headers
31 #include <core/types.hh>
33 
34 // Package headers
38 
39 #include <utility/vector1.hh>
40 
41 
42 namespace core {
43 namespace sequence {
44 
46 public:
47  /// @brief ctor
49 
50  /// @brief dtor
51  //@brief Autogenerated destructor definition
52  virtual ~SequenceAlignment();
53 
54 // ~SequenceAlignment() {
55 // clear();
56 // }
57 
59  return new SequenceAlignment( *this );
60  }
61 
62  void clear() {
63  comments_.clear();
64  sequences_.clear();
65  }
66 
67  void add_sequence( SequenceOP myseq );
68 
69  /// @brief Returns the number of sequences.
70  Size size() const;
71 
72  /// @brief Returns the length of all sequences in this SequenceAlignment.
73  Size length() const;
74 
75  SequenceOP sequence( Size idx ) const;
76 
77  std::string to_string() const;
78  void read_data( std::istream & in );
79 
80  /// @brief Accessors for the score of this SequenceAlignment.
81  void score( Real const & sc );
82  Real score() const;
83  Real score( std::string const & name ) const;
84  void score( std::string const & name, Real const value );
85  std::map< std::string, core::Real > scores() const;
86  void scores( std::map< std::string, core::Real > new_scores );
87 
88  /// @brief initialize this SequenceAlignment object from the
89  /// given file.
90  void read_from_file( std::string const & filename );
91 
92  /// @brief returns a SequenceMapping of the sequence at index
93  /// idx1 mapped to the sequence at idx2.
95  core::Size const idx1,
96  core::Size const idx2
97  ) const;
98 
99  /// @brief Removes positions that are gapped in all
100  /// columns of the alignment.
102 
103  /// @brief calculates the score of this alignment under
104  /// the given ScoringScheme by summing up all of pairwise
105  /// alignment scores between all pairs of sequence.
107 
108  /// @brief calculates pairwise scores similar to
109  /// calculate_score_sum_of_pairs.
112 
113  /// @brief Returns true if all of the sequences are
114  /// "in-frame," which means that residue x in the first
115  /// sequence maps to residue x in all other sequences.
116  /// This method intentionally ignores any sequence at the
117  /// position where that sequence has a gap.
118  bool sequences_are_in_frame() const;
119 
120  /// @brief Returns a vector1 of the sequence indices in
121  /// the given column of the SequenceAlignment that are
122  /// calculated using the Sequence resnum() method.
124  core::Size const column
125  ) const;
126 
127  /// @brief getter/setters for comments
128  void comment( std::string const & comment );
130 
131  void data_integrity_check() const;
132 
133  /// @brief Returns the number of positions at which all
134  // of the characters are the same, ignoring gaps.
135  Size identities() const;
136 
137  /// @brief Returns the number of positions in the
138  /// SequenceAlignment with at least one gap.
139  Size gapped_positions() const;
140 
141  /// @brief Returns the number of gaps contained by
142  /// the sequence in the alignment with the most gaps.
143  Real max_gap_percentage() const;
144 
145  /// @brief Returns true if the given alignment column index is gapped,
146  /// false otherwise.
147  bool is_gapped( Size const col_idx ) const;
148 
149  /// @brief this gives the id of the second sequence
150  /// --- in a typical alignment it is 1) query, 2) template
151  std::string alignment_id() const;
152 
153  /// @brief copy constructor
154  SequenceAlignment( SequenceAlignment const & src );
155 
156  /// @brief assignment operator
158  operator=( SequenceAlignment const & src );
159 
160  /// @brief Equality operator
161  bool operator==(const SequenceAlignment& other) const {
162  if ( alignment_id() != other.alignment_id() ) return false;
163  if ( size() != other.size() ) return false;
164 
165  using core::Size;
166  for ( Size ii = 1, end = size(); ii <= end; ++ii ) {
167  if ( ! (*sequence(ii) == *other.sequence(ii)) ) return false;
168  }
169 
170  return sequence_mapping(1,2) == other.sequence_mapping(1,2);
171  }
172 
173  /// @brief Less-than operator. Usd for storing SequenceAlignment objects in a
174  /// std::set.
175  friend bool
176  operator<(
177  SequenceAlignment const & lhs,
178  SequenceAlignment const & rhs
179  );
180 
181 public: // output operators
182 
183  /// @brief Print SequenceAlignment object to the given
184  /// std::ostream.
185  friend std::ostream & operator << (
186  std::ostream & out,
187  const SequenceAlignment & sa
188  );
189 
190  friend std::istream & operator>>(
191  std::istream & in,
192  SequenceAlignment & aln
193  );
194 
195  void printGrishinFormat (
196  std::ostream & out
197  ) const;
198 
199 private:
202  std::map< std::string, core::Real > scores_;
203 }; // class SequenceAlignment
204 
205 
206 /// @class Computes a hash value for a SequenceAlignment based on its sequences.
207 /// Allows SequenceAlignment's to be used as keys in unordered_{set|map}.
208 struct SequenceAlignmentHasher : std::unary_function<SequenceAlignment, size_t> {
209  size_t operator()(const SequenceAlignment& alignment) const {
210  size_t h = 0;
211  for (core::Size i = 1; i <= alignment.size(); ++i)
212  boost::hash_combine(h, alignment.sequence(i)->sequence());
213 
214  return h;
215  }
216 };
217 
218 } // sequence
219 } // core
220 
221 #endif