1 #ifndef _MUSSA_CLASS_H_
2 #define _MUSSA_CLASS_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 // ---------- mussa_class.hh -----------
15 // ----------------------------------------
18 #include <boost/filesystem/path.hpp>
19 #include <boost/shared_ptr.hpp>
27 #include "alg/annotation_colors.hpp"
28 #include "alg/mussa_callback.hpp"
29 #include "alg/nway_paths.hpp"
30 #include "alg/sequence.hpp"
32 std::string int_to_str(int an_int);
34 class Mussa : public QObject
39 //! call whatever signaling system we want
40 void progress(const std::string& description, int cur, int max);
41 //! triggered when our state changes between unsaved(true) and saved(false)
42 void isModified(bool);
45 typedef std::set<Sequence> motif_set;
46 enum analysis_modes { TransitiveNway, RadialNway, EntropyNway,
53 void save(boost::filesystem::path save_path="");
54 //! save the nway comparison
55 void save_muway(boost::filesystem::path save_path);
56 //! load a saved analysis directory
57 void load(boost::filesystem::path ana_path);
58 // ! return path to the where the analysis is stored
59 boost::filesystem::path get_analysis_path() const;
61 void set_analysis_path(boost::filesystem::path);
63 //! clear parameters and initialize data lists
66 //! set parameters from a file - 'mupa' ~ mussa parameters
67 void load_mupa_file(std::string para_file_path) { load_mupa_file(boost::filesystem::path(para_file_path));}
68 void load_mupa_file(boost::filesystem::path para_file_path);
70 // set parameters individually (eg from user input into gui classes)
72 void set_name(std::string a_name);
73 //! return name for this analysis
74 std::string get_name() const;
75 //! return a reasonable window title for this analysis
76 /*! this returns the "variable" portion for a title
78 std::string get_title() const;
80 //! return number of sequences in this analyzis
81 /*! this returns either the_seqs.size() or seq_files.size()
82 * depending on which has data loaded in
83 * (silly delayed loading of sequence data)
87 //! set number of bases for this window size
88 void set_window(int a_window);
89 //! get number of bases for the sliding window
90 int get_window() const;
91 //! set number of bases that must match for a window to be saved
92 //! if threshold > soft_threshold this also sets soft_threshold
93 void set_threshold(int a_threshold);
94 //! get number of bases that must match for a window to be saved
95 int get_threshold() const;
96 //! sets the threshold used for computing the nway paths
97 //! must be in range [threshold..window size]
98 void set_soft_threshold(int sft_thres);
99 int get_soft_threshold() const;
101 void set_analysis_mode(enum analysis_modes new_ana_mode);
102 enum analysis_modes get_analysis_mode() const;
103 //! return a string name for an analysis mode
104 std::string get_analysis_mode_name() const;
105 //! set our current dirty state
106 void set_dirty(bool);
107 //! return if we have unsaved changes
108 bool is_dirty() const;
109 //! is there anything loaded into this analysis?
112 //! return the refined paths found by the nway analysis.
113 const NwayPaths& paths() const;
115 //! given selected_paths, and view_paths, compute per base pair matches
116 //template <class IteratorT>
117 void createLocalAlignment(std::list<ConservedPath>::iterator begin,
118 std::list<ConservedPath>::iterator end,
119 std::list<ConservedPath::path_type>& result,
120 std::list<std::vector<bool> >& reversed);
122 //! run seqcomp and the nway filtering algorithm.
123 /*!analyze will run seqcomp and then the nway algorithm
124 * on whatever sequences have been loaded into this mussa instance.
125 * \throws mussa_analysis_error
128 /*! Run the nway filtering algorithm,
129 * this might be used when changing the soft threshhold?
133 //! appends a string sequence to the list of the_seqs
134 // void append_sequence(std::string a_seq);
135 //! appends a sequence to the list of the_seqs (makes copy)
136 void append_sequence(const Sequence& a_seq);
137 //! append a sequence to the list of seqs (shared)
138 void append_sequence(boost::shared_ptr<Sequence> a_seq);
140 //! Load a sequence from a fasta file and any annotations
141 /*! \param[in] seq_file the full path to the fasta file
142 * \param[in] annot_file the full path to an annotation file,
143 * if is an empty string, we won't bother loading anything
144 * \param[in] fasta_index specify which sequence in a multisequence fasta
146 * \param[in] sub_seq_start starting slice index to select a subsequence
147 * use 0 start from the beginning.
148 * \param[in] sub_seq_end ending slice index to select a subsequence
149 * use 0 to go to the end.
150 * \param[in] name sequence name, only used if not null
152 void load_sequence(boost::filesystem::path seq_file,
153 boost::filesystem::path annot_file,
154 int fasta_index, int sub_seq_start=0, int sub_seq_end=0,
155 std::string *name=0);
156 //! allow examining the sequences we have loaded
157 typedef std::vector<boost::shared_ptr<Sequence> > vector_sequence_type;
158 const vector_sequence_type& sequences() const;
160 // deprecated - support bridge for python version of mussa
161 // these save & load from the old file format
163 void load_old(char * load_file_path, int s_num);
165 // manage motif lists
166 //! add a motif it wont be applied until update_sequences_motif is called
167 void add_motif(const Sequence& motifs, const Color& colors);
168 //! add vector of motifs and colors to our motif collection
169 /*! this will automatically call update_sequences_motif
170 * this depends on sets and color maps being unique
171 * (aka if you add the same item more than once it doesn't
172 * increase the size of the data structure)
174 void set_motifs(const std::vector<Sequence>& motifs,
175 const std::vector<Color>& colors);
176 /*! The file should look something like
177 * <sequence> <red> <green> <blue>
178 * where sequence is a string of IUPAC symbols
179 * and red,green,blue are a white space separated list of floats
180 * in the range [0.0, 1.0]
182 //! load a list of motifs from a file named filename
183 void load_motifs(boost::filesystem::path filename);
184 //! load motifs from an ifstream
185 /*! \sa Mussa::load_motifs(boost::filesystem::path)
187 void load_motifs(std::istream &);
188 //! save motif list to the specified filename
189 void save_motifs(boost::filesystem::path filename);
190 //! save motif list to an ostream
191 void save_motifs(std::ostream &);
192 //! return our motifs;
193 const motif_set& motifs() const;
195 //! return color mapper
196 boost::shared_ptr<AnnotationColors> colorMapper();
199 //! push motifs to our attached sequences
200 void update_sequences_motifs();
203 // parameters needed for a mussa analysis
204 //! name of this analysis. (will also be used when saving an analysis)
205 std::string analysis_name;
206 //! how many base pairs to include in a sliding window
208 //! how many base pairs need to match order to record a window as conserved
210 //! stores current filter used by GUI to change the connections shown
212 //! which nway comparison algorithm to use.
213 enum analysis_modes ana_mode;
215 //! should we append _w<window_size> to the saved analysis
217 //! should we append _t<threshold> to the saved analysis
221 vector_sequence_type the_seqs;
223 std::vector<std::vector<FLPs> > all_comps;
224 //! N-way data, ie the mussa results
228 motif_set motif_sequences;
230 boost::shared_ptr<AnnotationColors> color_mapper;
231 //! path to our analysis
232 boost::filesystem::path analysis_path;
233 //! flag indicating if we have unsaved changes
237 //! runs all the seqcomps needed to support the nway comparison
241 //! provide a simple name to point to our Mussa shared_ptr
242 typedef boost::shared_ptr<Mussa> MussaRef;