add callback for tracking analysis progress
[mussa.git] / alg / nway_paths.hpp
1 #ifndef _MUSSA_NWAY_H_
2 #define _MUSSA_NWAY_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
6
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.
11
12
13 //                        ----------------------------------------
14 //                         ----------  mussa_nway.hh  -----------
15 //                        ----------------------------------------
16 #include <boost/filesystem/path.hpp>
17
18 #include <list>
19 #include <string>
20 #include <vector>
21
22 #include "alg/conserved_path.hpp"
23 #include "alg/flp.hpp"
24 #include "alg/mussa_callback.hpp"
25
26 class NwayPaths
27 {
28   friend class ConnView;
29   friend class SeqView;
30   protected:
31     int threshold;
32     size_t win_size;
33     int soft_thres;
34
35     double ent_thres;
36     std::vector<char *> c_sequences; //used by entropy_path_search
37     analysis_callback progress_cb;
38
39   public:
40     NwayPaths();
41     //! setup an nway comparison, initialize # of species, window size, 
42     //! threshold
43     void setup(int w, int t);
44     void setup_ent(double new_entropy_thres, std::vector<std::string> some_Seqs);
45     void set_soft_threshold(int soft_thres);
46     //! return minimum threshold for this analysis
47     int get_threshold() const;
48     //! return window size used for this analysis
49     int get_window() const;
50     //! set analysis progress callback
51     void set_progress_callback(analysis_callback cb);
52     //! get analysis progress callback
53     analysis_callback get_progress_callback() const;
54
55     void radiate_path_search(std::vector<std::vector<FLPs> > all_comparisons);
56     void trans_path_search(std::vector<std::vector<FLPs> > all_comparisons);
57     void entropy_path_search(std::vector<std::vector<FLPs> > all_comparisons);
58     double path_entropy(std::vector<int> path);
59
60   // old recursive transitive nway ... has issues checking all links?
61     void find_paths_r(std::vector<std::vector<FLPs> > all_comparisons);
62     void path_search(std::vector<std::vector<FLPs> > all_comparisons, ConservedPath path, size_t depth);
63
64     void simple_refine();
65     void save(boost::filesystem::path save_file_path);
66     //! load a muway file, \throws mussa_load_error
67     void load(boost::filesystem::path load_file_path);
68     void add_path(int threshold, std::vector<int>& loaded_path);
69     void add_path(ConservedPath loaded_path);
70     //! how many sequences are in our comparison
71     size_t sequence_count();
72
73     void find_paths(std::vector<std::vector<FLPs> > all_comparisons);
74     void refine();
75
76     void save_old(boost::filesystem::path save_file_path);
77     void print(std::list<std::vector<int> >&);
78
79     // The following iterator functions are mostly for the python interface
80     // they'll have problems when being called from within a const object
81     std::list<ConservedPath>::iterator pbegin() { return pathz.begin() ; }
82     std::list<ConservedPath>::iterator pend() { return pathz.end() ; }
83     size_t path_size() const { return refined_pathz.size(); }
84     std::list<ConservedPath>::iterator rpbegin() { return refined_pathz.begin() ; }
85     std::list<ConservedPath>::iterator rpend() { return refined_pathz.end() ; }
86     size_t refined_path_size() const { return refined_pathz.size(); }
87
88     // these probably shouldn't be public, but lets start 
89     // simple
90     std::list<ConservedPath> pathz;
91     std::list<ConservedPath > refined_pathz;
92 };
93 #endif