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

Go to the SVN repository for this file.

1 /* $Id: ftable_formatter.cpp 77661 2017-05-01 14:35:36Z foleyjp $
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: Aaron Ucko, NCBI
27 * Mati Shomrat
28 *
29 * File Description:
30 *
31 *
32 */
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistd.hpp>
35 
40 #include <objmgr/util/sequence.hpp>
41 
42 
45 
46 
48 {
49 }
50 
51 
52 ///////////////////////////////////////////////////////////////////////////
53 //
54 // REFERENCE
55 
57 (const CReferenceItem& ref,
58  IFlatTextOStream& text_os)
59 {
60 }
61 
62 
63 ///////////////////////////////////////////////////////////////////////////
64 //
65 // FEATURES
66 
67 // Fetures Header
68 
70 (const CFeatHeaderItem& fh,
71  IFlatTextOStream& text_os)
72 {
73  const CSeq_id* id = &fh.GetId();
74  if ( id->IsGi() ) {
75  // !!! Get id for GI (need support from objmgr)
76  }
77 
78  if ( id != 0 ) {
79  list<string> l;
80  l.push_back(">Feature " + id->AsFastaString());
81  text_os.AddParagraph(l);
82  }
83 }
84 
85 // Source and "regular" features
86 
88 (const CFeatureItemBase& f,
89  IFlatTextOStream& text_os)
90 {
91  list<string> l;
93  CBioseqContext& bctx = *f.GetContext();
94 
95  x_FormatLocation(f.GetLoc(), feat->GetKey(), bctx, l);
96  x_FormatQuals(feat->GetQuals(), bctx, l);
97  text_os.AddParagraph(l);
98 }
99 
100 
101 bool s_IsBetween(const CSeq_loc& loc)
102 {
103  return loc.IsPnt() &&
104  loc.GetPnt().IsSetFuzz() &&
105  loc.GetPnt().GetFuzz().IsLim() &&
107 }
108 
109 
111 (const CSeq_loc& loc,
112  const string& key,
113  CBioseqContext& ctx,
114  list<string>& l)
115 {
116  bool need_key = true;
117  for (CSeq_loc_CI it(loc); it; ++it) {
118  const CSeq_loc& curr = it.GetEmbeddingSeq_loc();
119  bool is_between = s_IsBetween(curr);
120 
121  const bool minus_strand = it.GetStrand() == eNa_strand_minus;
122  CSeq_loc_CI::TRange range = it.GetRange();
123  TSeqPos start, stop;
124  if ( range.IsWhole() ) {
125  start = 1;
126  stop = sequence::GetLength(it.GetEmbeddingSeq_loc(), &ctx.GetScope()) + 1;
127  } else {
128  start = range.GetFrom() + 1;
129  stop = range.GetTo() + 1;
130  }
131  if ( is_between ) {
132  ++stop;
133  }
134  string left, right;
135 
136  if ( curr.IsPartialStart(eExtreme_Positional) ) {
137  left = minus_strand ? '>' : '<';
138  }
139  left += NStr::IntToString(start);
140  if ( is_between ) {
141  left += '^';
142  }
143  if ( curr.IsPartialStop(eExtreme_Positional) ) {
144  right = minus_strand ? '<' : '>';
145  }
146  right += NStr::IntToString(stop);
147 
148  string line;
149  if ( minus_strand ) {
150  line = right + '\t' + left;
151  } else {
152  line = left + '\t' + right;
153  }
154  if ( need_key ) {
155  line += '\t' + key;
156  need_key = false;
157  }
158  l.push_back(line);
159  }
160 }
161 
162 
164 (const CFlatFeature::TQuals& quals,
165  CBioseqContext& ctx,
166  list<string>& l)
167 {
168  string line;
169  ITERATE (CFlatFeature::TQuals, it, quals) {
170  line = "\t\t\t" + (*it)->GetName();
171  if ((*it)->GetStyle() != CFormatQual::eEmpty) {
172  string value;
173  NStr::Replace((*it)->GetValue(), " \b", kEmptyStr, value);
174  line += '\t' + value;
175  }
176  l.push_back(line);
177  }
178 }
179 
180 
virtual void AddParagraph(const list< string > &text, const CSerialObject *obj=0)
This adds a list of strings to the stream one at a time, unconditionally adding a newline to each one...
CBioseqContext * GetContext(void)
Definition: item_base.hpp:113
CConstRef –.
Definition: ncbiobj.hpp:1192
bool IsGi(void) const
Check if variant Gi is selected.
Definition: Seq_id_.hpp:883
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:73
const struct ncbi::grid::netcache::search::fields::KEY key
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:836
bool s_IsBetween(const CSeq_loc &loc)
bool IsPnt(void) const
Check if variant Pnt is selected.
Definition: Seq_loc_.hpp:540
const TPnt & GetPnt(void) const
Get the variant data.
Definition: Seq_loc_.cpp:238
#define kEmptyStr
Definition: ncbistr.hpp:120
vector< CRef< CFormatQual > > TQuals
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:776
const TQuals & GetQuals(void) const
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5079
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
bool IsPartialStart(ESeqLocExtremes ext) const
check start or stop of location for e_Lim fuzz
Definition: Seq_loc.cpp:3205
const TFuzz & GetFuzz(void) const
Get the Fuzz member data.
Definition: Seq_point_.hpp:410
Seq-loc iterator class – iterates all intervals from a seq-loc in the correct order.
Definition: Seq_loc.hpp:437
const CSeq_id & GetId(void) const
numerical value
Definition: Na_strand.hpp:63
void FormatReference(const CReferenceItem &keys, IFlatTextOStream &text_os)
void x_FormatLocation(const CSeq_loc &loc, const string &key, CBioseqContext &ctx, list< string > &l)
void FormatFeature(const CFeatureItemBase &feat, IFlatTextOStream &text_os)
position_type GetTo(void) const
Definition: range.hpp:142
char value[7]
Definition: config.c:428
void FormatFeatHeader(const CFeatHeaderItem &fh, IFlatTextOStream &text_os)
position_type GetFrom(void) const
Definition: range.hpp:134
CScope & GetScope(void) const
Definition: context.hpp:101
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:3215
const string & GetKey(void) const
const string AsFastaString(void) const
Definition: Seq_id.cpp:1581
void x_FormatQuals(const CFlatFeature::TQuals &quals, CBioseqContext &ctx, list< string > &l)
bool IsSetFuzz(void) const
Check if a value has been assigned to Fuzz data member.
Definition: Seq_point_.hpp:398
bool IsWhole(void) const
Definition: range.hpp:284
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:70
space to right of position
Definition: Int_fuzz_.hpp:205
bool IsPartialStop(ESeqLocExtremes ext) const
Definition: Seq_loc.cpp:3234
const CSeq_loc & GetLoc(void) const
TLim GetLim(void) const
Get the variant data.
Definition: Int_fuzz_.hpp:634
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
bool IsLim(void) const
Check if variant Lim is selected.
Definition: Int_fuzz_.hpp:628
TSeqPos GetLength(const CSeq_id &id, CScope *scope)
Get sequence length if scope not null, else return max possible TSeqPos.
CConstRef< CFlatFeature > Format(void) const
Modified on Wed May 24 16:19:59 2017 by modify_doxy.py rev. 533848