00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00014
00015 #define _gnSeqFilter_h_
00016
00017 #include <string>
00018 #include "gn/gnClone.h"
00019 #include "gn/gnDefs.h"
00020 #include "gn/gnBaseFilter.h"
00021
00022 const gnSeqC NO_REVCOMP_CHAR = 0;
00023
00024 class GNDLLEXPORT gnFilter : public gnBaseFilter
00025 {
00026 public:
00027
00028 static const gnFilter *alphabetCharacterFilter();
00029 static const gnFilter *numberCharacterFilter();
00030
00031 static const gnFilter *proteinSeqFilter();
00032 static const gnFilter *basicDNASeqFilter();
00033 static const gnFilter *fullDNASeqFilter();
00034 static const gnFilter *basicRNASeqFilter();
00035 static const gnFilter *fullRNASeqFilter();
00036
00037 static const gnFilter *DNAtoRNAFilter();
00038 static const gnFilter *RNAtoDNAFilter();
00039 static const gnFilter *DNAComplementFilter();
00040 static const gnFilter *RNAComplementFilter();
00041
00042 enum gnFilterType{
00043 alphabetCharacterFilterType,
00044 numberCharacterFilterType,
00045
00046 proteinSeqFilterType,
00047 basicDNASeqFilterType,
00048 fullDNASeqFilterType,
00049 basicRNASeqFilterType,
00050 fullRNASeqFilterType,
00051
00052 DNAtoRNAFilterType,
00053 RNAtoDNAFilterType,
00054 DNAComplementFilterType,
00055 RNAComplementFilterType
00056 };
00057
00058 public:
00059 gnFilter();
00066 gnFilter( const gnFilterType f_type );
00067 gnFilter( const gnSeqC defaultChar, const gnSeqC rdefaultChar );
00068 gnFilter( const gnFilter& sf );
00069 ~gnFilter();
00070
00071 gnFilter* Clone() const;
00072
00073
00074 boolean IsValid( const gnSeqC ch ) const;
00075 gnSeqC MakeValid( const gnSeqC ch ) const;
00076 gnSeqC Filter( const gnSeqC ch ) const;
00077
00083 uint32 IsValid( const gnSeqC* seq, const uint32 len ) const;
00084 void MakeValid( gnSeqC* seq, const uint32 len ) const;
00085 void Filter( gnSeqC** seq, uint32& len ) const;
00086 void ReverseFilter( gnSeqC** seq, uint32& len ) const;
00087
00088 uint32 IsValid( const string &seq ) const;
00089 void MakeValid( string &seq ) const;
00090 void Filter( string &seq ) const;
00091 void ReverseFilter( string &seq ) const;
00092
00093
00094 void SetDefaultChar( const gnSeqC ch1, const gnSeqC ch2 );
00095 gnSeqC GetDefaultChar() const;
00096 gnSeqC GetRDefaultChar() const;
00097
00098 void SetSingle( const gnSeqC ch );
00099 void SetPair( const gnSeqC ch1, const gnSeqC ch2 );
00100 boolean RemovePair( const gnSeqC ch );
00101 boolean RemoveSingle( const gnSeqC ch );
00102
00103
00104
00105 private:
00106 void CreateAlphabetCharacterFilter();
00107 void CreateNumberCharacterFilter();
00108
00109 void CreateProteinFilter();
00110
00111 void CreateBasicDNAFilter();
00112 void CreateFullDNAFilter();
00113
00114 void CreateBasicRNAFilter();
00115 void CreateFullRNAFilter();
00116
00117 void CreateDNAtoRNAFilter();
00118 void CreateRNAtoDNAFilter();
00119 void CreateDNAComplementFilter();
00120 void CreateRNAComplementFilter();
00121
00122 gnSeqC m_pairArray[GNSEQC_MAX];
00123 gnSeqC m_defaultChar;
00124 gnSeqC m_rDefaultChar;
00125
00126 };
00127
00128 inline
00129 gnFilter* gnFilter::Clone() const
00130 {
00131 return new gnFilter(*this);
00132 }
00133
00134
00135 inline
00136 boolean gnFilter::IsValid( const gnSeqC ch ) const
00137 {
00138 return m_pairArray[ch] != NO_REVCOMP_CHAR;
00139 }
00140 inline
00141 gnSeqC gnFilter::MakeValid( const gnSeqC ch ) const
00142 {
00143 return (m_pairArray[ch] != NO_REVCOMP_CHAR? ch: m_defaultChar);
00144 }
00145 inline
00146 gnSeqC gnFilter::Filter( const gnSeqC ch ) const
00147 {
00148
00149 return m_pairArray[ch] != NO_REVCOMP_CHAR ? m_pairArray[ch] : m_defaultChar;
00150 }
00151
00152 inline
00153 uint32 gnFilter::IsValid( const gnSeqC* seq, const uint32 len ) const
00154 {
00155 for( uint32 i=0; i < len ; ++i )
00156 {
00157 if( !IsValid( seq[i] ) )
00158 return i;
00159 }
00160 return len;
00161 }
00162 inline
00163 void gnFilter::MakeValid( gnSeqC* seq, const uint32 len ) const
00164 {
00165 for( uint32 i=0; i < len ; ++i )
00166 {
00167 seq[i] = MakeValid( seq[i] );
00168 }
00169 }
00170
00171
00172 inline
00173 uint32 gnFilter::IsValid( const string &seq ) const
00174 {
00175 return IsValid( (gnSeqC*)seq.data(), seq.length() );
00176 }
00177 inline
00178 void gnFilter::MakeValid( string &seq ) const
00179 {
00180 MakeValid( (gnSeqC*)seq.data(), seq.length() );
00181 }
00182
00183
00184 inline
00185 void gnFilter::SetDefaultChar( const gnSeqC ch1, const gnSeqC ch2 )
00186 {
00187 m_defaultChar = ch1;
00188 m_rDefaultChar = ch2;
00189 }
00190 inline
00191 gnSeqC gnFilter::GetDefaultChar() const
00192 {
00193 return m_defaultChar;
00194 }
00195 inline
00196 gnSeqC gnFilter::GetRDefaultChar() const
00197 {
00198 return m_rDefaultChar;
00199 }
00200
00201 inline
00202 void gnFilter::SetSingle( const gnSeqC ch )
00203 {
00204 m_pairArray[ch] = ch;
00205 }
00206 inline
00207 void gnFilter::SetPair( const gnSeqC ch1, const gnSeqC ch2 )
00208 {
00209 m_pairArray[ch1] = ch2;
00210
00211 }
00212 inline
00213 boolean gnFilter::RemovePair( const gnSeqC ch )
00214 {
00215 m_pairArray[ch] = NO_REVCOMP_CHAR;
00216
00217 return true;
00218 }
00219 inline
00220 boolean gnFilter::RemoveSingle( const gnSeqC ch )
00221 {
00222 m_pairArray[ch] = NO_REVCOMP_CHAR;
00223 return true;
00224 }
00225
00226 #endif
00227