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

Go to the SVN repository for this file.

1 /* $Id: editing_actions.cpp 47479 2023-05-02 13:24:02Z ucko $
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: Igor Filippov
27  */
28 
29 #include <ncbi_pch.hpp>
31 #include <objmgr/util/feature.hpp>
32 #include <objmgr/util/sequence.hpp>
33 #include <objmgr/seq_annot_ci.hpp>
34 #include <objmgr/bioseq_ci.hpp>
51 #include <objects/seq/Seq_data.hpp>
52 #include <objmgr/seq_vector.hpp>
54 
62 
70 
71 
74 
75 
77  : m_Name(name), m_TopSeqEntry(seh), m_SeqSubmit(submit), m_Other(NULL), m_existing_text(edit::eExistingText_replace_old), m_constraint(CRef<CEditingActionConstraint>(new CEditingActionConstraint)),
78  m_ChangedIds(false), m_update_mrna(false), m_retranslate_cds(false), m_max_records(numeric_limits<size_t>::max())
79 {
80 }
81 
82 const string IEditingAction::GetName(void) const
83 {
84  return m_Name;
85 }
86 
88 {
89  return m_ChangedFeatures;
90 }
91 
93 {
94  return m_CreatedFeatures;
95 }
96 
98 {
99  return m_ChangedDescriptors;
100 }
101 
103 {
105 }
106 
108 {
109  return m_CreatedDescriptors;
110 }
111 
113 {
114  return m_DeletedDescriptors;
115 }
116 
118 {
119  return m_ChangedInstances;
120 }
121 
123 {
124  return m_ChangedSubmitBlock;
125 }
126 
128 {
129  return m_ChangedIds;
130 }
131 
132 const vector<string>& IEditingAction::GetChangedValues()
133 {
134  return m_ChangedValues;
135 }
136 
138 {
141  ResetScope();
142 }
143 
145 {
151 }
152 
154 {
156 }
157 
159 {
160  m_ChangedIds = false;
161 }
162 
164 {
165  m_ChangedValues.clear();
166 }
167 
168 CRef<CCmdComposite> IEditingAction::GetActionCommand() // only do it for "From" part of the two-action commands
169 {
171  CRef<CCmdComposite> cmd(new CCmdComposite("AECR action"));
172  const map<CSeq_feat_Handle, CRef<CSeq_feat> > &changed_features = GetChangedFeatures();
174 
175  // offset for making new protein IDs (when needed)
176  int offset = 1;
178  for (map<CSeq_feat_Handle, CRef<CSeq_feat> >::const_iterator it = changed_features.begin(); it != changed_features.end(); ++it)
179  {
180  const CSeq_feat_Handle fh = it->first;
181  CRef<CSeq_feat> feat = it->second;
182  cleanup.BasicCleanup(*feat);
183  CIRef<IEditCommand> chgFeat;
184  CIRef<IEditCommand> update_mrna_cmd;
185  CRef<CCmdComposite> retranslate_cds_cmd;
187  if (cf != created_features.end())
188  {
189  CSeq_entry_Handle eh = cf->second;
190  chgFeat.Reset(new CCmdCreateFeat(eh, *feat));
191  }
192  else
193  {
194  chgFeat.Reset(new CCmdChangeSeq_feat(fh, *feat));
195  if (m_update_mrna)
196  update_mrna_cmd = GetUpdateMRNAProductNameCmd(fh, feat);
197  if (m_retranslate_cds)
198  {
200  fh.GetOriginalSeq_feat()->IsSetExcept_text() && NStr::Find(fh.GetOriginalSeq_feat()->GetExcept_text(), "RNA editing") != string::npos)
201  {
202  chgFeat.Reset();
203  }
204  else
205  {
206  retranslate_cds_cmd = GetRetranslateCdsCmd(fh, feat, offset, create_general_only);
207  }
208  }
209  }
210 
211  if (chgFeat)
212  cmd->AddCommand(*chgFeat);
213  if (update_mrna_cmd)
214  cmd->AddCommand(*update_mrna_cmd);
215  if (retranslate_cds_cmd)
216  cmd->AddCommand(*retranslate_cds_cmd);
217  }
218 
219  const map<const CSeqdesc*, CRef<CSeqdesc> > &changed_descriptors = GetChangedDescriptors();
221  const map<const CSeqdesc*, CSeq_entry_Handle> &created_descriptors = GetCreatedDescriptors();
222  const map<const CSeqdesc*, CSeq_entry_Handle> &deleted_descriptors = GetDeletedDescriptors();
223 
224  for (map<const CSeqdesc*, CRef<CSeqdesc> >::const_iterator it = changed_descriptors.begin(); it != changed_descriptors.end(); ++it)
225  {
226  map<const CSeqdesc*, CSeq_entry_Handle>::const_iterator cd = created_descriptors.find(it->first);
227  map<const CSeqdesc*, CSeq_entry_Handle>::const_iterator dd = deleted_descriptors.find(it->first);
228  if (cd != created_descriptors.end())
229  {
230  const CSeq_entry_Handle seh = cd->second;
231  CRef<CSeqdesc> new_desc = it->second;
232  if (new_desc->IsSource())
233  {
234  cleanup.BasicCleanup(new_desc->SetSource());
235  }
236  cmd->AddCommand( *CRef<CCmdCreateDesc>(new CCmdCreateDesc(seh, *new_desc)) );
237  }
238  else if (dd != deleted_descriptors.end())
239  {
240  const CSeq_entry_Handle seh = dd->second;
241  const CSeqdesc *old_desc = it->first;
242  cmd->AddCommand( *CRef<CCmdDelDesc>(new CCmdDelDesc(seh, *old_desc)) );
243  }
244  else
245  {
246  const CSeqdesc *old_desc = it->first;
247  string old_taxname;
248  if (old_desc->IsSource() && old_desc->GetSource().IsSetOrg() && old_desc->GetSource().GetOrg().IsSetTaxname()) {
249  old_taxname = old_desc->GetSource().GetOrg().GetTaxname();
250  }
251 
252  CRef<CSeqdesc> new_desc = it->second;
253 
254  string new_taxname;
255  if (new_desc->IsSource() && new_desc->GetSource().IsSetOrg() && new_desc->GetSource().GetOrg().IsSetTaxname()) {
256  new_taxname = new_desc->GetSource().GetOrg().GetTaxname();
257  }
258 
259  if (!NStr::IsBlank(old_taxname) && !NStr::Equal(old_taxname, new_taxname)) {
261  }
262 
263  if (new_desc->IsSource())
264  {
265  cleanup.BasicCleanup(new_desc->SetSource());
266  }
267  auto ctxt_it = descr_contexts.find(old_desc);
268  if (ctxt_it != descr_contexts.end()) {
269  CRef<CCmdChangeSeqdesc> ecmd(new CCmdChangeSeqdesc(ctxt_it->second, *old_desc, *new_desc));
270  cmd->AddCommand(*ecmd);
271  }
272  }
273  }
274 
276  if (new_submit && m_SeqSubmit)
277  {
278  const CSubmit_block &submit = m_SeqSubmit->GetSub();
279  const CObject* actual = dynamic_cast<const CObject*>(&submit);
281  chg_submit->Add(const_cast<CObject*>(actual), CConstRef<CObject>(new_submit));
282  cmd->AddCommand(*chg_submit);
283  }
284 
285  const map<CBioseq_Handle, CRef<CSeq_inst> > &changed_instances = GetChangedInstances();
286  for ( map<CBioseq_Handle, CRef<CSeq_inst> >::const_iterator ci = changed_instances.begin(); ci != changed_instances.end(); ++ci)
287  {
288  const CBioseq_Handle bsh = ci->first;
289  CRef<CSeq_inst> new_inst = ci->second;
290 
291  cmd->AddCommand( *CRef<CCmdChangeBioseqInst>(new CCmdChangeBioseqInst(bsh, *new_inst)) );
292  }
293  return cmd;
294 }
295 
297 {
299  CConstRef<CSeq_feat> orig_mrna;
300  CSeqFeatData::ESubtype subtype = feat->GetData().GetSubtype();
301  CScope &scope = fh.GetScope();
302  string prot_product;
303 
304  if (subtype == CSeqFeatData::eSubtype_prot)
305  {
306  FOR_EACH_NAME_ON_PROTREF(name_it, feat->GetData().GetProt())
307  {
308  prot_product = *name_it;
309  if (!prot_product.empty())
310  break;
311  }
312 
313  // for proteins: find first the CDS and then find the original overlapping mRNA
314  CBioseq_Handle prot_bsh = scope.GetBioseqHandle(fh.GetLocation());
315  const CSeq_feat* cds = sequence::GetCDSForProduct(prot_bsh);
316  if (cds)
317  {
318  orig_mrna.Reset(sequence::GetmRNAforCDS(*cds, scope));
319  }
320  }
321 
322  if (orig_mrna)
323  {
324  CRef<CSeq_feat> new_mrna(new CSeq_feat());
325  new_mrna->Assign(*orig_mrna);
326  string remainder;
327  new_mrna->SetData().SetRna().SetRnaProductName(prot_product, remainder);
328  CSeq_feat_Handle mrna_fh = scope.GetSeq_featHandle(*orig_mrna);
329  cmd.Reset(new CCmdChangeSeq_feat(mrna_fh, *new_mrna));
330  }
331  return cmd;
332 }
333 
335 {
336  CScope &scope = fh.GetScope();
337  bool cds_change(false);
338  CRef<CSeq_feat> cds(new CSeq_feat);
339  cds->Assign(*feat);
340  return CRetranslateCDS::RetranslateCDSCommand(scope, *fh.GetOriginalSeq_feat(), *cds, cds_change, offset, create_general_only);
341 }
342 
344 {
345  m_TopSeqEntry = seh;
347  {
349  }
350 }
351 
353 {
354  return m_SeqSubmit;
355 }
356 
358 {
359  swap(m_ChangedFeatures, source->m_ChangedFeatures);
360  swap(m_CreatedFeatures, source->m_CreatedFeatures);
361  swap(m_ChangedDescriptors, source->m_ChangedDescriptors);
362  swap(m_ContextForDescriptors, source->m_ContextForDescriptors);
363  swap(m_CreatedDescriptors, source->m_CreatedDescriptors);
364  swap(m_DeletedDescriptors, source->m_DeletedDescriptors);
365  swap(m_ChangedInstances, source->m_ChangedInstances);
366  swap(m_ChangedSubmitBlock, source->m_ChangedSubmitBlock);
367  swap(m_ChangedValues, source->m_ChangedValues);
368 }
369 
371 {
372  m_existing_text = existing_text;
373 }
374 
376 {
377  m_constraint = constraint;
378 }
379 
381 {
383  {
384  string curr_val = GetValue();
385  if (AddValueToString(curr_val, value, m_existing_text))
386  {
387  SetValue(curr_val);
388  m_modified = true;
389  }
390  }
391  else
392  {
393  SetValue(value);
394  m_modified = true;
395  }
396 }
397 
398 const vector<string>& IEditingAction::GetValues()
399 {
402  return GetChangedValues();
403 }
404 
406 {
409  return !GetChangedValues().empty();
410 }
411 
413 {
414  if (IsSetValue())
415  {
416  string val = GetValue();
417  return m_constraint->Match(val);
418  }
419  return false;
420 }
421 
422 void IEditingAction::Apply(const string& value)
423 {
424  m_value = value;
426 }
427 
428 void IEditingAction::Edit(const string& find, const string& replace, macro::CMacroFunction_EditStringQual::ESearchLoc edit_loc, bool case_insensitive, bool is_regex)
429 {
430  m_find = find;
431  m_replace = replace;
432  m_edit_loc = edit_loc;
433  m_case_insensitive = case_insensitive;
434  m_is_regex = is_regex;
436 }
437 
439 {
441 }
442 
444 {
445  m_remove_options = options;
447 }
448 
449 void IEditingAction::ConvertFrom(ECapChange cap_change, bool leave_on_original, const string& strip_name, IEditingAction* destination)
450 {
451  m_cap_change = cap_change;
452  m_leave_on_original = leave_on_original;
453  m_strip_name = strip_name;
454  m_Other = destination;
456 }
457 
459 {
460  m_value = value;
461  m_Other = source;
462  if (SameObject() && m_Other->SameObject())
463  {
466  source->SwapContext(this);
467  }
468  else
469  {
472  source->IEditingAction::SwapContext(this);
473  }
474 }
475 
477 {
478  m_Other = destination;
480 }
481 
483 {
484  m_value = value;
485  m_Other = source;
486  if (SameObject() && m_Other->SameObject())
487  {
490  source->SwapContext(this);
491  }
492  else
493  {
496  source->IEditingAction::SwapContext(this);
497  }
498 }
499 
501 {
502  m_Other = destination;
504 }
505 
507 {
508  m_value = value;
509  m_Other = source;
510  if (SameObject() && m_Other->SameObject())
511  {
514  source->SwapContext(this);
515  }
516  else
517  {
520  source->IEditingAction::SwapContext(this);
521  }
522 }
523 
524 void IEditingAction::ParseFrom(edit::CParseTextOptions parse_options, IEditingAction* destination)
525 {
526  m_parse_options = parse_options;
527  m_Other = destination;
529 }
530 
532 {
533  m_value = value;
534  m_Other = source;
535  if (SameObject() && m_Other->SameObject())
536  {
539  source->SwapContext(this);
540  }
541  else
542  {
545  source->IEditingAction::SwapContext(this);
546  }
547 }
548 
550 {
552 }
553 
555 {
556  if (m_constraint->Match() || CheckValue())
557  {
559  }
560 }
561 
563 {
564  if (CheckValue())
565  {
566  string str = GetValue();
567  string old(str);
568  macro::CMacroFunction_EditStringQual::s_EditText(str, m_find, m_replace, m_edit_loc, !m_case_insensitive, m_is_regex);
569  if (str != old)
570  {
571  SetValue(str);
572  m_modified = true;
573  }
574  }
575 }
576 
578 {
579  if (CheckValue())
580  {
581  ResetValue();
582  m_modified = true;
583  }
584 }
585 
587 {
588  if (CheckValue())
589  {
590  string str = GetValue();
591  bool modified = m_remove_options->EditText(str);
592  if (modified)
593  {
594  SetValue(str);
595  m_modified = true;
596  }
597  }
598 }
599 
601 {
602  if (CheckValue())
603  {
604  string val = GetValue();
607 
609  m_Other->ConvertTo(val, this);
610  bool other_modified = m_Other->IsModified();
611  if (!m_leave_on_original && other_modified)
612  {
613  ResetValue();
614  m_modified = true;
615  }
616  }
617 }
618 
620 {
621  if (CheckValue())
622  {
623  string current = GetValue();
624  m_ChangedValues.push_back(current);
625  }
627 }
628 
630 {
631  if (CheckValue())
632  {
633  string val = GetValue();
635  m_Other->CopyTo(val, this);
636  }
637 }
638 
640 {
641  if (CheckValue())
642  {
643  string current = GetValue();
644  m_ChangedValues.push_back(current);
645  }
647 }
648 
650 {
651  if (CheckValue())
652  {
653  string val = GetValue();
655  m_value.clear();
656  m_Other->SwapTo(val, this);
657  bool other_modified = m_Other->IsModified();
658  if (other_modified)
659  {
660  SetValue(m_value);
661  m_modified = true;
662  }
663  }
664 }
665 
667 {
668  if (IsSetValue())
669  {
670  string current = GetValue();
671  SetValue(m_value);
672  m_Other->m_value = current;
673  m_modified = true;
674  }
675 }
676 
678 {
679  if (CheckValue())
680  {
681  string val = GetValue();
682  string val2 = m_parse_options.GetSelectedText(val);
683 
684  if (NStr::IsBlank(val2))
685  {
686  return;
687  }
688 
690  m_Other->ParseTo(val2, this);
691  bool other_modified = m_Other->IsModified();
692  if (m_parse_options.ShouldRemoveFromParsed() && other_modified)
693  {
694  m_parse_options.RemoveSelectedText(val);
695  if (NStr::IsBlank(val))
696  {
697  ResetValue();
698  m_modified = true;
699  }
700  else
701  {
702  SetValue(val);
703  m_modified = true;
704  }
705  }
706  }
707 }
708 
710 {
711  if (CheckValue())
712  {
713  string current = GetValue();
714  m_ChangedValues.push_back(current);
715  }
717 }
718 
720 {
721  if (CheckValue())
722  {
723  string current = GetValue();
724  m_ChangedValues.push_back(current);
725  m_modified = true;
726  }
727 }
728 
730 {
731  m_modified = false;
732  switch (action)
733  {
734  case eActionType_Apply: DoApply(); break;
735  case eActionType_Edit: DoEdit(); break;
736  case eActionType_Remove: DoRemove(); break;
738  case eActionType_ConvertFrom: DoConvertFrom(); break;
739  case eActionType_ConvertTo: DoConvertTo(); break;
740  case eActionType_CopyFrom: DoCopyFrom(); break;
741  case eActionType_CopyTo: DoCopyTo(); break;
742  case eActionType_SwapFrom: DoSwapFrom(); break;
743  case eActionType_SwapTo: DoSwapTo(); break;
744  case eActionType_ParseFrom: DoParseFrom(); break;
745  case eActionType_ParseTo: DoParseTo(); break;
746  case eActionType_NOOP: DoNOOP(); break;
747  default: break;
748  }
749 }
750 
752 {
753  return action == eActionType_NOOP;
754 }
755 
757 {
758  return action == eActionType_ConvertFrom || action == eActionType_CopyFrom || action == eActionType_SwapFrom || action == eActionType_ParseFrom;
759 }
760 
762 {
763  return action == eActionType_ConvertTo || action == eActionType_CopyTo || action == eActionType_SwapTo || action == eActionType_ParseTo;
764 }
765 
767 {
768  return m_existing_text == edit::eExistingText_add_qual && !IsFrom(action) && !IsNOOP(action);
769 }
770 
771 int IEditingAction::CheckForExistingText(CIRef<IEditingAction> action2, EActionType action_type, edit::CParseTextOptions parse_options)
772 {
774 
775  switch (action_type)
776  {
777  case eActionType_Apply :
778  {
779  NOOP();
780  }
781  break;
782  case eActionType_Edit :
783  {
784  // nothing here
785  }
786  break;
787  case eActionType_Remove :
788  {
789  // nothing here
790  }
791  break;
793  {
794  // nothing here
795  }
796  break;
798  {
799  ConvertFrom(eCapChange_none, true, kEmptyStr, action2);
800  }
801  break;
802  case eActionType_CopyFrom :
803  {
804  CopyFrom(action2);
805  }
806  break;
807  case eActionType_SwapFrom :
808  {
809  // nothing here
810  }
811  break;
812  case eActionType_ParseFrom :
813  {
814  parse_options.SetShouldRemove(false);
815  ParseFrom(parse_options, action2);
816  }
817  break;
818  default : break;
819  }
820  int num = static_cast<int>(GetChangedValues().size());
824  ResetChangedIds();
826  if (action2)
827  {
828  action2->ResetChangedFeatures();
829  action2->ResetChangedDescriptors();
830  action2->ResetChangedInstances();
831  action2->ResetChangedIds();
832  action2->ResetChangedValues();
833  }
834  return num;
835 }
836 
837 
838 
840  const string &field,
841  CFieldNamePanel::EFieldType field_type,
842  int subtype,
843  const string& ncRNA_class,
845 {
846  if (subtype > 0 && subtype < CSeqFeatData::eSubtype_any && field_type == CFieldNamePanel::eFieldType_Feature)
847  {
848  return CIRef<IEditingAction>(CreateActionFeat(seh, field,
849  static_cast<CSeqFeatData::ESubtype>(subtype),
851  ncRNA_class));
852  }
853  else if (field_type == CFieldNamePanel::eFieldType_RNA)
854  {
855  if (subtype == -1)
856  subtype = CSeqFeatData::eSubtype_any;
857  return CIRef<IEditingAction>(CreateActionRna(seh, field, static_cast<CSeqFeatData::ESubtype>(subtype), ncRNA_class));
858  }
859  else if (subtype > 0 && subtype < CSeqFeatData::eSubtype_any && field_type == CFieldNamePanel::eFieldType_CDSGeneProt)
860  {
861  return CIRef<IEditingAction>(CreateActionCdsGeneProt(seh, field, static_cast<CSeqFeatData::ESubtype>(subtype)));
862  }
864  || field_type == CFieldNamePanel::eFieldType_Dbxref)
865  {
866  return CIRef<IEditingAction>(CreateActionBiosource(seh, field));
867  }
871  {
872  return CIRef<IEditingAction>(CreateActionDesc(seh, field, submit));
873  }
875  {
876  return CIRef<IEditingAction>(CreateActionSeqid(seh, field));
877  }
878  else if (field_type == CFieldNamePanel::eFieldType_FlatFile)
879  {
880  return CIRef<IEditingAction>(CreateActionMisc(seh, field));
881  }
882  return CIRef<IEditingAction>(NULL);
883 }
884 
885 
886 int GetSubtype(CFieldNamePanel *field_name_panel, string& ncRNA_class)
887 {
888  if (!field_name_panel)
889  return -1;
890 
891  CFeatureFieldNamePanel *feat_panel = dynamic_cast<CFeatureFieldNamePanel*>(field_name_panel);
892  if (feat_panel)
893  {
894  string field_name = feat_panel->GetFeatureType();
895  if (field_name.empty())
896  return -1;
898  return CorrectForncRNASubtypes(subtype, ncRNA_class);
899  }
900 
901  CCDSGeneProtFieldNamePanel *cds_gene_prot = dynamic_cast<CCDSGeneProtFieldNamePanel*>(field_name_panel);
902  if (cds_gene_prot)
903  {
904  string field = cds_gene_prot->GetFieldName();
905  if (field == "protein name" || field == "protein description" || field == "protein EC number"
906  || field == "protein activity" || field == "protein comment")
907  {
909  }
910  else if (field == "CDS comment" || field == "CDS inference" || field == "codon-start")
911  {
913  }
914  else if ( field == "gene description" || field == "gene comment"
915  || field == "gene inference" || field == "gene allele" || field == "gene maploc"
916  || field == "gene locus tag" || field == "gene synonym" || field == "gene old_locus_tag"
917  || field == "gene locus")
918  {
920  }
921  else if (field == "mRNA product" || field == "mRNA comment")
922  {
924  }
925  else if (field == "mat_peptide name" || field == "mat_peptide description" || field == "mat_peptide EC number"
926  || field == "mat_peptide activity" || field == "mat_peptide comment")
927  {
929  }
930  }
931 
932  CRNAFieldNamePanel *rna_panel = dynamic_cast<CRNAFieldNamePanel*>(field_name_panel);
933  CDualRNAFieldNamePanel *dual_rna_panel = dynamic_cast<CDualRNAFieldNamePanel*>(field_name_panel);
934  string rna_type;
935  string ncrna_class;
936  if (rna_panel)
937  {
938  rna_type = rna_panel->GetRnaTypeOnly();
939  ncrna_class = rna_panel->GetNcrnaType();
940  }
941  if (dual_rna_panel)
942  {
943  rna_type = dual_rna_panel->GetRnaTypeOnly();
944  ncrna_class = dual_rna_panel->GetNcrnaType();
945  }
946 
947  if (!rna_type.empty())
948  {
949  if (rna_type == "preRNA")
951  else if (rna_type =="mRNA")
953  else if (rna_type == "tRNA")
955  else if (rna_type == "rRNA")
957  else if (rna_type == "ncRNA") {
958  ncRNA_class = ncrna_class;
960  }
961  else if (rna_type == "tmRNA")
963  else if (rna_type == "miscRNA")
965  }
966 
967  // for all other panels:
968  return -1;
969 }
970 
971 int CorrectForncRNASubtypes(CSeqFeatData::ESubtype subtype, string& ncRNA_class)
972 {
973  if (subtype == CSeqFeatData::eSubtype_ncRNA) {
974  ncRNA_class = "any";
975  }
976  else if (subtype == CSeqFeatData::eSubtype_snRNA) {
978  ncRNA_class = "snRNA";
979  }
980  else if (subtype == CSeqFeatData::eSubtype_scRNA) {
982  ncRNA_class = "scRNA";
983  }
984  else if (subtype == CSeqFeatData::eSubtype_snoRNA) {
986  ncRNA_class = "snoRNA";
987  }
988  return subtype;
989 }
990 
992 {
993  const CSeqdesc * old_desc = dynamic_cast<const CSeqdesc *>(object.GetPointer());
994  const CSeq_feat* old_feat = dynamic_cast<const CSeq_feat * >(object.GetPointer());
995  CRef<CObject> new_obj(NULL);
996 
997  if (old_desc) {
998  // prepare replacement descriptor
999  CRef<CSeqdesc> new_desc(new CSeqdesc());
1000  new_desc->Assign(*old_desc);
1001  new_obj = (CObject *)new_desc;
1002  } else if (old_feat) {
1003  // prepare replacement feature
1004  CRef<CSeq_feat> new_feat(new CSeq_feat());
1005  new_feat->Assign(*old_feat);
1006  new_obj = (CObject *)new_feat;
1007  }
1008  return new_obj;
1009 }
1010 
1011 
1013 {
1014  CRef<CCmdComposite> cmd(new CCmdComposite("Convert Value"));
1015  bool success = false;
1016 
1017  const CSeqdesc * old_desc = dynamic_cast<const CSeqdesc *>(oldobj.GetPointer());
1018  const CSeq_feat* old_feat = dynamic_cast<const CSeq_feat * >(oldobj.GetPointer());
1019 
1020  if (old_desc) {
1021  CSeq_entry_Handle seh = edit::GetSeqEntryForSeqdesc(Ref(&scope), *old_desc);
1022  const CSeqdesc* new_desc = dynamic_cast<const CSeqdesc*>(newobj.GetPointer());
1023  if (seh && new_desc) {
1024  CRef<CCmdChangeSeqdesc> ecmd(new CCmdChangeSeqdesc(seh, *old_desc, *new_desc));
1025  cmd->AddCommand(*ecmd);
1026  success = true;
1027  }
1028  } else if (old_feat) {
1029  CSeq_feat* new_feat = dynamic_cast<CSeq_feat * >(newobj.GetPointer());
1030  cmd->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(scope.GetSeq_featHandle(*old_feat), *new_feat)));
1031  success = true;
1032  }
1033 
1034  if (!success) {
1035  cmd.Reset(NULL);
1036  }
1037  return cmd;
1038 }
1039 
1040 
1041 vector<CConstRef<CObject>> GetObjects(CSeq_entry_Handle seh,
1042  const string &field,
1043  CFieldNamePanel::EFieldType field_type,
1044  int subtype,
1045  const string& ncRNA_class,
1046  CConstRef<CSeq_submit> submit,
1047  CRef<CEditingActionConstraint> constraint, vector<CSeq_entry_Handle>* descr_context)
1048 {
1049  CIRef<IEditingAction> action = CreateAction(seh, field, field_type, subtype, ncRNA_class, submit);
1050  action->SetConstraint(constraint);
1051  action->NOOP();
1052 
1053  const map<CSeq_feat_Handle, CRef<CSeq_feat>>& feathdlesmap = action->GetChangedFeatures();
1054  const map<const CSeqdesc*, CRef<CSeqdesc>>& descrmap = action->GetChangedDescriptors();
1055  const map<CBioseq_Handle, CRef<CSeq_inst>>& instmap = action->GetChangedInstances();
1056  CRef<CSubmit_block> submit_block = action->GetChangedSubmitBlock();
1057  vector<CConstRef<CObject> > objs;
1058  for (auto &fh : feathdlesmap)
1059  {
1060  objs.emplace_back(fh.first.GetSeq_feat());
1061  }
1062  for (auto &dh : descrmap)
1063  {
1064  objs.emplace_back(CConstRef<CObject>(dh.first));
1065  }
1066  for (auto &bh : instmap)
1067  {
1068  objs.emplace_back(CConstRef<CObject>(&bh.first.GetInst()));
1069  }
1070  if (submit_block)
1071  {
1072  objs.emplace_back(CConstRef<CObject>(&submit->GetSub()));
1073  }
1074 
1075  if (!descrmap.empty() && descr_context) {
1076  const map<const CSeqdesc*, CSeq_entry_Handle>& contextmap = action->GetContextForDescriptors();
1077  descr_context->clear();
1078  for (auto& it : contextmap) {
1079  descr_context->emplace_back(it.second);
1080  }
1081  }
1082  return objs;
1083 }
1084 
1086 
CSeq_entry_Handle GetSeqEntryForSeqdesc(CRef< CScope > scope, const CSeqdesc &seq_desc)
bool IsGeneralIdProtPresent(objects::CSeq_entry_Handle tse)
CBioseq_Handle –.
virtual string GetFieldName(const bool subfield=false)
Returns the name of the field as selected in the panel.
void Add(CObject *obj, const CObject *new_obj)
virtual bool Match(const string &value)
CObject –.
Definition: ncbiobj.hpp:180
CRef –.
Definition: ncbiobj.hpp:618
static CRef< CCmdComposite > RetranslateCDSCommand(CScope &scope, const CSeq_feat &old_cds, CSeq_feat &cds, bool &cds_change, int &offset, bool create_general_only)
CScope –.
Definition: scope.hpp:92
ESubtype GetSubtype(void) const
static E_Choice GetTypeFromSubtype(ESubtype subtype)
static ESubtype SubtypeNameToValue(CTempString sName)
Turn a string into its ESubtype which is NOT necessarily related to the identifier of the enum.
CSeq_entry_Handle –.
CSeq_feat_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
CSubmit_block –.
void SetExistingText(edit::EExistingText existing_text)
const string GetName(void) const
void SetTopSeqEntry(CSeq_entry_Handle seh)
virtual void FindRelated(EActionType action)=0
virtual void SetValue(const string &value)=0
edit::EExistingText m_existing_text
map< const CSeqdesc *, CSeq_entry_Handle > m_ContextForDescriptors
CRef< CSubmit_block > GetChangedSubmitBlock(void)
void ResetChangedFeatures(void)
virtual void Find(EActionType action)=0
void ConvertFrom(ECapChange cap_change, bool leave_on_original, const string &strip_name, IEditingAction *destination)
void Apply(const string &value)
virtual void Modify(EActionType action)=0
map< const CSeqdesc *, CSeq_entry_Handle > m_CreatedDescriptors
void SetConstraint(CRef< CEditingActionConstraint > constraint)
const vector< string > & GetChangedValues(void)
const map< const CSeqdesc *, CSeq_entry_Handle > & GetDeletedDescriptors(void)
CSeq_entry_Handle m_TopSeqEntry
void ResetChangedDescriptors(void)
CConstRef< objects::CSeq_submit > m_SeqSubmit
const map< CSeq_feat_Handle, CRef< CSeq_feat > > & GetChangedFeatures(void)
const map< CBioseq_Handle, CRef< CSeq_inst > > & GetChangedInstances(void)
void ConvertTo(const string &value, IEditingAction *source)
void ResetChangedIds(void)
map< const CSeqdesc *, CRef< CSeqdesc > > m_ChangedDescriptors
bool GetChangedIds(void)
IEditingAction(CSeq_entry_Handle seh, const string &name, CConstRef< objects::CSeq_submit > submit=CConstRef< objects::CSeq_submit >(NULL))
macro::CMacroFunction_EditStringQual::ESearchLoc m_edit_loc
map< CSeq_feat_Handle, CRef< CSeq_feat > > m_ChangedFeatures
CRef< CCmdComposite > GetActionCommand(void)
IEditingAction * m_Other
CRef< CCmdComposite > GetRetranslateCdsCmd(const CSeq_feat_Handle fh, const CRef< CSeq_feat > feat, int &offset, bool create_general_only)
void DoParseFrom(void)
void DoRemoveOutside(void)
void RemoveOutside(CRef< macro::CRemoveTextOptions > options)
CRef< CSubmit_block > m_ChangedSubmitBlock
virtual bool SameObject()=0
const map< const CSeqdesc *, CSeq_entry_Handle > & GetContextForDescriptors(void)
bool IsTo(EActionType action)
int CheckForExistingText(CIRef< IEditingAction > action2, EActionType action_type, edit::CParseTextOptions parse_options=edit::CParseTextOptions())
void CopyTo(const string &value, IEditingAction *source)
CIRef< IEditCommand > GetUpdateMRNAProductNameCmd(const CSeq_feat_Handle fh, const CRef< CSeq_feat > feat)
CSeq_entry_Handle m_CurrentSeqEntry
void SwapFrom(IEditingAction *destination)
CConstRef< objects::CSeq_submit > GetSeqSubmit(void)
void CopyFrom(IEditingAction *destination)
void Action(EActionType action)
vector< string > m_ChangedValues
const map< const CSeqdesc *, CRef< CSeqdesc > > & GetChangedDescriptors(void)
void SwapTo(const string &value, IEditingAction *source)
ECapChange m_cap_change
void ParseFrom(edit::CParseTextOptions parse_options, IEditingAction *destination)
CRef< macro::CRemoveTextOptions > m_remove_options
map< CSeq_feat_Handle, CSeq_entry_Handle > m_CreatedFeatures
void ResetChangedInstances(void)
const vector< string > & GetValues(void)
void DoConvertFrom(void)
edit::CParseTextOptions m_parse_options
virtual void SwapContext(IEditingAction *source)
bool IsFrom(EActionType action)
virtual bool IsSetValue(void)=0
const map< CSeq_feat_Handle, CSeq_entry_Handle > & GetCreatedFeatures(void)
virtual void ResetValue(void)=0
bool CheckValue(void)
void DoParseTo(void)
void DoConvertTo(void)
CRef< CEditingActionConstraint > m_constraint
void ResetChangedValues(void)
bool IsCreateNew(EActionType action)
const map< const CSeqdesc *, CSeq_entry_Handle > & GetCreatedDescriptors(void)
virtual void ResetScope()
map< const CSeqdesc *, CSeq_entry_Handle > m_DeletedDescriptors
void Edit(const string &find, const string &replace, macro::CMacroFunction_EditStringQual::ESearchLoc edit_loc, bool case_insensitive, bool is_regex)
void DoCopyFrom(void)
void ParseTo(const string &value, IEditingAction *source)
bool CheckValues(void)
virtual string GetValue(void)=0
void DoSwapFrom(void)
bool IsNOOP(EActionType action)
void HandleValue(const string &value)
map< CBioseq_Handle, CRef< CSeq_inst > > m_ChangedInstances
const_iterator begin() const
Definition: map.hpp:151
const_iterator end() const
Definition: map.hpp:152
bool empty() const
Definition: map.hpp:149
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: map.hpp:338
@ eCapChange_none
CChangeUnindexedObjectCommand< objects::CSubmit_block > CChangeSubmitBlockCommand
static auto & RemoveFieldNameFromString
static auto & FixCapitalizationInString
IEditingActionBiosource * CreateActionBiosource(CSeq_entry_Handle seh, string field)
IEditingActionDesc * CreateActionDesc(CSeq_entry_Handle seh, const string &field, CConstRef< objects::CSeq_submit > submit=CConstRef< objects::CSeq_submit >(NULL))
IEditingActionFeat * CreateActionCdsGeneProt(CSeq_entry_Handle seh, string field, const CSeqFeatData::ESubtype subtype, const string &ncRNA_class=kEmptyStr)
IEditingActionFeat * CreateActionFeat(CSeq_entry_Handle seh, string field, const CSeqFeatData::ESubtype subtype, const CSeqFeatData::E_Choice feat_type, const string &ncRNA_class)
IEditingActionFeat * CreateActionRna(CSeq_entry_Handle seh, string field, const CSeqFeatData::ESubtype subtype, const string &ncRNA_class)
IEditingAction * CreateActionMisc(CSeq_entry_Handle seh, const string &field)
CEditingActionSeqid * CreateActionSeqid(CSeq_entry_Handle seh, const string &field)
USING_SCOPE(objects)
int CorrectForncRNASubtypes(CSeqFeatData::ESubtype subtype, string &ncRNA_class)
int GetSubtype(CFieldNamePanel *field_name_panel, string &ncRNA_class)
CRef< CCmdComposite > GetReplacementCommand(CConstRef< CObject > oldobj, CRef< CObject > newobj, CScope &scope, const string &cmd_name)
vector< CConstRef< CObject > > GetObjects(CSeq_entry_Handle seh, const string &field, CFieldNamePanel::EFieldType field_type, int subtype, const string &ncRNA_class, CConstRef< CSeq_submit > submit, CRef< CEditingActionConstraint > constraint, vector< CSeq_entry_Handle > *descr_context)
CRef< CObject > GetNewObject(CConstRef< CObject > object)
CIRef< IEditingAction > CreateAction(CSeq_entry_Handle seh, const string &field, CFieldNamePanel::EFieldType field_type, int subtype, const string &ncRNA_class, CConstRef< objects::CSeq_submit > submit)
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void cleanup(void)
Definition: ct_dynamic.c:30
#define false
Definition: bool.h:36
static const char * str(char *buf, int n)
Definition: stats.c:84
int offset
Definition: replacements.h:160
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
Definition: ncbimisc.hpp:1508
#define NULL
Definition: ncbistd.hpp:225
void CleanupForTaxnameChange(CObjectInfo oi)
Definition: macro_util.cpp:526
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
const CSeq_feat * GetCDSForProduct(const CBioseq &product, CScope *scope)
Get the encoding CDS feature of a given protein sequence.
Definition: sequence.cpp:2549
CConstRef< CSeq_feat > GetmRNAforCDS(const CSeq_feat &cds, CScope &scope)
GetmRNAforCDS A function to find a CSeq_feat representing the appropriate mRNA for a given CDS.
Definition: sequence.cpp:1261
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
CSeq_feat_Handle GetSeq_featHandle(const CSeq_feat &feat, EMissing action=eMissing_Default)
Definition: scope.cpp:200
TClass GetClass(void) const
TSet GetSet(void) const
virtual const CSeq_loc & GetLocation(void) const
CSeq_entry_Handle GetTopLevelEntry(void) const
Get top level Seq-entry handle.
bool IsSetClass(void) const
CScope & GetScope(void) const
Get scope this handle belongs to.
CConstRef< CSeq_feat > GetOriginalSeq_feat(void) const
bool IsSet(void) const
bool HasParentEntry(void) const
Check if current seq-entry has a parent.
CSeq_entry_Handle GetParentEntry(void) const
Get parent Seq-entry handle.
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
CRef< C > Ref(C *object)
Helper functions to get CRef<> and CConstRef<> objects.
Definition: ncbiobj.hpp:2015
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define numeric_limits
Pre-declaration of the "numeric_limits<>" template Forcibly overrides (using preprocessor) the origin...
Definition: ncbi_limits.hpp:92
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define kEmptyStr
Definition: ncbistr.hpp:123
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
static SIZE_TYPE Find(const CTempString str, const CTempString pattern, ECase use_case=eCase, EDirection direction=eForwardSearch, SIZE_TYPE occurrence=0)
Find the pattern in the string.
Definition: ncbistr.cpp:2891
static bool Equal(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Test for equality of a substring with another string.
Definition: ncbistr.hpp:5384
bool IsSetOrg(void) const
Check if a value has been assigned to Org data member.
Definition: BioSource_.hpp:497
const TOrg & GetOrg(void) const
Get the Org member data.
Definition: BioSource_.hpp:509
const TTaxname & GetTaxname(void) const
Get the Taxname member data.
Definition: Org_ref_.hpp:372
bool IsSetTaxname(void) const
preferred formal name Check if a value has been assigned to Taxname data member.
Definition: Org_ref_.hpp:360
bool IsSetData(void) const
the specific data Check if a value has been assigned to Data data member.
Definition: Seq_feat_.hpp:913
bool IsCdregion(void) const
Check if variant Cdregion is selected.
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
const TExcept_text & GetExcept_text(void) const
Get the Except_text member data.
Definition: Seq_feat_.hpp:1405
bool IsSetExcept_text(void) const
explain if except=TRUE Check if a value has been assigned to Except_text data member.
Definition: Seq_feat_.hpp:1393
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_feat_.cpp:94
const TProt & GetProt(void) const
Get the variant data.
@ eClass_nuc_prot
nuc acid and coded proteins
Definition: Bioseq_set_.hpp:99
const TSource & GetSource(void) const
Get the variant data.
Definition: Seqdesc_.cpp:566
bool IsSource(void) const
Check if variant Source is selected.
Definition: Seqdesc_.hpp:1190
TSource & SetSource(void)
Select the variant.
Definition: Seqdesc_.cpp:572
const TSub & GetSub(void) const
Get the Sub member data.
Definition: fix_pub.hpp:45
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
const CharType(& source)[N]
Definition: pointer.h:1149
T max(T x_, T y_)
The Object manager core.
Utility macros and typedefs for exploring NCBI objects from seqfeat.asn.
#define FOR_EACH_NAME_ON_PROTREF(Itr, Var)
FOR_EACH_NAME_ON_PROTREF EDIT_EACH_NAME_ON_PROTREF.
EExistingText
@ eExistingText_add_qual
@ eExistingText_replace_old
bool AddValueToString(string &str, const string &value, EExistingText existing_text)
Add text to an existing string, using the "existing_text" directive to combine new text with existing...
Modified on Sun Apr 14 05:24:58 2024 by modify_doxy.py rev. 669887