NCBI C++ ToolKit
process_invert.hpp
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:
27 *
28 * File Description:
29 *
30 * ===========================================================================
31 */
32 
33 #ifndef __process_invert__hpp__
34 #define __process_invert__hpp__
35 
36 // ============================================================================
38 // ============================================================================
39  : public CScopedProcess
40 {
41 public:
42  // ------------------------------------------------------------------------
44  // ------------------------------------------------------------------------
45  : CScopedProcess()
46  , m_out( 0 )
47  {};
48 
49  // ------------------------------------------------------------------------
51  // ------------------------------------------------------------------------
52  {
53  };
54 
55  // ------------------------------------------------------------------------
57  const CArgs& args )
58  // ------------------------------------------------------------------------
59  {
61 
62  m_out = args["o"] ? &(args["o"].AsOutputFile()) : &cout;
63  };
64 
65  // ------------------------------------------------------------------------
66  virtual void SeqEntryInitialize(
67  CRef<CSeq_entry>& se )
68  // ------------------------------------------------------------------------
69  {
71  };
72 
73  // ------------------------------------------------------------------------
75  // ------------------------------------------------------------------------
76  {
77  try {
79  CBioseq& bioseq = *bsp_itr;
80  CBioseq_Handle bsh = m_scope->GetBioseqHandle(bioseq);
81  if (!bsh) continue;
82  SAnnotSelector sel;
83  for (CFeat_CI feat_ci(bsh, sel); feat_ci; ++feat_ci) {
84  const CSeq_feat& const_feat = feat_ci->GetOriginalFeature();
85  CRef<CSeq_feat> feat(new CSeq_feat);
86  feat->Assign(const_feat);
87  bool unordered = false;
89  for (CSeq_loc_CI curr(feat->SetLocation()); curr; ++curr) {
90  if ( prev && curr /* &&
91  m_scope->IsSameBioseq(curr.GetSeq_id(), prev.GetSeq_id(), CScope::eGetBioseq_Loaded) */ ) {
92  CSeq_loc_CI::TRange prev_range = prev.GetRange();
93  CSeq_loc_CI::TRange curr_range = curr.GetRange();
94  if ( curr.GetStrand() == eNa_strand_minus ) {
95  if (prev_range.GetTo() < curr_range.GetTo()) {
96  unordered = true;
97  }
98  } else {
99  if (prev_range.GetTo() > curr_range.GetTo()) {
100  unordered = true;
101  }
102  }
103  }
104  prev = curr;
105  }
106  if (unordered) {
107  /*
108  feat->SetPseudo(true);
109  */
110  CSeq_loc& location = feat->SetLocation();
111  if (location.Which() == CSeq_loc::e_Mix) {
112  CRef<CSeq_loc> rev_loc( new CSeq_loc );
113  CSeq_loc_mix& mix = rev_loc->SetMix();
114 
115  ITERATE (CSeq_loc_mix::Tdata, it, location.GetMix().Get()) {
116  mix.Set().push_front(*it);
117  }
118 
119  feat->SetLocation(*rev_loc);
120  CSeq_feat_EditHandle(feat_ci->GetSeq_feat_Handle()).Replace(*feat);
121  }
122  }
123  }
124  }
125 
126  *m_out << MSerial_AsnText << *m_entry << endl;
127  }
128  catch (CException& e) {
129  ERR_POST(Error << "error processing seqentry: " << e.what());
130  }
131  };
132 
133 protected:
135 };
136 
137 #endif
CArgs –.
Definition: ncbiargs.hpp:379
CBioseq_Handle –.
CFeat_CI –.
Definition: feat_ci.hpp:64
CNcbiOstream * m_out
virtual void SeqEntryInitialize(CRef< CSeq_entry > &se)
void ProcessInitialize(const CArgs &args)
void ProcessInitialize(const CArgs &args)
virtual void SeqEntryInitialize(CRef< CSeq_entry > &se)
CRef< CScope > m_scope
CRef< CSeq_entry > m_entry
Definition: process.hpp:114
CSeq_feat_EditHandle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
Seq-loc iterator class – iterates all intervals from a seq-loc in the correct order.
Definition: Seq_loc.hpp:453
static const char location[]
Definition: config.c:97
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:61
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
Definition: ncbiexpt.cpp:342
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
void SetMix(TMix &v)
Definition: Seq_loc.hpp:987
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
void Replace(const CSeq_feat &new_feat) const
Replace the feature with new Seq-feat object.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
TTo GetTo(void) const
Get the To member data.
Definition: Range_.hpp:269
void SetLocation(TLocation &value)
Assign a value to Location data member.
Definition: Seq_feat_.cpp:131
list< CRef< CSeq_loc > > Tdata
Tdata & Set(void)
Assign a value to data member.
@ eNa_strand_minus
Definition: Na_strand_.hpp:67
#define EXPLORE_ALL_BIOSEQS_WITHIN_SEQENTRY(Itr, Var)
EXPLORE_ALL_BIOSEQS_WITHIN_SEQENTRY.
SAnnotSelector –.
Modified on Fri Dec 01 04:46:39 2023 by modify_doxy.py rev. 669887