libXpertMass Developer Documentation
  • libXpertMass
  • Monomer
  • Monomer Class

    class MsXpS::libXpertMass::Monomer

    The Monomer class provides abstractions to work with monomers. More...

    Header: #include <Monomer.hpp>
    Inherits: MsXpS::libXpertMass::PolChemDefEntity, MsXpS::libXpertMass::Formula, MsXpS::libXpertMass::Ponderable, and MsXpS::libXpertMass::PropListHolder

    Public Functions

    Monomer(PolChemDefCstSPtr pol_chem_def_csp, QString name, QString code = QString(), QString formula = QString())
    Monomer(const Monomer &other)
    virtual ~Monomer()
    bool accountMasses(Ponderable *ponderable, int times) const
    virtual bool calculateMasses(int monomer_chemical_entities)
    bool checkCodeSyntax() const
    QString code() const
    void debugPutStdErr() const
    QString *formatXmlMnmElement(int offset, const QString &indent = QString(" "))
    QString *formatXmlMonomerElement(int offset, const QString &indent = QString(" ")) const
    int isCodeKnown() const
    bool isModified() const
    int isNameKnown() const
    int modifCount(const QString &modif_name)
    QList<Modif *> *modifList() const
    bool modify(Modif *modif, bool override, QStringList &errorList)
    bool renderXmlMnmElement(const QDomElement &element, int version)
    bool renderXmlMonomerElement(const QDomElement &element, int version)
    void setCode(const QString &code)
    bool unmodify()
    bool unmodify(Modif *modif)
    bool validate()
    bool operator!=(const Monomer &other) const
    Monomer &operator=(const Monomer &other)
    bool operator==(const Monomer &other) const

    Reimplemented Public Functions

    virtual bool accountMasses(double *mono = 0, double *avg = 0, int times = 1) const override

    Static Public Members

    int isCodeInList(const QString &code, const QList<Monomer *> &refList, Monomer *monomer_p = 0)
    int isNameInList(const QString &name, const QList<Monomer *> &refList, Monomer *monomer_p = 0)

    Detailed Description

    In libmass, a momomer is an entity that is part of a polymer chemistry definition. A monomer models a chemical entity that is part of a polymer.

    In protein chemistry, that would be a residue, that is, an amino-acid that has been polymerized into a residue chain (that is, a protein, or a peptide). The chemical reaction that polymerizez an amino acid into an elongating protein structure is a condensation, with loss of H2O from the amino acid to actually lead to a what is called a residue of a monomer, or for short a residue.

    Note: The monomer, that is partly defined by its formula, has the formula of the residue, not of the amino acid. This is always true, whatever the polymer chemistry definition at hand: protein, saccharide, nucleic acid.

    Member Function Documentation

    Monomer::Monomer(PolChemDefCstSPtr pol_chem_def_csp, QString name, QString code = QString(), QString formula = QString())

    Constructs a monomer with its member data set to name, code, formula.

    The pol_chem_def_csp polymer chemistry definition is set to the PolChemDefEntity base class' member.

    Monomer::Monomer(const Monomer &other)

    Constructs a monomer as a copy of other.

    [virtual noexcept] Monomer::~Monomer()

    Destroys the monomer.

    [override virtual] bool Monomer::accountMasses(double *mono = 0, double *avg = 0, int times = 1) const

    Reimplements: Ponderable::accountMasses(double *mono, double *avg, int times) const.

    Accounts this monomer's masses in mono and avg.

    The mono and avg masses are updated only if they are non-nullptr.

    This monomer's masses are stored in member data m_mono and m_avg. This monomer's masses multiplied by times before setting the values to mono and avg.

    Returns true.

    bool Monomer::accountMasses(Ponderable *ponderable, int times) const

    Accounts this monomer's masses in ponderable's mono and avg masses.

    This monomer's masses are stored in member data m_mono and m_avg. These masses are multiplied by times before setting the values to ponderable. ponderable cannot be nullptr.

    Returns true.

    [virtual] bool Monomer::calculateMasses(int monomer_chemical_entities)

    Calculates this monomer's monoisotopic and avg masses.

    The calculation is performed by computing the masses of this monomer's formula.

    If monomer_chemical_entities & MONOMER_CHEMENT_MODIF is true, then the masses are updated to account for the mass of modifications.

    Returns true if the calculations were successful, false otherwise.

    See also Formula::accountMasses().

    bool Monomer::checkCodeSyntax() const

    Checks the code's syntactic validity.

    The monomer code is verified and has to verify these criteria:

    Returns true if the code syntax checked successfully, false otherwise.

    See also validate().

    QString Monomer::code() const

    Returns the code

    See also setCode().

    void Monomer::debugPutStdErr() const

    Outputs a string representing this monomer using qDebug().

    QString *Monomer::formatXmlMnmElement(int offset, const QString &indent = QString(" "))

    Formats this monomer's data as a string suitable to be used as an XML element in the polymer chemistry definition.

    The typical monomer element that is generated in this function looks like this:

    <monomers>
    <mnm>
      <name>Glycine</name>
      <code>G</code>
      <formula>C2H3N1O1</formula>
    </mnm>

    The formatting of the XML element takes into account offset and indent by prepending the string with offset * indent character substring.

    indent defaults to two spaces.

    Returns a dynamically allocated string that needs to be freed after use.

    QString *Monomer::formatXmlMonomerElement(int offset, const QString &indent = QString(" ")) const

    Formats a string suitable to be used as an XML element in a polymer sequence file.

    The typical monomer element that is generated in this function looks like this:

    <monomer>
    <code>S</code>
    <prop>
    <name>MODIF</name>
    <data>Phosphorylation</data>
    </prop>
    <prop>
    <name>COMMENT</name>
    <data>Phosphorylation is only partial</data>
    </prop>
    </monomer>

    The formatting of the XML element takes into account offset and indent by prepending the string with offset * indent character substring.

    indent defaults to two spaces.

    Returns a dynamically allocated string that needs to be freed after use.

    [static] int Monomer::isCodeInList(const QString &code, const QList<Monomer *> &refList, Monomer *monomer_p = 0)

    Tells if a monomer by the monomer code is in refList.

    The monomers in refList are searched through for the monomer code.

    If a monomer is found and monomer_p is non-nullptr, the monomer pointed to by monomer_p is set to the contents of the found monomer.

    Returns the index of the found monomer or -1 either if m_code is empty or if the monomer was not found.

    int Monomer::isCodeKnown() const

    Tells if a monomer by this monomer's code is known in the polymer chemistry definition.

    The monomers in the list of monomers of the polymer chemistry definition (mcsp_polChemDef) are searched through for this monomer's code (m_code).

    Returns the index of the found monomer or -1 either if m_code is empty or if the monomer was not found.

    bool Monomer::isModified() const

    Returns true if this monomer has at least one modification, false otherwise.

    [static] int Monomer::isNameInList(const QString &name, const QList<Monomer *> &refList, Monomer *monomer_p = 0)

    Tells if a monomer by the monomer name is in refList.

    The monomers in refList are searched through for the monomer name.

    If a monomer is found and monomer_p is non-nullptr, the monomer pointed to by monomer_p is set to the contents of the found monomer.

    Returns the index of the found monomer or -1 either if m_name is empty or if the monomer was not found.

    int Monomer::isNameKnown() const

    Tells if a monomer by this monomer's name is known in the polymer chemistry definition.

    The monomers in the list of monomers of the polymer chemistry definition (mcsp_polChemDef) are searched through for this monomer's name (m_name).

    Returns the index of the found monomer or -1 either if m_name is empty or if the monomer was not found.

    int Monomer::modifCount(const QString &modif_name)

    Returns the count of modifications by name modif_name in this monomer.

    QList<Modif *> *Monomer::modifList() const

    Returns the modification list

    bool Monomer::modify(Modif *modif, bool override, QStringList &errorList)

    Modifies this monomer using modif.

    The two verifications that are done:

    The two restriction above can be overridden by setting override to true.

    If errors are encountered, these are reported as strings in errorList.

    The modif's ownership is taken by this monomer.

    Returns true on success, false otherwise.

    bool Monomer::renderXmlMnmElement(const QDomElement &element, int version)

    Parses the monomer XML element specifically for version.

    Parses the monomer XML element passed as argument and for each encountered data will set the data to this monomer (this is called XML rendering).The parsing is delegated to a function that is specific for for version of the polymer chemistry definition.

    The XML element is found in the polymer chemistry definition and has the following form:

    <monomers>
      <mnm>
        <name>Glycine</name>
        <code>G</code>
        <formula>C2H3N1O1</formula>
      </mnm>
      <mnm>
        <name>Alanine</name>
        <code>A</code>
        <formula>C3H5N1O1</formula>
      </mnm>

    After setting all the data, this monomer calculates it masses and validates itself. If any of these steps fails, the error is reported by returning false.

    See also validate().

    bool Monomer::renderXmlMonomerElement(const QDomElement &element, int version)

    Parses into this monomer the XML monomer element passed as argument.

    The XML element comes from a polymer sequence file, where the monomer is singled out (not in a sequence string) because it might be modified.

    version indicates the format version of this XML element.

    As soon as the monomer code is known, while parsing the element, the corresponding monomer is searched in the list of monomers in the member polymer chemistry definition (mcsp_polChemDef). Then, the found monomer is copied into this monomer so that both monomers are identical, effectively initializing this monomer to the monomer described by the element.

    If the element contains one or more mdf modifications, these modifications are allocated as Modif's and validated. If these modifications validate successfully, they are appended to this monomer's list of modifications.

    Returns true if initializationt of his monomer with the contents of element succeeded, false otherwise.

    See also formatXmlMonomerElement(int offset, const QString &indent).

    void Monomer::setCode(const QString &code)

    Sets the code to code

    See also code().

    bool Monomer::unmodify()

    Removes all the modification from this monomer.

    Returns true.

    bool Monomer::unmodify(Modif *modif)

    Removes modif from this monomer.

    The member list of modifications must exist (it is a heap-allocated list that is allocated upon the first modification of the monomer) and must be non-empty.

    Returns true.

    bool Monomer::validate()

    Returns true if this monomer is valid, false otherwise.

    Validation of the monomer occurs if:

    See also checkCodeSyntax().

    bool Monomer::operator!=(const Monomer &other) const

    Returns true if this monomer and other differ, false otherwise.

    The comparison involves also the comparison of the Modif objects in mpa_modifList.

    Monomer &Monomer::operator=(const Monomer &other)

    Assigns other's member data to this monomer.

    The copy is deep, in particular with the mpa_modifList being copied.

    Returns a reference to this monomer.

    bool Monomer::operator==(const Monomer &other) const

    Returns true if this monomer and other are identical, false otherwise.

    The comparison involves also the comparison of the Modif objects in mpa_modifList.