NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stats.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 
32 #include <nvbio/basic/timer.h>
33 #include <vector>
34 #include <deque>
35 
36 namespace nvbio { namespace io { struct BestAlignments; } }
37 
38 namespace nvbio {
39 namespace bowtie2 {
40 namespace cuda {
41 
43 
44 
46 {
48  : n_mapped(0),
49  n_ambiguous(0),
50  n_unambiguous(0),
51  n_unique(0),
52  n_multiple(0),
53  mapped_ed_histogram(4096, 0),
54  mapped_ed_histogram_fwd(4096, 0),
55  mapped_ed_histogram_rev(4096, 0),
57  {
58  for(uint32 c = 0; c < 64; c++)
59  mapq_bins[c] = 0;
60 
61  for(uint32 c = 0; c < 8; c++)
62  mapq_log_bins[c] = 0;
63 
64  for(uint32 c = 0; c < 64; c++)
65  for(uint32 d = 0; d < 64; d++)
66  mapped_ed_correlation[c][d] = 0;
67  }
68 
69  // mapping quality stats
72 
73  // mapping stats
74  uint32 n_mapped; // number of mapped reads
75 
76  uint32 n_ambiguous; // number of reads mapped to more than one place with the same score
77  uint32 n_unambiguous; // number of reads with a single best score (even if mapped to multiple locations)
78 
79  uint32 n_unique; // number of reads mapped to a single location
80  uint32 n_multiple; // number of reads mapped to more than one location
81 
82  // edit distance scoring histograms
83  std::vector<uint32> mapped_ed_histogram; // aggregate histogram of edit-distance scores per read
84  std::vector<uint32> mapped_ed_histogram_fwd; // histogram of edit-distance scores for reads mapped to the forward sequence
85  std::vector<uint32> mapped_ed_histogram_rev; // histogram of edit-distance scores for reads mapped to the reverse-complemented sequence
86  std::vector<uint32> mapped_log_ed_histogram; // aggregate histogram of log edit-distance scores per read
87  std::vector<uint32> mapped_log_mapq_histogram; // aggregate histogram of log mapq scores per read
88 
89  // edit distance correlation (xxxnsubtil: what exactly does this measure?)
91 
92  // merge stats
93  void merge(const AlignmentStats& stats)
94  {
95  n_mapped += stats.n_mapped;
96  n_ambiguous += stats.n_ambiguous;
98  n_unique += stats.n_unique;
99  n_multiple += stats.n_multiple;
100 
101  for (uint32 i = 0; i < mapped_ed_histogram.size(); ++i)
102  {
106  }
107  for (uint32 i = 0; i < 12; ++i)
109 
110  for(uint32 c = 0; c < 64; c++)
111  mapq_bins[c] += stats.mapq_bins[c];
112 
113  for(uint32 c = 0; c < 8; c++)
114  mapq_log_bins[c] += stats.mapq_log_bins[c];
115 
116  for(uint32 c = 0; c < 64; c++)
117  for(uint32 d = 0; d < 64; d++)
118  mapped_ed_correlation[c][d] += stats.mapped_ed_correlation[c][d];
119  }
120 };
121 
122 //
123 // Global statistics
124 //
125 struct Stats
126 {
127  // constructor
128  Stats(const Params _params = Params());
129 
130  // timing stats
131  float global_time;
146 
147  // detailed mapping stats
152 
153  // mapping stats
155 
156  // extensive (seeding) stats
166 
168 
170  const io::BestAlignments& alignment1,
171  const io::BestAlignments& alignment2,
172  const uint8 mapq);
173 
175  AlignmentStats* mate,
176  const io::BestAlignments& alignment,
177  const uint8 mapq);
178 };
179 
180 void generate_report_header(const uint32 n_reads, const Params& params, AlignmentStats& aln_stats, const uint32 n_devices, const Stats* device_stats, const char* report);
181 void generate_device_report(const uint32 id, Stats& stats, AlignmentStats& aln_stats, const char* report);
182 
183 } // namespace cuda
184 } // namespace bowtie2
185 } // namespace nvbio