gnCompare.h Source File

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

# gnCompare.h

Go to the documentation of this file.

    00001
    00002 // File:            gnCompare.h
    00003 // Purpose:         Compares all sequences
    00004 // Description:     Compares sequences
    00005 // Changes:
    00006 // Version:         libGenome 0.1.0
    00007 // Author:          Aaron Darling
    00008 // Last Edited:     April 15, 2001, 10:34:50pm
    00009 // Modified by:
    00010 // Copyright:       (c) Aaron Darling
    00011 // Licenses:        Proprietary
    00013 #ifndef _gnCompare_h_
    00014 #define _gnCompare_h_
    00015
    00016 #include "gn/gnDefs.h"
    00017
    00018 #include <string>
    00019 #include "gn/gnClone.h"
    00020
    00021 class GNDLLEXPORT gnCompare : public gnClone
    00022 {
    00023 public:
    00024
    00029         static const gnCompare *ProteinSeqCompare();
    00035         static const gnCompare *DNASeqCompare();
    00041         static const gnCompare *RNASeqCompare();
    00042
    00043         enum gnCompareType{
    00044                 ProteinSeqCompareType,
    00045                 DNASeqCompareType,
    00046                 RNASeqCompareType,
    00047         };
    00048
    00049         gnCompare();
    00058         gnCompare( const gnCompareType c_type );
    00059         gnCompare( const gnCompare& sf );
    00060         ~gnCompare();
    00061
    00062         gnCompare* Clone() const;
    00063
    00064         string GetName() const;
    00065         void SetName( string name );
    00066
    00067         // Use less than comparisons since all other operators can be derived
    00068         // gnSeqC less than operations
    00069         boolean LessThan( gnSeqC ch, gnSeqC ch2, boolean case_sensitive = false) const;
    00073         boolean Contains( gnSeqC ch, gnSeqC ch2, boolean case_sensitive = false ) const;
    00074         // True if ch2 is general enough to equal ch
    00075         // gnSeqC[] less than operations
    00076         boolean LessThan( const gnSeqC* seq, const gnSeqC* seq2, const uint32 len, boolean case_sensitive = false ) const;
    00077         boolean Contains( const gnSeqC* seq, const gnSeqC* seq2, const uint32 len, boolean case_sensitive = false ) const;
    00078         // string
    00079         boolean LessThan( const string &seq, const string &seq2, boolean case_sensitive = false) const;
    00080         boolean Contains( const string &seq, const string &seq2, boolean case_sensitive = false) const;
    00081
    00082         // fill map
    00083
    00084         //adds a character which is equivalent to itself
    00085         void SetSingle( const gnSeqC ch );
    00086         //adds a pair of equivalent characters
    00087         void SetPair( const gnSeqC ch, const gnSeqC ch2 );
    00088         //adds ch as being wholly contained by ch2
    00089         void SetContained( const gnSeqC ch, const gnSeqC ch2 );
    00090
    00091         void RemoveSingle( const gnSeqC ch );
    00092         void RemovePair( const gnSeqC ch, const gnSeqC ch2 );
    00093         void RemoveContained( const gnSeqC ch, const gnSeqC ch2 );
    00094
    00095 private:
    00096         void CreateProteinComparator();
    00097         void CreateDNAComparator();
    00098         void CreateRNAComparator();
    00099
    00100         void AddArrayEntry( gnSeqC *array[GNSEQC_MAX], const gnSeqC ch, const gnSeqC ch2);
    00101         void DelArrayEntry( gnSeqC *array[GNSEQC_MAX], const gnSeqC ch, const gnSeqC ch2);
    00102
    00103         string m_name;
    00104         boolean m_ignoreCase;
    00105
    00106         gnSeqC* m_pairArray[GNSEQC_MAX];
    00107         gnSeqC* m_containArray[GNSEQC_MAX];
    00108
    00109 };//class gnCompare
    00110
    00111 inline
    00112 gnCompare* gnCompare::Clone() const{
    00113         return new gnCompare(*this);
    00114 }
    00115
    00116 inline
    00117 string gnCompare::GetName() const{
    00118         return m_name;
    00119 }
    00120 inline
    00121 void gnCompare::SetName( string name ){
    00122         m_name = name;
    00123 }
    00124
    00125 // gnSeqC
    00126 inline
    00127 boolean gnCompare::LessThan( gnSeqC ch, gnSeqC ch2, boolean case_sensitive) const
    00128 {
    00129         if(!case_sensitive){
    00130                 ch = toupper(ch);
    00131                 ch2 = toupper(ch2);
    00132         }
    00133
    00134         if(strchr(m_pairArray[ch], ch2) == 0)
    00135                 return ch < ch2 ? true : false;
    00136         return false;
    00137 }
    00138
    00139
    00140 // gnSeqC[]
    00141 inline
    00142 boolean gnCompare::LessThan( const gnSeqC* seq, const gnSeqC* seq2, const uint32 len, boolean case_sensitive ) const{
    00143         for( uint32 i=0; i < len ; ++i )
    00144                 if(LessThan(seq[i], seq2[i], case_sensitive))
    00145                         return true;
    00146         return false;
    00147 }
    00148
    00149 // string
    00150 inline
    00151 boolean gnCompare::LessThan( const string &seq, const string &seq2, boolean case_sensitive) const
    00152 {
    00153         gnSeqI shorter_len = seq.length() < seq2.length() ? seq.length() : seq2.length();
    00154         return LessThan( (gnSeqC*)seq.data(), (gnSeqC*)seq2.data(), shorter_len, case_sensitive );
    00155 }
    00156
    00157 // fill map
    00158 inline
    00159 void gnCompare::SetSingle( const gnSeqC ch ){
    00160         AddArrayEntry(m_pairArray, ch, ch);
    00161         AddArrayEntry(m_containArray, ch, ch);
    00162 }
    00163 inline
    00164 void gnCompare::SetPair( const gnSeqC ch, const gnSeqC ch2 ){
    00165         AddArrayEntry(m_pairArray, ch, ch2);
    00166         AddArrayEntry(m_pairArray, ch2, ch);
    00167 }
    00168 inline
    00169 void gnCompare::SetContained( const gnSeqC ch, const gnSeqC ch2 ){
    00170         AddArrayEntry(m_containArray, ch2, ch);
    00171 }
    00172
    00173 inline
    00174 void gnCompare::RemoveSingle( const gnSeqC ch )
    00175 {
    00176         DelArrayEntry(m_pairArray, ch, ch);
    00177         DelArrayEntry(m_containArray, ch, ch);
    00178 }
    00179 inline
    00180 void gnCompare::RemovePair( const gnSeqC ch, const gnSeqC ch2 )
    00181 {
    00182         DelArrayEntry(m_pairArray, ch, ch2);
    00183         DelArrayEntry(m_pairArray, ch2, ch);
    00184 }
    00185 inline
    00186 void gnCompare::RemoveContained( const gnSeqC ch, const gnSeqC ch2 )
    00187 {
    00188         DelArrayEntry(m_containArray, ch2, ch);
    00189 }
    00190
    00191 #endif
    00192         // _gnSeqCompare_h_