1 #ifndef BIOSEQ_CI__HPP
2 #define BIOSEQ_CI__HPP
3 
4 /*  $Id: bioseq_ci.hpp 414728 2013-09-26 15:15:41Z vasilche $
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 official 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 * Author: Aleksey Grichenko
30 *
31 * File Description:
32 *   Iterates over bioseqs from a given seq-entry and scope
33 *
34 */
35 
36 
37 #include <corelib/ncbiobj.hpp>
38 #include <objmgr/bioseq_handle.hpp>
39 #include <objmgr/impl/heap_scope.hpp>
40 #include <objmgr/seq_entry_handle.hpp>
41 #include <objmgr/seq_entry_ci.hpp>
42 #include <objects/seq/Seq_inst.hpp>
43 
44 #include <vector>
45 
46 BEGIN_NCBI_SCOPE
47 BEGIN_SCOPE(objects)
48 
49 
50 /** @addtogroup ObjectManagerIterators
51  *
52  * @{
53  */
54 
55 
56 class CScope;
57 class CBioseq_Handle;
58 class CSeq_entry;
59 
60 
61 /////////////////////////////////////////////////////////////////////////////
62 ///
63 ///  CBioseq_CI --
64 ///
65 ///  Enumerate bioseqs in a given seq-entry
66 ///
67 
68 class NCBI_XOBJMGR_EXPORT CBioseq_CI
69 {
70 public:
71     /// Class of bioseqs to iterate
72     enum EBioseqLevelFlag {
73         eLevel_All,          ///< Any bioseq
74         eLevel_Mains,        ///< Main bioseq only
75         eLevel_Parts,        ///< Parts only
76         eLevel_IgnoreClass   ///< Search for bioseqs in any bioseq-set
77                              ///< regardless of types and classes.
78     };
79 
80     // 'ctors
81     CBioseq_CI(void);
82 
83     /// Create an iterator that enumerates bioseqs
84     /// from the entry taken from the scope. Use optional
85     /// filter to iterate over selected bioseq types only.
86     /// Filter value eMol_na may be used to include both
87     /// dna and rna bioseqs.
88     explicit
89     CBioseq_CI(const CSeq_entry_Handle& entry,
90                CSeq_inst::EMol filter = CSeq_inst::eMol_not_set,
91                EBioseqLevelFlag level = eLevel_All);
92 
93     explicit
94     CBioseq_CI(const CBioseq_set_Handle& bioseq_set,
95                CSeq_inst::EMol filter = CSeq_inst::eMol_not_set,
96                EBioseqLevelFlag level = eLevel_All);
97 
98     /// Create an iterator that enumerates bioseqs
99     /// from the entry taken from the given scope. Use optional
100     /// filter to iterate over selected bioseq types only.
101     /// Filter value eMol_na may be used to include both
102     /// dna and rna bioseqs.
103     CBioseq_CI(CScope& scope, const CSeq_entry& entry,
104                CSeq_inst::EMol filter = CSeq_inst::eMol_not_set,
105                EBioseqLevelFlag level = eLevel_All);
106 
107     CBioseq_CI(const CBioseq_CI& bioseq_ci);
108     ~CBioseq_CI(void);
109 
110     /// Get the current scope for the iterator
111     CScope& GetScope(void) const;
112 
113     CBioseq_CI& operator= (const CBioseq_CI& bioseq_ci);
114 
115     /// Move to the next object in iterated sequence
116     CBioseq_CI& operator++ (void);
117 
118     /// Check if iterator points to an object
119     DECLARE_OPERATOR_BOOL(m_CurrentBioseq);
120 
121     const CBioseq_Handle& operator* (void) const;
122     const CBioseq_Handle* operator-> (void) const;
123 
124 private:
125     void x_Initialize(const CSeq_entry_Handle& entry);
126 
127     void x_PushEntry(const CSeq_entry_Handle& entry);
128     void x_PopEntry(bool next = true);
129     void x_NextEntry(void);
130 
131     void x_Settle(void);
132 
133     bool x_IsValidMolType(const CBioseq_Info& seq) const;
134     bool x_SkipClass(CBioseq_set::TClass set_class);
135 
136     typedef vector<CSeq_entry_CI> TEntryStack;
137 
138     CHeapScope          m_Scope;
139     CSeq_inst::EMol     m_Filter;
140     EBioseqLevelFlag    m_Level;
141     CSeq_entry_Handle   m_CurrentEntry; // current entry to process (whole)
142     CBioseq_Handle      m_CurrentBioseq; // current found Bioseq
143     TEntryStack         m_EntryStack; // path to the current entry
144     int                 m_InParts;
145 };
146 
147 
148 inline
operator *(void) const149 const CBioseq_Handle& CBioseq_CI::operator* (void) const
150 {
151     return m_CurrentBioseq;
152 }
153 
154 
155 inline
operator ->(void) const156 const CBioseq_Handle* CBioseq_CI::operator-> (void) const
157 {
158     return &m_CurrentBioseq;
159 }
160 
161 
162 inline
GetScope(void) const163 CScope& CBioseq_CI::GetScope(void) const
164 {
165     return m_Scope.GetScope();
166 }
167 
168 
169 /* @} */
170 
171 
172 END_SCOPE(objects)
173 END_NCBI_SCOPE
174 
175 #endif  // BIOSEQ_CI__HPP
176