[go: up one dir, main page]

File: blast_hit.h

package info (click to toggle)
seqan 1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 21,368 kB
  • ctags: 17,376
  • sloc: cpp: 81,339; ansic: 58,225; makefile: 96; sh: 14
file content (292 lines) | stat: -rw-r--r-- 7,260 bytes parent folder | download
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/*==========================================================================
 SeqAn - The Library for Sequence Analysis
 http://www.seqan.de
 ============================================================================
 Copyright (C) 2007
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 3 of the License, or (at your option) any later version.
 
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.
 
 ============================================================================
 $Id: blast_hit.h 4714 2009-08-24 13:38:02Z weese@PCPOOL.MI.FU-BERLIN.DE $
 ==========================================================================*/
#ifndef SEQAN_HEADER_BLAST_HIT_H
#define SEQAN_HEADER_BLAST_HIT_H


namespace SEQAN_NAMESPACE_MAIN
{

template<typename TBlastHsp, typename TStoreSpec>
class BlastHit;


/**
.Class.BlastHit:
..cat:Blast
..summary:Object for storing Blast hits. 
..signature:BlastHit<TBlastHsp, TSpec>  
..param.TBlastHsp:The type of HSPs that are stored.
..param.TSpec:The specializing type.
...type:Spec.StreamReport
...type:Spec.StoreReport
..remarks:Use Metafunction.Hit to get the BlastHit type used in a BlastReport object.
*/
template<typename TBlastHsp, typename TSpec>
class BlastHit<TBlastHsp, StoreReport<TSpec> > 
{
	public:
		String<char> name;
		unsigned int length; //length of whole sequence 

		String<TBlastHsp> hsps;
		
		BlastHit()
		{
		SEQAN_CHECKPOINT
		}

		//BlastHit(String<char> name, unsigned int len)
		//{
		//	name = name;
		//	length = length;
		//	clear(hsps);
		//}

		BlastHit(BlastHit const& other)
		{
		SEQAN_CHECKPOINT
			assign(hsps,other.hsps);
			name = other.name;
			length = other.length;
		}

		BlastHit & operator = (BlastHit const & other)
		{
		SEQAN_CHECKPOINT
			assign(hsps,other.hsps);
			name = other.name;
			length = other.length;
			return *this;
		}

