NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
output_priv.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 
34 
35 #include <thrust/host_vector.h>
36 #include <thrust/device_vector.h>
37 
40 
41 #include <stdio.h>
42 
43 namespace nvbio {
44 namespace io {
45 
46 // Utility struct to gather all data related to a given alignment.
47 // This breaks out the alignment data for a given alignment by setting up
48 // pointers to the relevant bits of data pulled from the GPU buffers.
50 {
54 
55  bool valid;
56  const Alignment* aln;
60 
61  // Pointers to the read_data, cigar and mds arrays for this read.
62  // These are not really meant to be used outside AlignmentData and
63  // should probably be removed
64 
68 
69  // the remaining fields are derived from best, read_data_batch,
70  // cigar_array and mds_array in the ctor
71  // they are commonly used when writing alignment data out to disk
72 
75  const char *read_name;
76 
78  const char *qual;
79 
80  const Cigar *cigar;
84  const uint8 *mds_vec;
85 
87  : valid(false),
88  aln(NULL),
89  aln_id(0xffffffff),
90  read_id(0xffffffff),
91  read_data_batch_p(NULL),
92  cigar_array_p(NULL),
93  mds_array_p(NULL),
94  read_offset(0xffffffff),
95  read_len(0xffffffff),
96  read_name(NULL),
97  qual(NULL),
98  cigar(NULL),
99  cigar_pos(0xffffffff),
100  cigar_len(0xffffffff)
101  {}
102 
104  const uint32 _mapq,
105  const uint32 _aln_id,
106  const uint32 _read_id,
107  const io::SequenceDataHost* read_data_batch,
108  const HostCigarArray* cigar_array,
109  const HostMdsArray* mds_array)
110  : valid(true),
111  aln(_aln),
112  aln_id(_aln_id),
113  read_id(_read_id),
114  mapq(_mapq),
115  read_data_batch_p(read_data_batch),
116  cigar_array_p(cigar_array),
117  mds_array_p(mds_array)
118  {
119  uint2 cigar_coord;
120 
121  read_access_type read_data_access( *read_data_batch );
122 
123  read_offset = read_data_access.sequence_index()[read_id];
124  read_len = read_data_access.sequence_index()[read_id + 1] - read_offset;
125  read_name = read_data_access.name_stream() + read_data_access.name_index()[read_id];
126 
127  read_data = read_data_access.sequence_stream() + read_offset;
128  qual = read_data_access.qual_stream() + read_offset;
129 
131  cigar_coord = cigar_array_p->coords[aln_id];
132  cigar_pos = compute_cigar_pos(cigar_coord.x, aln->alignment());
133  cigar_len = cigar_coord.y;
134 
135  mds_vec = (*mds_array)[aln_id];
136  }
137 
138  static AlignmentData invalid(void) { return AlignmentData(); }
139 };
140 
141 // extract alignment data for a given mate
142 // note that the mates can be different for the cigar, since mate 1 is always the anchor mate for cigars
143 AlignmentData get(HostOutputBatchSE& batch, const uint32 aln_id);
144 
145 // extract alignment data for a given mate
146 AlignmentData get_mate(HostOutputBatchPE& batch, const uint32 aln_id, const AlignmentMate mate);
147 // extract alignment data for the anchor mate
148 AlignmentData get_anchor_mate(HostOutputBatchPE& batch, const uint32 aln_id);
149 // extract alignment data for the opposite mate
150 AlignmentData get_opposite_mate(HostOutputBatchPE& batch, const uint32 aln_id);
151 
152 } // namespace io
153 } // namespace nvbio