File: gnFastTranslator.h

package info (click to toggle)
libgenome 1.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 2,148 kB
  • ctags: 1,215
  • sloc: cpp: 10,910; sh: 8,264; makefile: 82
file content (116 lines) | stat: -rw-r--r-- 3,139 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/////////////////////////////////////////////////////////////////////////////
// File:            gnFastTranslator.h
// Purpose:         Fast translator for all Sequences
// Description:     Caches translations of each possible sequence in a tree
// Changes:        
// Version:         libGenome 0.5.1 
// Author:          Aaron Darling 
// Modified by:     
// Copyright:       (c) Aaron Darling 
// Licenses:        See COPYING file for details 
/////////////////////////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifndef _gnFastTranslator_h_
#define _gnFastTranslator_h_


#include "libGenome/gnDefs.h"

#include <string>
#include <vector>
#include <map>
#include "libGenome/gnClone.h"
#include "libGenome/gnBaseFilter.h"
#include "libGenome/gnTranslator.h"


namespace genome {

class GNDLLEXPORT gnFastTranslator : public gnBaseFilter
{
public:

	static const gnFastTranslator *ProteinDNATranslator();
	static const gnFastTranslator *DNAProteinTranslator();

	enum gnTranslatorType{
		ProteinDNATranslatorType,
		DNAProteinTranslatorType,
	};

	gnFastTranslator();
	gnFastTranslator( gnTranslatorType t_type );
	gnFastTranslator( const gnFastTranslator& sf );
	gnFastTranslator& operator= (const gnFastTranslator& sf);
	gnFastTranslator* Clone() const;
	
	/**
	 * Queries the specified gnTranslator for every possible combination translation
	 * of the characters specified in the inputs std::string.  An input_width may be specified
	 * so that every possible combination of "input_width" characters in "inputs" will be
	 * cached.  This is useful for DNA to protein translations, for example.
	 * @param tranny The gnTranslator to cache.
	 * @param inputs The characters to cache from tranny.
	 * @param input_width The number of characters in each query to make to tranny.
	 */
	virtual void CacheTranslator(const gnTranslator* tranny, std::string inputs, const gnSeqI input_width);

	// gnSeqC 
	virtual gnSeqC Filter( const gnSeqC ch ) const;

	virtual void Filter( gnSeqC** seq, gnSeqI& len ) const;
	// std::string
	virtual void Filter( std::string &seq ) const;

	// Default gnSeqC
	void SetDefaultChar( const gnSeqC ch1 );
	gnSeqC GetDefaultChar() const;
	void UseDefaultChar( const boolean use = true);
	// fill map
	void SetPair( const std::string& ch1, const std::string& ch2 );
	void RemovePair( const std::string& ch );

private:

	void CreateProteinDNATranslator();
	void CreateDNAProteinTranslator();

	//map an input std::string to an output std::string
	std::map<std::string, std::string> m_transCache;
	const gnTranslator * m_translator;
	
	boolean use_default;
	gnSeqC m_defaultChar;
};//class gnFastTranslator

inline
gnFastTranslator* gnFastTranslator::Clone() const
{
	return new gnFastTranslator(*this);
}

inline
void gnFastTranslator::SetDefaultChar( const gnSeqC ch1 )
{
	m_defaultChar = ch1;
	use_default = true;
}
inline
gnSeqC gnFastTranslator::GetDefaultChar() const
{
	return m_defaultChar;
}

inline
void gnFastTranslator::UseDefaultChar(const boolean use)
{
	use_default = use;
}


}	// end namespace genome

#endif // _gnFastTranslator_h_