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

Go to the SVN repository for this file.

1 /* $Id: PDB_seq_id.cpp 99060 2023-02-08 19:01:23Z vasilche $
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: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using specifications from the ASN data definition file
34  * 'seqloc.asn'.
35  */
36 
37 #include <ncbi_pch.hpp>
40 
42 BEGIN_objects_SCOPE // namespace ncbi::objects::
43 
44 
45 // destructor
47 {
48  return;
49 }
50 
51 
52 // comparison function
53 bool CPDB_seq_id::Match(const CPDB_seq_id& psip2) const
54 {
55  if (IsSetChain() && psip2.IsSetChain()) {
56  if (GetChain() != psip2.GetChain()) {
57  return false;
58  }
59  }
60  if (IsSetChain_id() && psip2.IsSetChain_id()) {
61  if ( PCase().Compare(GetChain_id(), psip2.GetChain_id())) {
62  return false;
63  }
64  }
65  return
66  PCase().Equals(GetMol(), psip2.GetMol());
67 }
68 
69 
70 static string s_GetEffectiveChain_id(const CPDB_seq_id& id)
71 {
72  if ( id.IsSetChain_id() ) {
73  return id.GetChain_id();
74  }
75  if ( id.IsSetChain() ) {
76  return string(1, char(id.GetChain()));
77  }
78  return string();
79 }
80 
81 int CPDB_seq_id::Compare(const CPDB_seq_id& psip2) const
82 {
83  if ( int diff = PNocase().Compare(GetMol(), psip2.GetMol()) ) {
84  return diff;
85  }
86  // optimization to avoid creation of temporary strings if both chain-id are set
87  if ( IsSetChain_id() && psip2.IsSetChain_id() ) {
88  return PCase().Compare(GetChain_id(), psip2.GetChain_id());
89  }
90  return PCase().Compare(s_GetEffectiveChain_id(*this), s_GetEffectiveChain_id(psip2));
91 }
92 
93 // format a FASTA style string
94 ostream& CPDB_seq_id::AsFastaString(ostream& s) const
95 {
96  if (IsSetChain_id()) {
97  return s << GetMol().Get() << '|' << GetChain_id();
98  }
99  // no Upcase per Ostell - Karl 7/2001
100  char chain = (char) GetChain();
101 
102  if (chain == '|') {
103  return s << GetMol().Get() << '|'; // historically |VB
104  } else if ( chain == '\0' ) {
105  return s << GetMol().Get() << "| ";
106  }
107  return s << GetMol().Get() << '|' << chain;
108 }
109 
110 /*
111 ==================================================
112 ==================================================
113 */
114 
115 
117 {
118  // Use chain's default when neither fields are set
119  if (bothUnsetPriority == eBothUnset_Chain && !IsSetChain() && !IsSetChain_id()) {
120  return string(char(GetChain()), 1);
121  }
122 
123  return s_GetEffectiveChain_id(*this);
124 }
125 
127 {
128  if( IsSetChain() && IsSetChain_id() ) {
129 
130  TChain chainChar = (char) GetChain();
131  string chain(1, chainChar);
132  if (encodingMode == eConflictMode_default || isupper(chainChar) || isdigit(chainChar) ) {
133  return (chain != GetChain_id());
134  }
135  else {
136 
137  // Historic special case: the vertical bar character
138  if (chainChar == '|' && GetChain_id() == "VB") {
139  return false;
140  }
141 
142  if (chain == GetChain_id()) { // 'a' == "a"
143  return false;
144  } else if (encodingMode == eConflictMode_legacy && islower(chainChar)) {
145  string chainUpperDoubled = chain + chain;
146  NStr::ToUpper(chainUpperDoubled);
147  return (chainUpperDoubled != GetChain_id()); // conflict unless 'a' == "AA"
148  }
149  else {
150  return true; // unexpected type of conflict
151  }
152  }
153  }
154  return false;
155 }
156 
158 {
159  ResetChain_id();
160  ResetChain();
161 }
162 
164 {
165  CTempString chain_id = NStr::TruncateSpaces_Unsafe(chainIdentifier, NStr::eTrunc_Both);
166 
167  // A single space is a valid chain identifier; multiple spaces are not.
168  if (chain_id.empty() && chainIdentifier.length() == 1 ) {
169  chain_id = " ";
170  }
171 
172  // chainIdentifier is either empty or a string of two or more spaces.
173  if (chainIdentifier.empty() || chain_id.empty()) {
175  }
176  else if (chain_id.length() == 1) { // empty chain_id means chainIdentifier was a single space
177  SetChain( static_cast<unsigned char>(chain_id[0]) );
178  SetChain_id(chain_id);
179  }
180  else { // multi-character chain code
181  ResetChain();
182  SetChain_id(chain_id);
183  }
184 }
185 
187 {
188  string s(1, (char) chain);
190 }
191 
192 END_objects_SCOPE // namespace ncbi::objects::
User-defined methods of the data storage class.
static string s_GetEffectiveChain_id(const CPDB_seq_id &id)
Definition: PDB_seq_id.cpp:70
bool IsChainConflict(EConflictMode encodingMode=eConflictMode_default) const
Definition: PDB_seq_id.cpp:126
int Compare(const CPDB_seq_id &psip2) const
Definition: PDB_seq_id.cpp:81
@ eConflictMode_default
Definition: PDB_seq_id.hpp:102
@ eConflictMode_legacy
Definition: PDB_seq_id.hpp:103
void SetChainIdentifiers(TChain chainIdentifier)
Definition: PDB_seq_id.cpp:186
void ResetChainIdentifiers(void)
Definition: PDB_seq_id.cpp:157
bool Match(const CPDB_seq_id &psip2) const
Definition: PDB_seq_id.cpp:53
ostream & AsFastaString(ostream &s) const
Definition: PDB_seq_id.cpp:94
string GetEffectiveChain_id(EBothUnsetPriority bothUnsetPriority=eBothUnset_ChainId) const
Definition: PDB_seq_id.cpp:116
~CPDB_seq_id(void)
Definition: PDB_seq_id.cpp:46
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
string
Definition: cgiapp.hpp:687
const TPrim & Get(void) const
Definition: serialbase.hpp:347
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
PCase_Generic< string > PCase
Definition: ncbistr.hpp:4878
static CTempString TruncateSpaces_Unsafe(const CTempString str, ETrunc where=eTrunc_Both)
Truncate spaces in a string.
Definition: ncbistr.cpp:3191
PNocase_Generic< string > PNocase
Definition: ncbistr.hpp:4908
bool empty(void) const
Return true if the represented string is empty (i.e., the length is zero)
Definition: tempstr.hpp:334
size_type length(void) const
Return the length of the represented array.
Definition: tempstr.hpp:320
static string & ToUpper(string &str)
Convert string to upper case – string& version.
Definition: ncbistr.cpp:424
@ eTrunc_Both
Truncate spaces at both begin and end of string.
Definition: ncbistr.hpp:2242
TChain GetChain(void) const
Get the Chain member data.
bool IsSetChain_id(void) const
chain identifier; length-independent generalization of 'chain' Check if a value has been assigned to ...
bool IsSetChain(void) const
Deprecated: 'chain' can't support multiple character PDB chain identifiers (introduced in 2015).
TChain_id & SetChain_id(void)
Assign a value to Chain_id data member.
TChain & SetChain(void)
Assign a value to Chain data member.
void ResetChain_id(void)
Reset Chain_id data member.
Definition: PDB_seq_id_.cpp:74
const TMol & GetMol(void) const
Get the Mol member data.
const TChain_id & GetChain_id(void) const
Get the Chain_id member data.
void ResetChain(void)
Reset Chain data member.
int isdigit(Uchar c)
Definition: ncbictype.hpp:64
int islower(Uchar c)
Definition: ncbictype.hpp:66
int isupper(Uchar c)
Definition: ncbictype.hpp:70
Modified on Fri Apr 26 16:27:15 2024 by modify_doxy.py rev. 669887