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