NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
scoring_inl.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 <stdio.h>
31 
32 namespace nvbio {
33 namespace bowtie2 {
34 namespace cuda {
35 
36 inline
38 {
39  FILE* file = fopen( name, "r" );
40  if (file == NULL)
42 
43  std::map<std::string,std::string> options;
44  char key[1024];
45  char value[1024];
46 
47  while (fscanf( file, "%s %s", key, value ) == 2)
48  options[ key ] = std::string( value );
49 
50  fclose( file );
51 
52  return SmithWatermanScoringScheme<>( options, type );
53 }
54 
55 template <
56  typename MMCost,
57  typename NCost>
59 {
60  std::map<std::string,std::string> options;
61  options["match"] = std::string("1");
62  options["mm-penalty-min"] = std::string("3");
63  options["mm-penalty-max"] = std::string("3");
64  options["N-penalty-min"] = std::string("3");
65  options["N-penalty-max"] = std::string("3");
66  options["score-min-const"] = std::string("37.0f");
67  options["score-min-coeff"] = std::string("0.3f");
68  options["N-ceil-const"] = std::string("2.0f");
69  options["N-ceil-coeff"] = std::string("0.1f");
70  options["read-gap-const"] = std::string("11");
71  options["read-gap-coeff"] = std::string("4");
72  options["ref-gap-const"] = std::string("11");
73  options["ref-gap-coeff"] = std::string("4");
74  options["gap-free"] = std::string("5");
76 }
77 
78 template <
79  typename MMCost,
80  typename NCost>
82 {
83  std::map<std::string,std::string> options;
84  options["match"] = std::string("2");
85  options["mm-penalty-min"] = std::string("2");
86  options["mm-penalty-max"] = std::string("6");
87  options["N-penalty-min"] = std::string("1");
88  options["N-penalty-max"] = std::string("1");
89  options["score-min-const"] = std::string("0.0f");
90  options["score-min-coeff"] = std::string("10.0f");
91  options["score-min-type"] = std::string("log");
92  options["N-ceil-const"] = std::string("0.0f");
93  options["N-ceil-coeff"] = std::string("0.15f");
94  options["read-gap-const"] = std::string("5");
95  options["read-gap-coeff"] = std::string("3");
96  options["ref-gap-const"] = std::string("5");
97  options["ref-gap-coeff"] = std::string("3");
98  options["gap-free"] = std::string("5");
100 }
101 
102 // default constructor
103 //
104 template <
105  typename MMCost,
106  typename NCost>
109  m_score_min( SimpleFunc::LinearFunc, -0.6f, -0.6f ),
110  m_n_ceil_const( 0.0f ),
111  m_n_ceil_coeff( 0.15f ),
112  m_read_gap_const( 5 ),
113  m_read_gap_coeff( 3 ),
114  m_ref_gap_const( 5 ),
115  m_ref_gap_coeff( 3 ),
116  m_gap_free( 5 ),
117  m_match( 0, 0 ),
118  m_mmp( 2, 6 ),
119  m_np( 1, 1 ),
120  m_monotone( true ),
121  m_local( false )
122 {}
123 
124 // constructor
125 //
126 // \param options key/value string options
127 template <
128  typename MMCost,
129  typename NCost>
131  const std::map<std::string,std::string>& options,
132  const AlignmentType type) :
133  m_score_min( min_score_function(options) ),
134  m_n_ceil_const( float_option( options, "N-ceil-const", 0.0f ) ),
135  m_n_ceil_coeff( float_option( options, "N-ceil-coeff", 0.15f ) ),
136  m_read_gap_const( int_option( options, "read-gap-const", 5 ) ),
137  m_read_gap_coeff( int_option( options, "read-gap-coeff", 3 ) ),
138  m_ref_gap_const( int_option( options, "ref-gap-const", 5 ) ),
139  m_ref_gap_coeff( int_option( options, "ref-gap-coeff", 3 ) ),
140  m_gap_free( int_option( options, "gap-free", 5 ) ),
141  m_match( match_cost(options) ),
142  m_mmp( mm_cost(options) ),
143  m_np( n_cost(options) ),
144  m_monotone( m_match(0) == 0 ),
145  m_local( type == LocalAlignment ? true : false )
146 {}
147 
148 
149 template <
150  typename MMCost,
151  typename NCost>
153 {
154  if (strcmp( type.c_str(), "log" ) == 0)
155  return SimpleFunc::LogFunc;
156  else if (strcmp( type.c_str(), "sqrt" ) == 0)
157  return SimpleFunc::SqrtFunc;
158 
159  return SimpleFunc::LinearFunc;
160 }
161 
162 template <
163  typename MMCost,
164  typename NCost>
165 SimpleFunc SmithWatermanScoringScheme<MMCost,NCost>::min_score_function(const std::map<std::string,std::string>& options)
166 {
167  return SimpleFunc(
168  func_type( string_option( options, "score-min-type", "linear" ) ),
169  float_option( options, "score-min-const", -0.6f ), // 37.0f
170  float_option( options, "score-min-coeff", -0.6f ) ); // 0.3f
171 }
172 template <
173  typename MMCost,
174  typename NCost>
175 typename SmithWatermanScoringScheme<MMCost,NCost>::MatchCost SmithWatermanScoringScheme<MMCost,NCost>::match_cost(const std::map<std::string,std::string>& options)
176 {
177  const int match_cost = int_option( options, "match", 0 );
178  return MatchCost( match_cost, match_cost );
179 }
180 template <
181  typename MMCost,
182  typename NCost>
183 MMCost SmithWatermanScoringScheme<MMCost,NCost>::mm_cost(const std::map<std::string,std::string>& options)
184 {
185  const int mmp_min = int_option( options, "mm-penalty-min", 2 );
186  const int mmp_max = int_option( options, "mm-penalty-max", 6 );
187  return MMCost( mmp_min, mmp_max );
188 }
189 template <
190  typename MMCost,
191  typename NCost>
192 NCost SmithWatermanScoringScheme<MMCost,NCost>::n_cost(const std::map<std::string,std::string>& options)
193 {
194  const int np_min = int_option( options, "N-penalty-min", 1 );
195  const int np_max = int_option( options, "N-penalty-max", 1 );
196  return NCost( np_min, np_max );
197 }
198 
199 } // namespace cuda
200 } // namespace bowtie2
201 } // namespace nvbio