Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AnnotatedSequence.cc
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 src/core/sequence/AnnotatedSequence.cc
11 /// @brief
12 /// @author Oliver Lange
13 
14 // C/C++ headers
15 #include <string>
16 #include <map>
17 
18 #include <core/chemical/AA.hh>
19 // unit headers
20 
22 
23 #include <utility/exit.hh>
24 
25 namespace core {
26 namespace sequence {
27 
29  : map_is_clean_( true )
30 {}
31 
33  : std::string( str_in ),
34  map_is_clean_( false )
35 {}
36 
38  std::string( other ),
39  pos_map_( other.pos_map_ ),
40  map_is_clean_( other.map_is_clean_ )
41 {}
42 
44  if ( this==&other ) return *this;
45  std::string::operator=( other );
47  pos_map_ = other.pos_map_;
48  return *this;
49 }
50 
52  std::string::operator=( other );
53  map_is_clean_ = false;
54 }
55 
56 //@brief sequence position is patched
58  if ( !map_is_clean_ ) calculate_map();
59  runtime_assert( seqpos <= pos_map_.size() );
60  Size apos( pos_map_[ seqpos ] );
61  std::string const& annotated_seq = *this;
62  if ( apos < annotated_seq.length()-1 ) {
63  return annotated_seq[ apos+1 ]=='[';
64  }
65  return false;
66 }
67 
68 //@brief return the string within the [ ] or ""
70  if ( !map_is_clean_ ) calculate_map();
71  runtime_assert( seqpos <= pos_map_.size() );
72  Size apos( pos_map_[ seqpos ] );
73  std::string const& annotated_seq = *this;
74  std::string patch_txt;
75  if ( apos < annotated_seq.length()-2 ) {
76  if ( !annotated_seq[ apos+1 ]=='[' ) return "";
77  for ( Size i = apos+2; i < annotated_seq.length() && annotated_seq[ i ]!= ']'; ++i ) {
78  patch_txt = patch_txt + annotated_seq[ i ];
79  }
80  }
81  return patch_txt;
82 }
83 
85  if ( !map_is_clean_ ) calculate_map();
86  runtime_assert( seqpos <= pos_map_.size() );
87  Size apos( pos_map_[ seqpos ] );
88  std::string const& annotated_seq = *this;
89  return annotated_seq[ apos ];
90 }
91 
94 }
95 
97  std::string const& annotated_seq = *this;
98  std::string sequence("");
99  bool in_bracket = false;
100  for ( Size i = 0, ie = annotated_seq.length(); i < ie; ++i ) {
101  char c = annotated_seq[i];
102  if ( c == '[' ) {
103  in_bracket = true;
104  continue;
105  } else if ( c == ']' ) {
106  in_bracket = false;
107  continue;
108  } else {
109  if ( in_bracket ) {
110  continue;
111  } else {
112  sequence = sequence + c;
113  }
114  }
115  }
116  runtime_assert( !in_bracket );
117  return sequence;
118 }
119 
121  if ( map_is_clean_ ) return;
122  map_is_clean_ = true;
123 
124  std::string const& annotated_seq = *this;
125  bool in_bracket = false;
126  pos_map_.clear();
127  pos_map_.reserve( annotated_seq.length() ); //a little more ... but avoiding resizing...
128  for ( Size i = 0, ie = annotated_seq.length(); i < ie; ++i ) {
129  char c = annotated_seq[i];
130  if ( c == '[' ) {
131  in_bracket = true;
132  continue;
133  } else if ( c == ']' ) {
134  in_bracket = false;
135  continue;
136  } else {
137  if ( in_bracket ) {
138  continue;
139  } else {
140  pos_map_.push_back( i );
141  }
142  }
143  }
144 }
145 
146 
147 }
148 }