NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
seed_hit.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 
35 #include <nvbio/basic/cuda/arch.h>
36 #include <nvbio/basic/pod.h>
37 #include <nvbio/io/utils.h>
38 #include <algorithm>
39 
40 namespace nvbio {
41 namespace bowtie2 {
42 namespace cuda {
43 
46 
49 
54 struct SeedHit
55 {
56  struct Flags { uint32 m_pos:10, m_rc:1, m_indexdir:1; };
57 
62  const ReadType readtype,
63  const DirType indexdir,
64  const uint32 pos)
65  {
66  Flags flags;
67  flags.m_pos = pos;
68  flags.m_rc = readtype;
69  flags.m_indexdir = indexdir;
70  return flags;
71  }
72 
76  SeedHit() {}
77 
85  SeedHit(const ReadType readtype,
86  const DirType indexdir,
87  const uint32 pos,
88  const uint2& range)
89  : m_range_begin( range.x ),
90  m_range_delta( range.y - range.x ),
91  m_pos( pos ),
92  m_rc( readtype ),
93  m_indexdir( indexdir )
94  {
95  NVBIO_CUDA_ASSERT( range.x <= range.y );
96  NVBIO_CUDA_ASSERT( range.y - range.x < (1u << 20) );
97  }
98 
104  SeedHit(const Flags flags,
105  const uint2& range)
106  : m_range_begin( range.x ),
107  m_range_delta( range.y - range.x ),
108  m_pos( flags.m_pos ),
109  m_rc( flags.m_rc ),
110  m_indexdir( flags.m_indexdir )
111  {
112  NVBIO_CUDA_ASSERT( range.x <= range.y );
113  NVBIO_CUDA_ASSERT( range.y - range.x < (1u << 20) );
114  }
115 
119  void set_range(const uint2 range)
120  {
121  NVBIO_CUDA_ASSERT( range.x <= range.y );
122  NVBIO_CUDA_ASSERT( range.y - range.x < (1u << 20) );
123  m_range_begin = range.x;
124  m_range_delta = range.y - range.x;
125  }
126 
130  uint2 get_range() const
131  { return make_uint2( m_range_begin, m_range_begin + m_range_delta ); }
132 
136  bool empty() const
137  { return m_range_delta == 0; }
138 
143  { return m_range_delta; }
144 
148  uint32 front() const { return m_range_begin; }
149 
153  uint32 back() const { return m_range_begin + m_range_delta - 1u; }
154 
159  {
160  const uint32 r = m_range_begin++;
161  --m_range_delta;
162  return r;
163  }
164 
169  {
170  const uint32 r = m_range_begin;
171  m_range_begin += n;
172  m_range_delta -= n;
173  return r;
174  }
175 
180  {
181  --m_range_delta;
182  return m_range_begin + m_range_delta;
183  }
184 
189  {
190  m_range_delta -= n;
191  return m_range_begin + m_range_delta;
192  }
193 
197  void set_posinread(const uint32 p)
198  { m_pos = p; }
199 
203  void set_readtype(const ReadType d)
204  { m_rc = d; }
205 
209  void set_indexdir(const DirType d)
210  { m_indexdir = d; }
211 
216  { return m_pos; }
217 
222  { return ReadType( m_rc ); }
223 
228  { return DirType( m_indexdir ); }
229 
230 private:
231  uint32 m_range_begin;
232  uint32 m_range_delta:20, m_pos:10, m_rc:1, m_indexdir:1;
233 };
234 
236 {
238  bool operator() (const SeedHit& f, const SeedHit& s)
239  {
240  const uint32 size_f = f.get_range_size();
241  const uint32 size_s = s.get_range_size();
242  return (size_f > size_s);
243  }
244 };
245 
248 
249 } // namespace cuda
250 } // namespace bowtie2
251 } // namespace nvbio