gnTranslator.h Source File

Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members

# gnTranslator.h

Go to the documentation of this file.

    00001 /////////////////////////////////////////////////////////////////////////////
    00002 // File:            gnTranslator.h
    00003 // Purpose:         Translator for all Sequences
    00004 // Description:     Translates DNA and protein sequences
    00005 // Changes:
    00006 // Version:         libGenome 0.5.1
    00007 // Author:          Aaron Darling
    00008 // Modified by:
    00009 // Copyright:       (c) Aaron Darling
    00010 // Licenses:        See COPYING file for details
    00011 /////////////////////////////////////////////////////////////////////////////
    00012 #ifndef _gnTranslator_h_
    00013 #define _gnTranslator_h_
    00014
    00015
    00016 #include "gn/gnDefs.h"
    00017
    00018 #include <string>
    00019 #include <vector>
    00020 #include "gn/gnClone.h"
    00021 #include "gn/gnBaseFilter.h"
    00022 #include "gn/gnCompare.h"
    00023
    00024
    00025 /**
    00026  * The gnTranslator class facilitates the translation of ambiguous DNA and RNA
    00027  * sequences to protein sequence.  It can also perform reverse translation from
    00028  * Protein to RNA or DNA though the utility of this functionality is somewhat
    00029  * questionable since it does not assign nucleotides probabilistically.
    00030  * Do not attempt to instantiate this class unless you are defining a new
    00031  * translation type.  Instead use the static member access functions ProteinDNATranslator(),
    00032  * ProteinRNATranslator(), DNAProteinTranslator(), and RNAProteinTranslator()
    00033  * In general, the gnFastTranslator class should be used instead of this one.
    00034  * @see gnFastTranslator
    00035  */
    00036 class GNDLLEXPORT gnTranslator : public gnBaseFilter
    00037 {
    00038 public:
    00039
    00040         static const gnTranslator *ProteinDNATranslator();
    00041         static const gnTranslator *ProteinRNATranslator();
    00042         static const gnTranslator *DNAProteinTranslator();
    00043         static const gnTranslator *RNAProteinTranslator();
    00044
    00045         enum gnTranslatorType{
    00046                 ProteinDNATranslatorType,
    00047                 ProteinRNATranslatorType,
    00048                 DNAProteinTranslatorType,
    00049                 RNAProteinTranslatorType,
    00050         };
    00051
    00052         gnTranslator();
    00053         gnTranslator( gnTranslatorType t_type );
    00054         gnTranslator( const gnTranslator& sf );
    00055
    00056         gnTranslator* Clone() const;
    00057
    00058         // gnSeqC
    00059         virtual gnSeqC Filter( const gnSeqC ch ) const;
    00060
    00061         virtual void Filter( gnSeqC** seq, uint32& len ) const;
    00062         // string
    00063         virtual void Filter( string &seq ) const;
    00064
    00065         // Default gnSeqC
    00066         /**
    00067          * Sets the default character to insert when no valid translation exists.
    00068          * @param ch1 The default character
    00069          */
    00070         void SetDefaultChar( const gnSeqC ch1 );
    00071         /**
    00072          * Gets the default character which is inserted into the destination
    00073          * sequence when no valid translation exists.
    00074          * @return The default character
    00075          */
    00076         gnSeqC GetDefaultChar() const;
    00077         /**
    00078          * Set whether the default character is inserted upon translation failure.
    00079          * @param use True if the default character should be used.
    00080          */
    00081         void UseDefaultChar( const boolean use = true);
    00082         /**
    00083          * Set the expected number of characters in each unit of translation.  For DNA to
    00084          * Protein, for instance, this is 3 because each codon is 3 characters of input.
    00085          * @param defaultInputWidth The expected input width
    00086          */
    00087         void SetDefaultInputWidth( const uint32 defaultInputWidth);
    00088         /**
    00089          * Get the expected number of characters in each unit of translation.  For DNA to
    00090          * Protein, for instance, this is 3 because each codon is 3 characters of input.
    00091          * @return The expected input width
    00092          */
    00093         uint32 GetDefaultInputWidth() const;
    00094
    00095         // fill map
    00096         /**
    00097          * Set a translation mapping.  The first value is the input, the second value is the
    00098          * output.  During translation, any occurrences of the first string will be transformed
    00099          * to the second string.  A gnCompare object is used to facilitate ambiguity matching.
    00100          * @param input The input string
    00101          * @param output The string to output every time the input string is encountered
    00102          */
    00103         void SetPair( const string& input, const string& output );
    00104         /**
    00105          * Removes a translation mapping.  RemovePair removes the translation mapping
    00106          * corresponding to the given input string.
    00107          * @param input The input string to delete
    00108          */
    00109         void RemovePair( const string& input );
    00110         /**
    00111          * Set the comparator to use.  Ambiguous base matching is facilitated using a gnCompare
    00112          * object.  This must be set to allow sequences to be compared.
    00113          * @param comp A pointer to the gnCompare object to use.
    00114          */
    00115         void SetCompare( const gnCompare* comp );
    00116 private:
    00117         void CreateProteinDNATranslator();
    00118         void CreateProteinRNATranslator();
    00119         void CreateDNAProteinTranslator();
    00120         void CreateRNAProteinTranslator();
    00121
    00122         //for each entry in the input table there is a corresponding
    00123         //entry in the output table.
    00124         vector<string> m_inputTable, m_outputTable;
    00125
    00126         const gnCompare* compare;
    00127
    00128         boolean use_default;
    00129         gnSeqC m_defaultChar;
    00130         uint32 m_defaultInputWidth;
    00131 };//class gnTranslator
    00132
    00133 inline
    00134 gnTranslator* gnTranslator::Clone() const
    00135 {
    00136         return new gnTranslator(*this);
    00137 }
    00138
    00139 inline
    00140 void gnTranslator::SetDefaultChar( const gnSeqC ch1 )
    00141 {
    00142         m_defaultChar = ch1;
    00143         use_default = true;
    00144 }
    00145 inline
    00146 gnSeqC gnTranslator::GetDefaultChar() const
    00147 {
    00148         return m_defaultChar;
    00149 }
    00150
    00151 inline
    00152 void gnTranslator::UseDefaultChar(const boolean use)
    00153 {
    00154         use_default = use;
    00155 }
    00156
    00157 inline
    00158 void gnTranslator::SetDefaultInputWidth( const uint32 defaultInputWidth){
    00159         m_defaultInputWidth = defaultInputWidth;
    00160 }
    00161
    00162 inline
    00163 uint32 gnTranslator::GetDefaultInputWidth() const{
    00164         return m_defaultInputWidth;
    00165 }
    00166
    00167 inline
    00168 void gnTranslator::SetCompare( const gnCompare* comp ){
    00169         compare = comp;
    00170 }
    00171
    00172 #endif // _gnTranslator_h_