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

Go to the SVN repository for this file.

1 /* $Id: assembly_object_loader.cpp 41353 2018-07-12 18:47:59Z katargir $
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: Roman Katargin
27 */
28 
29 
30 #include <ncbi_pch.hpp>
31 
33 
34 #include <util/icanceled.hpp>
35 
37 
38 #include <gui/objutils/label.hpp>
39 
41 
49 
52 
53 CAssemblyObjectLoader::CAssemblyObjectLoader(const vector<string>& accessions)
54  : m_Accessions(accessions)
55 {
56  m_Descr = "Retrieving Gencoll assemblies: ";
57  for (size_t i = 0; i < m_Accessions.size(); ++i) {
58  if (i > 0) {
59  m_Descr += ", ";
60  }
62  }
63 }
64 
66 {
67  return m_Objects;
68 }
69 
71 {
72  return m_Descr;
73 }
74 
76 {
77  return true;
78 }
79 
81 {
83  CRef<CScope> scope(new CScope(*obj_mgr));
84  scope->AddDefaults();
85 
86  string currAcc;
87  CGencollSvc::TAssmAccs AssmAccs(m_Accessions.begin(), m_Accessions.end());
88  CGC_Assemblies Assemblies;
89  CGencollSvc::GetAssmsInfo(AssmAccs, "Gbench", Assemblies.SetAssemblies(), this);
90 
91  for(auto iAssemblies: Assemblies.GetAssemblies()) {
92  if (canceled.IsCanceled()) {
93  return false;
94  }
95  CRef<CGC_Assembly>& gc_assm(iAssemblies);
96  currAcc = gc_assm->GetAccession();
97 
98  try {
99  string label;
100  CLabel::GetLabel(*gc_assm, &label, CLabel::eDefault, scope);
101  if (label.empty())
102  label = currAcc;
103 
104  string descr = "Name: " + label;
105  if (gc_assm->IsAssembly_set()) {
108  descr += " (full assembly)";
110  descr += " (assembly set)";
111  }
112  }
113 
114  list< CRef<CDbtag> > ids;
116 
117  if (gc_assm->IsAssembly_set()) {
118  desc.Reset(&gc_assm->GetAssembly_set().GetDesc());
119  ids = gc_assm->GetAssembly_set().GetId();
120  } else if (gc_assm->IsUnit()) {
121  desc.Reset(&gc_assm->GetUnit().GetDesc());
122  ids = gc_assm->GetUnit().GetId();
123  }
124 
125  ITERATE (list< CRef<CDbtag> >, iter, ids) {
126  if ((*iter)->GetDb() == "GenColl" && (*iter)->GetTag().IsStr()) {
127  descr += "\nAccession: " + (*iter)->GetTag().GetStr();
128  }
129  if ((*iter)->GetDb() == "UCSC_name" && (*iter)->GetTag().IsStr()) {
130  descr += "\nUCSC name: " + (*iter)->GetTag().GetStr();
131  }
132  }
133  descr += "\nRelease type: ";
134  descr += gc_assm->IsRefSeq() ? "RefSeq" : "Genbank";
135  if (desc) {
136  if (desc->IsSetLong_name()) {
137  descr += "\nDescription: " + desc->GetLong_name();
138  }
139  if (desc->IsSetDescr()) {
140  ITERATE (CGC_AssemblyDesc::TDescr::Tdata, it, desc->GetDescr().Get()) {
141  if ((*it)->IsSource()) {
142  descr += "\nOrganism: ";
143  if ((*it)->GetSource().IsSetTaxname()) {
144  descr += (*it)->GetSource().GetTaxname();
145  }
146  if ((*it)->GetSource().IsSetCommon()) {
147  descr += " (" + (*it)->GetSource().GetCommon() + ")";
148  }
149  }
150  }
151  }
152  }
153 
154  if (label != currAcc) {
155  label += " (";
156  label += currAcc;
157  label += ')';
158  }
159  m_Objects.push_back(SObject(*gc_assm, label, descr));
160  }
161  catch (const CException& e) {
162  x_UpdateHTMLResults(currAcc, 0, e.GetMsg(), "", wxT("Accession:"));
163  }
164  catch (const exception& e) {
165  x_UpdateHTMLResults(currAcc, 0, e.what(), "", wxT("Accession:"));
166  }
167  }
168 
169  return true;
170 }
171 
173 {
174  x_ShowErrorsDlg(wxT("Assembly import errors"));
175  return true;
176 }
177 
178 void CAssemblyObjectLoader::ReportError(const string &accession, const string &error)
179 {
180  x_UpdateHTMLResults(accession, 0, error, "", wxT("Accession:"));
181 }
182 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
User-defined methods of the data storage class.
USING_SCOPE(objects)
CConstRef –.
Definition: ncbiobj.hpp:1266
CGC_Assemblies –.
string GetAccession() const
Retrieve the accession for this assembly.
Definition: GC_Assembly.cpp:99
bool IsRefSeq() const
Is this assembly a RefSeq assembly?
static void GetAssmsInfo(const TAssmAccs &assm_accs, const string &mode, TAssemblies &assemblies, IGencollSvcErrors *errors=nullptr)
query GenColl for assembly information, return list of assemblies mode is as described above for GetG...
list< string > TAssmAccs
Definition: gencoll_svc.hpp:57
void x_ShowErrorsDlg(const wxString &title)
void x_UpdateHTMLResults(const wxString &object, objects::ILineErrorListener *errCont, const string &exception="", const string &error_msg="", const wxString &objectName=wxT("File:"))
CScope –.
Definition: scope.hpp:92
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
vector< SObject > TObjects
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
Definition: ncbiexpt.cpp:342
virtual void ReportError(const string &accession, const string &error)
virtual string GetDescription() const
virtual bool Execute(ICanceled &canceled)
CAssemblyObjectLoader(const vector< string > &accessions)
virtual TObjects & GetObjects()
static void GetLabel(const CObject &obj, string *label, ELabelType type=eDefault)
Definition: label.cpp:140
@ eDefault
Definition: label.hpp:73
static CRef< CObjectManager > GetInstance(void)
Return the existing object manager or create one.
void AddDefaults(TPriority pri=kPriority_Default)
Add default data loaders from object manager.
Definition: scope.cpp:504
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:1439
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
virtual bool IsCanceled(void) const =0
static const char label[]
const TId & GetId(void) const
Get the Id member data.
const TUnit & GetUnit(void) const
Get the variant data.
const TDesc & GetDesc(void) const
Get the Desc member data.
bool IsAssembly_set(void) const
Check if variant Assembly_set is selected.
const TAssemblies & GetAssemblies(void) const
Get the Assemblies member data.
const TDesc & GetDesc(void) const
Get the Desc member data.
const TAssembly_set & GetAssembly_set(void) const
Get the variant data.
TSet_type GetSet_type(void) const
Get the Set_type member data.
bool IsUnit(void) const
Check if variant Unit is selected.
TAssemblies & SetAssemblies(void)
Assign a value to Assemblies data member.
const TId & GetId(void) const
Get the Id member data.
@ eSet_type_full_assembly
full-assembly: set of asm-units
@ eSet_type_assembly_set
set of full-assemblies stopper
list< CRef< CSeqdesc > > Tdata
Definition: Seq_descr_.hpp:91
int i
#define wxT(x)
Definition: muParser.cpp:41
The Object manager core.
Definition: type.c:6
Modified on Sun Apr 14 05:27:14 2024 by modify_doxy.py rev. 669887