17c1b78840fc9ee4f9f1515ee579df2930f02057
[mussa.git] / alg / sequence.hh
1 #ifndef _MUSSA_SEQUENCE_H_
2 #define _MUSSA_SEQUENCE_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 //                           ---------- sequence.hh -----------
15 //                        ----------------------------------------
16
17
18 #include <fstream>
19 #include <list>
20 #include <string>
21 #include <vector>
22
23 // Sequence data class
24
25 //! Attach annotation information to a sequence track
26 struct annot
27 {
28   int start, end;
29   std::string name, type;
30 };
31
32 //! sequence track for mussa.
33 class Sequence
34 {
35   friend class ConnView;
36   friend class SeqView;
37   private:
38     std::string sequence;
39     std::string header;
40     std::string species;
41
42     std::list<annot> annots;
43
44     void motif_scan(std::string a_motif, std::vector<int> * motif_match_starts);
45     std::string rc_motif(std::string a_motif);
46     std::string motif_validate(std::string a_motif);
47
48   public:
49     Sequence();
50     Sequence(std::string seq);
51     //! assignment to constant sequences
52     //Sequence &operator=(const Sequence&);
53     //! load sequence AGCT from fasta file
54     //! throws mussa_load_error if something goes wrong
55     void load_fasta(const std::string file_path, int seq_num=1, 
56                     int start_index=0, int end_index=0);
57     //! load sequence annotations
58     //! throws mussa_load_error if something goes wrong
59     void load_annot(const std::string file_path, int start_index, int end_index);
60     const std::list<annot> annotations() const;
61     void set_seq(const std::string& a_seq);
62     const std::string& get_seq() const;
63     const char * c_seq() const;
64     std::string subseq(int start, int end) const;
65     std::string rev_comp() const;
66     //! the number of base pairs in this sequence
67     std::string::size_type size() const;
68     //! alias for size, (included as this is much like a string)
69     std::string::size_type length() const;
70     const std::string& get_header() const;
71     //std::string sp_name() const;
72     std::vector<int> find_motif(std::string a_motif);
73     void clear();
74     void save(std::fstream &save_file);
75     void load_museq(std::string load_file_path, int seq_num); 
76     // FIXME: filter sequence should be a class not instance function
77     //! convert a (sub)string to being just AGCTN mapping
78     //! mapping lower case to upper case, and any invalid char to N
79     std::string filter_sequence(const std::string& seq, 
80                                 std::string::size_type start=0, 
81                                 std::string::size_type count=0) const;
82 };
83 #endif