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

Go to the SVN repository for this file.

1 /* $Id: cmd_add_cds.cpp 32264 2015-01-26 21:04:48Z filippov $
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, based on a file by Roman Katargin
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 #include <objmgr/seq_entry_ci.hpp>
33 #include <objmgr/seq_annot_ci.hpp>
34 #include <objmgr/bioseq_ci.hpp>
35 #include <objmgr/seqdesc_ci.hpp>
36 #include <objmgr/util/sequence.hpp>
41 
44 
45 
48 
50 {
51  CSeq_entry_EditHandle eh = m_seh.GetEditHandle();
52  if (!eh.IsSet()) {
53  eh.ConvertSeqToSet();
54  eh.SetSet().SetClass(objects::CBioseq_set::eClass_nuc_prot);
55  CBioseq_CI bi(eh, objects::CSeq_inst::eMol_na);
56  CBioseq_EditHandle nuc_h = bi->GetEditHandle();
57 
58  // move all source and pub descriptors from Bioseq to Nuc-prot set
59  CSeq_descr::Tdata& seq_descr = nuc_h.SetDescr();
60  CSeq_descr::Tdata::iterator desc_it = seq_descr.begin();
61  while (desc_it != seq_descr.end()) {
62  if ((*desc_it)->IsSource() || (*desc_it)->IsPub()) {
63  CRef<objects::CSeqdesc> cpy(new objects::CSeqdesc());
64  cpy->Assign(**desc_it);
65  eh.AddSeqdesc(*cpy);
66  desc_it = seq_descr.erase(desc_it);
67  } else {
68  ++desc_it;
69  }
70  }
71  }
72 
73 
74  CSeq_annot_Handle ftable;
75 
77  for (; annot_ci; ++annot_ci) {
78  if ((*annot_ci).IsFtable()) {
79  ftable = *annot_ci;
80  break;
81  }
82  }
83 
84  if (!ftable)
85  for (objects::CBioseq_CI bi(m_seh, objects::CSeq_inst::eMol_na); bi; ++bi)
86  {
87  for (CSeq_annot_CI annot_ci(bi->GetParentEntry(), CSeq_annot_CI::eSearch_entry); annot_ci; ++annot_ci)
88  {
89  if ((*annot_ci).IsFtable())
90  {
91  ftable = *annot_ci;
92  break;
93  }
94  }
95  if (ftable)
96  break;
97  }
98 
99  if (!ftable) {
100  CRef<CSeq_annot> new_annot(new CSeq_annot());
101  ftable = m_FTableCreated = eh.AttachAnnot(*new_annot);
102  }
103 
104 
105  // add protein sequence that is translation
106  CBioseq_EditHandle prot_h;
107  CBioseq_CI pbi(eh, objects::CSeq_inst::eMol_aa);
108  if (pbi)
109  prot_h = pbi->GetEditHandle();
110 
112  CRef<objects::CSeq_id> prot_id(new objects::CSeq_id());
113  if (m_CDS->IsSetProduct() && (!prot_h || !prot_h.IsSynonym(*(m_CDS->GetProduct().GetId())))) {
114  prot_id->Assign(*(m_CDS->GetProduct().GetId()));
115  } else {
116  // make up some new protein ID
117  CBioseq_Handle nuc_h = m_seh.GetScope().GetBioseqHandle(m_CDS->GetLocation());
118  prot_id->Assign(*GetNewProteinId(m_seh, nuc_h));
119  //m_CDS->SetProduct().SetId(*prot_id);
120  m_CDS->SetProduct().SetWhole().Assign(*prot_id);
121  }
122  protein->SetId().push_back(prot_id);
123  m_ProtHandle = eh.AttachBioseq(*protein, -1);
124 
125  CSeq_annot_EditHandle aeh(ftable);
126  m_feh_CDS = aeh.AddFeat(*m_CDS);
127 
128  // create molinfo descriptor
129  CRef<objects::CSeqdesc> pdesc(new objects::CSeqdesc());
130  pdesc->SetMolinfo().SetBiomol(objects::CMolInfo::eBiomol_peptide);
131  pdesc->SetMolinfo().SetCompleteness(objects::CMolInfo::eCompleteness_complete);
132 
133  // set location for protein feature
134 
135  if (m_CDS->GetLocation().IsPartialStart(objects::eExtreme_Biological)) {
136  if (m_Prot)
137  {
138  m_Prot->SetLocation().SetPartialStart(true, objects::eExtreme_Biological);
139  m_Prot->SetPartial(true);
140  }
141  pdesc->SetMolinfo().SetCompleteness(objects::CMolInfo::eCompleteness_no_left);
142  }
143  if (m_CDS->GetLocation().IsPartialStop(objects::eExtreme_Biological)) {
144  if (m_Prot)
145  {
146  m_Prot->SetLocation().SetPartialStop(true, objects::eExtreme_Biological);
147  m_Prot->SetPartial(true);
148  }
149  if (pdesc->GetMolinfo().GetCompleteness() == objects::CMolInfo::eCompleteness_complete) {
150  pdesc->SetMolinfo().SetCompleteness(objects::CMolInfo::eCompleteness_no_right);
151  } else {
152  pdesc->SetMolinfo().SetCompleteness(objects::CMolInfo::eCompleteness_no_ends);
153  }
154  }
155 
156  if (m_Prot)
157  {
158  m_Prot->SetLocation().SetInt().SetId(*prot_id);
159  m_Prot->SetLocation().SetInt().SetFrom(0);
160  m_Prot->SetLocation().SetInt().SetTo(protein->GetLength() - 1);
161 
162  CRef<CSeq_annot> new_prot_annot(new CSeq_annot());
163  CSeq_annot_Handle prot_ftable = m_ProtHandle.AttachAnnot(*new_prot_annot);
164  CSeq_annot_EditHandle paeh(prot_ftable);
165  paeh.AddFeat(*m_Prot);
166  }
167 
168  // add molinfo descriptor
169  m_ProtHandle.AddSeqdesc(*pdesc);
170 
171 }
172 
174 {
175  m_ProtHandle.Remove();
176  CSeq_entry_EditHandle eh = m_seh.GetEditHandle();
177  if (eh.IsSet() && eh.GetSet().GetCompleteBioseq_set()->GetSeq_set().size() == 1) {
178  eh.ConvertSetToSeq();
179  }
180 
181  m_feh_CDS.Remove();
182 
183  if (m_FTableCreated) {
184  m_FTableCreated.Remove();
185  }
186 }
187 
189 {
190  return "Convert nuc to nuc-prot set";
191 }
192 
193 
194 
TSet SetSet(void) const
CBioseq_Handle –.
CSeq_annot_EditHandle AttachAnnot(CSeq_annot &annot) const
Attach an annotation.
void SetDescr(TDescr &v) const
objects::CSeq_entry_Handle m_seh
Definition: cmd_add_cds.hpp:65
CBioseq_EditHandle –.
CBioseq_EditHandle AttachBioseq(CBioseq &seq, int index=-1) const
Attach an existing bioseq.
CSeq_annot_CI –.
objects::CBioseq_EditHandle m_ProtHandle
Definition: cmd_add_cds.hpp:70
CConstRef< CBioseq_set > GetCompleteBioseq_set(void) const
Return the complete bioseq-set object.
bool IsSynonym(const CSeq_id &id) const
Check if this id can be used to obtain this bioseq handle.
CScope & GetScope(void) const
Get scope this handle belongs to.
TSet GetSet(void) const
CBioseq_EditHandle GetEditHandle(void) const
Get 'edit' version of handle.
virtual string GetLabel()
TSet ConvertSeqToSet(TClass set_class=CBioseq_set::eClass_not_set) const
Convert the entry from Bioseq to Bioseq-set.
bool AddSeqdesc(CSeqdesc &v) const
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:101
static CRef< CBioseq > TranslateToProtein(const CSeq_feat &cds, CScope &scope)
Definition: sequence.cpp:3448
const TSeq_set & GetSeq_set(void) const
Get the Seq_set member data.
list< CRef< CSeqdesc > > Tdata
Definition: Seq_descr_.hpp:91
CSeq_entry_Handle –.
TSeq ConvertSetToSeq(void) const
Do the same as CollapseSet() when sub-entry is of type bioseq.
CSeq_annot_Handle –.
CRef< objects::CSeq_id > GetNewProteinId(objects::CSeq_entry_Handle seh, objects::CBioseq_Handle bsh)
virtual void Unexecute()
Undo (opposite to Execute())
objects::CSeq_annot_EditHandle m_FTableCreated
Definition: cmd_add_cds.hpp:69
CRef< objects::CSeq_feat > m_Prot
Definition: cmd_add_cds.hpp:67
CBioseq_CI –.
Definition: bioseq_ci.hpp:68
USING_SCOPE(objects)
bool IsSet(void) const
virtual void Execute()
Do the editing action.
Definition: cmd_add_cds.cpp:49
CSeq_feat_EditHandle AddFeat(const CSeq_feat &new_obj) const
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:98
CRef< objects::CSeq_feat > m_CDS
Definition: cmd_add_cds.hpp:66
objects::CSeq_feat_EditHandle m_feh_CDS
Definition: cmd_add_cds.hpp:68
Modified on Tue Jul 28 11:16:34 2015 by modify_doxy.py rev. 426318