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

Go to the SVN repository for this file.

1 /* $Id: text_item_seq_feat.cpp 32647 2015-04-07 16:12:16Z katargir $
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: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include "text_item_seq_feat.hpp"
35 
36 #include <gui/objutils/label.hpp>
37 #include <objmgr/util/sequence.hpp>
38 
42 
43 #include <gui/objutils/utils.hpp>
44 
47 
50 
52 {
53  return new CTextItemSeq_feat(object, mode);
54 }
55 
56 static void s_RenderAccList(
57  CStyledTextOStream& ostream, const CUser_field::TData::TStrs& item_data, const string& title)
58 {
59  string s(title);
60  if ( !s.empty() ) {
61  s += ": ";
62  }
63 
64  list<string> refseq;
65  list<string> non_refseq;
66  ITERATE (CUser_field::TData::TStrs, it, item_data) {
69  refseq.push_back(*it);
70  } else {
71  non_refseq.push_back(*it);
72  }
73  }
74 
75  string accs;
76  if (refseq.size()) {
77  accs += NStr::Join(refseq, ", ");
78  }
79 
80  if (non_refseq.size()) {
81  if ( !accs.empty() ) {
82  accs += ", ";
83  }
84  accs += NStr::Join(non_refseq, ", ");
85  }
86 
87  if ( !accs.empty() ) {
88  s += accs;
89  } else {
90  s += "<unknown>";
91  }
92 
93  list<string> lines;
94  NStr::Wrap(s, 78, lines);
95  if ( !lines.empty() ) {
96  ITERATE (list<string>, iter, lines) {
97  if (iter != lines.begin()) {
98  ostream << " " << *iter << NewLine();
99  } else {
100  ostream << *iter << NewLine();
101  }
102  }
103  }
104 }
105 
107  CStyledTextOStream& ostream, const CSeq_feat& feat, CScope& /*scope*/)
108 {
109  if ( !feat.IsSetExt() && !feat.IsSetExts()) {
110  return;
111  }
112 
113  list< CConstRef<CUser_object> > objs;
114  if (feat.IsSetExt()) {
115  CConstRef<CUser_object> o(&feat.GetExt());
116  if (o->IsSetType() && o->GetType().IsStr() && o->GetType().GetStr() == "CombinedFeatureUserObjects") {
117  ITERATE (CUser_object::TData, it, o->GetData()) {
118  const CUser_field& field = **it;
119  CConstRef<CUser_object> sub_o(&field.GetData().GetObject());
120  objs.push_back(sub_o);
121  }
122  } else {
123  objs.push_back(o);
124  }
125  }
126  if (feat.IsSetExts()) {
127  copy(feat.GetExts().begin(), feat.GetExts().end(), back_inserter(objs));
128  }
129 
130  ITERATE (list< CConstRef<CUser_object> >, obj_it, objs) {
131  const CUser_object& obj = **obj_it;
132  if ( !obj.IsSetType() ||
133  !obj.GetType().IsStr() ||
134  obj.GetType().GetStr() != "ModelEvidence") {
135  continue;
136  }
137 
138  string s;
140 
141  ostream << NewLine();
142 
143  ///
144  /// generation method
145  string method;
146  ostream << "Model Generation Method: ";
147  f = obj.GetFieldRef("Method");
148  if (f) {
149  method = f->GetData().GetStr();
150  ostream << method;
151  } else {
152  ostream << "<unknown>";
153  }
154 
155  ostream << NewLine();
156 
157  ///
158  /// list of support
159  if (method == "Chainer" || method == "Gnomon") {
160 
161  ///
162  /// scan for multiple 'Core' entries
163  f = obj.GetFieldRef("Support");
164  if (f) {
165  string core;
166  ITERATE (CUser_field::TData::TFields, it, f->GetData().GetFields()) {
167  const CUser_field& this_f = **it;
168  if (this_f.GetLabel().GetStr() == "Core") {
169  if ( !core.empty() ) {
170  core += ", ";
171  }
172  core += this_f.GetData().GetStr();
173  }
174  }
175  if ( !core.empty() ) {
176  s = "Model Based On: ";
177  s += core;
178  ostream << s << NewLine();
179  }
180  }
181 
182  ///
183  /// supporting proteins
184  f = obj.GetFieldRef("Support.Proteins");
185  if (f) {
186  s_RenderAccList(ostream, f->GetData().GetStrs(), "Source Proteins");
187  }
188 
189  ///
190  /// supporting proteins
191  f = obj.GetFieldRef("Support.mRNAs");
192  if (f) {
193  s_RenderAccList(ostream, f->GetData().GetStrs(), "Source mRNAs");
194  }
195  }
196  }
197 }
198 
199 static void s_Render_SeqFeat(
200  CStyledTextOStream& ostream, const CSeq_feat& feat, CScope& scope)
201 {
202  try {
203  string text;
204  /// start with the description text
205  CLabel::GetLabel( feat, &text, CLabel::eDescription, &scope );
206  ostream.WriteMultiLineText(text);
207 
208  /// add information about the feature's location
210  ostream << "Total Range: ";
211  switch( sequence::GetStrand(feat.GetLocation(), &scope) ){
212  case eNa_strand_plus:
213  ostream << "(+) ";
214  break;
215  case eNa_strand_minus:
216  ostream << "(-) ";
217  break;
218  default:
219  break;
220  }
221 
222  ostream << NStr::IntToString(range.GetFrom() + 1, NStr::fWithCommas)
223  << " - "
224  << NStr::IntToString(range.GetTo() + 1, NStr::fWithCommas)
225  << NewLine();
226 
227  ostream << "Total Length: "
228  << NStr::IntToString(range.GetLength(), NStr::fWithCommas)
229  << NewLine();
230 
231  ostream << "Processed Length: "
234  << NewLine();
235 
236  if (feat.IsSetProduct()) {
237  try {
238  string prod_len_str;
239  CBioseq_Handle h = scope.GetBioseqHandle(feat.GetProduct());
240  if (h) {
241  ostream << "Product Length: "
244  << NewLine();
245  }
246  }
247  catch (CException&) {
248  }
249  }
250  ostream << NewLine();
251 
252  /// next, include the flat file text for this feature
253  CFlatFileConfig cfg;
254  cfg.SetNeverTranslateCDS();
255 
256  /// hack: search for this feature using CFeat_CI
257  /// it'd be better to use CMappedFeat instead of CSeq_feat
259  sel.IncludeFeatSubtype(feat.GetData().GetSubtype());
260 
261  CFeat_CI feat_it(scope, feat.GetLocation(), sel);
262  for (; feat_it ; ++feat_it) {
263  if (&feat_it->GetOriginalFeature() != &feat){
264  continue;
265  }
266  string s =
267  CFlatFileGenerator::GetSeqFeatText(*feat_it, scope, cfg);
268  string::size_type pos = s.find_first_not_of(" \n\r\t");
269  if( pos != string::npos ){
270  s.erase(0, pos);
271  }
272 
273  string::size_type lpos = string::npos;
274  do {
275  pos = lpos +1;
276  lpos = s.find_first_of("\n\r", pos );
277 
278  if( lpos == string::npos ){
279  text = s.substr( pos );
280  } else {
281  text = s.substr( pos, lpos - pos );
282  }
283  ostream << text << NewLine();
284 
285  } while( lpos != string::npos );
286  } // for
287 
288  /// lastly, add items relating to model evidence
289  s_Render_Feat_Evidence(ostream, feat, scope);
290  }
291  catch (CException&) {
292  }
293 }
294 
296 {
297  x_Indent(ostream);
298 
299  if (m_Mode == kBrief) {
300  string text;
302  ostream.WriteMultiLineText(text);
303  return;
304  }
305 
306  if (m_Mode != kFull)
307  return;
308 
309  const objects::CSeq_feat* seq_feat =
310  dynamic_cast<const objects::CSeq_feat*>(m_Object.GetPointer());
311  if (!seq_feat) {
312  ostream
313  << CTextStyle(255,0,0,255,255,255,wxTRANSPARENT,false,false)
314  << "Invalid object: should be Seq-feat";
315  return;
316  }
317 
318  s_Render_SeqFeat(ostream, *seq_feat, *m_Scope);
319 }
320 
CBioseq_Handle –.
CFeat_CI –.
Definition: feat_ci.hpp:64
CFlatFileConfig & SetNeverTranslateCDS(bool val=true)
static string GetSeqFeatText(const CMappedFeat &feat, CScope &scope, const CFlatFileConfig &cfg, CRef< feature::CFeatTree > ftree=null)
CRef< objects::CScope > m_Scope
CConstRef< CObject > m_Object
CScope –.
Definition: scope.hpp:92
ESubtype GetSubtype(void) const
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
void WriteMultiLineText(const string &text)
virtual void x_RenderText(CStyledTextOStream &ostream, CTextPanelContext *context) const
static ITextItem * CreateObject(SConstScopedObject &object, EMode mode)
CTextItemSeq_feat(SConstScopedObject &object, EMode mode)
virtual void x_Indent(CStyledTextOStream &ostream) const
Definition: text_item.cpp:166
CConstRef< CUser_field > GetFieldRef(const string &str, const string &delim=".", NStr::ECase use_case=NStr::eCase) const
Definition: User_object.cpp:84
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
static objects::SAnnotSelector GetAnnotSelector(TAnnotFlags flags=0)
request an annotation selector for a given type
Definition: utils.cpp:167
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
@ eDescription
Definition: label.hpp:68
static EAccessionInfo IdentifyAccession(const CTempString &accession, TParseFlags flags=fParse_AnyRaw)
Deduces information from a bare accession a la WHICH_db_accession; may report false negatives on prop...
Definition: Seq_id.cpp:1634
EAccessionInfo
For IdentifyAccession (below)
Definition: Seq_id.hpp:220
@ eAcc_type_mask
Definition: Seq_id.hpp:247
TRange GetTotalRange(void) const
Definition: Seq_loc.hpp:913
TSeqPos GetLength(const CSeq_id &id, CScope *scope)
Get sequence length if scope not null, else return max possible TSeqPos.
ENa_strand GetStrand(const CSeq_loc &loc, CScope *scope=0)
Returns eNa_strand_unknown if multiple Bioseqs in loc Returns eNa_strand_other if multiple strands in...
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
TSeqPos GetBioseqLength(void) const
SAnnotSelector & IncludeFeatSubtype(TFeatSubtype subtype)
Include feature subtype in the search.
const CSeq_feat & GetOriginalFeature(void) const
Get original feature with unmapped location/product.
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
#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 string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
static string Join(const TContainer &arr, const CTempString &delim)
Join strings using the specified delimiter.
Definition: ncbistr.hpp:2697
static void Wrap(const string &str, SIZE_TYPE width, IWrapDest &dest, TWrapFlags flags, const string *prefix, const string *prefix1)
Definition: ncbistr.cpp:5347
@ fWithCommas
Use commas as thousands separator.
Definition: ncbistr.hpp:254
const TStr & GetStr(void) const
Get the variant data.
bool IsStr(void) const
Check if variant Str is selected.
Definition: Object_id_.hpp:291
bool IsSetType(void) const
type of object within class Check if a value has been assigned to Type data member.
const TData & GetData(void) const
Get the Data member data.
vector< CRef< CUser_field > > TFields
const TStr & GetStr(void) const
Get the variant data.
Definition: Object_id_.hpp:297
const TData & GetData(void) const
Get the Data member data.
const TObject & GetObject(void) const
Get the variant data.
const TLabel & GetLabel(void) const
Get the Label member data.
const TType & GetType(void) const
Get the Type member data.
vector< CStringUTF8 > TStrs
vector< CRef< CUser_field > > TData
const TExts & GetExts(void) const
Get the Exts member data.
Definition: Seq_feat_.hpp:1477
bool IsSetExt(void) const
user defined structure extension Check if a value has been assigned to Ext data member.
Definition: Seq_feat_.hpp:1207
const TLocation & GetLocation(void) const
Get the Location member data.
Definition: Seq_feat_.hpp:1117
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
const TProduct & GetProduct(void) const
Get the Product member data.
Definition: Seq_feat_.hpp:1096
bool IsSetExts(void) const
set of extensions; will replace 'ext' field Check if a value has been assigned to Exts data member.
Definition: Seq_feat_.hpp:1465
bool IsSetProduct(void) const
product of process Check if a value has been assigned to Product data member.
Definition: Seq_feat_.hpp:1084
const TExt & GetExt(void) const
Get the Ext member data.
Definition: Seq_feat_.hpp:1219
@ eNa_strand_plus
Definition: Na_strand_.hpp:66
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
@ e_Other
for historical reasons, 'other' = 'refseq'
Definition: Seq_id_.hpp:104
static void text(MDB_val *v)
Definition: mdb_dump.c:62
static MDB_envinfo info
Definition: mdb_load.c:37
range(_Ty, _Ty) -> range< _Ty >
mdb_mode_t mode
Definition: lmdb++.h:38
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
SAnnotSelector –.
USING_SCOPE(objects)
static void s_Render_SeqFeat(CStyledTextOStream &ostream, const CSeq_feat &feat, CScope &scope)
static void s_RenderAccList(CStyledTextOStream &ostream, const CUser_field::TData::TStrs &item_data, const string &title)
static void s_Render_Feat_Evidence(CStyledTextOStream &ostream, const CSeq_feat &feat, CScope &)
Modified on Thu Apr 25 08:18:57 2024 by modify_doxy.py rev. 669887