		~BlastHit()
		{
		}

};



template<typename TBlastHsp, typename TSpec>
inline void
clear(BlastHit<TBlastHsp, StoreReport<TSpec> >& blastHit)
{
SEQAN_CHECKPOINT
	
	for(unsigned int i = 0; i < length(blastHit.hsps); ++i)
		clear(blastHit.hsps[i]);
	resize(blastHit.hsps,0);
	resize(blastHit.name,0);
}


template<typename TBlastHsp, typename TStoreSpec>
inline String<char> &
name(BlastHit<TBlastHsp, TStoreSpec>& blastHit)
{
SEQAN_CHECKPOINT
	return blastHit.name;
}

template<typename TBlastHsp, typename TStoreSpec>
inline String<char> 
getName(BlastHit<TBlastHsp, TStoreSpec>& blastHit)
{
SEQAN_CHECKPOINT
	return blastHit.name;
}

template<typename TBlastHsp, typename TStoreSpec>
inline unsigned int &
length(BlastHit<TBlastHsp, TStoreSpec>& blastHit)
{
SEQAN_CHECKPOINT
	return blastHit.length;
}

template<typename TBlastHsp, typename TStoreSpec>
inline unsigned int 
getLength(BlastHit<TBlastHsp, TStoreSpec>& blastHit)
{
SEQAN_CHECKPOINT
	return blastHit.length;
}

// for StoreReport only
template<typename TBlastHsp, typename TSpec>
inline unsigned int 
numHsps(BlastHit<TBlastHsp, StoreReport<TSpec> >& blastHit)
{
SEQAN_CHECKPOINT
	return length(blastHit.hsps);
}		


/////////////////////////////////////////////////////////////////////

//parse BlastHit
template<typename TFile, typename TChar, typename TBlastHit>
inline typename Position<TFile>::Type
_parseBlastHit(TFile & file,
			TChar & c, 
			TBlastHit & hit)
{
	typedef typename Position<TFile>::Type TPosition;
	typedef typename Hsp<TBlastHit>::Type TBlastHsp;

	String<char> pword;
	int pint;
	TPosition start_pos,act_pos;
	act_pos = _streamTellG(file);

	if(_parse_untilBeginLine(file,c,'>'))
	{
		start_pos = _streamTellG(file);
		c = _streamGet(file);
		pword = _parse_readWord(file, c);
		while (!_streamEOF(file) && c != '\n' && c != '\r')
			pword += _parse_readWord(file, c);
		if(pword[length(pword)-1] == ' ')
			resize(pword,length(pword)-1);
		hit.name = pword;
		_parse_skipWhitespace(file,c);
		String<char> search = "Length";
		if(_parse_untilBeginLine(file,c,search,6))
		{
			_parse_skipWhitespace(file,c);
			if(c == '=')
				c = _streamGet(file);
			_parse_skipWhitespace(file,c);
			pint = _parse_readNumber(file, c);
			hit.length = pint;
		}
//		TPosition temp = _streamTellG(file);
		//foreach Hsp
		//if(_parse_untilBeginLine(file,c,'S') && _parse_readWord(file,c)=="Score")
		search = "Score";
		if(_parse_untilBeginLine(file,c,search,5))
		{
			//c = _streamGet(file);
			bool in_hit = true;
			TPosition act_hsp_pos,next_hsp_pos;
			while(in_hit){
				act_hsp_pos = _streamTellG(file);
				TBlastHsp hsp;
				next_hsp_pos = _parseBlastHsp(file,c,hsp);
				//resize(hit.hsps, length(hit.hsps)+1);
				//hit.hsps[length(hit.hsps)-1] = hsp;
				appendValue(hit.hsps,hsp);
				//append(hit.hsps,hsp);
				if(next_hsp_pos == act_hsp_pos)
					in_hit = false;
				if(next_hsp_pos == (TPosition)0)
					return (TPosition) 0;
			}
			_streamSeekG(file,next_hsp_pos);
			c = _streamGet(file);
			if(_parse_untilBeginLine(file,c,'>'))
				return _streamTellG(file);
		}

		
	}//end hit
	_streamSeekG(file,act_pos);
	return act_pos;
}






////////////////////////// MetaFunctions ////////////////////////////////

template<typename TBlastHsp, typename TStoreSpec>
struct Value<BlastHit<TBlastHsp, TStoreSpec> > 
{
	typedef BlastHit<TBlastHsp,TStoreSpec> Type;
};

template<typename TBlastHsp, typename TStoreSpec>
struct Value<BlastHit<TBlastHsp, TStoreSpec> const> 
{
	typedef BlastHit<TBlastHsp,TStoreSpec> Type;
};

template<typename TBlastHsp, typename TStoreSpec>
struct Hit<BlastHit<TBlastHsp, TStoreSpec> > 
{
	typedef BlastHit<TBlastHsp,TStoreSpec> Type;
};

template<typename TBlastHsp, typename TStoreSpec>
struct Hit<BlastHit<TBlastHsp, TStoreSpec> const> 
{
	typedef BlastHit<TBlastHsp,TStoreSpec> Type;
};



template<typename TBlastHsp, typename TStoreSpec>
struct Hsp<BlastHit<TBlastHsp, TStoreSpec> > 
{
	typedef TBlastHsp Type;
};

template<typename TBlastHsp, typename TStoreSpec>
struct Hsp<BlastHit<TBlastHsp, TStoreSpec> const> 
{
	typedef TBlastHsp Type;
};


/////////////komisch///////////

	template<typename TBlastHsp, typename TStoreSpec>
	struct Hsp<String<BlastHit<TBlastHsp, TStoreSpec> > > 
	{
		typedef TBlastHsp Type;
	};

	template<typename TBlastHsp, typename TStoreSpec>
	struct Hsp<String<BlastHit<TBlastHsp, TStoreSpec> const> > 
	{
		typedef TBlastHsp Type;
	};

	template<typename TBlastSpec, typename TStoreSpec>
	struct Hsp<String<BlastHsp<TBlastSpec, TStoreSpec> > > 
	{
		typedef BlastHsp<TBlastSpec, TStoreSpec> Type;
	};

	template<typename TBlastSpec, typename TStoreSpec>
	struct Hsp<String<BlastHsp<TBlastSpec, TStoreSpec> const> > 
	{
		typedef BlastHsp<TBlastSpec, TStoreSpec> Type;
	};




}// namespace SEQAN_NAMESPACE_MAIN

#endif //#ifndef SEQAN_HEADER_...