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

Go to the SVN repository for this file.

1 /* $Id: cmd_add_seqentry.cpp 43474 2019-07-11 19:20:45Z 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
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>
42 #include <objects/seq/Seqdesc.hpp>
43 
44 #include <objects/seq/MolInfo.hpp>
45 #include <objects/seq/Bioseq.hpp>
46 #include <objmgr/scope.hpp>
47 #include <objmgr/seqdesc_ci.hpp>
48 #include <objtools/readers/source_mod_parser.hpp>
50 
52 
55 
57  : m_SEH(seh), m_Add(seqentry)
58 {
59 }
60 
62 {
64  if (!eh.IsSet() && m_Add->IsSeq() && m_Add->GetSeq().IsAa()) {
65  CBioseq_set_Handle nuc_parent = eh.GetParentBioseq_set();
66  if (nuc_parent && nuc_parent.IsSetClass() && nuc_parent.GetClass() == objects::CBioseq_set::eClass_nuc_prot) {
67  m_SEH = nuc_parent.GetParentEntry();
68  eh = m_SEH.GetEditHandle();
69 
70  }
71  }
72  if (!eh.IsSet()) {
73  eh.ConvertSeqToSet();
74  if (m_Add->IsSeq() && m_Add->GetSeq().IsAa()) {
75  // when add protein sequence, convert sequence to nuc-prot set
76  eh.SetSet().SetClass(CBioseq_set::eClass_nuc_prot);
79  if (set && set->IsSetSeq_set()) {
80  CConstRef<CSeq_entry> nuc = set->GetSeq_set().front();
82  CBioseq_set::TDescr::Tdata::const_iterator it = nuc->GetDescr().Get().begin();
83  // move all descriptors from nucleotide sequence to the set
84  // except molinfo, title, OriginalID and AutodefOptions user objects
85  while (it != nuc->GetDescr().Get().end()) {
86  if (!(*it)->IsMolinfo()
87  && !(*it)->IsTitle()
88  && !((*it)->IsUser() && ( (*it)->GetUser().GetObjectType() == CUser_object::eObjectType_AutodefOptions
89  || (*it)->GetUser().GetObjectType() == CUser_object::eObjectType_OriginalId))) {
91  copy->Assign(**it);
92  eh.AddSeqdesc(*copy);
93  neh.RemoveSeqdesc(**it);
94  if (nuc->IsSetDescr()) {
95  it = nuc->GetDescr().Get().begin();
96  } else {
97  break;
98  }
99  } else {
100  ++it;
101  }
102  }
103  }
104  }
105  }
106 
107 
109  m_index = eh.GetSet().GetSeq_entry_Index(added);
110 }
111 
113 {
114  int pos = 0;
116  if (entry->IsSet()) {
117  const CBioseq_set& set = entry->GetSet();
118  CBioseq_set::TSeq_set::const_iterator it = set.GetSeq_set().begin();
119  while (it != set.GetSeq_set().end() && pos < m_index) {
120  ++pos;
121  ++it;
122  }
123 
124  if (it != set.GetSeq_set().end()) {
126  eh.Remove();
127  if (set.GetSeq_set().size() == 1) {
128  eh = m_SEH.GetEditHandle();
129  eh.ConvertSetToSeq();
130  }
131  }
132  }
133 }
134 
136 {
137  return "Add SeqEntry";
138 }
139 
140 bool SetMolinfoCompleteness (CMolInfo& mi, bool partial5, bool partial3)
141 {
142  bool changed = false;
143  CMolInfo::ECompleteness new_val;
144  if ( partial5 && partial3 ) {
146  } else if ( partial5 ) {
148  } else if ( partial3 ) {
150  } else {
152  }
153  if (!mi.IsSetCompleteness() || mi.GetCompleteness() != new_val) {
154  mi.SetCompleteness(new_val);
155  changed = true;
156  }
157  return changed;
158 }
159 
160 
161 void SetMolinfoForProtein (CRef<objects::CSeq_entry> protein, bool partial5, bool partial3)
162 {
164  NON_CONST_ITERATE(objects::CSeq_descr::Tdata, it, protein->SetDescr().Set()) {
165  if ((*it)->IsMolinfo()) {
166  pdesc = *it;
167  break;
168  }
169  }
170  if (!pdesc) {
171  pdesc = new objects::CSeqdesc();
172  protein->SetDescr().Set().push_back(pdesc);
173  }
174  pdesc->SetMolinfo().SetBiomol(objects::CMolInfo::eBiomol_peptide);
175  SetMolinfoCompleteness(pdesc->SetMolinfo(), partial5, partial3);
176 
177 }
178 
179 
181 {
183  NON_CONST_ITERATE(objects::CSeq_entry::TAnnot, annot_it, protein->SetSeq().SetAnnot()) {
184  if ((*annot_it)->IsFtable()) {
185  ftable = *annot_it;
186  break;
187  }
188  }
189  if (!ftable) {
190  ftable = new objects::CSeq_annot();
191  protein->SetSeq().SetAnnot().push_back(ftable);
192  }
193 
194  CRef<objects::CSeq_feat> prot_feat(NULL);
195  NON_CONST_ITERATE(objects::CSeq_annot::TData::TFtable, feat_it, ftable->SetData().SetFtable()) {
196  if ((*feat_it)->IsSetData() && (*feat_it)->GetData().IsProt() && !(*feat_it)->GetData().GetProt().IsSetProcessed()) {
197  prot_feat = *feat_it;
198  break;
199  }
200  }
201  if (!prot_feat) {
202  prot_feat = new objects::CSeq_feat();
203  prot_feat->SetData().SetProt();
204  ftable->SetData().SetFtable().push_back(prot_feat);
205  }
206  CRef<objects::CSeq_id> prot_id(new objects::CSeq_id());
207  prot_id->Assign(*(protein->GetSeq().GetId().front()));
208  prot_feat->SetLocation().SetInt().SetId(*prot_id);
209  prot_feat->SetLocation().SetInt().SetFrom(0);
210  prot_feat->SetLocation().SetInt().SetTo(protein->GetSeq().GetLength() - 1);
211  prot_feat->SetLocation().SetPartialStart(partial5, objects::eExtreme_Biological);
212  prot_feat->SetLocation().SetPartialStop(partial3, objects::eExtreme_Biological);
213  if (partial5 || partial3) {
214  prot_feat->SetPartial(true);
215  } else {
216  prot_feat->ResetPartial();
217  }
218  return prot_feat;
219 }
220 
221 
223 {
224  objects::CSourceModParser smp(
225  objects::CSourceModParser::eHandleBadMod_Ignore );
226  // later - fix protein title by removing attributes used?
228  = protein->GetSeq().GetClosestDescriptor(objects::CSeqdesc::e_Title);
229  if (title_desc) {
230  string& title(const_cast<string&>(title_desc->GetTitle()));
231  title = smp.ParseTitle(title, CConstRef<objects::CSeq_id>(protein->GetSeq().GetFirstId()) );
232  smp.ApplyAllMods(protein->SetSeq());
233  }
234 
235  return AddEmptyProteinFeatureToProtein(protein, partial5, partial3);
236 }
237 
238 
239 CRef<objects::CSeq_entry> CreateTranslatedProteinSequence (CRef<objects::CSeq_feat> cds, objects::CBioseq_Handle nuc_h, bool create_general_only, int *offset)
240 {
241  CRef<objects::CBioseq> protein = objects::CSeqTranslator::TranslateToProtein (*cds, nuc_h.GetScope());
242  objects::CSeqTranslator::ChangeDeltaProteinToRawProtein(protein);
243  CRef<objects::CSeq_id> prot_id(new objects::CSeq_id());
244  if (cds->IsSetProduct()) {
245  prot_id->Assign(*(cds->GetProduct().GetId()));
246  } else {
247  // make up some new protein ID
248  int local_offset = 1;
249  if (offset)
250  local_offset = *offset;
251  string id_label;
252  prot_id->Assign(*objects::edit::GetNewProtId(nuc_h, local_offset, id_label, create_general_only));
253  cds->SetProduct().SetWhole().Assign(*prot_id);
254  ++local_offset;
255  if (offset)
256  *offset = local_offset;
257  }
258  protein->SetId().push_back(prot_id);
259  CRef<objects::CSeq_entry> entry(new objects::CSeq_entry());
260  entry->SetSeq().Assign(*protein);
261  SetMolinfoForProtein (entry,
262  cds->GetLocation().IsPartialStart(objects::eExtreme_Biological),
263  cds->GetLocation().IsPartialStop(objects::eExtreme_Biological));
264  return entry;
265 }
266 
@ eExtreme_Biological
5' and 3'
Definition: Na_strand.hpp:62
CRef< objects::CSeq_id > GetNewProtId(objects::CBioseq_Handle bsh, int &offset, string &id_label, bool general_only)
CBioseq_set_Handle –.
bool IsAa(void) const
Definition: Bioseq.cpp:350
virtual string GetLabel()
virtual void Unexecute()
Undo (opposite to Execute())
CCmdAddSeqEntry(CSeq_entry *seqentry, CSeq_entry_Handle seh)
CRef< CSeq_entry > m_Add
CSeq_entry_Handle m_SEH
virtual void Execute()
Do the editing action.
CSeq_entry_Handle –.
CSeq_entry_Handle –.
Definition: Seq_entry.hpp:56
@ eObjectType_AutodefOptions
Definition: set.hpp:45
const_iterator begin() const
Definition: set.hpp:135
size_type size() const
Definition: set.hpp:132
const_iterator end() const
Definition: set.hpp:136
bool SetMolinfoCompleteness(CMolInfo &mi, bool partial5, bool partial3)
USING_SCOPE(objects)
void SetMolinfoForProtein(CRef< objects::CSeq_entry > protein, bool partial5, bool partial3)
CRef< objects::CSeq_feat > AddEmptyProteinFeatureToProtein(CRef< objects::CSeq_entry > protein, bool partial5, bool partial3)
CRef< objects::CSeq_entry > CreateTranslatedProteinSequence(CRef< objects::CSeq_feat > cds, objects::CBioseq_Handle nuc_h, bool create_general_only, int *offset)
CRef< objects::CSeq_feat > AddProteinFeatureToProtein(CRef< objects::CSeq_entry > protein, bool partial5, bool partial3)
int offset
Definition: replacements.h:160
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NULL
Definition: ncbistd.hpp:225
CSeq_entry_EditHandle GetSeq_entryEditHandle(const CSeq_entry &entry)
Definition: scope.cpp:207
TSeq ConvertSetToSeq(void) const
Do the same as CollapseSet() when sub-entry is of type bioseq.
TClass GetClass(void) const
CRef< CSeqdesc > RemoveSeqdesc(const CSeqdesc &v) const
CBioseq_set_EditHandle GetParentBioseq_set(void) const
Get parent bioseq-set edit handle.
TSet GetSet(void) const
void Remove(void) const
Remove this Seq-entry from parent, or scope if it's top level Seq-entry.
TSet ConvertSeqToSet(TClass set_class=CBioseq_set::eClass_not_set) const
Convert the entry from Bioseq to Bioseq-set.
CConstRef< CBioseq_set > GetCompleteBioseq_set(void) const
Return the complete bioseq-set object.
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
CConstRef< CSeq_entry > GetCompleteSeq_entry(void) const
Complete and get const reference to the seq-entry.
CScope & GetScope(void) const
Get scope this handle belongs to.
CSeq_entry_EditHandle AttachEntry(CSeq_entry &entry, int index=-1) const
Attach an existing seq-entry.
bool IsSet(void) const
bool AddSeqdesc(CSeqdesc &v) const
int GetSeq_entry_Index(const CSeq_entry_Handle &handle) 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
const TSeq & GetSeq(void) const
Get the variant data.
Definition: Seq_entry_.cpp:102
const TSet & GetSet(void) const
Get the variant data.
Definition: Seq_entry_.cpp:124
bool IsSeq(void) const
Check if variant Seq is selected.
Definition: Seq_entry_.hpp:257
bool IsSet(void) const
Check if variant Set is selected.
Definition: Seq_entry_.hpp:263
@ eClass_nuc_prot
nuc acid and coded proteins
Definition: Bioseq_set_.hpp:99
void SetCompleteness(TCompleteness value)
Assign a value to Completeness data member.
Definition: MolInfo_.hpp:600
bool IsSetCompleteness(void) const
Check if a value has been assigned to Completeness data member.
Definition: MolInfo_.hpp:569
TCompleteness GetCompleteness(void) const
Get the Completeness member data.
Definition: MolInfo_.hpp:594
@ eCompleteness_complete
complete biological entity
Definition: MolInfo_.hpp:156
@ eCompleteness_no_left
missing 5' or NH3 end
Definition: MolInfo_.hpp:158
@ eCompleteness_no_right
missing 3' or COOH end
Definition: MolInfo_.hpp:159
@ eCompleteness_no_ends
missing both ends
Definition: MolInfo_.hpp:160
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
Definition: smp.h:26
#define ftable
Definition: utilfeat.h:37
Modified on Sat May 18 11:35:48 2024 by modify_doxy.py rev. 669887