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

Go to the SVN repository for this file.

1 /* $Id: gather_iter.cpp 63349 2014-06-18 23:38:10Z kans $
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: Michael Kornbluh
27 *
28 * File Description:
29 * This returns, in order, the bioseq_handles that will be gathered for
30 * formatting.
31 *
32 * ===========================================================================
33 */
34 
35 #include <ncbi_pch.hpp>
36 
38 
40 
41 #include <objmgr/bioseq_ci.hpp>
42 #include <objmgr/util/sequence.hpp>
43 
46 
48  const CSeq_entry_Handle& top_seq_entry,
50  : m_Config(config)
51 {
52  x_found = false;
53  x_AddSeqEntryToStack( top_seq_entry );
54 }
55 
56 CGather_Iter::operator bool(void) const
57 {
58  return NULL != m_BioseqIter.get() || ! m_SeqEntryIterStack.empty();
59 }
60 
61 
63 {
64  _ASSERT( NULL != m_BioseqIter.get() );
65 
66  ++(*m_BioseqIter);
67  for ( ; (*m_BioseqIter); ++(*m_BioseqIter) ) {
68  if( ! x_IsBioseqHandleOkay(**m_BioseqIter) ) {
69  continue;
70  }
71 
72  // The next one is good, so keep it
73  return *this;
74  }
75  // m_BioseqIter is exhausted, so we need to climb upwards
76  m_BioseqIter.reset();
77 
78  // The m_BioseqIter is exhausted, so we need to find the next one.
79  while( ! m_SeqEntryIterStack.empty() ) {
80  CSeq_entry_CI& lowest_seq_entry_iter = m_SeqEntryIterStack.back();
81  ++lowest_seq_entry_iter;
82  if( *lowest_seq_entry_iter ) {
83  // lowest one still valid, try to add what's under the next Seq-entry
84  if( x_AddSeqEntryToStack(*lowest_seq_entry_iter) ) {
85  return *this;
86  }
87  } else {
88  // This one's exhausted. Pop off that one, and try iterating the next one up.
89  m_SeqEntryIterStack.pop_back();
90  }
91  }
92 
93  return *this;
94 }
95 
97 {
99  return **m_BioseqIter;
100 }
101 
103  const CSeq_entry_Handle& entry )
104 {
105  _ASSERT( m_SeqEntryIterStack.empty() ||
106  *m_SeqEntryIterStack.back() == entry );
107 
108  if ( entry.IsSet() && entry.GetSet().IsSetClass() ) {
109  CBioseq_set::TClass clss = entry.GetSet().GetClass();
110  if ( clss == CBioseq_set::eClass_genbank ||
111  clss == CBioseq_set::eClass_mut_set ||
112  clss == CBioseq_set::eClass_pop_set ||
113  clss == CBioseq_set::eClass_phy_set ||
114  clss == CBioseq_set::eClass_eco_set ||
115  clss == CBioseq_set::eClass_wgs_set ||
117  {
118  CSeq_entry_CI it(entry);
119  if( it ) {
120  for ( ; it; ++it ) {
121  m_SeqEntryIterStack.push_back(it);
122  if( x_AddSeqEntryToStack(*it) ) {
123  return true;
124  }
125  m_SeqEntryIterStack.pop_back();
126  }
127  }
128  return false;
129  }
130  }
131 
132  CSeq_inst::TMol mol_type;
133  if (m_Config.IsViewFirst() && x_found) {
134  return false;
135  } else if (m_Config.IsViewAll()) {
136  mol_type = CSeq_inst::eMol_not_set;
137  } else if (m_Config.IsViewNuc()) {
138  mol_type = CSeq_inst::eMol_na;
139  } else if (m_Config.IsViewProt()) {
140  mol_type = CSeq_inst::eMol_aa;
141  } else {
142  return false;
143  }
144 
145  auto_ptr<CBioseq_CI> seq_iter( new CBioseq_CI(entry, mol_type, CBioseq_CI::eLevel_Mains) );
146  for( ; (*seq_iter); ++(*seq_iter) ) {
147  if( ! x_IsBioseqHandleOkay(**seq_iter) ) {
148  continue;
149  }
150 
151  // found a good one
152  m_BioseqIter = seq_iter;
153  x_found = true;
154  return true;
155  }
156  return false;
157 }
158 
160 {
162  if ( m_Config.SuppressLocalId() && id.GetSeqId()->IsLocal() ) {
163  return false;
164  }
165 
166  return true;
167 }
168 
CBioseq_Handle –.
CGather_Iter & operator++(void)
Definition: gather_iter.cpp:62
bool IsViewProt(void) const
bool IsViewFirst(void) const
bool
Definition: cgiapp.hpp:496
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:73
const CBioseq_Handle & operator*(void) const
Definition: gather_iter.cpp:96
bool x_IsBioseqHandleOkay(const CBioseq_Handle &bioseq)
TSet GetSet(void) const
ecological sample study
bool x_AddSeqEntryToStack(const CSeq_entry_Handle &seq_entry)
#define NULL
Definition: ncbistd.hpp:225
bool IsViewAll(void) const
CSeq_entry_CI –.
return the "best" gi (uses FindBestScore(), with CSeq_id::CalculateScore() as the score function ...
Definition: sequence.hpp:99
bool IsSetClass(void) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
whole genome shotgun project
auto_ptr< CBioseq_CI > m_BioseqIter
Definition: gather_iter.hpp:78
bool SuppressLocalId(void) const
TClass GetClass(void) const
CSeq_entry_Handle –.
EMol
molecule class in living organism
Definition: Seq_inst_.hpp:108
bool IsViewNuc(void) const
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found...
std::vector< CSeq_entry_CI > m_SeqEntryIterStack
Definition: gather_iter.hpp:77
Main bioseq only.
Definition: bioseq_ci.hpp:74
#define _ASSERT
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:70
CBioseq_CI –.
Definition: bioseq_ci.hpp:68
const CFlatFileConfig & m_Config
Definition: gather_iter.hpp:80
#define const
Definition: zconf.h:217
just a nucleic acid
Definition: Seq_inst_.hpp:113
bool IsSet(void) const
genomic products, chrom+mRNA+protein
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
Modified on Sun Jun 25 17:42:30 2017 by modify_doxy.py rev. 533848