NCBI C++ ToolKit
vectorscreen.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: vectorscreen.hpp 98214 2022-10-12 15:36:06Z boukn $
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: Jian Ye
27  *
28  * @file vectorscreen.hpp
29  * vector screen display (using HTML table)
30  *
31  */
32 
33 #ifndef OBJTOOLS_ALIGN_FORMAT___VECTORSCREEN_HPP
34 #define OBJTOOLS_ALIGN_FORMAT___VECTORSCREEN_HPP
35 
36 #include <html/html.hpp>
37 #include <corelib/ncbiobj.hpp>
40 #include <objmgr/scope.hpp>
41 #include <util/range.hpp>
43 
45 BEGIN_SCOPE(align_format)
46 
47 
48 /**
49  * Example:
50  * @code
51  * CVecscreen vec(align_set, master_length);
52  * vec.SetImagePath("images/");
53  * CRef<objects::CSeq_align_set> temp_aln = vec.ProcessSeqAlign();
54  * vec.VecscreenPrint(out);
55  * @endcode
56  */
57 
59 public:
60 
61  ///vector match defines
62  enum MatchType{
63  eStrong = 0,
67  eNoMatch
68  };
69 
70  vector<CRef<objects::CSeq_align> > x_OrigAlignsById;
75 
76  int x_GetId(const objects::CSeq_align& a) {
77  int id=0;
78  a.GetNamedScore("vs_id", id);
79  return id;
80  }
81 
82  void x_GetAllDropIdsForKeepId(int keep_id, set<int>& drop_ids)
83  {
84  size_t prev_size = drop_ids.size();
85  drop_ids.insert(x_IdToDropIdMap[keep_id].begin(), x_IdToDropIdMap[keep_id].end());
86 
87  while(prev_size != drop_ids.size()) {
88  prev_size = drop_ids.size();
89  ITERATE(set<int>, ci, drop_ids) {
90  drop_ids.insert(x_IdToDropIdMap[*ci].begin(), x_IdToDropIdMap[*ci].end());
91  }
92  }
93  }
94 
95  ///Match info
96  struct AlnInfo {
99 
100  typedef list<CRef<objects::CSeq_align> > TAlignList;
103  const TAlignList& get_aligns() const { return align_parts; }
104  const TAlignList& get_drops() const { return align_drops; }
105  void add_align(CRef<objects::CSeq_align> a) { align_parts.push_back(a); }
106  void add_aligns(const TAlignList& al) {
107  x_add_aligns(align_parts, al);
108  }
109  void add_drops(const TAlignList& al) {
110  x_add_aligns(align_drops, al);
111  }
112  void x_add_aligns(TAlignList & dest, const TAlignList& al) {
113  ITERATE(TAlignList, iter, al) {
114  if( (*iter)->GetSeqRange(0).IntersectingWith(range) ) {
115  dest.push_back(*iter);
116  }
117  }
118  }
119 
120 
122  : range(r), type(m) { add_aligns(l); }
123  /// to allow sorting in std::list
124  int operator<(const AlnInfo& rhs) const {
125  if (this == &rhs) {
126  return 0;
127  }
128  int rv = static_cast<int>(this->type < rhs.type);
129  if (rv == 0) {
130  // range is the tie-breaker
131  rv = this->range < rhs.range;
132  }
133  return rv;
134  }
135  };
136 
137  ///Constructors
138  ///@param seqalign: alignment to show
139  ///@param master_length: master seq length
140  ///@param terminal_flexibility: wiggle room from sequence edge, default 25
141  ///
142  CVecscreen(const objects::CSeq_align_set& seqalign, TSeqPos master_length, TSeqPos terminal_flexibility=25);
143 
144  ///Destructor
145  ~CVecscreen();
146 
147  ///Set path to pre-made image gif files with different colors
148  ///@param path: the path. i.e. "mypath/". Internal default "./"
149  ///
150  void SetImagePath(string path) {
151  m_ImagePath = path;
152  }
153 
154  ///provide url link to help docs. Default is
155  ///"/VecScreen/VecScreen_docs.html"
156  ///@param url: the url
157  ///
158  void SetHelpDocsUrl(string url) {
159  m_HelpDocsUrl = url;
160  }
161 
162  ///Do not show weak(eWeak) match
164  m_ShowWeakMatch = false;
165  }
166 
167  ///Process alignment to show
168  ///@return: the processed seqalign ref
169  ///
170  CRef<objects::CSeq_align_set> ProcessSeqAlign(void);
171 
172  ///return alignment info list
173  ///@return: the info list
174  ///
175  const list<AlnInfo*>* GetAlnInfoList() const {
176  return &m_AlnInfoList;
177  }
178 
179  ///show alignment graphic view
180  ///@param out: stream for display
181  ///
182  void VecscreenPrint(CNcbiOstream& out);
183 
184  ///Returns a string concerning the strength of the match for a given enum value
185  static const string& GetStrengthString(MatchType match_type);
186 
187 protected:
188 
189 
190  ///the current seqalign
192  ///the processed seqalign
194  ///gif image file path
195  string m_ImagePath;
196  ///help url
198  ///master seq length
200  ///internal match list
201  list<AlnInfo*> m_AlnInfoList;
202  ///Show weak match?
204  // how close to an edge still counts as an 'edge', defaults to 25,
206 
207  ///Sort on range from
208  ///@param info1: the first range
209  ///@param info2: the second range
210  ///
211  inline static bool FromRangeAscendingSort(AlnInfo* const& info1,
212  AlnInfo* const& info2)
213  {
214  if (info1->range.GetFrom() == info2->range.GetFrom()){
215  return info1->range.GetTo() < info2->range.GetTo();
216  } else {
217  return info1->range.GetFrom() < info2->range.GetFrom();
218  }
219  }
220 
221  ///merge overlapping seqalign
222  ///@param seqalign: the seqalign to merge
223  ///
224  void x_MergeSeqalign(objects::CSeq_align_set& seqalign);
225 
226  ///merge a seqalign if its range is in another seqalign
227  ///@param seqalign: the seqalign to merge
228  ///
229  void x_MergeInclusiveSeqalign(objects::CSeq_align_set& seqalign);
230 
231  ///merge a seqalign if its range is in another higher ranked seqalign
232  ///@param seqalign_higher: higher-ranked seqalign
233  ///@param seqalign_lower: lower-ranked seqalign
234  ///
235  void x_MergeLowerRankSeqalign(objects::CSeq_align_set& seqalign_higher,
236  objects::CSeq_align_set& seqalign_lower);
237 
238 
239  void x_GetEdgeRanges(const objects::CSeq_align& seqalign,
240  TSeqPos master_len,
241  TSeqPos& start_edge,
242  TSeqPos& end_edge);
243  ///Get match type
244  ///@param seqalign: the seqalign
245  ///@param master_len: the master seq length
246  ///@return: the type
247  ///
248  MatchType x_GetMatchType(const objects::CSeq_align& seqalign,
249  TSeqPos master_len,
250  TSeqPos start_edge,
251  TSeqPos end_edge);
252 
253  ///Build non overlapping internal match list
254  ///@param seqalign_vec: a vecter of catagorized seqalign set
255  ///
256  void x_BuildNonOverlappingRange(vector<CRef<objects::CSeq_align_set> > seqalign_vec);
257 
258  ///get align info
259  ///@param from: align from
260  ///@param to: align to
261  ///@param type: the match type
262  ///
263  AlnInfo* x_GetAlnInfo(TSeqPos from, TSeqPos to, MatchType type, const AlnInfo::TAlignList aligns=AlnInfo::TAlignList() );
264 
265  ///Output the graphic
266  ///@param out: the stream for output
267  ///
268  void x_BuildHtmlBar(CNcbiOstream& out);
269 };
270 
271 END_SCOPE(align_format)
273 
274 #endif /* OBJTOOLS_ALIGN_FORMAT___VECTORSCREEN_HPP */
Example:
MatchType
vector match defines
TIdToDropIdMap x_IdToDropIdMap
map< int, list< int > > TIdToDropIdMap
void SetImagePath(string path)
Set path to pre-made image gif files with different colors.
TSeqPos m_TerminalFlexibility
list< AlnInfo * > m_AlnInfoList
internal match list
void NoShowWeakMatch()
Do not show weak(eWeak) match.
CConstRef< objects::CSeq_align_set > m_SeqalignSetRef
the current seqalign
const list< AlnInfo * > * GetAlnInfoList() const
return alignment info list
int x_GetId(const objects::CSeq_align &a)
map< int, int > TDropToKeepMap
string m_ImagePath
gif image file path
void SetHelpDocsUrl(string url)
provide url link to help docs.
string m_HelpDocsUrl
help url
static bool FromRangeAscendingSort(AlnInfo *const &info1, AlnInfo *const &info2)
Sort on range from.
TSeqPos m_MasterLen
master seq length
vector< CRef< objects::CSeq_align > > x_OrigAlignsById
bool m_ShowWeakMatch
Show weak match?
TDropToKeepMap x_DropToKeepMap
void x_GetAllDropIdsForKeepId(int keep_id, set< int > &drop_ids)
CRef< objects::CSeq_align_set > m_FinalSeqalign
the processed seqalign
Definition: map.hpp:338
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
size_type size() const
Definition: set.hpp:132
list< CRef< CSeq_align > > TAlignList
std::ofstream out("events_result.xml")
main entry point for tests
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
static TThisType GetEmpty(void)
Definition: range.hpp:306
#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
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define NCBI_ALIGN_FORMAT_EXPORT
Definition: ncbi_export.h:1081
TTo GetTo(void) const
Get the To member data.
Definition: Range_.hpp:269
TFrom GetFrom(void) const
Get the From member data.
Definition: Range_.hpp:222
HTML classes.
range(_Ty, _Ty) -> range< _Ty >
unsigned int a
Definition: ncbi_localip.c:102
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
@ eNoMatch
Definition: ncbistr.cpp:284
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
void add_align(CRef< objects::CSeq_align > a)
const TAlignList & get_aligns() const
const TAlignList & get_drops() const
void add_aligns(const TAlignList &al)
void x_add_aligns(TAlignList &dest, const TAlignList &al)
AlnInfo(TSeqRange r=TSeqRange::GetEmpty(), MatchType m=eNoMatch, const TAlignList &l=TAlignList())
int operator<(const AlnInfo &rhs) const
to allow sorting in std::list
list< CRef< objects::CSeq_align > > TAlignList
void add_drops(const TAlignList &al)
Definition: type.c:6
@ eStrong
Modified on Tue May 28 05:51:50 2024 by modify_doxy.py rev. 669887