There can be only one (filename convention)
[mussa.git] / alg / sequence.hpp
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   public:
48     typedef std::string::iterator iterator;
49     typedef std::string::const_iterator const_iterator;
50     typedef std::string::size_type size_type;
51
52     Sequence();
53     Sequence(std::string seq);
54     //! assignment to constant sequences
55     Sequence &operator=(const Sequence&);
56     Sequence &operator=(const std::string &);
57
58     //! set sequence to a (sub)string containing nothing but AGCTN
59     void set_filtered_sequence(const std::string& seq, 
60                                std::string::size_type start=0, 
61                                std::string::size_type count=0);
62
63     //! load sequence AGCT from fasta file
64     /*! \throws mussa_load_error 
65      */
66     void load_fasta(const std::string file_path, int seq_num=1, 
67                     int start_index=0, int end_index=0);
68     //! load sequence annotations
69     /*! \throws mussa_load_error 
70      */
71     void load_annot(const std::string file_path, int start_index, int end_index);
72     const std::list<annot> annotations() const;
73
74     // simple access functions
75     void set_seq(const std::string& a_seq);
76     const std::string& get_seq() const;
77     const char *c_seq() const;
78     std::string subseq(int start, int end) const;
79     std::string rev_comp() const;
80
81     // string-like functions
82     iterator begin();
83     const_iterator begin() const;
84     iterator end();
85     const_iterator end() const;
86     bool empty() const;
87     //! alias for size, (included as this is much like a string)
88     std::string::size_type length() const;
89     //! the number of base pairs in this sequence
90     std::string::size_type size() const;
91     void clear();
92
93     const std::string& get_header() const;
94     std::vector<int> find_motif(std::string a_motif);
95     void save(std::fstream &save_file);
96     void load_museq(std::string load_file_path, int seq_num); 
97 };
98 #endif