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

Go to the SVN repository for this file.

1 /* $Id: dblink_quals.cpp 36594 2016-10-12 20:17:36Z evgeniev $
2  * ===========================================================================
3  *
4  *
5  * PUBLIC DOMAIN NOTICE
6  * National Center for Biotechnology Information
7  *
8  * This software/database is a "United States Government Work" under the
9  * terms of the United States Copyright Act. It was written as part of
10  * the author's official duties as a United States Government employee and
11  * thus cannot be copyrighted. This software/database is freely available
12  * to the public for use. The National Library of Medicine and the U.S.
13  * Government have not placed any restriction on its use or reproduction.
14  *
15  * Although all reasonable efforts have been taken to ensure the accuracy
16  * and reliability of the software and data, the NLM and the U.S.
17  * Government do not and cannot warrant the performance or results that
18  * may be obtained by using this software or data. The NLM and the U.S.
19  * Government disclaim all warranties, express or implied, including
20  * warranties of performance, merchantability or fitness for any particular
21  * purpose.
22  *
23  * Please cite the author in any work or product based on this material.
24  *
25  * ===========================================================================
26  *
27  * Authors: Jie Chen
28  * File: spilt dblink quals at commas
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <objmgr/bioseq_ci.hpp>
34 #include <objmgr/seqdesc_ci.hpp>
35 #include <objmgr/feat_ci.hpp>
36 #include <objects/seq/Seqdesc.hpp>
38 
40 
41 using namespace ncbi;
42 using namespace objects;
43 
44 static string strtmp;
45 static vector <string> arr;
46 
48 {
49  arr.clear();
50  arr = NStr::Split(dt_str, ",", arr);
52  unsigned cnt = 0;
53  new_dt->SetStrs().reserve(arr.size());
54  ITERATE (vector <string>, it, arr) {
55  if (!NStr::TruncateSpaces(*it).empty()) {
56  cnt++;
57  new_dt->SetStrs().push_back(
59  }
60  }
61  new_fld->SetData(*new_dt);
62  new_fld->SetNum(cnt);
63 };
64 
66 {
67  CRef <CUser_field> new_fld(new CUser_field);
68  new_fld->SetLabel(fld->SetLabel());
69  strtmp = kEmptyStr;
70  ITERATE (vector <CStringUTF8>, sit, fld->GetData().GetStrs())
72  strtmp = strtmp.substr(0, strtmp.size()-1);
73  x_ConvertStrToStrs(strtmp, new_fld);
74  add_to_cmd<objects::CUser_field> (
75  (CObject*)(fld.GetPointer()), (CObject*)(new_fld.GetPointer()), composite);
76 };
77 
79 {
80  ITERATE (vector <CRef <CUser_field> >, it, user_obj.GetData()) {
81  if ((*it)->GetData().IsStr()) {
82  strtmp = CUtf8::AsSingleByteString( (*it)->GetData().GetStr(), eEncoding_Ascii);
83  if (strtmp.find(",") != string::npos) {
84  CRef <CUser_field> new_fld(new CUser_field);
85  new_fld->Assign(**it);
86  x_ConvertStrToStrs(strtmp, new_fld);
87  add_to_cmd<objects::CUser_field> (
88  (CObject*)((*it).GetPointer()), (CObject*)(new_fld.GetPointer()), composite);
89  }
90  }
91  else if ( (*it)->GetData().IsStrs()) {
92  ITERATE (vector <CStringUTF8>, sit, (*it)->GetData().GetStrs()) {
94  if (strtmp.find(",") != string::npos) {
95  x_ConvertStrsToStrs(*it, composite);
96  break;
97  }
98  }
99  }
100  }
101 };
102 
104 {
105  if (uobj.GetType().IsStr() && uobj.GetType().GetStr() == "DBLink") return true;
106  else return false;
107 };
108 
110 {
111  set <const CSeqdesc*> psds;
112  for (CBioseq_CI bit(tse); bit; ++bit) {
113  for (CSeqdesc_CI it(*bit, CSeqdesc::e_User); it; ++it) {
114  if (psds.find(&(*it)) != psds.end()) continue;
115  if (x_IsDblinkObj(it->GetUser())) {
116  psds.insert(&(*it));
117  x_SplitQuals(it->GetUser(), composite);
118  }
119  }
120  for (CFeat_CI it (*bit, CSeqFeatData::e_User); it; ++it) {
121  if (x_IsDblinkObj(it->GetOriginalFeature().GetData().GetUser()))
122  x_SplitQuals(it->GetOriginalFeature().GetData().GetUser(), composite);
123  }
124  }
125 };
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
CFeat_CI –.
Definition: feat_ci.hpp:64
CSeq_entry_Handle –.
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
void x_ConvertStrToStrs(const string &dt_str, CRef< CUser_field > new_fld)
virtual void apply_to(const CSeq_entry_Handle &tse, CRef< CCmdComposite > composite)
void x_ConvertStrsToStrs(CRef< CUser_field > fld, CRef< CCmdComposite > composite)
void x_SplitQuals(const CUser_object &user_obj, CRef< CCmdComposite > composite)
bool x_IsDblinkObj(const CUser_object &uobj)
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
#define kEmptyStr
Definition: ncbistr.hpp:123
static string AsSingleByteString(const CTempString &src, EEncoding encoding, const char *substitute_on_error=0, EValidate validate=eNoValidate)
Convert UTF8 string into a single-byte character representation.
Definition: ncbistr.cpp:6979
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:3457
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
Definition: ncbistr.hpp:3889
static string TruncateSpaces(const string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string.
Definition: ncbistr.cpp:3182
@ eEncoding_Ascii
Definition: ncbistr.hpp:202
@ eEncoding_UTF8
Definition: ncbistr.hpp:201
bool IsStr(void) const
Check if variant Str is selected.
Definition: Object_id_.hpp:291
const TStrs & GetStrs(void) const
Get the variant data.
const TData & GetData(void) const
Get the Data member data.
void SetNum(TNum value)
Assign a value to Num data member.
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
void SetLabel(TLabel &value)
Assign a value to Label data member.
const TData & GetData(void) const
Get the Data member data.
void SetData(TData &value)
Assign a value to Data data member.
const TType & GetType(void) const
Get the Type member data.
@ e_User
user defined structure
@ e_User
user defined object
Definition: Seqdesc_.hpp:124
Magic spell ;-) needed for some weird compilers... very empiric.
static unsigned cnt[256]
Modified on Thu Mar 28 17:13:14 2024 by modify_doxy.py rev. 669887