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 
30 #include <nvbio-aln-diff/utils.h>
32 
33 namespace nvbio {
34 namespace alndiff {
35 
36 enum Type { LOWER = 0, HIGHER = 1 };
37 enum Bins { LINEAR = 0, LOG = 1 };
38 
40 {
50 };
51 
52 template <Type TYPE_T, Bins BINS_T>
53 struct Stats
54 {
55  static const Type TYPE = TYPE_T;
56  static const Bins BINS = BINS_T;
57 
59 
60  Bins bin_type() const { return BINS; }
61 
62  int32 push(const int32 val1, const int32 val2, const uint32 length_bin, const uint32 mapQ1, const uint32 mapQ2)
63  {
64  l.hist.push( (BINS == LOG) ? log_bin(val1) : val1 );
65  l.hist_by_length.push( length_bin, log_bin( val1 ) );
66  l.hist_by_mapQ.push( log_bin( mapQ1 ), log_bin( val1 ) );
67 
68  r.hist.push( (BINS == LOG) ? log_bin(val2) : val2 );
69  r.hist_by_length.push( length_bin, log_bin( val2 ) );
70  r.hist_by_mapQ.push( log_bin( mapQ2 ), log_bin( val2) );
71 
72  if (TYPE == LOWER)
73  {
74  const int32 diff = int32(val2) - int32(val1);
75  if (diff >= 0)
76  {
77  const int32 log_diff = log_bin( diff );
78  l.diff_hist.push( (BINS == LOG) ? log_diff : diff );
79  l.diff_hist_by_length.push( length_bin, log_diff );
80  l.diff_hist_by_mapQ1.push( log_bin(mapQ1), log_diff );
81  l.diff_hist_by_mapQ2.push( log_bin(mapQ2), log_diff );
82  if (val1 < 0)
83  l.diff_hist_by_value_neg.push( log_bin(-val1), log_diff );
84  else
85  l.diff_hist_by_value_pos.push( log_bin(val1), log_diff );
86  }
87  if (diff <= 0)
88  {
89  const int32 log_diff = log_bin( -diff );
90  r.diff_hist.push( (BINS == LOG) ? log_diff : -diff );
91  r.diff_hist_by_length.push( length_bin, log_diff );
92  r.diff_hist_by_mapQ1.push( log_bin(mapQ1), log_diff );
93  r.diff_hist_by_mapQ2.push( log_bin(mapQ2), log_diff );
94  if (val2 < 0)
95  r.diff_hist_by_value_neg.push( log_bin(-val2), log_diff );
96  else
97  r.diff_hist_by_value_pos.push( log_bin(val2), log_diff );
98  }
99  return diff;
100  }
101  else
102  {
103  const int32 diff = int32(val1) - int32(val2);
104  if (diff >= 0)
105  {
106  const int32 log_diff = log_bin( diff );
107  l.diff_hist.push( (BINS == LOG) ? log_diff : diff );
108  l.diff_hist_by_length.push( length_bin, log_diff );
109  l.diff_hist_by_mapQ1.push( log_bin(mapQ1), log_diff );
110  l.diff_hist_by_mapQ2.push( log_bin(mapQ2), log_diff );
111  if (val2 < 0)
112  l.diff_hist_by_value_neg.push( log_bin(-val2), log_diff );
113  else
114  l.diff_hist_by_value_pos.push( log_bin(val2), log_diff );
115  }
116  if (diff <= 0)
117  {
118  const int32 log_diff = log_bin( -diff );
119  r.diff_hist.push( (BINS == LOG) ? log_diff : -diff );
120  r.diff_hist_by_length.push( length_bin, log_diff );
121  r.diff_hist_by_mapQ1.push( log_bin(mapQ1), log_diff );
122  r.diff_hist_by_mapQ2.push( log_bin(mapQ2), log_diff );
123  if (val1 < 0)
124  r.diff_hist_by_value_neg.push( log_bin(-val1), log_diff );
125  else
126  r.diff_hist_by_value_pos.push( log_bin(val1), log_diff );
127  }
128  return diff;
129  }
130  }
131 
134 };
135 
137 {
147 };
148 
149 } // namespace alndiff
150 } // namespace nvbio