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

Go to the SVN repository for this file.

1 /* $Id: cmd_promote_cds.cpp 45439 2020-08-04 15:43:47Z asztalos $
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  * Authors: Colleen Bollin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 #include <objects/seq/Bioseq.hpp>
32 #include <objmgr/scope.hpp>
33 #include <objmgr/seq_annot_ci.hpp>
34 #include <objmgr/bioseq_ci.hpp>
36 #include <gui/objutils/utils.hpp>
37 
40 
41 
43 {
44  // only move coding regions to nuc-prot set
45  if (!m_OrigFeat.IsSetData() || !m_OrigFeat.GetData().IsCdregion()) {
46  return;
47  }
48  // don't move if pseudo
49  if (m_OrigFeat.IsSetPseudo() && m_OrigFeat.GetPseudo()) {
50  return;
51  }
52 
53  CBioseq_Handle nuc_bsh = GetBioseqForSeqFeat(*m_OrigFeat.GetOriginalSeq_feat(), m_OrigFeat.GetScope());
54 
55  // This is necessary, to make sure that we are in "editing mode"
56  const CSeq_annot_Handle& annot_handle = m_OrigFeat.GetAnnot();
57  m_OrigAnnoteh = annot_handle.GetEditHandle();
58  m_ParentHandle = m_OrigAnnoteh.GetParentEntry();
59 
60  CSeq_entry_Handle parent_entry = m_OrigFeh.GetAnnot().GetParentEntry();
61 
62  if (parent_entry.IsSet()
63  && parent_entry.GetSet().IsSetClass()
64  && parent_entry.GetSet().GetClass() == CBioseq_set::eClass_nuc_prot) {
65  // already on nuc-prot set, leave it alone
66  }
67  else {
68  CBioseq_set_Handle nuc_parent = parent_entry.GetParentBioseq_set();
69  if (nuc_parent && nuc_parent.IsSetClass() && nuc_parent.GetClass() == CBioseq_set::eClass_nuc_prot) {
71  CSeq_entry_Handle parent_seh = nuc_parent.GetParentEntry();
72  CSeq_annot_CI annot_ci(parent_seh, CSeq_annot_CI::eSearch_entry);
73  for (; annot_ci; ++annot_ci) {
74  if ((*annot_ci).IsFtable()) {
75  ftable = *annot_ci;
76  break;
77  }
78  }
79 
80  if (!ftable) {
81  CRef<CSeq_annot> new_annot(new CSeq_annot());
82  new_annot->SetData().SetFtable();
83  CSeq_entry_EditHandle h = parent_seh.GetEditHandle();
84  ftable = h.AttachAnnot(*new_annot);
85  }
86 
87  CSeq_annot_EditHandle new_annot = ftable.GetEditHandle();
88  m_NewFeh = new_annot.TakeFeat(m_OrigFeh);
89  // as a result, feh will be in 'removed' state
90  const auto& feat_list = m_OrigAnnoteh.GetSeq_annotCore()->GetData().GetFtable();
91  if (feat_list.empty()) {
92  m_OrigAnnoteh.Remove();
93  }
94  }
95  }
96 }
97 
99 {
100  CSeq_entry_Handle parent_entry = m_NewFeh.GetAnnot().GetParentEntry();
101 
102  if (!parent_entry.IsSet() || !parent_entry.GetSet().IsSetClass() ||
103  parent_entry.GetSet().GetClass() != CBioseq_set::eClass_nuc_prot) {
104  // no change, not on nuc-prot set
105  return;
106  }
107 
108  CBioseq_CI bi(parent_entry, CSeq_inst::eMol_na);
109  if (!bi) {
110  // no nucleotide sequence to move to
111  return;
112  }
113 
114 
115  // This is necessary, to make sure that we are in "editing mode"
116  const CSeq_annot_Handle& annot_handle = m_NewFeh.GetAnnot();
117  CSeq_entry_EditHandle eh = annot_handle.GetParentEntry().GetEditHandle();
118 
120  CSeq_entry_Handle nuc_seh = bi->GetSeq_entry_Handle();
121  CSeq_annot_CI annot_ci(nuc_seh, CSeq_annot_CI::eSearch_entry);
122  for (; annot_ci; ++annot_ci) {
123  if ((*annot_ci).IsFtable()) {
124  ftable = *annot_ci;
125  break;
126  }
127  }
128 
129  if (!ftable) {
130  CRef<CSeq_annot> new_annot(new CSeq_annot());
131  new_annot->SetData().SetFtable();
132  CSeq_entry_EditHandle eh = nuc_seh.GetEditHandle();
133  ftable = eh.AttachAnnot(*new_annot);
134  }
135 
136  CSeq_annot_EditHandle old_annot = annot_handle.GetEditHandle();
137  CSeq_annot_EditHandle new_annot = ftable.GetEditHandle();
138 
139  CConstRef<CSeq_feat> feat_obj = m_NewFeh.GetSeq_feat();
140  m_NewFeh.Remove(); // remove it from new place
141 
142  if (m_OrigAnnoteh.IsRemoved()) {
143  m_ParentHandle.AttachAnnot(m_OrigAnnoteh);
144  }
145  m_OrigFeh.Replace(*feat_obj); // reattach it to the old feature handle
146 
147  const auto &feat_list = old_annot.GetSeq_annotCore()->GetData().GetFtable();
148  if (feat_list.empty()) {
149  old_annot.Remove();
150  }
151 }
152 
154 {
155  return "Promote CDS";
156 }
157 
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
CBioseq_Handle –.
CBioseq_set_Handle –.
objects::CSeq_feat_Handle m_OrigFeat
objects::CSeq_entry_EditHandle m_ParentHandle
virtual void Unexecute()
Undo (opposite to Execute())
virtual string GetLabel()
objects::CSeq_feat_EditHandle m_NewFeh
objects::CSeq_annot_EditHandle m_OrigAnnoteh
objects::CSeq_feat_EditHandle m_OrigFeh
virtual void Execute()
Do the editing action.
CSeq_annot_CI –.
CSeq_annot_Handle –.
CSeq_entry_Handle –.
CSeq_entry_Handle –.
USING_SCOPE(objects)
objects::CBioseq_Handle GetBioseqForSeqFeat(const objects::CSeq_feat &f, objects::CScope &scope)
TClass GetClass(void) const
void Remove(void) const
Remove current annot.
TSet GetSet(void) const
CSeq_entry_Handle GetSeq_entry_Handle(void) const
Get parent Seq-entry handle.
CSeq_annot_EditHandle AttachAnnot(CSeq_annot &annot) const
Attach an annotation.
CBioseq_set_Handle GetParentBioseq_set(void) const
Get parent bioseq-set handle.
CSeq_entry_Handle GetParentEntry(void) const
Get parent Seq-entry handle.
CSeq_entry_EditHandle GetEditHandle(void) const
Get 'edit' version of handle.
CSeq_entry_Handle GetParentEntry(void) const
Return a handle for the parent seq-entry of the bioseq.
bool IsSetClass(void) const
CSeq_annot_EditHandle GetEditHandle(void) const
Get 'edit' version of handle.
CSeq_feat_EditHandle TakeFeat(const CSeq_feat_EditHandle &handle) const
bool IsSet(void) const
CConstRef< CSeq_annot > GetSeq_annotCore(void) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
@ eClass_nuc_prot
nuc acid and coded proteins
Definition: Bioseq_set_.hpp:99
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_annot_.cpp:244
const TFtable & GetFtable(void) const
Get the variant data.
Definition: Seq_annot_.hpp:621
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_annot_.hpp:873
@ eMol_na
just a nucleic acid
Definition: Seq_inst_.hpp:113
#define ftable
Definition: utilfeat.h:37
Modified on Fri Sep 20 14:57:41 2024 by modify_doxy.py rev. 669887