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

Go to the SVN repository for this file.

1 #ifndef ALGO_COBALT___HITLIST__HPP
2 #define ALGO_COBALT___HITLIST__HPP
3 
4 /* $Id: hitlist.hpp 51599 2011-10-17 17:22:03Z boratyng $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's offical duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================*/
28 
29 /*****************************************************************************
30 
31 File name: hitlist.hpp
32 
33 Author: Jason Papadopoulos
34 
35 Contents: Interface for CHitList class
36 
37 ******************************************************************************/
38 
39 /// @file hitlist.hpp
40 /// Interface for CHitList class
41 
42 #include <algo/cobalt/base.hpp>
43 #include <algo/cobalt/hit.hpp>
44 
46 BEGIN_SCOPE(cobalt)
47 
48 /// An ordered collection of CHit objects
50 {
51 
52 public:
53  /// add a reminder of whether a hit should be kept
54  typedef pair<bool, CHit *> TListEntry;
55 
56  /// base type of hitlist
57  typedef vector<TListEntry> TList;
58 
59  /// constructor
60  ///
61  CHitList() {}
62 
63  /// destructor (deletes all hits stored)
64  ///
66  {
67  NON_CONST_ITERATE(TList, itr, m_List) {
68  delete (*itr).second;
69  }
70  }
71 
72  /// Retrieve number of hits in list
73  /// @return The number of hits
74  ///
75  int Size() const { return m_List.size(); }
76 
77  /// Determine whether a list contains no hits
78  /// @return true if list has no hits
79  bool Empty() { return m_List.empty(); }
80 
81  /// Append a hit to the hitlist
82  /// @param hit The hit to append
83  ///
84  void AddToHitList(CHit *hit)
85  {
86  m_List.push_back(TListEntry(true, hit));
87  }
88 
89  /// Retrieve a hit from the hitlist
90  /// @param index Which hit to retrieve [in]
91  /// @return Pointer to the specified hit
92  ///
93  CHit *GetHit(int index)
94  {
95  _ASSERT(index < Size());
96  return m_List[index].second;
97  }
98 
99  /// Retrieve a hit from the hitlist
100  /// @param index Which hit to retrieve [in]
101  /// @return Pointer to the specified hit
102  ///
103  const CHit *GetHit(int index) const
104  {
105  _ASSERT(index < Size());
106  return m_List[index].second;
107  }
108 
109 
110  /// Determine whether a hit in the hitlist has
111  /// been scheduled for deletion
112  /// @param index Which hit to query [in]
113  /// @return true if hit is to be kept, false otherwise
114  ///
115  bool GetKeepHit(int index)
116  {
117  _ASSERT(index < Size());
118  return m_List[index].first;
119  }
120 
121  /// Set whether a hit in the hitlist will be
122  /// scheduled for deletion
123  /// @param index Which hit to set [in]
124  /// @param keep true if hit is to be kept, false otherwise [in]
125  ///
126  void SetKeepHit(int index, bool keep)
127  {
128  _ASSERT(index < Size());
129  m_List[index].first = keep;
130  }
131 
132  /// Delete all hits scheduled to be deleted
133  ///
135  {
136  int i, j;
137  for (i = j = 0; i < Size(); i++) {
138  if (m_List[i].first == false)
139  delete m_List[i].second;
140  else
141  m_List[j++] = m_List[i];
142  }
143  m_List.resize(j);
144  }
145 
146  /// Delete all hits unconditionally
147  ///
149  {
150  for (int i = 0; i < Size(); i++)
151  delete m_List[i].second;
152  m_List.clear();
153  }
154 
155  /// Empty out the list without deleting the
156  /// hits in it. Useful for cases where the
157  /// hitlist is a subset of another hitlist
158  ///
159  void ResetList() { m_List.clear(); }
160 
161  /// Sort the hits in the hitlist in order of
162  /// decreasing score
163  ///
164  void SortByScore();
165 
166  /// Sort the hits in the hitlist by increasing
167  /// sequence1 index, then by increasing sequence1
168  /// start offset, then increasing sequence2
169  /// start offset
170  ///
171  void SortByStartOffset();
172 
173  /// Sort the list in a canonical form: first swap
174  /// the indices and ranges on all hits and subhits so
175  /// that the ordinal ID of sequence 1 is always less
176  /// than that of sequence2. The sort by increasing
177  /// sequence1 index, then increasing sequence1
178  /// start offset, then increasing sequence2 start
179  /// offset. Finally, delete all duplicate hits
180  ///
181  void MakeCanonical();
182 
183  /// For each pair of hits with the same sequence2,
184  /// produce a list of hits between sequence1 of the first
185  /// hit and sequence1 of the second hit. This new hit
186  /// contains one subhit for each of the subhits in the
187  /// originals that overlap on sequence2.
188  /// @param matched_list Collection of matched hits [out]
189  ///
190  void MatchOverlappingSubHits(CHitList& matched_list);
191 
192  /// Append one hitlist to another. The hits in the
193  /// input list are duplicated
194  /// @param hitlist The list to append [in]
195  ///
196  void Append(CHitList& hitlist);
197 
198 private:
199  TList m_List; ///< current list of hits
200 };
201 
202 
203 END_SCOPE(cobalt)
205 
206 #endif // ALGO_COBALT___HITLIST__HPP
Interface for CHit class, used to encapsulate operations involving pairwise alignments.
Definitions used by all COBALT aligner components.
An ordered collection of CHit objects.
Definition: hitlist.hpp:50
int Size() const
Retrieve number of hits in list.
Definition: hitlist.hpp:75
void SetKeepHit(int index, bool keep)
Set whether a hit in the hitlist will be scheduled for deletion.
Definition: hitlist.hpp:126
~CHitList()
destructor (deletes all hits stored)
Definition: hitlist.hpp:65
void PurgeAllHits()
Delete all hits unconditionally.
Definition: hitlist.hpp:148
bool Empty()
Determine whether a list contains no hits.
Definition: hitlist.hpp:79
pair< bool, CHit * > TListEntry
add a reminder of whether a hit should be kept
Definition: hitlist.hpp:54
CHit * GetHit(int index)
Retrieve a hit from the hitlist.
Definition: hitlist.hpp:93
const CHit * GetHit(int index) const
Retrieve a hit from the hitlist.
Definition: hitlist.hpp:103
void ResetList()
Empty out the list without deleting the hits in it.
Definition: hitlist.hpp:159
CHitList()
constructor
Definition: hitlist.hpp:61
void PurgeUnwantedHits()
Delete all hits scheduled to be deleted.
Definition: hitlist.hpp:134
bool GetKeepHit(int index)
Determine whether a hit in the hitlist has been scheduled for deletion.
Definition: hitlist.hpp:115
vector< TListEntry > TList
base type of hitlist
Definition: hitlist.hpp:57
TList m_List
current list of hits
Definition: hitlist.hpp:199
void AddToHitList(CHit *hit)
Append a hit to the hitlist.
Definition: hitlist.hpp:84
A generalized representation of a pairwise alignment.
Definition: hit.hpp:86
static DLIST_TYPE *DLIST_NAME() first(DLIST_LIST_TYPE *list)
Definition: dlist.tmpl.h:46
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#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
#define NCBI_COBALT_EXPORT
Definition: ncbi_export.h:977
int i
#define _ASSERT
Modified on Tue May 28 05:53:29 2024 by modify_doxy.py rev. 669887