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

Go to the SVN repository for this file.

1 /* $Id: cmd_feat_id_xrefs_from_qualifiers.cpp 41199 2018-06-11 17:59:58Z 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: Andrea Asztalos
27  */
28 
29 
30 #include <ncbi_pch.hpp>
31 
32 #include <objmgr/util/sequence.hpp>
33 
36 
39 
41 
43 
46 
47 static const char* kLabel = "Link CDS-mRNA pair by qualifier";
48 
49 CIRef<IEditCommand> CCmdFeatIdXrefsFromQualifiers::Create(const objects::CSeq_entry_Handle& seh, const vector<string>& quals)
50 {
52  cmd->AddCommand(*CIRef<IEditCommand>(new CCmdAssignFeatLocalIds(seh)));
53  cmd->AddCommand(*CIRef<IEditCommand>(new CCmdFeatIdXrefsFromQualifiers(seh, quals)));
54  return CIRef<IEditCommand>(cmd);
55 }
56 
58 {
59  return kLabel;
60 }
61 
62 static bool s_IsDirectXrefBetween(const CSeq_feat& from_feat, const CSeq_feat& to_feat)
63 {
64  if (!from_feat.IsSetXref() || !to_feat.IsSetId()) {
65  return false;
66  }
67 
68  const CFeat_id& feat_id = to_feat.GetId();
69  FOR_EACH_SEQFEATXREF_ON_SEQFEAT(it, from_feat) {
70  if ((*it)->IsSetId()
71  && (*it)->GetId().IsLocal()
72  && feat_id.Equals((*it)->GetId()))
73  return true;
74  }
75 
76  return false;
77 }
78 
79 static void s_CreateXRefLink(CSeq_feat& from_feat, const CSeq_feat& to_feat)
80 {
82  xref->SetId().Assign(to_feat.GetId());
83  from_feat.SetXref().push_back(xref);
84 }
85 
87 {
88  if (!composite)
89  composite.Reset(new CCmdComposite(kLabel));
90  composite->AddCommand(command);
91 }
92 
94 {
95  CScope& scope = m_seh.GetScope();
96  string error_msg;
98 
99  for (CFeat_CI feat_it(m_seh, SAnnotSelector(CSeqFeatData::eSubtype_mRNA)); feat_it; ++feat_it) {
100  CConstRef<CSeq_feat> mrna = feat_it->GetOriginalSeq_feat();
101  FOR_EACH_GBQUAL_ON_FEATURE(qual_it, *mrna) {
102  const CGb_qual& qual = **qual_it;
103  if (find(m_Quals.begin(), m_Quals.end(), qual.GetQual()) != m_Quals.end() && qual.IsSetVal()) {
104  CRef<CSeq_id> seq_id(new CSeq_id);
105  try {
106  seq_id->Set(qual.GetVal(), CSeq_id::fParse_Default);
107  }
108  catch (const CException&) {
109  if (!error_msg.empty()) {
110  error_msg += "\n";
111  }
112  error_msg += "'" + qual.GetVal() + "' is not a valid seq ID";
113  continue;
114  }
115 
116  CBioseq_Handle proth = scope.GetBioseqHandle(*seq_id);
117  if (!proth || !proth.IsAa()) {
118  if (!error_msg.empty()) {
119  error_msg += "\n";
120  }
121  error_msg += "Sequence with '" + qual.GetVal() + "' seq ID is not a protein";
122  continue;
123  }
124  const CSeq_feat* cds = sequence::GetCDSForProduct(proth);
125  if (cds) {
126  CRef<CSeq_feat> new_mrna(new CSeq_feat);
127  new_mrna->Assign(*mrna);
128 
129  // update the mRNA product name if it's empty
130  string mrna_product = new_mrna->GetData().GetRna().GetRnaProductName();
131  if (mrna_product.empty()) {
132  string protein_name;
134  if (prot_it) {
135  CConstRef<CSeq_feat> prot_feat = prot_it->GetOriginalSeq_feat();
136  const CProt_ref& prot_ref = prot_feat->GetData().GetProt();
137  if (prot_ref.IsSetName() && !prot_ref.GetName().empty()) {
138  protein_name = prot_ref.GetName().front();
139  }
140  }
141 
142  if (!protein_name.empty()) {
143  // command to change the mrna
144  string remainder;
145  new_mrna->SetData().SetRna().SetRnaProductName(protein_name, remainder);
146  }
147  }
148 
149 
150  if (!s_IsDirectXrefBetween(*mrna, *cds)) {
151  s_CreateXRefLink(*new_mrna, *cds);
152  CIRef<IEditCommand> chg_mrna(new CCmdChangeSeq_feat(scope.GetSeq_featHandle(*mrna), *new_mrna));
153  s_AddCommand(cmd, *chg_mrna);
154  }
155 
156  if (!s_IsDirectXrefBetween(*cds, *mrna)) {
157  CRef<CSeq_feat> new_cds(new CSeq_feat);
158  new_cds->Assign(*cds);
159  s_CreateXRefLink(*new_cds, *mrna);
160  CIRef<IEditCommand> chg_cds(new CCmdChangeSeq_feat(scope.GetSeq_featHandle(*cds), *new_cds));
161  s_AddCommand(cmd, *chg_cds);
162  }
163 
164 
165  }
166  }
167  }
168  }
169 
170  if (!error_msg.empty()) {
171  NcbiMessageBox(error_msg);
172  return CIRef<IEditCommand>();
173  }
174 
175  return CIRef<IEditCommand>(cmd);
176 }
177 
CBioseq_Handle –.
void AddCommand(IEditCommand &command)
static CIRef< IEditCommand > Create(const objects::CSeq_entry_Handle &seh, const vector< string > &quals)
virtual CIRef< IEditCommand > x_CreateActionCmd()
CCmdFeatIdXrefsFromQualifiers(const objects::CSeq_entry_Handle &seh, const vector< string > &quals)
CFeat_CI –.
Definition: feat_ci.hpp:64
CFeat_id –.
Definition: Feat_id.hpp:66
@Gb_qual.hpp User-defined methods of the data storage class.
Definition: Gb_qual.hpp:61
string GetRnaProductName(void) const
Definition: RNA_ref.cpp:145
CScope –.
Definition: scope.hpp:92
CSeqFeatXref –.
Definition: SeqFeatXref.hpp:66
namespace ncbi::objects::
Definition: Seq_feat.hpp:58
Interface (functor) for object editing.
USING_SCOPE(objects)
static const char * kLabel
static void s_AddCommand(CRef< CCmdComposite > &composite, IEditCommand &command)
static bool s_IsDirectXrefBetween(const CSeq_feat &from_feat, const CSeq_feat &to_feat)
static void s_CreateXRefLink(CSeq_feat &from_feat, const CSeq_feat &to_feat)
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
EDialogReturnValue NcbiMessageBox(const string &message, TDialogType type=eDialog_Ok, EDialogIcon icon=eIcon_Exclamation, const string &title="Error", EDialogTextMode text_mode=eRaw)
Definition: message_box.cpp:48
virtual void Assign(const CSerialObject &source, ESerialRecursionMode how=eRecursive)
Set object to copy of another one.
virtual bool Equals(const CSerialObject &object, ESerialRecursionMode how=eRecursive) const
Check if both objects contain the same values.
CSeq_id & Set(const CTempString &the_id, TParseFlags flags=fParse_AnyRaw)
Reassign based on flat specifications; arguments interpreted as with constructors.
Definition: Seq_id.cpp:2456
@ fParse_Default
By default in ParseIDs and IsValid, allow raw parsable non-numeric accessions and plausible local acc...
Definition: Seq_id.hpp:102
const CSeq_feat * GetCDSForProduct(const CBioseq &product, CScope *scope)
Get the encoding CDS feature of a given protein sequence.
Definition: sequence.cpp:2549
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
bool IsAa(void) const
CConstRef< CSeq_feat > GetOriginalSeq_feat(void) const
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
const TName & GetName(void) const
Get the Name member data.
Definition: Prot_ref_.hpp:378
bool IsSetName(void) const
protein name Check if a value has been assigned to Name data member.
Definition: Prot_ref_.hpp:366
const TVal & GetVal(void) const
Get the Val member data.
Definition: Gb_qual_.hpp:259
TXref & SetXref(void)
Assign a value to Xref data member.
Definition: Seq_feat_.hpp:1314
const TId & GetId(void) const
Get the Id member data.
Definition: Seq_feat_.hpp:904
bool IsSetXref(void) const
cite other relevant features Check if a value has been assigned to Xref data member.
Definition: Seq_feat_.hpp:1296
const TData & GetData(void) const
Get the Data member data.
Definition: Seq_feat_.hpp:925
void SetData(TData &value)
Assign a value to Data data member.
Definition: Seq_feat_.cpp:94
bool IsSetId(void) const
Check if a value has been assigned to Id data member.
Definition: Seq_feat_.hpp:892
const TProt & GetProt(void) const
Get the variant data.
const TQual & GetQual(void) const
Get the Qual member data.
Definition: Gb_qual_.hpp:212
const TRna & GetRna(void) const
Get the variant data.
bool IsSetVal(void) const
Check if a value has been assigned to Val data member.
Definition: Gb_qual_.hpp:247
const char * command
#define FOR_EACH_GBQUAL_ON_FEATURE
#define FOR_EACH_SEQFEATXREF_ON_SEQFEAT(Itr, Var)
FOR_EACH_SEQFEATXREF_ON_SEQFEAT EDIT_EACH_SEQFEATXREF_ON_SEQFEAT.
SAnnotSelector –.
Modified on Sat Dec 02 09:22:06 2023 by modify_doxy.py rev. 669887