NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
reduce.h
Go to the documentation of this file.
1 /*
2  * nvbio
3  * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the NVIDIA CORPORATION nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
31 
32 #pragma once
33 
37 
38 namespace nvbio {
39 namespace bowtie2 {
40 namespace cuda {
41 
42 struct ParamsPOD;
43 
44 template <typename ScoringScheme> struct BaseScoringPipelineState;
45 template <typename ScoringScheme> struct BestApproxScoringPipelineState;
46 
49 
52 
64 {
70  ReduceBestApproxContext(uint32* trys, const uint32 n_ext) : m_trys( trys ), m_ext( n_ext ) {}
71 
75  void best_score(const uint32 read_id, const ParamsPOD& params) const
76  {
77  // reset the try counter
78  m_trys[ read_id ] = params.max_effort;
79  }
83  void second_score(const uint32 read_id, const ParamsPOD& params) const
84  {
85  // reset the try counter
86  m_trys[ read_id ] = params.max_effort;
87  }
91  bool failure(const uint32 idx, const uint32 read_id, const uint32 top_flag, const ParamsPOD& params) const
92  {
93  if (m_trys[ read_id ] > 0)
94  {
95  if (((m_ext+idx >= params.min_ext) && (top_flag == 0) && (--m_trys[ read_id ] == 0)) || // bowtie2 does 1 more alignment than effort limit, we don't
96  (m_ext+idx >= params.max_ext))
97  return true;
98  }
99  return false;
100  }
101 
102 private:
103  uint32* m_trys;
104  uint32 m_ext;
105 };
106 
114 {
116 
120  void best_score(const uint32 read_id, const ParamsPOD& params) const {}
121 
125  void second_score(const uint32 read_id, const ParamsPOD& params) const {}
126 
130  bool failure(const uint32 idx, const uint32 read_id, const uint32 top_flag, const ParamsPOD& params) const { return false; }
131 };
132 
136 void score_reduce(
137  const ReduceBestApproxContext context,
138  const BestApproxScoringPipelineState<EditDistanceScoringScheme>& pipeline,
139  const ParamsPOD& params);
140 
144 void score_reduce(
145  const ReduceBestApproxContext context,
146  const BestApproxScoringPipelineState<SmithWatermanScoringScheme<> >& pipeline,
147  const ParamsPOD& params);
148 
153  const ReduceBestApproxContext context,
154  const BestApproxScoringPipelineState<EditDistanceScoringScheme>& pipeline,
155  const ParamsPOD& params);
156 
161  const ReduceBestApproxContext context,
162  const BestApproxScoringPipelineState<SmithWatermanScoringScheme<> >& pipeline,
163  const ParamsPOD& params);
164 
167 
168 } // namespace cuda
169 } // namespace bowtie2
170 } // namespace nvbio
171