Update mussa to build on ubuntu 10.04 with qt 4.6.2 +boost 1.40.0.1
[mussa.git] / alg / flp.hpp
1 #ifndef _MUSSA_FLP_H_
2 #define _MUSSA_FLP_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 //                            ---------- flp.hh  -----------
15 //                        ----------------------------------------
16 #include <boost/filesystem/path.hpp>
17
18 #include <list>
19 #include <string>
20 #include <vector>
21 #include <iostream>
22
23 class Sequence;
24 //! FLP = Fixed Length Pairs (Data)
25 /*!
26  * vector of linked lists of the match type struct
27  */
28 class FLPs
29 {
30 public:
31     typedef size_t size_type;
32     
33     FLPs();
34     FLPs(const FLPs& );
35     //! Setup a FLP and reserve space for the match lists
36     /*!
37      * Initialize the all_matches structure with a list of matches
38      * for enough windows for the size of sequence 1
39      */
40     
41     struct match
42     {
43       int index;
44       int score;
45
46       friend bool operator==(const match&, const match& );
47       friend std::ostream &operator<<(std::ostream&, const match&);
48     };
49
50     void setup(int win_size, int hard_thres);
51     //! compare two sequences and store the list of results in all_matches
52     void seqcomp(const Sequence& seq1, const Sequence& seq2, bool is_RC);
53     //bool FLPs::match_less(match *match1, match *match2);
54     //void FLPs::sort();
55     //! Return all the matches for a particular window? (index and score pairs)
56     std::list<match> matches(int index) const;
57     //! Return all the match indexes for a particular window?
58     std::list<int> match_locations(int index) const;
59     //! Return all the match indexes for a particular window above a threshold
60     std::list<int> thres_matches(int index, int thres) const;
61     //! Return the number of windows stored in this FLPs
62     /*! (this is should be the same as seq1_len-window_size+1
63      */
64     int size() const;
65     //! Save all the FLPs to save_file_path
66     void save(boost::filesystem::path save_file_path);
67     //! Load a vector of a lists of FLPs
68     void load(boost::filesystem::path file_path);
69
70     //! how far we are through current seqcomp
71     float progress() const;
72
73     const static int seqcomp_not_running = -1;
74   private:
75     //! the number of base pairs in the sliding window
76     int window_size;
77     //! the minimum tnumber of base pairs need for this window to be saved.
78     int hard_threshold;
79
80     //! add a match from location seq1_i to seq2_i with a threshold of a_score
81     /*! i2_offset is used to shift the window start when doing a reverse 
82      * compliment. (This is called by seqcomp() )
83      */
84     inline void add(int seq1_i, int seq2_i, int a_score, int i2_offset);
85     //! this list of matches between the two sequences
86     /*! All of the matches are stored here, it appears each window position
87      *  in sequence 1 gets an entry in the vector, the list contains matches
88      *  between sequence 1 and sequence 2
89      */
90     std::vector<std::list<match> > *all_matches;
91     //! reserve space for the appropriate number of windows.
92     /*! this is mostly so seqcomp can use operator[]
93      */
94     void alloc_matches(std::string::size_type len1=0);
95     
96     //! make sure that a sequence is acceptable to seqcomp
97     void validate_sequence(const Sequence&) const;
98     
99     //! current loop index
100     int seqcomp_i;
101     //! end seqcomp index (when terminating, seqcomp_i == seqcomp_end.
102     //! when not running seqcomp_i == seqcomp_end == seqcomp_not_running
103     int seqcomp_end;
104 };
105 #endif