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);
43 enum analysis_modes { TransitiveNway, RadialNway, EntropyNway,
50 void save(boost::filesystem::path save_path="");
51 //! save the nway comparison
52 void save_muway(boost::filesystem::path save_path);
53 //! load a saved analysis directory
54 void load(boost::filesystem::path ana_path);
55 // ! return path to the where the analysis is stored
56 boost::filesystem::path get_analysis_path() const;
58 void set_analysis_path(boost::filesystem::path);
60 //! clear parameters and initialize data lists
63 //! set parameters from a file - 'mupa' ~ mussa parameters
64 void load_mupa_file(std::string para_file_path) { load_mupa_file(boost::filesystem::path(para_file_path));}
65 void load_mupa_file(boost::filesystem::path para_file_path);
67 // set parameters individually (eg from user input into gui classes)
69 void set_name(std::string a_name);
70 //! return name for this analysis
71 std::string get_name() const;
72 //! return a reasonable window title for this analysis
73 /*! this returns the "variable" portion for a title
75 std::string get_title() const;
77 //! return number of sequences in this analyzis
78 /*! this returns either the_seqs.size() or seq_files.size()
79 * depending on which has data loaded in
80 * (silly delayed loading of sequence data)
84 //! set number of bases for this window size
85 void set_window(int a_window);
86 //! get number of bases for the sliding window
87 int get_window() const;
88 //! set number of bases that must match for a window to be saved
89 //! if threshold > soft_threshold this also sets soft_threshold
90 void set_threshold(int a_threshold);
91 //! get number of bases that must match for a window to be saved
92 int get_threshold() const;
93 //! sets the threshold used for computing the nway paths
94 //! must be in range [threshold..window size]
95 void set_soft_threshold(int sft_thres);
96 int get_soft_threshold() const;
98 void set_analysis_mode(enum analysis_modes new_ana_mode);
99 enum analysis_modes get_analysis_mode() const;
100 //! return a string name for an analysis mode
101 std::string get_analysis_mode_name() const;
102 //! return if we have unsaved changes
103 bool is_dirty() const;
104 //! is there anything loaded into this analysis?
107 //! return the refined paths found by the nway analysis.
108 const NwayPaths& paths() const;
110 //! given selected_paths, and view_paths, compute per base pair matches
111 //template <class IteratorT>
112 void createLocalAlignment(std::list<ConservedPath>::iterator begin,
113 std::list<ConservedPath>::iterator end,
114 std::list<ConservedPath::path_type>& result,
115 std::list<std::vector<bool> >& reversed);
117 //! run seqcomp and the nway filtering algorithm.
118 /*!analyze will run seqcomp and then the nway algorithm
119 * on whatever sequences have been loaded into this mussa instance.
120 * \throws mussa_analysis_error
123 /*! Run the nway filtering algorithm,
124 * this might be used when changing the soft threshhold?
128 //! appends a string sequence to the list of the_seqs
129 // void append_sequence(std::string a_seq);
130 //! appends a sequence to the list of the_seqs (makes copy)
131 void append_sequence(const Sequence& a_seq);
132 //! append a sequence to the list of seqs (shared)
133 void append_sequence(boost::shared_ptr<Sequence> a_seq);
135 //! Load a sequence from a fasta file and any annotations
136 /*! \param[in] seq_file the full path to the fasta file
137 * \param[in] annot_file the full path to an annotation file,
138 * if is an empty string, we won't bother loading anything
139 * \param[in] fasta_index specify which sequence in a multisequence fasta
141 * \param[in] sub_seq_start starting slice index to select a subsequence
142 * use 0 start from the beginning.
143 * \param[in] sub_seq_end ending slice index to select a subsequence
144 * use 0 to go to the end.
145 * \param[in] name sequence name, only used if not null
147 void load_sequence(boost::filesystem::path seq_file,
148 boost::filesystem::path annot_file,
149 int fasta_index, int sub_seq_start=0, int sub_seq_end=0,
150 std::string *name=0);
151 //! allow examining the sequences we have loaded
152 typedef std::vector<boost::shared_ptr<Sequence> > vector_sequence_type;
153 const vector_sequence_type& sequences() const;
155 // deprecated - support bridge for python version of mussa
156 // these save & load from the old file format
158 void load_old(char * load_file_path, int s_num);
160 // manage motif lists
161 //! add a motif it wont be applied until update_sequences_motif is called
162 void add_motif(const Sequence& motifs, const Color& colors);
163 //! add vector of motifs and colors to our motif collection
164 /*! this will automatically call update_sequences_motif
165 * this depends on sets and color maps being unique
166 * (aka if you add the same item more than once it doesn't
167 * increase the size of the data structure)
169 void set_motifs(const std::vector<Sequence>& motifs,
170 const std::vector<Color>& colors);
171 //! load motifs from an ifstream
172 /*! The file should look something like
173 * <sequence> <red> <green> <blue>
174 * where sequence is a string of IUPAC symbols
175 * and red,green,blue are a white space separated list of floats
176 * in the range [0.0, 1.0]
178 void load_motifs(std::istream &);
179 //! load a list of motifs from a file named filename
180 void load_motifs(boost::filesystem::path filename);
181 //! return our motifs;
182 const std::set<Sequence>& motifs() const;
184 //! return color mapper
185 boost::shared_ptr<AnnotationColors> colorMapper();
188 //! push motifs to our attached sequences
189 void update_sequences_motifs();
192 // parameters needed for a mussa analysis
193 //! name of this analysis. (will also be used when saving an analysis)
194 std::string analysis_name;
195 //! how many base pairs to include in a sliding window
197 //! how many base pairs need to match order to record a window as conserved
199 //! stores current filter used by GUI to change the connections shown
201 //! which nway comparison algorithm to use.
202 enum analysis_modes ana_mode;
204 //! should we append _w<window_size> to the saved analysis
206 //! should we append _t<threshold> to the saved analysis
210 vector_sequence_type the_seqs;
212 std::vector<std::vector<FLPs> > all_comps;
213 //! N-way data, ie the mussa results
217 std::set<Sequence> motif_sequences;
219 boost::shared_ptr<AnnotationColors> color_mapper;
220 //! path to our analysis
221 boost::filesystem::path analysis_path;
222 //! flag indicating if we have unsaved changes
226 //! runs all the seqcomps needed to support the nway comparison
230 //! provide a simple name to point to our Mussa shared_ptr
231 typedef boost::shared_ptr<Mussa> MussaRef;