NCBI C++ ToolKit
scoring_method.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: scoring_method.cpp 45564 2020-09-08 19:05:27Z shkeda $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Andrey Yazhuk
27  */
28 
29 #include <ncbi_pch.hpp>
30 
31 #include <corelib/ncbistd.hpp>
32 #include <corelib/ncbistl.hpp>
33 #include <corelib/ncbireg.hpp>
34 #include <corelib/ncbifile.hpp>
35 
37 
38 #include <math.h>
39 #include <stdio.h>
40 
42 
43 
44 const char* kDNATag = "DNA";
45 const char* kProteinTag = "Protein";
46 const char* kMixedTag = "Mixed";
47 const char* kInvalidTag = "Invalid";
48 
49 
51 {
52  switch(type) {
53  case IAlnExplorer::fDNA:
54  return kDNATag;
56  return kProteinTag;
58  return kMixedTag;
59  default:
60  _ASSERT(false);
61  return "Invalid";
62  }
63 }
64 
65 
67 {
68  if(tag == kDNATag) {
69  return IAlnExplorer::fDNA;
70  } else if(tag == kProteinTag) {
72  } else if(tag == kMixedTag) {
73  return IAlnExplorer::fMixed;
74  } else {
76  }
77 }
78 /*
79 
80 int IScoringAlignment::GetGenCode(IAlnExplorer::TNumrow row) const
81 {
82  int gencode = 1;
83  if (!m_GenCodeCache || (*m_GenCodeCache)[row] == -1) {
84  gencode = CSeqUtils::GetGenCode(GetBioseqHandle(row));
85  m_GenCodeCache.reset(new vector<int>(GetNumRows(), -1));
86  (*m_GenCodeCache)[row] = gencode;
87  } else {
88  gencode = (*m_GenCodeCache)[row];
89  }
90  return gencode;
91 }
92 */
93 ///////////////////////////////////////////////////////////////////////////////
94 /// CTemplateScoringMethod
95 
97  m_Averageable(false),
98  m_ColorGradType(eTwoColorGradient)
99 {
100 }
101 
102 
104 {
105 }
106 
107 
109 {
110  return m_Name;
111 }
112 
113 
115 {
116  return m_Descr;
117 }
118 
119 
121 {
122  return m_Type;
123 }
124 
125 
127 {
128  return m_Averageable;
129 }
130 
131 
133 {
134  return fBackground;
135 }
136 
137 
139 {
140  m_Name = reg.GetString("Info", "Name", "");
141  m_Descr = reg.GetString("Info", "Description", "");
142 
143  // process method type definition
144  string type = reg.GetString("Info", "Type", "");
145  list<string> values;
146  NStr::Split(type, ", ", values, NStr::fSplit_Tokenize); // parse into tokens
147 
148  m_Type = 0;
149  ITERATE(list<string>, it, values) { // convert tokens to flags
150  const string& val = *it;
151  if(val == "DNA") {
153  } else if(val == "Protein") {
155  } else {
156  ERR_POST("CTemplateScoringMethod::Load() - unsupported method type \""
157  << val << "\".");
158  }
159  }
160 
161  string gradient = reg.Get("Info", "Gradient");
162 
163  m_ColorGradType = (gradient == "3Colors") ? eThreeColorGradient
165  return true;
166 }
167 
168 
170 {
171  reg.Set("Info", "Name", m_Name, IRegistry::fPersistent);
172  reg.Set("Info", "Description", m_Descr, IRegistry::fPersistent);
173 
174  string types;
175  if (m_Type & IAlnExplorer::fDNA) {
176  types += "DNA ";
177  }
179  types += "Protein ";
180  }
181  reg.Set("Info", "Type", types,
183 
184  string gradtype;
186  gradtype = "3Colors";
187  } else {
188  gradtype = "2Colors";
189  }
190  reg.Set("Info", "Gradient", gradtype, IRegistry::fPersistent);
191 
192  return true;
193 }
194 
195 
197 {
198  return LoadInfo(reg);
199 }
200 
201 
202 void CTemplateScoringMethod::SetName(const string& s)
203 {
204  m_Name = s;
205 }
206 
207 
209 {
210  m_Descr = s;
211 }
212 
213 
215 {
216  return SaveInfo(reg);
217 }
218 
219 
221  const string& key,
222  const string def_value)
223 {
224  CRgbaColor color(0.0f, 0.0f, 0.0f);
225  try {
226  string str = reg.GetString("Table", key, def_value);
228  }
229  catch (std::exception&) {
230  }
231  return color;
232 }
233 
234 
CNcbiRegistry –.
Definition: ncbireg.hpp:913
class CRgbaColor provides a simple abstraction for managing colors.
Definition: rgba_color.hpp:58
virtual string GetDescription() const
returns a detailed description of the method that is used in UI
virtual string GetName() const
returns unique name of the method that is used in UI to identify it
virtual bool SaveInfo(CNcbiRegistry &reg)
saves only descriptive information
EColorGradType m_ColorGradType
virtual bool Save(CNcbiRegistry &reg)
virtual bool Load(CNcbiRegistry &reg)
CTemplateScoringMethod()
CTemplateScoringMethod.
CRgbaColor x_GetColor(CNcbiRegistry &reg, const string &key, const string def_value)
void SetDescription(const string &s)
virtual int GetType() const
returns combination of EAlignType flags defining types of alignments that can be colored with this me...
virtual bool LoadInfo(CNcbiRegistry &reg)
loads only descriptive information
void SetName(const string &s)
virtual int GetSupportedColorTypes() const
returns a combination of EColorType flags
virtual bool IsAverageable() const
return "true" if scores could be averaged
static const char * GetAlignmentTagByType(IAlnExplorer::EAlignType type)
returns symbolic label for the given alignment type, should be
static IAlnExplorer::EAlignType GetAlignmentTypeByTag(const string &tag)
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define false
Definition: bool.h:36
static const char * str(char *buf, int n)
Definition: stats.c:84
static const struct type types[]
Definition: type.c:22
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
static CRgbaColor GetColor(const string &color_type)
return a color based on a string.
virtual const string & Get(const string &section, const string &name, TFlags flags=0) const
Get the parameter value.
Definition: ncbireg.cpp:262
virtual string GetString(const string &section, const string &name, const string &default_value, TFlags flags=0) const
Get the parameter string value.
Definition: ncbireg.cpp:321
bool Set(const string &section, const string &name, const string &value, TFlags flags=0, const string &comment=kEmptyStr)
Set the configuration parameter value.
Definition: ncbireg.cpp:826
@ fTruncate
Leading, trailing blanks can be truncated.
Definition: ncbireg.hpp:87
@ fPersistent
Persistent – saved when file is written.
Definition: ncbireg.hpp:84
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3461
@ fSplit_Tokenize
All delimiters are merged and trimmed, to get non-empty tokens only.
Definition: ncbistr.hpp:2508
n background color
const struct ncbi::grid::netcache::search::fields::KEY key
const char * tag
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
Process information in the NCBI Registry, including working with configuration files.
The NCBI C++/STL use hints.
const char * kInvalidTag
const char * kDNATag
const char * kMixedTag
const char * kProteinTag
Definition: type.c:6
#define _ASSERT
Modified on Wed Jun 12 11:13:40 2024 by modify_doxy.py rev. 669887