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

Go to the SVN repository for this file.

1 /* $Id: seqgraphic_genbank_ds.cpp 44757 2020-03-05 18:58:50Z evgeniev $
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: Vlad Lebedev, Liangshou Wu
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
35 
36 #include <objmgr/util/sequence.hpp>
38 #include <objmgr/align_ci.hpp>
39 #include <objmgr/graph_ci.hpp>
40 #include <objmgr/seqdesc_ci.hpp>
41 #include <objmgr/data_loader.hpp>
43 #include <objmgr/impl/tse_info.hpp>
47 
49 #include <objects/seq/Seqdesc.hpp>
51 
53 
56 
57 ///////////////////////////////////////////////////////////////////////////////
58 /// CSGGenBankDS
59 ///
60 CSGGenBankDS::CSGGenBankDS(CScope& scope, const CSeq_id& id)
61  : m_JobListener(NULL)
62  , m_Depth(-1)
63  , m_Adaptive(true)
64 {
65  m_Handle = scope.GetBioseqHandle(id);
66  if ( !m_Handle ) {
68  string("Can't retrieve sequence for id: ") + id.AsFastaString());
69  }
70 
71  m_ActiveJobs.clear();
72 }
73 
74 
76 {
77  DeleteAllJobs();
78 }
79 
80 
82 {
83  vector<TJobID>::iterator it =
84  find(m_ActiveJobs.begin(), m_ActiveJobs.end(), job_id);
85  if (it != m_ActiveJobs.end()) {
86  m_ActiveJobs.erase(it);
87  }
88 }
89 
90 
92 {
94 
95  ITERATE(vector<TJobID>, it, m_ActiveJobs) {
96  TJobID job_id = *it;
97  try {
98  disp.DeleteJob(job_id);
99  } catch(CAppJobException& e) {
100  switch(e.GetErrCode()) {
103  /// this is fine - job probably already finished
104  break;
105  default:
106  // something wrong
107  LOG_POST(Error << "CSGGenBankDS::DeleteAllJobs() "
108  << "Error canceling job");
109  LOG_POST(e.ReportAll());
110  }
111  }
112  }
113 
114  m_ActiveJobs.clear();
115 }
116 
117 
119 {
121 }
122 
123 
125 {
126  IAppJob::EJobState state = job.Run();
127 
128  switch (state) {
129  case IAppJob::eCompleted:
130  {
131  CRef<CObject> res = job.GetResult();
132  _ASSERT(res);
133  CRef<CEvent> evt(new CAppJobNotification(-1, res));
134  m_JobListener->Send(evt);
135  break;
136  }
137  case IAppJob::eFailed:
138  {
140  if (err) {
141  CRef<CEvent> evt(new CAppJobNotification(-1, *err));
142  m_JobListener->Send(evt);
143  }
144  else {
145  CRef<CEvent> evt(new CAppJobNotification(-1, state));
146  m_JobListener->Send(evt);
147  }
148  break;
149  }
150  default:
151  break;
152  }
153 }
154 
155 
157  int report_period,
158  const string& pool)
159 {
160  TJobID job_id = -1;
162  try {
163  job_id = disp.StartJob(job, pool, *m_JobListener, report_period, true);
164  } catch(CAppJobException& e) {
165  LOG_POST(Error << "CSGGenBankDS::x_BackgroundJob() - Failed to start job");
166  LOG_POST(e.ReportAll());
167  }
168  return job_id;
169 }
170 
171 
173  int report_period,
174  const string& pool)
175 {
176  TJobID job_id = -1;
177  if (m_Background) {
178  job_id = x_BackgroundJob(job, report_period, pool);
179  if (job_id != -1) {
180  m_ActiveJobs.push_back(job_id);
181  }
182  } else {
183  x_ForegroundJob(job);
184  }
185 
186  return job_id;
187 }
188 
189 void CSGGenBankDS::SetGraphLevels(const string& annot)
190 {
191  CRef<CSeq_loc> seq_loc =
192  m_Handle.GetRangeSeq_loc(0,
193  m_Handle.GetSeqVector(CBioseq_Handle::eCoding_Iupac).size());
194 
196 }
197 
198 
199 ///////////////////////////////////////////////////////////////////////////////
200 /// CSGSequenceDS
202 {
203  m_Handle = scope.GetBioseqHandle(id);
204  if ( !m_Handle ) {
206  string("Can't retrieve sequence for id: ") + id.AsFastaString());
207  }
208 
209  CSeq_id_Handle idh = m_Handle.GetSeq_id_Handle();
211 
212  if ( !m_Best_idh ) {
213  m_Best_idh = idh;
214  }
217 }
218 
219 
221 {
222 }
223 
224 
225 void CSGSequenceDS::GetSequence(TSeqPos from, TSeqPos to, string& buffer) const
226 {
227  buffer.erase();
228  if (m_SeqVector) {
229  // CSeqVector::GetSeqData returns sequence for [from stop)
230  // so we need to add one more base to get sequence at 'to' position
231  m_SeqVector->GetSeqData(from, to + 1, buffer);
232  }
233 }
234 
235 
237 {
238  return sequence::CDeflineGenerator().GenerateDefline(m_Handle);
239 }
240 
241 
243 {
244  string acc_best;
245  m_Best_idh.GetSeqId()->GetLabel(&acc_best, CSeq_id::eContent);
246  return acc_best;
247 }
248 
249 
251 {
252  return CSeq_id::GetStringDescr(*m_Handle.GetBioseqCore(),
254 }
255 
256 
258 {
259  if (acc_info == CSeq_id::eAcc_refseq_chromosome) //NC_
260  return true;
261  if (acc_info == CSeq_id::eAcc_refseq_contig) //NT_
262  return true;
263  if (acc_info == CSeq_id::eAcc_refseq_genomic) //NG_
264  return true;
265  if (acc_info == CSeq_id::eAcc_refseq_genome) //NS_
266  return true;
267  if (acc_info == CSeq_id::eAcc_refseq_wgs_intermed) // NW_
268  return true;
269  return false;
270 }
271 
272 
274 {
275  CConstRef<CSeq_id> id = m_Best_idh.GetSeqId();
276  if (id && id->IsGeneral() &&
277  NStr::EqualNocase(id->GetGeneral().GetDb(), "TRACE_ASSM")) {
278  return true;
279  }
280 
281  return false;
282 }
283 
284 
286 {
287  CSeq_entry_Handle tse = m_Handle.GetTopLevelEntry();
288  if (tse.IsSet() && tse.GetSet().IsSetClass()) {
289  CBioseq_set::TClass bset_class = tse.GetSet().GetClass();
290  switch (bset_class) {
295  {{
296  CAlign_CI align_iter(m_Handle);
297  if (align_iter.GetSize()) {
298  return true;
299  }
300  }}
301  break;
302  default:
303  break;
304  }
305  }
306 
307  return false;
308 }
309 
310 
312 {
314 }
315 
316 
318 {
320  while (desc_ci) {
321  const CGB_block& block = desc_ci->GetGenbank();
322  if (block.CanGetKeywords()) {
323  ITERATE (CGB_block::TKeywords, k_iter, block.GetKeywords()) {
324  if (*k_iter == "RefSeqGene") {
325  return true;
326  }
327  }
328  }
329  ++desc_ci;
330  }
331 
332  return false;
333 }
334 
335 
336 ///////////////////////////////////////////////////////////////////////////////
337 /// CSGSequenceDSType
338 ///
339 
342 {
343  const CSeq_id& id = dynamic_cast<const CSeq_id&>(object.object.GetObject());
344  return new CSGSequenceDS(object.scope.GetObject(), id);
345 }
346 
348 {
349  static string sid("seqgraphic_genbank_ds_type");
350  return sid;
351 }
352 
354 {
355  static string slabel("Graphical View Genbank Data Source Type");
356  return slabel;
357 }
358 
359 /// check if the data source can be shared.
361 {
362  return true;
363 }
364 
User-defined methods of the data storage class.
CAlign_CI –.
Definition: align_ci.hpp:63
size_t GetSize(void) const
CAppJobDispatcher.
IAppJobListener Interface for components that need to be notified about changes in Jobs.
CAppJobNotification Notification send by CAppJobEventTranslator.
static void CalcGraphLevels(const string &annotName, objects::CScope &scope, const objects::CSeq_loc &loc, set< int > &levels)
Definition: graph_utils.cpp:64
TJobID x_LaunchJob(IAppJob &job, int report_period=1, const string &pool="ObjManagerEngine")
Launch either a background or foreground job.
void SetGraphLevels(const string &annot)
vector< TJobID > m_ActiveJobs
all currently active jobs for this DS
CAppJobDispatcher::TJobID TJobID
objects::CScope & GetScope(void) const
Get the scope from the handle.
CSGGenBankDS(objects::CScope &scope, const objects::CSeq_id &id)
CEventHandler * m_JobListener
our listener to JobDispatcher events
void x_ForegroundJob(IAppJob &job)
virtual void ClearJobID(TJobID job_id)
TGraphLevels m_GraphLevels
Existing coverage graph levels.
virtual void DeleteAllJobs()
Remove waiting jobs from queue or cancel the unfinished jobs.
objects::CBioseq_Handle m_Handle
TJobID x_BackgroundJob(IAppJob &job, int report_period, const string &pool)
Jobs on thread pool.
virtual ISGDataSource * CreateDS(SConstScopedObject &object) const
create an instance of the layout track type using default settings.
virtual string GetExtensionLabel() const
returns a displayable label for this extension ( please capitalize the key words - "My Extension" )
virtual string GetExtensionIdentifier() const
returns the unique human-readable identifier for the extension the id should use lowercase letters se...
virtual bool IsSharable() const
check if the data source can be shared.
CRef< objects::CSeqVector > m_SeqVector
CSGSequenceDS(objects::CScope &scope, const objects::CSeq_id &id)
CSGSequenceDS.
bool IsAccGenomic(objects::CSeq_id::EAccessionInfo acc_info) const
string GetAcc_All() const
all accession info we can get in FASTA format
bool IsTraceAssembly() const
string GetTitle() const
objects::CBioseq_Handle m_Handle
void GetSequence(TSeqPos from, TSeqPos to, string &buffer) const
retrieve a string representing the IUPAC characters for the sequence [from to].
string GetAcc_Best() const
this is more suitable for display purposes since the returned string will not always be good to recon...
objects::CSeq_id_Handle m_Best_idh
best id handle (obtained with sequence::GetId(..., sequence::eGetId_Best))
static bool IsRefSeq(const objects::CBioseq_Handle &handle)
CScope –.
Definition: scope.hpp:92
CSeqVector –.
Definition: seq_vector.hpp:65
CSeq_entry_Handle –.
CSeqdesc_CI –.
Definition: seqdesc_ci.hpp:65
IAppJob.
Definition: app_job.hpp:82
File Description:
#define true
Definition: bool.h:35
unsigned int TSeqPos
Type for sequence locations and lengths.
Definition: ncbimisc.hpp:875
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
static CAppJobDispatcher & GetInstance()
virtual CConstIRef< IAppJobError > GetError()=0
Returns IAppJobError object describing internal error that caused the Job to fail.
virtual CRef< CObject > GetResult()=0
Returns the Job Result.
bool DeleteJob(TJobID job_id)
when a Job is deleted the listener is not notified
EJobState
Job states (describe FSM)
Definition: app_job.hpp:86
TJobID StartJob(IAppJob &job, const string &engine_name, IEngineParams *params=NULL)
Starts a Job on the specified engine in "passive mode" - no notifications or progress reports will be...
virtual EJobState Run()=0
Function that does all the useful work, called by the Engine.
virtual bool Send(CEvent *evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
Sends an event synchronously.
@ eEngine_UnknownJob
the job is not registered in the Engine
@ eUnknownJob
Job record lost.
@ eUnknown
Definition: app_popup.hpp:72
@ eCompleted
Definition: app_job.hpp:89
@ eFailed
Definition: app_job.hpp:90
EAccessionInfo
For IdentifyAccession (below)
Definition: Seq_id.hpp:220
static string GetStringDescr(const CBioseq &bioseq, EStringFormat fmt)
Definition: Seq_id.cpp:2292
@ eAcc_refseq_contig
Definition: Seq_id.hpp:420
@ eAcc_refseq_chromosome
Definition: Seq_id.hpp:429
@ eAcc_refseq_genomic
Definition: Seq_id.hpp:430
@ eAcc_refseq_wgs_intermed
Definition: Seq_id.hpp:431
@ eAcc_refseq_genome
Definition: Seq_id.hpp:419
@ eFormat_FastA
Definition: Seq_id.hpp:662
@ eContent
Untagged human-readable accession or the like.
Definition: Seq_id.hpp:605
const CSeq_id & GetId(const CSeq_loc &loc, CScope *scope)
If all CSeq_ids embedded in CSeq_loc refer to the same CBioseq, returns the first CSeq_id found,...
@ eGetId_Best
return the "best" gi (uses FindBestScore(), with CSeq_id::CalculateScore() as the score function
Definition: sequence.hpp:101
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
TClass GetClass(void) const
TSet GetSet(void) const
bool IsSetClass(void) const
bool IsSet(void) const
@ eCoding_Iupac
Set coding to printable coding (Iupacna or Iupacaa)
TObjectType * GetPointer(void) const THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:1684
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
static bool EqualNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive equality of a substring with another string.
Definition: ncbistr.hpp:5353
list< string > TKeywords
Definition: GB_block_.hpp:93
const TKeywords & GetKeywords(void) const
Get the Keywords member data.
Definition: GB_block_.hpp:526
bool CanGetKeywords(void) const
Check if it is safe to call GetKeywords method.
Definition: GB_block_.hpp:520
const TDb & GetDb(void) const
Get the Db member data.
Definition: Dbtag_.hpp:220
bool IsGeneral(void) const
Check if variant General is selected.
Definition: Seq_id_.hpp:877
const TGeneral & GetGeneral(void) const
Get the variant data.
Definition: Seq_id_.cpp:369
@ eClass_pop_set
population study
@ eClass_phy_set
phylogenetic study
@ eClass_mut_set
set of mutations
@ eClass_eco_set
ecological sample study
const TGenbank & GetGenbank(void) const
Get the variant data.
Definition: Seqdesc_.cpp:334
@ e_Genbank
GenBank specific info.
Definition: Seqdesc_.hpp:121
The Object manager core.
static pcre_uint8 * buffer
Definition: pcretest.c:1051
USING_SCOPE(objects)
#define _ASSERT
Modified on Sun Apr 28 04:49:24 2024 by modify_doxy.py rev. 669887