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 //! save the nway comparison
51 void save_muway(boost::filesystem::path save_path);
52 //! load a saved analysis directory
53 void load(boost::filesystem::path ana_path);
55 //! clear parameters and initialize data lists
58 //! set parameters from a file - 'mupa' ~ mussa parameters
59 void load_mupa_file(std::string para_file_path) { load_mupa_file(boost::filesystem::path(para_file_path));}
60 void load_mupa_file(boost::filesystem::path para_file_path);
62 // set parameters individually (eg from user input into gui classes)
64 void set_name(std::string a_name);
65 //! return name for this analysis
66 std::string get_name();
68 //! return number of sequences in this analyzis
69 /*! this returns either the_seqs.size() or seq_files.size()
70 * depending on which has data loaded in
71 * (silly delayed loading of sequence data)
75 //! set number of bases for this window size
76 void set_window(int a_window);
77 //! get number of bases for the sliding window
78 int get_window() const;
79 //! set number of bases that must match for a window to be saved
80 //! if threshold > soft_threshold this also sets soft_threshold
81 void set_threshold(int a_threshold);
82 //! get number of bases that must match for a window to be saved
83 int get_threshold() const;
84 //! sets the threshold used for computing the nway paths
85 //! must be in range [threshold..window size]
86 void set_soft_threshold(int sft_thres);
87 int get_soft_threshold() const;
89 void set_analysis_mode(enum analysis_modes new_ana_mode);
90 enum analysis_modes get_analysis_mode() const;
91 //! return a string name for an analysis mode
92 std::string get_analysis_mode_name() const;
94 //! return the refined paths found by the nway analysis.
95 const NwayPaths& paths() const;
97 //! given selected_paths, and view_paths, compute per base pair matches
98 //template <class IteratorT>
99 void createLocalAlignment(std::list<ConservedPath>::iterator begin,
100 std::list<ConservedPath>::iterator end,
101 std::list<ConservedPath::path_type>& result,
102 std::list<std::vector<bool> >& reversed);
104 //! run seqcomp and the nway filtering algorithm.
105 /*!analyze will run seqcomp and then the nway algorithm
106 * on whatever sequences have been loaded into this mussa instance.
107 * \throws mussa_analysis_error
110 /*! Run the nway filtering algorithm,
111 * this might be used when changing the soft threshhold?
115 //! appends a string sequence to the list of the_seqs
116 // void append_sequence(std::string a_seq);
117 //! appends a sequence to the list of the_seqs (makes copy)
118 void append_sequence(const Sequence& a_seq);
119 //! append a sequence to the list of seqs (shared)
120 void append_sequence(boost::shared_ptr<Sequence> a_seq);
122 //! Load a sequence from a fasta file and any annotations
123 /*! \param[in] seq_file the full path to the fasta file
124 * \param[in] annot_file the full path to an annotation file,
125 * if is an empty string, we won't bother loading anything
126 * \param[in] fasta_index specify which sequence in a multisequence fasta
128 * \param[in] sub_seq_start starting slice index to select a subsequence
129 * use 0 start from the beginning.
130 * \param[in] sub_seq_end ending slice index to select a subsequence
131 * use 0 to go to the end.
133 void load_sequence(boost::filesystem::path seq_file,
134 boost::filesystem::path annot_file,
135 int fasta_index, int sub_seq_start=0, int sub_seq_end=0);
136 //! allow examining the sequences we have loaded
137 typedef std::vector<boost::shared_ptr<Sequence> > vector_sequence_type;
138 const vector_sequence_type& sequences() const;
140 // deprecated - support bridge for python version of mussa
141 // these save & load from the old file format
143 void load_old(char * load_file_path, int s_num);
145 // manage motif lists
146 //! add vector of motifs and colors to our motif collection
147 /*! this depends on sets and color maps being unique
148 * (aka if you add the same item more than once it doesn't
149 * increase the size of the data structure
151 void add_motifs(const std::vector<std::string>& motifs,
152 const std::vector<Color>& colors);
153 //! load motifs from an ifstream
154 /*! The file should look something like
155 * <sequence> <red> <green> <blue>
156 * where sequence is a string of IUPAC symbols
157 * and red,green,blue are a white space separated list of floats
158 * in the range [0.0, 1.0]
160 void load_motifs(std::istream &);
161 //! load a list of motifs from a file named filename
162 void load_motifs(boost::filesystem::path filename);
163 //! return our motifs;
164 const std::set<std::string>& motifs() const;
166 //! return color mapper
167 boost::shared_ptr<AnnotationColors> colorMapper();
170 //! push motifs to our attached sequences
171 void update_sequences_motifs();
174 // parameters needed for a mussa analysis
175 //! name of this analysis. (will also be used when saving an analysis)
176 std::string analysis_name;
177 //! how many base pairs to include in a sliding window
179 //! how many base pairs need to match order to record a window as conserved
182 //! which nway comparison algorithm to use.
183 enum analysis_modes ana_mode;
185 //! should we append _w<window_size> to the saved analysis
187 //! should we append _t<threshold> to the saved analysis
191 vector_sequence_type the_seqs;
193 std::vector<std::vector<FLPs> > all_comps;
194 //! N-way data, ie the mussa results
198 std::set<std::string> motif_sequences;
200 boost::shared_ptr<AnnotationColors> color_mapper;
203 //! runs all the seqcomps needed to support the nway comparison