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_GRAPH_REFINE_ALIGN_H
34 #define SEQAN_HEADER_GRAPH_REFINE_ALIGN_H
35 
36 
37 
38 namespace SEQAN_NAMESPACE_MAIN
39 {
40 
41 
42 ///////////////////////////////////////////////////////////////////////////////////////////////////////
43 //Functions for Align<TSource,TSpec>
44 //project onto other sequence
45 template<typename TSource,typename TSpec,typename TValue,typename TMap>
46 void
_getOtherSequenceAndProject(Align<TSource,TSpec> & segment,TValue seg_num,TMap & seq_map,TValue,TValue node_i,TValue & seq_j_id,TValue & node_j)47 _getOtherSequenceAndProject(Align<TSource,TSpec> & segment,
48 				TValue seg_num,
49 							TMap & seq_map,
50 						   TValue ,
51 						   TValue node_i,
52 						   TValue & seq_j_id,
53 						   TValue & node_j)
54 {
55 SEQAN_CHECKPOINT
56 
57 	if(seg_num == 0)
58 	{
59 		seq_j_id = seq_map[id(source(row(segment,1)))];
60 		node_j = toSourcePosition(row(segment,1),toViewPosition(row(segment,0),node_i));
61 	}
62 	else
63 	{
64 		seq_j_id  = seq_map[id(source(row(segment,0)))];
65 		node_j = toSourcePosition(row(segment,0),toViewPosition(row(segment,1),node_i));
66 	}
67 }
68 
69 
70 //unspektakul�re funktion, die die int ID zur�ckgibt (braucht man damit es f�r alle alignment typen geht)
71 //template<typename TSource,typename TSpec, typename TValue, typename TSeqMap>
72 //int
73 //_getSeqMapId(TSeqMap & seq_map,
74 //			Align<TSource,TSpec> & segment,
75 //			TValue seq_i)
76 //{
77 //SEQAN_CHECKPOINT
78 //	return seq_map[id(source(row(segment,seq_i)))];
79 //}
80 //
81 //given seq and segment, get the sequenceId (seq_i) and its begin and end
82 //if seq = 0 get first sequence (that takes part in the segment match)
83 //if seq = 1 get second sequence
84 template<typename TAliSource,typename TAliSpec, typename TValue>
85 void
_getSeqBeginAndEnd(Align<TAliSource,TAliSpec> & segment,std::map<const void *,int> & seq_map,TValue & seq_i_id,TValue & begin_i,TValue & end_i,TValue seq)86 _getSeqBeginAndEnd(Align<TAliSource,TAliSpec> & segment,
87 				  std::map<const void * ,int> & seq_map,
88 				  TValue & seq_i_id,
89 				  TValue & begin_i,
90 				  TValue & end_i,
91 				  TValue seq)
92 {
93 	seq_i_id = seq_map[id(source(row(segment,seq)))];
94 	begin_i = clippedBeginPosition(row(segment,seq));
95 	end_i = clippedEndPosition(row(segment,seq));
96 }
97 
98 
99 
100 ////////////////////////////////////////////////////////////////////////////////////////
101 // 50000 _getRefinedMatchScore Functions
102 ////////////////////////////////////////////////////////////////////////////////////////
103 ////////////////////////////////
104 //for Align<TAliSource,TAliSpec>
105 //get score for alignment of length len starting at pos_i on first sequence
106 //and pos_j on second sequence
107 template<typename TScoreValue,typename TScoreSpec,typename TStringSet,typename TAliSource,typename TAliSpec,typename TValue>
108 TScoreValue
_getRefinedMatchScore(Score<TScoreValue,TScoreSpec> & score_type,TStringSet &,Align<TAliSource,TAliSpec> & segment,TValue pos_i,TValue pos_j,TValue len,TValue)109 _getRefinedMatchScore(Score<TScoreValue,TScoreSpec> & score_type,
110 		 TStringSet &,
111 		 Align<TAliSource,TAliSpec> & segment,
112 		 TValue pos_i,
113 		 TValue pos_j,
114 		 TValue len,
115 		 TValue)
116 {
117 SEQAN_CHECKPOINT
118 	typedef Align<TAliSource,TAliSpec> TAlign;
119 	typedef typename Row<TAlign>::Type TRow;
120 //	typedef typename Iterator<TRow,GapsIterator<ArrayGaps> >::Type TIterator;
121 	typedef typename Iterator<TRow, Rooted>::Type TIterator;
122 	TIterator row0_it, row1_it;
123 	row0_it = iter(row(segment,0),toViewPosition(row(segment,0),pos_i));
124 	row1_it = iter(row(segment,1),toViewPosition(row(segment,1),pos_j));
125 	len = toViewPosition(row(segment,0),pos_i + len) - toViewPosition(row(segment,0),pos_i);
126 	TValue i = 0;
127 	TScoreValue ret_score = 0;
128 	while(i < len)
129 	{
130 		if(isGap(row1_it)||isGap(row0_it))
131 			ret_score += scoreGapExtend(score_type);
132 		else
133 			ret_score += score(score_type,getValue(row0_it),getValue(row1_it));
134 		++i;
135 		++row0_it;
136 		++row1_it;
137 	}
138 	return ret_score;
139 }
140 
141 
142 //get score for alignment starting at pos_i on first sequence
143 //and pos_j on second sequence, if len1!=len2 then the refinement
144 //process was stopped (the cut is not exact)
145 //template<typename TScore,typename TStringSet, typename TAliSource,typename TAliSpec,typename TValue>
146 //typename Value<TScore>::Type
147 //_getRefinedMatchScore(TScore & score_type,
148 //		 TStringSet &,
149 //		 Align<TAliSource,TAliSpec> & segment,
150 //		 TValue pos_i,
151 //		 TValue pos_j,
152 //		 TValue len1,
153 //		 TValue len2)
154 //{
155 //SEQAN_CHECKPOINT
156 //	typedef Align<TAliSource,TAliSpec> TAlign;
157 //	typedef typename Row<TAlign>::Type TRow;
158 //	typedef typename Iterator<TRow>::Type TIterator;
159 //	TIterator row0_it, row1_it;
160 //	TValue len;
161 //	row0_it = iter(row(segment,0),toViewPosition(row(segment,0),pos_i));
162 //	row1_it = iter(row(segment,1),toViewPosition(row(segment,1),pos_j));
163 //	len1 = toViewPosition(row(segment,0),pos_i + len1) - toViewPosition(row(segment,0),pos_i);
164 //	len2 = toViewPosition(row(segment,1),pos_j + len2) - toViewPosition(row(segment,1),pos_j);
165 //	len = (len1 < len2) ? len1 : len2;
166 //	int i = 0;
167 //	typename Value<TScore>::Type ret_score = 0;
168 //
169 //	//calculate score for aligned region
170 //	while(i < len)
171 //	{
172 //		ret_score += score(score_type,getValue(row0_it),getValue(row1_it));
173 //		++i;
174 //		++row0_it;
175 //		++row1_it;
176 //	}
177 //	//fill up with gaps if one sequence is longer than the other
178 //	len = (len1 > len2) ? len1 : len2;
179 //	ret_score += (len - i) * scoreGapExtend(score_type);
180 //
181 //	return ret_score;
182 //}
183 
184 
185 }
186 #endif //#ifndef SEQAN_HEADER_...
187