1 // ==========================================================================
2 //                 SeqAn - The Library for Sequence Analysis
3 // ==========================================================================
4 // Copyright (c) 2006-2018, 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 // Author: Tobias Rausch <rausch@embl.de>
33 // Author: Anne-Katrin Emde <anne-katrin.emde@fu-berlin.de>
34 // ==========================================================================
35 
36 #ifndef SEQAN_INCLUDE_SEQAN_GRAPH_ALGORITHM_REFINE_FRAGMENT_H_
37 #define SEQAN_INCLUDE_SEQAN_GRAPH_ALGORITHM_REFINE_FRAGMENT_H_
38 
39 namespace seqan {
40 
41 
42 ///////////////////////////////////////////////////////////////////////////////////////////////////////
43 //Functions for Fragments
44 //project onto other sequence for Graph<Alignment>
45 template<typename TFragSize, typename TFragSpec,typename TValue,typename TId1, typename TPos1, typename TId2, typename TPos2, typename TMap>
46 void
_getOtherSequenceAndProject(Fragment<TFragSize,TFragSpec> & segment,TValue seg_num,TMap &,TId1 seq_i_id,TPos1 pos_i,TId2 & seq_j_id,TPos2 & pos_j)47 _getOtherSequenceAndProject(Fragment<TFragSize,TFragSpec> & segment,
48                         TValue seg_num,
49                            TMap &,
50                            TId1 seq_i_id,
51                            TPos1 pos_i,
52                            TId2 & seq_j_id,
53                            TPos2 & pos_j)
54 {
55     getProjectedPosition(segment,seg_num, seq_i_id, pos_i,seq_j_id,pos_j);
56 
57     //if(seq_i_id == sequenceId(segment,0))
58     //    seq_j_id = sequenceId(segment,1);
59     //else
60     //    seq_j_id = sequenceId(segment,0);
61 }
62 
63 
64 //given seq and segment, get the sequenceId (seq_i) and its begin and end
65 //if seq = 0 get first sequence (that takes part in the segment match)
66 //if seq = 1 get second sequence
67 template<typename TFragSize, typename TFragSpec, typename TId, typename TPosition, typename TId2>
68 void
_getSeqBeginAndEnd(Fragment<TFragSize,TFragSpec> & segment,std::map<const void *,int> &,TId & seq_i_id,TPosition & begin_i,TPosition & end_i,TId2 seq)69 _getSeqBeginAndEnd(Fragment<TFragSize,TFragSpec> & segment,
70                   std::map<const void * ,int> &,
71                   TId & seq_i_id,
72                   TPosition & begin_i,
73                   TPosition & end_i,
74                   TId2 seq)
75 {
76     seq_i_id = sequenceId(segment,seq);
77     if(seq==0)
78         begin_i = segment.begin1; // fragmentBegin(segment,seq_i_id);
79     else
80         begin_i = segment.begin2; // fragmentBegin(segment,seq_i_id);
81     end_i = begin_i + segment.len; //fragmentLength(segment,seq_i_id);
82 }
83 
84 
85 ////////////////////////////////////////////////////////////////////////////////////////
86 // 50000 _getRefinedMatchScore Functions
87 ////////////////////////////////////////////////////////////////////////////////////////
88 //get score for alignment starting at pos_i on one sequence (first sequence if i_am_first==true)
89 //and pos_j on other sequence (second sequence if i_am_first==true), if len1!=len2 then the refinement
90 //process was stopped (the cut is not exact)
91 //template<typename TScore,typename TStringSet,typename TFragId,typename TFragPos,typename TFragSize, typename TFragSpec,typename TValue>
92 //typename Value<TScore>::Type
93 //_getRefinedMatchScore(TScore & score_type,
94 //         TStringSet & seqs,
95 //         Fragment<TFragId,TFragPos,TFragSize,TFragSpec> & segment,
96 //         TValue pos_i,
97 //         TValue pos_j,
98 //         TValue len1,
99 //         TValue len2)
100 //{
101 //    typename Infix<typename Value<TStringSet>::Type>::Type label0 = label(segment,seqs,sequenceId(segment,0));
102 //    typename Infix<typename Value<TStringSet>::Type>::Type label1 = label(segment,seqs,sequenceId(segment,1));
103 //    int i = 0;
104 //    typename Value<TScore>::Type ret_score = 0;
105 //    TValue len = (len1 < len2) ? len1 : len2;
106 //    while(i < len)
107 //    {
108 //        ret_score += score(score_type,label0[i],label1[i]);
109 //        ++i;
110 //    }
111 //    len = (len1 > len2) ? len1 : len2;
112 //    ret_score += (len - i) * scoreGapExtend(score_type);
113 //    return ret_score;
114 //}
115 //
116 //
117 ///////////////////////////////////////////////////////////////////////////////////////////////
118 ////die n�chsten beiden funktionen: f�r Fragmente und Score vom Typ Simple
119 ////f�r den fall dass es keine mismatches innerhalb der segmente gibt und Score vom typ Simple ist
120 ////TODO: m�sste f�r einen bestimmten TFragSpec sein (Exact oder noMismatches)
121 ////get score for alignment starting at pos_i on one sequence (first sequence if i_am_first==true)
122 ////and pos_j on other sequence (second sequence if i_am_first==true), if len1!=len2 then the refinement
123 ////process was stopped (the cut is not exact)
124 //template<typename TScoreValue,typename TStringSet,typename TFragId,typename TFragPos,typename TFragSize, typename TFragSpec>
125 //TScoreValue
126 //_getRefinedMatchScore(Score<TScoreValue, Simple> & score_type,
127 //         TStringSet & seqs,
128 //         Fragment<TFragId,TFragPos,TFragSize,TFragSpec> & segment,
129 //         TFragPos pos_i,
130 //         TFragPos pos_j,
131 //         TFragSize len1,
132 //         TFragSize len2)
133 //{
134 //    typename Infix<typename Value<TStringSet>::Type>::Type label0 = label(segment,seqs,sequenceId(segment,0));
135 //    typename Infix<typename Value<TStringSet>::Type>::Type label1 = label(segment,seqs,sequenceId(segment,1));
136 //    TScoreValue ret_score = 0;
137 //    TFragSize len;
138 //    if (len1 < len2) len = len1;
139 //    else len = len2;
140 //    if(len1 <= len2)
141 //    {
142 //        ret_score += len1 * scoreMatch(score_type);
143 //        ret_score += (len2 - len1) * scoreGapExtend(score_type);
144 //    }
145 //    else{
146 //        ret_score += len2 * scoreMatch(score_type);
147 //        ret_score += (len1 - len2) * scoreGapExtend(score_type);
148 //    }
149 //    return ret_score;
150 //}
151 
152 
153 //get score for alignment of length len starting at pos_i on one sequence (first sequence if i_am_first==true)
154 //and pos_j on other sequence (second sequence if i_am_first==true)
155 template<typename TScoreValue,typename TScoreSpec,typename TStringSet,typename TFragment,typename TFragPos,typename TFragSize>
156 TScoreValue
_getRefinedMatchScore(Score<TScoreValue,TScoreSpec> & score_type,TStringSet & seqs,TFragment & segment,TFragPos pos_i,TFragPos pos_j,TFragSize len,TFragSize)157 _getRefinedMatchScore(Score<TScoreValue,TScoreSpec> & score_type,
158          TStringSet & seqs,
159          TFragment& segment,
160          TFragPos pos_i,
161          TFragPos pos_j,
162          TFragSize len,
163          TFragSize)
164 {
165     typedef typename Infix<typename Value<TStringSet>::Type>::Type TSegmentLabel;
166     TSegmentLabel label0 = label(segment,seqs, sequenceId(segment, 0));
167     TSegmentLabel label1 = label(segment,seqs, sequenceId(segment, 1));
168     typename Iterator<TSegmentLabel, Rooted>::Type label_it0 = begin(label0) + (pos_i - fragmentBegin(segment,sequenceId(segment,0)));
169     typename Iterator<TSegmentLabel, Rooted>::Type label_it1 = begin(label1) + (pos_j - fragmentBegin(segment,sequenceId(segment,1)));
170     int i = 0;
171     TScoreValue ret_score = 0;
172     while(i < (int) len)
173     {
174         ret_score += score(score_type,*label_it0,*label_it1);
175         ++label_it0;
176         ++label_it1;
177         ++i;
178     }
179     return ret_score;
180 }
181 
182 
183 //get score for alignment of length len starting at pos_i on one sequence (first sequence if i_am_first==true)
184 //and pos_j on other sequence (second sequence if i_am_first==true)
185 template<typename TScoreValue,typename TStringSet,typename TFragPos,typename TFragSize, typename TSpec>
186 TScoreValue
_getRefinedMatchScore(Score<TScoreValue,Simple> & score_type,TStringSet &,Fragment<TFragSize,ExactFragment<TSpec>> &,TFragPos,TFragPos,TFragSize len,TFragSize)187 _getRefinedMatchScore(Score<TScoreValue, Simple> & score_type,
188          TStringSet &,
189          Fragment<TFragSize,ExactFragment<TSpec> > &,
190          TFragPos,
191          TFragPos,
192          TFragSize len,
193          TFragSize)
194 {
195     return len*scoreMatch(score_type);
196 }
197 
198 
199 }  // namespace
200 
201 #endif  // #ifndef SEQAN_INCLUDE_SEQAN_GRAPH_ALGORITHM_REFINE_FRAGMENT_H_
202