1 /* massXpert - the true massist's program.
2    --------------------------------------
3    Copyright(C) 2006,2007 Filippo Rusconi
4 
5    http://www.massxpert.org/massXpert
6 
7    This file is part of the massXpert project.
8 
9    The massxpert project is the successor to the "GNU polyxmass"
10    project that is an official GNU project package(see
11    www.gnu.org). The massXpert project is not endorsed by the GNU
12    project, although it is released ---in its entirety--- under the
13    GNU General Public License. A huge part of the code in massXpert
14    is actually a C++ rewrite of code in GNU polyxmass. As such
15    massXpert was started at the Centre National de la Recherche
16    Scientifique(FRANCE), that granted me the formal authorization to
17    publish it under this Free Software License.
18 
19    This software is free software; you can redistribute it and/or
20    modify it under the terms of the GNU  General Public
21    License version 3, as published by the Free Software Foundation.
22 
23 
24    This software is distributed in the hope that it will be useful,
25    but WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27    General Public License for more details.
28 
29    You should have received a copy of the GNU General Public License
30    along with this software; if not, write to the
31 
32    Free Software Foundation, Inc.,
33 
34    51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
35 */
36 
37 
38 #ifndef SEQUENCE_HPP
39 #define SEQUENCE_HPP
40 
41 
42 /////////////////////// Qt includes
43 #include <QString>
44 
45 
46 /////////////////////// Local includes
47 #include "monomer.hpp"
48 #include "prop.hpp"
49 
50 
51 namespace massXpert
52 {
53 
54   //! The Sequence class provides a simple sequence.
55   /*!  A simple sequence is made of monomers arranged either in the form
56     of a string of monomer codes concatenated one to the other with no
57     delimitation(like "ATGC" or "AlaThrGlyCys") or in the form of a
58     list(QList<Monomer *>) of full-fledged monomers.
59 
60     \attention The reference status of a sequence is in the form of a
61     list of monomer instances. The conversion to the string of codes
62     is only a utility. When a sequence is created(with an argument
63     that is a string of monomer codes) the caller should ensure that
64     the text sequence is converted into a list of monomers prior to
65     starting using its methods extensively(see
66     makeMonomerList()). Note that functions size() and
67     removeMonomerAt()) only work on a sequence in the form of a list
68     of monomers.
69 
70     Methods are provided to convert from one sequence kind
71    (concatenated codes) to the other sequence kind(list of monomer
72     instances).
73 
74     Equally interesting is the ability of the methods in this class to
75     be able to:
76 
77     - parse the monomer sequence and to extract monomer codes one
78     after the other;
79 
80     - remove monomers from the sequence at specified indexes;
81 
82     - add monomers to the sequence at specified indexes.
83 
84     However, for this rather basic class to be able to perform
85     interesting tasks it has to be able to know where to find polymer
86     chemistry definition data. This is possible only when a pointer to
87     a polymer chemistry definition is passed to the used functions.
88   */
89   class Sequence
90   {
91   protected:
92     //! Sequence in the form of a string of concatenated monomer codes.
93     /*! Used to fill the \c m_monomerList member.
94      */
95     QString m_monomerText;
96 
97     //! List of monomers in the sequence. Empty upon creation.
98     /*! Is filled with Monomer instances upon parsing of the text
99       version of the sequence.
100     */
101     QList<const Monomer *> m_monomerList;
102 
103   public:
104     Sequence(const QString & = QString());
105     virtual ~Sequence();
106 
107     void setMonomerText(const QString &);
108     void appendMonomerText(const QString &);
109     const QString *monomerText();
110 
111     const QList<const Monomer *> &monomerList() const;
112     QList<const Monomer *> *monomerListPtr();
113 
114     int nextCode(QString *, int *, QString *, int);
115     const Monomer *at(int) const;
116     int monomerIndex(const Monomer *);
117 
118     int size() const;
119 
120     void unspacifyMonomerText();
121 
122     virtual int makeMonomerText();
123     QString *monomerText(int, int, bool) const;
124     QString *monomerText(const CoordinateList &, bool, bool) const;
125 
126     int makeMonomerList(const PolChemDef *, bool = true,
127 			 QList<int> * = 0);
128 
129     bool insertMonomerAt(const Monomer *, int);
130     virtual bool prepareMonomerRemoval(const Monomer *);
131     virtual bool removeMonomerAt(int);
132 
133     bool findForwardMotif(Sequence *, const PolChemDef *, int *);
134 
135     bool validate(const PolChemDef *);
136 
137     quint16 checksum(int = -1, int = -1, bool = false) const;
138   };
139 
140 } // namespace massXpert
141 
142 
143 #endif // SEQUENCE_HPP
144