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

Go to the SVN repository for this file.

1 /* $Id: merge_biosources.cpp 42255 2019-01-22 15:35:14Z 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: Igor Filippov
27  */
28 
29 
30 #include <ncbi_pch.hpp>
32 #include <objmgr/bioseq_handle.hpp>
33 #include <objmgr/bioseq_ci.hpp>
34 #include <objmgr/feat_ci.hpp>
35 #include <objmgr/seqdesc_ci.hpp>
42 
45 
47 {
48  if (!tse)
49  return CRef<CCmdComposite>(NULL);
50  bool modified = false;
51  CRef<CCmdComposite> composite( new CCmdComposite("Merge BioSources") );
52 
53  for (CBioseq_CI bit(tse); bit; ++bit)
54  {
55  CBioseq_Handle bsh = *bit;
56  vector<CSeqdesc_CI> descs;
57  vector<const CBioSource*> biosources;
58  vector<CSeq_feat_Handle> feats;
59  for (CSeqdesc_CI source_ci(bsh, CSeqdesc::e_Source); source_ci; ++source_ci)
60  {
61  const CBioSource* biosource = &source_ci->GetSource();
62  biosources.push_back(biosource);
63  descs.push_back(source_ci);
65  feats.push_back(fh);
66  }
67  for (CFeat_CI feat_ci(bsh, CSeqFeatData::e_Biosrc); feat_ci; ++feat_ci)
68  {
69  const CBioSource* biosource = &feat_ci->GetData().GetBiosrc();
70  biosources.push_back(biosource);
71  descs.push_back(CSeqdesc_CI());
72  feats.push_back(feat_ci->GetSeq_feat_Handle());
73  }
74  vector<CRef<CBioSource> > new_biosources(biosources.size(), CRef<CBioSource>(NULL));
75  for (size_t i = 0; i < biosources.size(); i++)
76  if (biosources[i] != NULL)
77  {
78  for (size_t j = i + 1; j < biosources.size(); j++)
79  if (biosources[j] != NULL)
80  {
81  if (CCleanup::AreBioSourcesMergeable(*biosources[i], *biosources[j]))
82  {
83  CRef<CBioSource> new_biosource(new CBioSource);
84  if (new_biosources[i])
85  new_biosource->Assign(*new_biosources[i]);
86  else
87  new_biosource->Assign(*biosources[i]);
88  CCleanup::MergeDupBioSources(*new_biosource, *biosources[j]);
89  CRef<CSeq_feat> new_feat(new CSeq_feat);
90  new_feat->SetData().SetBiosrc(*new_biosource);
91  new_biosources[i] = CCleanup::BioSrcFromFeat(*new_feat);
92  if (descs[j])
93  {
94  CSeq_entry_Handle seh = descs[j].GetSeq_entry_Handle();
95  CIRef<IEditCommand> cmdDelDesc(new CCmdDelDesc(seh, *descs[j]));
96  composite->AddCommand(*cmdDelDesc);
97  descs[j] = CSeqdesc_CI();
98  biosources[j] = NULL;
99  }
100  else if (feats[j])
101  {
102  composite->AddCommand(*CRef<CCmdDelSeq_feat>(new CCmdDelSeq_feat(feats[j])));
103  feats[j].Reset();
104  biosources[j] = NULL;
105  }
106  }
107  }
108  }
109 
110  for (size_t i = 0; i < new_biosources.size(); i++)
111  if (new_biosources[i])
112  {
113  modified = true;
114  if (descs[i])
115  {
116  CRef<CSeqdesc> new_desc(new CSeqdesc);
117  new_desc->SetSource(*new_biosources[i]);
118  CRef<CCmdChangeSeqdesc> cmd(new CCmdChangeSeqdesc(descs[i].GetSeq_entry_Handle(), *descs[i], *new_desc));
119  composite->AddCommand(*cmd);
120  }
121  else if (feats[i])
122  {
123  CRef<CSeq_feat> new_feat(new CSeq_feat);
124  new_feat->Assign(*feats[i].GetOriginalSeq_feat());
125  new_feat->SetData().SetBiosrc(*new_biosources[i]);
126  composite->AddCommand(*CRef<CCmdChangeSeq_feat>(new CCmdChangeSeq_feat(feats[i], *new_feat)));
127  }
128  }
129  }
130  if (!modified)
131  composite.Reset();
132  return composite;
133 }
134 
135 
136 
static CSeq_entry_Handle GetSeq_entry_Handle(TTypeInfo type, TConstObjectPtr ptr, CScope &scope)
CBioseq_CI –.
Definition: bioseq_ci.hpp:69
CBioseq_Handle –.
static CRef< CBioSource > BioSrcFromFeat(const CSeq_feat &f)
Get BioSource from feature to use for source descriptor.
Definition: cleanup.cpp:3824
static bool MergeDupBioSources(CSeq_descr &descr)
Definition: cleanup.cpp:3765
static bool AreBioSourcesMergeable(const CBioSource &src1, const CBioSource &src2)
Definition: cleanup.cpp:3536
void AddCommand(IEditCommand &command)
CFeat_CI –.
Definition: feat_ci.hpp:64
static CRef< CCmdComposite > apply(objects::CSeq_entry_Handle tse)
CSeq_entry_Handle –.
CSeq_feat_Handle –.
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define NULL
Definition: ncbistd.hpp:225
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_feat_.cpp:94
TSource & SetSource(void)
Select the variant.
Definition: Seqdesc_.cpp:572
@ e_Source
source of materials, includes Org-ref
Definition: Seqdesc_.hpp:133
int i
USING_SCOPE(ncbi::objects)
Modified on Wed Sep 04 14:59:51 2024 by modify_doxy.py rev. 669887