/* massXpert - the true massist's program.
   --------------------------------------
   Copyright(C) 2006,2007 Filippo Rusconi

   http://www.massxpert.org/massXpert

   This file is part of the massXpert project.

   The massxpert project is the successor to the "GNU polyxmass"
   project that is an official GNU project package(see
   www.gnu.org). The massXpert project is not endorsed by the GNU
   project, although it is released ---in its entirety--- under the
   GNU General Public License. A huge part of the code in massXpert
   is actually a C++ rewrite of code in GNU polyxmass. As such
   massXpert was started at the Centre National de la Recherche
   Scientifique(FRANCE), that granted me the formal authorization to
   publish it under this Free Software License.

   This software is free software; you can redistribute it and/or
   modify it under the terms of the GNU  General Public
   License version 3, as published by the Free Software Foundation.
   

   This software is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this software; if not, write to the

   Free Software Foundation, Inc.,

   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/


#ifndef SEQUENCE_HPP
#define SEQUENCE_HPP


/////////////////////// Qt includes
#include <QString>


/////////////////////// Local includes
#include "monomer.hpp"
#include "prop.hpp"


namespace massXpert
{

  //! The Sequence class provides a simple sequence.
  /*!  A simple sequence is made of monomers arranged either in the form
    of a string of monomer codes concatenated one to the other with no
    delimitation(like "ATGC" or "AlaThrGlyCys") or in the form of a
    list(QList<Monomer *>) of full-fledged monomers.

    \attention The reference status of a sequence is in the form of a
    list of monomer instances. The conversion to the string of codes
    is only a utility. When a sequence is created(with an argument
    that is a string of monomer codes) the caller should ensure that
    the text sequence is converted into a list of monomers prior to
    starting using its methods extensively(see
    makeMonomerList()). Note that functions size() and
    removeMonomerAt()) only work on a sequence in the form of a list
    of monomers.

    Methods are provided to convert from one sequence kind
   (concatenated codes) to the other sequence kind(list of monomer
    instances).

    Equally interesting is the ability of the methods in this class to
    be able to:

    - parse the monomer sequence and to extract monomer codes one
    after the other;
  
    - remove monomers from the sequence at specified indexes;

    - add monomers to the sequence at specified indexes.

    However, for this rather basic class to be able to perform
    interesting tasks it has to be able to know where to find polymer
    chemistry definition data. This is possible only when a pointer to
    a polymer chemistry definition is passed to the used functions.
  */
  class Sequence
  {
  protected:
    //! Sequence in the form of a string of concatenated monomer codes.
    /*! Used to fill the \c m_monomerList member.
     */
    QString m_monomerText;
  
    //! List of monomers in the sequence. Empty upon creation.
    /*! Is filled with Monomer instances upon parsing of the text
      version of the sequence.
    */
    QList<const Monomer *> m_monomerList;
  
  public:
    Sequence(const QString & = QString());
    virtual ~Sequence();
  
    void setMonomerText(const QString &);
    void appendMonomerText(const QString &);
    const QString *monomerText();
      
    const QList<const Monomer *> &monomerList() const;
    QList<const Monomer *> *monomerListPtr();
    
    int nextCode(QString *, int *, QString *, int);
    const Monomer *at(int) const;
    int monomerIndex(const Monomer *);
    
    int size() const;
  
    void unspacifyMonomerText();
    
    virtual int makeMonomerText();
    QString *monomerText(int, int, bool) const;
    QString *monomerText(const CoordinateList &, bool, bool) const;

    int makeMonomerList(const PolChemDef *, bool = true, 
			 QList<int> * = 0);
    
    bool insertMonomerAt(const Monomer *, int);
    virtual bool prepareMonomerRemoval(const Monomer *);
    virtual bool removeMonomerAt(int);
    
    bool findForwardMotif(Sequence *, const PolChemDef *, int *);
    
    bool validate(const PolChemDef *);
    
    quint16 checksum(int = -1, int = -1, bool = false) const;
  };

} // namespace massXpert


#endif // SEQUENCE_HPP
