NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sequence_access.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 
28 #pragma once
29 
30 #include <nvbio/strings/alphabet.h>
35 
36 namespace nvbio {
37 namespace io {
38 
41 
44 
77 template <
78  Alphabet SEQUENCE_ALPHABET_T,
79  typename SequenceDataT = ConstSequenceDataView>
81 {
82  static const Alphabet SEQUENCE_ALPHABET = SEQUENCE_ALPHABET_T;
86 
87  typedef typename SequenceDataT::const_index_iterator index_iterator;
88  typedef typename SequenceDataT::const_sequence_storage_iterator sequence_storage_iterator;
89  typedef typename SequenceDataT::const_qual_storage_iterator qual_storage_iterator;
90  typedef typename SequenceDataT::const_name_storage_iterator name_storage_iterator;
91 
92  typedef SequenceDataViewCore<
97 
98  typedef PackedStream<
100 
104 
105  typedef ConcatenatedStringSet<
108 
109  typedef ConcatenatedStringSet<
112 
113  typedef ConcatenatedStringSet<
116 
124 
130 
133  NVBIO_HOST_DEVICE NVBIO_FORCEINLINE SequenceDataAccess(const SequenceDataT& data) : m_data( data )
134  {
135  #if !defined(NVBIO_DEVICE_COMPILATION) || defined(NVBIO_CUDA_DEBUG)
136  assert( m_data.m_alphabet == SEQUENCE_ALPHABET );
137  #endif
138  }
139 
142  NVBIO_HOST_DEVICE NVBIO_FORCEINLINE uint2 get_range(const uint32 i) const { return make_uint2(sequence_index()[i],sequence_index()[i+1]); }
143 
147 
151  {
153  size(),
155  sequence_index() );
156  }
157 
161  {
162  const uint2 sequence_range = get_range( i );
163  return sequence_string( sequence_range.y - sequence_range.x, sequence_stream().begin() + sequence_range.x );
164  }
165 
169  {
170  const uint2 sequence_range = get_range( i );
171  return qual_string( sequence_range.y - sequence_range.x, qual_stream() + sequence_range.x );
172  }
173 
177  {
178  const uint2 name_range = make_uint2( name_index()[i], name_index()[i+1] );
179  return name_string( name_range.y - name_range.x - 1u, name_stream() + name_range.x );
180  }
181 
185  {
186  return qual_string_set_type(
187  size(),
188  qual_stream(),
189  sequence_index() );
190  }
191 
192 
196  {
197  return name_string_set_type(
198  size(),
199  name_stream(),
200  name_index() );
201  }
202 
204 };
205 
206 template <Alphabet ALPHABET, typename SequenceDataT>
208 {
210 }
211 
221 template <
222  Alphabet SEQUENCE_ALPHABET_T,
223  typename SequenceDataT>
225 {
226  static const Alphabet SEQUENCE_ALPHABET = SEQUENCE_ALPHABET_T;
230 
231  typedef typename SequenceDataT::index_iterator index_iterator;
232  typedef typename SequenceDataT::sequence_storage_iterator sequence_storage_iterator;
233  typedef typename SequenceDataT::qual_storage_iterator qual_storage_iterator;
234  typedef typename SequenceDataT::name_storage_iterator name_storage_iterator;
235 
236  typedef SequenceDataViewCore<
241 
242  typedef PackedStream<
244 
246 
247  typedef ConcatenatedStringSet<
250 
251  typedef ConcatenatedStringSet<
254 
255  typedef ConcatenatedStringSet<
258 
266 
272 
278 
282  {
283  #if !defined(NVBIO_DEVICE_COMPILATION) || defined(NVBIO_CUDA_DEBUG)
284  assert( m_data.m_alphabet == SEQUENCE_ALPHABET );
285  #endif
286  }
287 
290  NVBIO_HOST_DEVICE NVBIO_FORCEINLINE uint2 get_range(const uint32 i) const { return make_uint2(sequence_index()[i],sequence_index()[i+1]); }
291 
295 
299 
303  {
305  size(),
307  sequence_index() );
308  }
309 
313  {
315  size(),
317  sequence_index() );
318  }
319 
323  {
324  const uint2 sequence_range = get_range( i );
325  return sequence_string( sequence_range.y - sequence_range.x, sequence_stream().begin() + sequence_range.x );
326  }
327 
331  {
332  return qual_string_set_type(
333  size(),
334  qual_stream(),
335  sequence_index() );
336  }
337 
341  {
342  return qual_string_set_type(
343  size(),
344  qual_stream(),
345  sequence_index() );
346  }
347 
351  {
352  return name_string_set_type(
353  size(),
354  name_stream(),
355  name_index() );
356  }
357 
361  {
362  return name_string_set_type(
363  size(),
364  name_stream(),
365  name_index() );
366  }
367 
369 };
370 
373 
374 } // namespace io
375 } // namespace nvbio