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

Go to the SVN repository for this file.

1 /* $Id: track_data.cpp 93579 2021-05-01 20:54:52Z stakhovv $
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  * Author: Frank Ludwig
27  *
28  * File Description:
29  * WIGGLE transient data structures
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistd.hpp>
35 #include <corelib/ncbiapp.hpp>
36 
41 
47 
49 BEGIN_SCOPE(objects) // namespace ncbi::objects::
50 
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
54 {
55 }
56 
57 
58 // ----------------------------------------------------------------------------
60  const LineData& linedata )
61 // ----------------------------------------------------------------------------
62 {
63  return ( !linedata.empty() && linedata[0] == "track" );
64 }
65 
66 // ----------------------------------------------------------------------------
68  const LineData& linedata )
69 // ----------------------------------------------------------------------------
70 {
71  if ( !IsTrackData(linedata) ) {
72  return false;
73  }
74  string s = mData["name"];
75  mData.clear();
76 
77  LineData::const_iterator cit = linedata.begin();
78  for ( cit++; cit != linedata.end(); ++cit ) {
79  string key, value;
80  NStr::SplitInTwo( *cit, "=", key, value );
81  value = NStr::Replace(value, "\"", " ");
83  mData[key] = value;
84  }
85  return true;
86 }
87 
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
91 {
92  string offset = ValueOf("offset");
93  if (offset.empty()) {
94  return 0;
95  }
96  return NStr::StringToInt(offset);
97 };
98 
99 // ----------------------------------------------------------------------------
101  const string& key) const
102 // ----------------------------------------------------------------------------
103 {
104  auto valueIt = mData.find(key);
105  if (valueIt != mData.end()) {
106  return valueIt->second;
107  }
108  return "";
109 }
110 
111 // -----------------------------------------------------------------------------
112 bool
114  CSeq_annot& annot)
115 // -----------------------------------------------------------------------------
116 {
117  CAnnot_descr& desc = annot.SetDesc();
118  CRef<CUser_object> pTrackdata(new CUser_object());
119  pTrackdata->SetType().SetStr("Track Data");
120 
121  if (!Description().empty()) {
122  annot.SetTitleDesc(Description());
123  }
124  if (!Name().empty()) {
125  annot.SetNameDesc(Name());
126  }
127  pTrackdata->SetData();
128 
130  while ( cit != Values().end() ) {
131  pTrackdata->AddField( cit->first, cit->second );
132  ++cit;
133  }
134  CRef<CAnnotdesc> user(new CAnnotdesc());
135  user->SetUser(*pTrackdata);
136  desc.Set().push_back(user);
137  return true;
138 }
139 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CAnnot_descr –.
Definition: Annot_descr.hpp:66
CAnnotdesc –.
Definition: Annotdesc.hpp:66
void SetNameDesc(const string &name)
Definition: Seq_annot.cpp:66
void SetTitleDesc(const string &title)
Definition: Seq_annot.cpp:96
TrackData mData
Definition: track_data.hpp:68
string ValueOf(const std::string &) const
Definition: track_data.cpp:100
const TrackData & Values() const
Definition: track_data.hpp:53
bool WriteToAnnot(CSeq_annot &)
Definition: track_data.cpp:113
bool ParseLine(const LineData &)
Definition: track_data.cpp:67
static bool IsTrackData(const LineData &)
Definition: track_data.cpp:59
int Offset() const
Definition: track_data.cpp:89
string Description() const
Definition: track_data.hpp:60
string Name() const
Definition: track_data.hpp:61
std::vector< std::string > LineData
Definition: track_data.hpp:44
CUser_object & AddField(const string &label, const string &value, EParseField parse=eParse_String)
add a data field to the user object that holds a given value
container_type::const_iterator const_iterator
Definition: map.hpp:53
char value[7]
Definition: config.c:431
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static void TruncateSpacesInPlace(string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string (in-place)
Definition: ncbistr.cpp:3197
static string & Replace(const string &src, const string &search, const string &replace, string &dst, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
Definition: ncbistr.cpp:3310
static bool SplitInTwo(const CTempString str, const CTempString delim, string &str1, string &str2, TSplitFlags flags=0)
Split a string into two pieces using the specified delimiters.
Definition: ncbistr.cpp:3550
TData & SetData(void)
Assign a value to Data data member.
void SetType(TType &value)
Assign a value to Type data member.
Tdata & Set(void)
Assign a value to data member.
void SetDesc(TDesc &value)
Assign a value to Desc data member.
Definition: Seq_annot_.cpp:223
TUser & SetUser(void)
Select the variant.
Definition: Annotdesc_.cpp:190
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::KEY key
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
int offset
Definition: replacements.h:160
#define const
Definition: zconf.h:232
Modified on Fri Mar 29 09:52:31 2024 by modify_doxy.py rev. 669887