stats.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. #pragma once
  28. #include <nvBowtie/bowtie2/cuda/defs.h>
  29. #include <nvBowtie/bowtie2/cuda/params.h>
  30. #include <nvbio/basic/timer.h>
  31. #include <vector>
  32. #include <deque>
  33. namespace nvbio { namespace io { struct BestAlignments; } }
  34. namespace nvbio {
  35. namespace bowtie2 {
  36. namespace cuda {
  37. typedef nvbio::TimeSeries KernelStats;
  38. struct AlignmentStats
  39. {
  40. AlignmentStats()
  41. : n_mapped(0),
  42. n_ambiguous(0),
  43. n_unambiguous(0),
  44. n_unique(0),
  45. n_multiple(0),
  46. mapped_ed_histogram(4096, 0),
  47. mapped_ed_histogram_fwd(4096, 0),
  48. mapped_ed_histogram_rev(4096, 0),
  49. mapped_log_ed_histogram(12, 0)
  50. {
  51. for(uint32 c = 0; c < 64; c++)
  52. mapq_bins[c] = 0;
  53. for(uint32 c = 0; c < 8; c++)
  54. mapq_log_bins[c] = 0;
  55. for(uint32 c = 0; c < 64; c++)
  56. for(uint32 d = 0; d < 64; d++)
  57. mapped_ed_correlation[c][d] = 0;
  58. }
  59. // mapping quality stats
  60. uint64 mapq_bins[64];
  61. uint64 mapq_log_bins[8];
  62. // mapping stats
  63. uint32 n_mapped; // number of mapped reads
  64. uint32 n_ambiguous; // number of reads mapped to more than one place with the same score
  65. uint32 n_unambiguous; // number of reads with a single best score (even if mapped to multiple locations)
  66. uint32 n_unique; // number of reads mapped to a single location
  67. uint32 n_multiple; // number of reads mapped to more than one location
  68. // edit distance scoring histograms
  69. std::vector<uint32> mapped_ed_histogram; // aggregate histogram of edit-distance scores per read
  70. std::vector<uint32> mapped_ed_histogram_fwd; // histogram of edit-distance scores for reads mapped to the forward sequence
  71. std::vector<uint32> mapped_ed_histogram_rev; // histogram of edit-distance scores for reads mapped to the reverse-complemented sequence
  72. std::vector<uint32> mapped_log_ed_histogram; // aggregate histogram of log edit-distance scores per read
  73. std::vector<uint32> mapped_log_mapq_histogram; // aggregate histogram of log mapq scores per read
  74. // edit distance correlation (xxxnsubtil: what exactly does this measure?)
  75. uint32 mapped_ed_correlation[64][64];
  76. // merge stats
  77. void merge(const AlignmentStats& stats)
  78. {
  79. n_mapped += stats.n_mapped;
  80. n_ambiguous += stats.n_ambiguous;
  81. n_unambiguous += stats.n_unambiguous;
  82. n_unique += stats.n_unique;
  83. n_multiple += stats.n_multiple;
  84. for (uint32 i = 0; i < mapped_ed_histogram.size(); ++i)
  85. {
  86. mapped_ed_histogram[i] += stats.mapped_ed_histogram[i];
  87. mapped_ed_histogram_fwd[i] += stats.mapped_ed_histogram_fwd[i];
  88. mapped_ed_histogram_rev[i] += stats.mapped_ed_histogram_rev[i];
  89. }
  90. for (uint32 i = 0; i < 12; ++i)
  91. mapped_log_ed_histogram[i] += stats.mapped_log_ed_histogram[i];
  92. for(uint32 c = 0; c < 64; c++)
  93. mapq_bins[c] += stats.mapq_bins[c];
  94. for(uint32 c = 0; c < 8; c++)
  95. mapq_log_bins[c] += stats.mapq_log_bins[c];
  96. for(uint32 c = 0; c < 64; c++)
  97. for(uint32 d = 0; d < 64; d++)
  98. mapped_ed_correlation[c][d] += stats.mapped_ed_correlation[c][d];
  99. }
  100. };
  101. //
  102. // Global statistics
  103. //
  104. struct Stats
  105. {
  106. // constructor
  107. Stats(const Params _params = Params());
  108. // timing stats
  109. float global_time;
  110. KernelStats map;
  111. KernelStats select;
  112. KernelStats sort;
  113. KernelStats locate;
  114. KernelStats score;
  115. KernelStats opposite_score;
  116. KernelStats backtrack;
  117. KernelStats backtrack_opposite;
  118. KernelStats finalize;
  119. KernelStats alignments_DtoH;
  120. KernelStats read_HtoD;
  121. KernelStats read_io;
  122. KernelStats io;
  123. KernelStats scoring_pipe;
  124. // detailed mapping stats
  125. AlignmentStats concordant;
  126. AlignmentStats discordant;
  127. AlignmentStats mate1;
  128. AlignmentStats mate2;
  129. // mapping stats
  130. uint32 n_reads;
  131. // extensive (seeding) stats
  132. uint64 hits_total;
  133. uint64 hits_ranges;
  134. uint32 hits_max;
  135. uint32 hits_max_range;
  136. uint64 hits_top_total;
  137. uint32 hits_top_max;
  138. uint64 hits_bins[28];
  139. uint64 hits_top_bins[28];
  140. uint32 hits_stats;
  141. Params params;
  142. void track_alignment_statistics(
  143. const io::BestAlignments& alignment1,
  144. const io::BestAlignments& alignment2,
  145. const uint8 mapq);
  146. void track_alignment_statistics(
  147. AlignmentStats* mate,
  148. const io::BestAlignments& alignment,
  149. const uint8 mapq);
  150. };
  151. 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);
  152. void generate_device_report(const uint32 id, Stats& stats, AlignmentStats& aln_stats, const char* report);
  153. } // namespace cuda
  154. } // namespace bowtie2
  155. } // namespace nvbio