1 #ifndef _MUSSA_SEQUENCE_H_
2 #define _MUSSA_SEQUENCE_H_
3 // This file is part of the Mussa source distribution.
4 // http://mussa.caltech.edu/
5 // Contact author: Tristan De Buysscher, tristan@caltech.edu
7 // This program and all associated source code files are Copyright (C) 2005
8 // the California Institute of Technology, Pasadena, CA, 91125 USA. It is
9 // under the GNU Public License; please see the included LICENSE.txt
10 // file for more information, or contact Tristan directly.
13 // ----------------------------------------
14 // ---------- sequence.hh -----------
15 // ----------------------------------------
17 #include <boost/filesystem/path.hpp>
18 #include <boost/filesystem/fstream.hpp>
20 #include <boost/serialization/base_object.hpp>
21 #include <boost/serialization/list.hpp>
22 #include <boost/serialization/string.hpp>
23 #include <boost/serialization/utility.hpp>
24 #include <boost/serialization/export.hpp>
31 // Sequence data class
33 //! Attach annotation information to a sequence track
37 annot(int begin, int end, std::string type, std::string name);
45 friend bool operator==(const annot& left, const annot& right);
47 // boost::serialization support
48 friend class boost::serialization::access;
49 template<class Archive>
50 void serialize(Archive& ar, const unsigned int /*version*/) {
57 BOOST_CLASS_EXPORT(annot);
60 /* The way that motifs are found currently doesn't really
61 * indicate that the match was a reverse compliment
63 struct motif : public annot
67 motif() : annot(), sequence("") {};
68 //! this constructor is for when we're adding motifs to our annotations
69 motif(int begin, std::string motif);
72 // boost::serialization support
74 friend class boost::serialization::access;
75 template<class Archive>
76 void motif::serialize(Archive& ar, const unsigned int /*version*/) {
77 ar & boost::serialization::base_object<annot>(*this);
81 BOOST_CLASS_EXPORT(motif);
83 //! sequence track for mussa.
84 class Sequence : public std::string
90 std::list<annot> annots;
91 //! a seperate list for motifs since we're currently not saving them
92 std::list<motif> motif_list;
94 void motif_scan(std::string a_motif, std::vector<int> * motif_match_starts);
95 std::string rc_motif(std::string a_motif);
96 //! look for a string sequence type and and it to an annotation list
97 void add_string_annotation(std::string a_seq, std::string name);
99 // boost::serialization support
100 friend class boost::serialization::access;
101 template<class Archive>
102 void serialize(Archive& ar, const unsigned int /*version*/) {
103 ar & boost::serialization::base_object<std::string>(*this);
113 Sequence(const char* seq);
114 Sequence(const std::string& seq);
115 Sequence(const Sequence& seq);
116 //! assignment to constant sequences
117 Sequence &operator=(const Sequence&);
119 //! set sequence to a (sub)string containing nothing but AGCTN
120 void set_filtered_sequence(const std::string& seq,
121 std::string::size_type start=0,
122 std::string::size_type count=0);
124 //! load sequence AGCT from fasta file
125 //! \throw mussa_load_error
126 //! \throw sequence_empty_error
127 //! \throw sequence_empty_file_error
128 void load_fasta(const boost::filesystem::path file_path, int seq_num=1,
129 int start_index=0, int end_index=0);
130 //! load sequence from stream
131 //! \throw mussa_load_error
132 //! \throw sequence_empty_error
133 //! \throw sequence_empty_file_error
134 void load_fasta(std::iostream& file, int seq_num=1,
135 int start_index=0, int end_index=0);
136 //! load sequence annotations
137 //! \throws mussa_load_error
138 void load_annot(const boost::filesystem::path file_path, int start_index, int end_index);
139 //! load sequence annotations
140 //! \throws mussa_load_error
141 void load_annot(std::fstream& data_stream, int start_index, int end_index);
142 bool parse_annot(std::string data, int start_index=0, int end_index=0);
143 //! add an annotation to our list of annotations
144 void add_annotation(const annot& a);
145 const std::list<annot>& annotations() const;
146 const std::list<motif>& motifs() const;
148 //! return a subsequence, copying over any appropriate annotation
149 Sequence subseq(int start=0, int count = std::string::npos) const;
150 //! return a reverse compliment
151 std::string rev_comp() const;
153 //! clear the sequence and its annotations
157 void set_species(const std::string &);
159 std::string get_species() const;
160 //! set the fasta header
161 void set_fasta_header(std::string header);
162 //! get the fasta header
163 std::string get_fasta_header() const;
164 //! get name (will return the first non-empty, of fasta_header, species)
165 std::string get_name() const;
167 //! add a motif to our list of motifs
168 //! \throws motif_normalize_error if there's something wrong with a_motif
169 void add_motif(const Sequence& a_motif);
170 //! clear our list of found motifs
172 //! search a sequence for a_motif
173 //! \throws motif_normalize_error if there's something wrong with a_motif
174 std::vector<int> find_motif(std::string a_motif);
175 //! convert IUPAC symbols to upperase
176 //! \throws motif_normalize_error if there is an invalid symbol
177 static std::string motif_normalize(std::string a_motif);
179 //! annotate the current sequence with other sequences
180 void find_sequences(std::list<Sequence>::iterator start,
181 std::list<Sequence>::iterator end);
183 void save(boost::filesystem::fstream &save_file);
184 void load_museq(boost::filesystem::path load_file_path, int seq_num);
187 BOOST_CLASS_EXPORT(Sequence);