1 // ==========================================================================
2 // SeqAn - The Library for Sequence Analysis
3 // ==========================================================================
4 // Copyright (c) 2006-2010, Knut Reinert, FU Berlin
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 // * Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 // * Neither the name of Knut Reinert or the FU Berlin nor the names of
16 // its contributors may be used to endorse or promote products derived
17 // from this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
23 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
29 // DAMAGE.
30 //
31 // ==========================================================================
32
33 #ifndef SEQAN_HEADER_BLAST_STREAM_HIT_H
34 #define SEQAN_HEADER_BLAST_STREAM_HIT_H
35
36
37 namespace SEQAN_NAMESPACE_MAIN
38 {
39
40
41 ////////////////////////////////////////////////////////////////////////////////////////////
42 // Blast Hit storing only one hsp at a time
43 ////////////////////////////////////////////////////////////////////////////////////////////
44
45 template<typename TBlastHsp, typename TFile>
46 class BlastHit<TBlastHsp, StreamReport<TFile> >
47 {
48 public:
49 typedef typename Position<TFile>::Type TPosition_;
50
51 String<char> name;
52 unsigned int length; //length of whole sequence
53 TBlastHsp act_hsp;
54 TPosition_ begin_pos, first_hsp_pos;
55
56 BlastReport<TBlastHsp,StreamReport<TFile> >* data_host;
57
58
BlastHit()59 BlastHit()
60 {
61 }
62
~BlastHit()63 ~BlastHit()
64 {
65 }
66
67 };
68
69
70
71
72 //parse BlastHit
73 template<typename TFile, typename TChar, typename TBlastSpec>
74 inline typename Position<TFile>::Type
_parseBlastHit(TFile & file,TChar & c,BlastHit<TBlastSpec,StreamReport<TFile>> & hit)75 _parseBlastHit(TFile & file,
76 TChar & c,
77 BlastHit<TBlastSpec,StreamReport<TFile> > & hit)
78 {
79 typedef typename Position<TFile>::Type TPosition;
80 typedef BlastHit<TBlastSpec,StreamReport<TFile> > TBlastHit;
81 typedef typename Hsp<TBlastHit>::Type TBlastHsp;
82
83 String<char> pword;
84 int pint;
85 TPosition start_pos,act_pos;
86 act_pos = _streamTellG(file);
87
88 if(_parseUntilBeginLine(file,c,'>'))
89 {
90 hit.begin_pos = _streamTellG(file);
91 c = _streamGet(file);
92 pword = _parseReadWord(file, c);
93 while (!_streamEOF(file) && c != '\n' && c != '\r')
94 pword += _parseReadWord(file, c);
95 if(pword[length(pword)-1] == ' ')
96 resize(pword,length(pword)-1);
97 hit.name = pword;
98 _parseSkipWhitespace(file,c);
99 String<char> search = "Length";
100 if(_parseUntilBeginLine(file,c,search,6))
101 {
102 _parseSkipWhitespace(file,c);
103 if(c == '=')
104 c = _streamGet(file);
105 _parseSkipWhitespace(file,c);
106 pint = _parseReadNumber(file, c);
107 hit.length = pint;
108 }
109 // TPosition temp = _streamTellG(file);
110 //foreach Hsp
111 //if(_parseUntilBeginLine(file,c,'S') && _parseReadWord(file,c)=="Score")
112 search = "Score";
113 if(_parseUntilBeginLine(file,c,search,5))
114 {
115 hit.first_hsp_pos = _streamTellG(file);
116 //if(_parseUntilBeginLine(file,c,'>'))
117 // return _streamTellG(file);
118 }
119
120
121 }//end hit
122 _streamSeekG(file,act_pos);
123 c = '>';
124 return act_pos;
125 }
126
127
128
129
130
131
132
133 }// namespace SEQAN_NAMESPACE_MAIN
134
135 #endif //#ifndef SEQAN_HEADER_...
136