| <large>libXpertMassCore and libXpertMassGui Developer Documentation</large>

- libXpertMassCore
- MonomerDictionary

# MsXpS::libXpertMassCore::MonomerDictionary Class

class MsXpS::libXpertMassCore::MonomerDictionary

The MonomerDictionary class provides a Monomer code dictionary allowing the user to automatically translate Monomer codes from x-letter codes to y-letter codes. For example, a monomer dictionary file can define how to translate 3-letter monomer codes to 1-letter codes. This is typically useful when working on Protein Database (PDB) file. More...

Header: | `#include <MsXpS/libXpertMassCore/MonomerDictionary.hpp>`

- List of all members, including inherited members
- MonomerDictionary is part of libXpertMassCore Utilities.

## Public Functions

| MonomerDictionary(QString file_path = QString(), const QStringList &input_chain_string_list = QStringList(), int input_code_length = -1, int output_code_length = -1)
| ~MonomerDictionary()
bool | loadDictionary()
void | setFilePath(QString &file_path)
void | setInputChainStringList(const QStringList &input_chain_string_list)
void | setInputCodeLength(int code_length)
void | setOutputCodeLength(int code_length)
QStringList * | translate(const QStringList &chain_string_list = QStringList())

## Protected Functions

bool | isLineProperSectionDivider(const QString &line)
int | parseSection(QTextStream *stream)

## Protected Variables

QHash<QString, QString> | m_dictionaryHash
bool | m_dictionaryLoaded
QString | m_filePath
QStringList | m_inputChainStringList
int | m_inputCodeLength
int | m_outputCodeLength

## Detailed Description

The format of the dictionary file is the following:

    # Converts from code on the left of '>' to code on the right.
    # Number of letters allowed in each code is
    # described with syntax 3>1 and that line should be the first
    # non-comment line in this file.
    3>1
    ALA>A
    CYS>C
    ASP>D

There might be more than one section in the file, with, for example, 3>1 translations and then 1>3 translations.

## Member Function Documentation

### MonomerDictionary::MonomerDictionary(QString file_path = QString(), const QStringList &input_chain_string_list = QStringList(), int input_code_length = -1, int output_code_length = -1)

Constructs a MonomerDictionary instance.

- file_path: the path to the file containing the Monomer dictionary.
- input_chain_string_list: the list of sequences to be converted.
- input_code_length: the count of letters in the Monomer codes in the input string.
- output_code_length: the count of letters in the Monomer codes in the output string.

### `[noexcept]` MonomerDictionary::~MonomerDictionary()

Destructs this MonomerDictionary instance.

### `[protected]` bool MonomerDictionary::isLineProperSectionDivider(const QString &line)

Return true if the line parsed is in the form X>Y, that is, that it specifies the kind of Monomer code translation.

### bool MonomerDictionary::loadDictionary()

Returns true if the Monomer dictionary file could be loaded successfully, false otherwise.

### `[protected]` int MonomerDictionary::parseSection(QTextStream *stream)

Parses the Monomer dictionary file section in stream and fills in the m_dictionaryHash with the translation pair.

### void MonomerDictionary::setFilePath(QString &file_path)

Sets the file_path to the Monomer dictionary file.

### void MonomerDictionary::setInputChainStringList(const QStringList &input_chain_string_list)

Sets the list of input sequences to input_chain_string_list.

### void MonomerDictionary::setInputCodeLength(int code_length)

Set the count of letters in the input Monomer codes to code_length.

### void MonomerDictionary::setOutputCodeLength(int code_length)

Set the count of letters in the output Monomer codes to code_length.

### QStringList *MonomerDictionary::translate(const QStringList &chain_string_list = QStringList())

Perform the actual translation from the input Monomer code form to the output Monomer code form on all the strings contained in chain_string_list.

## Member Variable Documentation

### QHash<QString, QString> MonomerDictionary::m_dictionaryHash

This variable holds the hash that documents the translations.

### bool MonomerDictionary::m_dictionaryLoaded

Indicates if the dictionary file has been loaded already.

### QString MonomerDictionary::m_filePath

Path to the file documenting the translations.

### QStringList MonomerDictionary::m_inputChainStringList

This variable holds the list of sequences to be converted.

### int MonomerDictionary::m_inputCodeLength

This variable holds the count of letters in the input Monomer code.

In a dictionary file that has a section

    3>1

this value would be 3.

### int MonomerDictionary::m_outputCodeLength

This variable holds the count of letters in the output Monomer code.

In a dictionary file that has a section

    3>1

this value would be 1.