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

Go to the SVN repository for this file.

1 
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: Christiam Camacho
27  *
28  */
29 
30 /// @file psiblast_iteration.cpp
31 /// Defines class which represents the iteration state in PSI-BLAST
32 
33 #include <ncbi_pch.hpp>
39 #include "psiblast_aux_priv.hpp"
40 
41 /** @addtogroup AlgoBlast
42  *
43  * @{
44  */
45 
48 BEGIN_SCOPE(blast)
49 
50 CPsiBlastIterationState::CPsiBlastIterationState(unsigned int num_iterations)
51  : m_TotalNumIterationsToDo(num_iterations), m_IterationsDone(0)
52 {}
53 
55 {}
56 
57 bool
59 {
60  if (m_TotalNumIterationsToDo == 0 ||
62  return true;
63  }
64  return false;
65 }
66 
67 bool
69 {
70  // For an object that hasn't been 'advanced' or one that only has performed
71  // one iteration (i.e.: called Advance() once), it doesn't make sense to
72  // have converged
73  if (m_IterationsDone <= 1) {
74  return false;
75  }
76  // if the most current list of ids is empty, that means that no new
77  // sequences were found and therefore we have converged.
78  if ( !m_PreviousData.empty() && m_CurrentData.empty() ) {
79  return true;
80  }
81 
82  // Element by element comparison: has every element in the current Seq-id
83  // list been found in the previous iterations?
84  bool retval = true;
85  ITERATE(TSeqIds, current_id, m_CurrentData) {
86  if (m_PreviousData.find(*current_id) == m_PreviousData.end()) {
87  retval = false;
88  break;
89  }
90  }
91  return retval;
92 }
93 
94 CPsiBlastIterationState::operator bool()
95 {
96  return (HasMoreIterations() && !HasConverged());
97 }
98 
99 void
101 {
102  if (!(*this)) {
103  string msg("Should not modify a PSI-BLAST iteration after it has "
104  "converged or exhausted its iterations");
105  NCBI_THROW(CBlastException, eNotSupported, msg);
106  }
107 }
108 
109 // Note that this class returns m_CurrentData, as this is what's appropriate to
110 // return from the context of the PSI-BLAST command line binary (see
111 // trunk/c++/src/app/blast/psiblast_app.cpp) because of the way it's invoked.
114 {
115  return m_CurrentData;
116 }
117 
118 void
120 {
122 
124  m_CurrentData = list;
126 }
127 
128 unsigned int
130 {
131  return m_IterationsDone+1;
132 }
133 
134 void
137  TSeqIds& retval)
138 {
139  retval.clear();
141  proc(*seqalign, opts->GetInclusionThreshold(), retval);
142 }
143 
144 END_SCOPE(blast)
146 
147 /* @} */
Declares the BLAST exception class.
Defines BLAST error codes (user errors included)
Auxiliary class to retrieve sequence identifiers its position in the alignment which are below the in...
Represents the iteration state in PSI-BLAST.
void clear()
Definition: set.hpp:153
bool empty() const
Definition: set.hpp:133
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
#define bool
Definition: bool.h:34
static const char * proc
Definition: stats.c:21
TSeqIds m_PreviousData
Identifiers for sequences found in the previous iteration.
TSeqIds m_CurrentData
Identifiers for sequences found in the current iteration.
unsigned int m_TotalNumIterationsToDo
Number of iterations to perform.
bool HasMoreIterations() const
Determines if more iterations are still needed.
unsigned int GetIterationNumber() const
Return the number of the current iteration.
unsigned int m_IterationsDone
Number of iterations already done.
TSeqIds GetPreviouslyFoundSeqIds() const
Retrieve the set of Seq-id's found in the previous iteration.
bool HasConverged()
Determines if the PSI-BLAST search has converged (i.e.
void Advance(const TSeqIds &list)
Advance the iterator by passing it the list of Seq-ids which passed the inclusion criteria for the cu...
void x_ThrowExceptionOnLogicError()
After the iteration state object has converged or exhausted its iterations, it shouldn't be modified,...
static void GetSeqIds(CConstRef< objects::CSeq_align_set > seqalign, CConstRef< CPSIBlastOptionsHandle > opts, TSeqIds &retval)
Extract the sequence ids from the sequence alignment which identify those sequences that will be used...
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define USING_SCOPE(ns)
Use the specified namespace.
Definition: ncbistl.hpp:78
#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
Declarations of auxiliary functions/classes for PSI-BLAST.
Defines class which represents the iteration state in PSI-BLAST.
Declares the CPSIBlastOptionsHandle class.
Modified on Sat Jun 15 11:50:02 2024 by modify_doxy.py rev. 669887