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>
24 // Sequence data class
26 //! Attach annotation information to a sequence track
30 annot(int start, int end, std::string type, std::string name);
38 friend bool operator==(const annot& left, const annot& right);
41 /* The way that motifs are found currently doesn't really
42 * indicate that the match was a reverse compliment
44 struct motif : public annot
48 //! this constructor is for when we're adding motifs to our annotations
49 motif(int start, std::string motif);
53 //! sequence track for mussa.
54 class Sequence : public std::string
60 std::list<annot> annots;
61 //! a seperate list for motifs since we're currently not saving them
62 std::list<motif> motif_list;
64 void motif_scan(std::string a_motif, std::vector<int> * motif_match_starts);
65 std::string rc_motif(std::string a_motif);
66 //! look for a string sequence type and and it to an annotation list
67 void add_string_annotation(std::string a_seq, std::string name);
72 Sequence(const char* seq);
73 Sequence(const std::string& seq);
74 Sequence(const Sequence& seq);
75 //! assignment to constant sequences
76 Sequence &operator=(const Sequence&);
78 //! set sequence to a (sub)string containing nothing but AGCTN
79 void set_filtered_sequence(const std::string& seq,
80 std::string::size_type start=0,
81 std::string::size_type count=0);
83 //! load sequence AGCT from fasta file
84 //! \throw mussa_load_error
85 //! \throw sequence_empty_error
86 //! \throw sequence_empty_file_error
87 void load_fasta(const boost::filesystem::path file_path, int seq_num=1,
88 int start_index=0, int end_index=0);
89 //! load sequence from stream
90 //! \throw mussa_load_error
91 //! \throw sequence_empty_error
92 //! \throw sequence_empty_file_error
93 void load_fasta(std::iostream& file, int seq_num=1,
94 int start_index=0, int end_index=0);
95 //! load sequence annotations
96 //! \throws mussa_load_error
97 void load_annot(const boost::filesystem::path file_path, int start_index, int end_index);
98 //! load sequence annotations
99 //! \throws mussa_load_error
100 void load_annot(std::fstream& data_stream, int start_index, int end_index);
101 void parse_annot(std::string data, int start_index, int end_index);
102 //! add an annotation to our list of annotations
103 void add_annotation(const annot& a);
104 const std::list<annot>& annotations() const;
105 const std::list<motif>& motifs() const;
106 void set_species(const std::string &);
107 const std::string& get_species() const;
109 //! return a subsequence, copying over any appropriate annotation
110 Sequence subseq(int start=0, int count = std::string::npos) const;
111 //! return a reverse compliment
112 std::string rev_comp() const;
114 //! clear the sequence and its annotations
117 void set_header(std::string header);
118 std::string get_header() const;
119 //! add a motif to our list of motifs
120 //! \throws motif_normalize_error if there's something wrong with a_motif
121 void add_motif(const Sequence& a_motif);
122 //! clear our list of found motifs
124 //! search a sequence for a_motif
125 //! \throws motif_normalize_error if there's something wrong with a_motif
126 std::vector<int> find_motif(std::string a_motif);
127 //! convert IUPAC symbols to upperase
128 //! \throws motif_normalize_error if there is an invalid symbol
129 static std::string motif_normalize(std::string a_motif);
131 //! annotate the current sequence with other sequences
132 void find_sequences(std::list<Sequence>::iterator start,
133 std::list<Sequence>::iterator end);
135 void save(boost::filesystem::fstream &save_file);
136 void load_museq(boost::filesystem::path load_file_path, int seq_num);