NCBI C++ ToolKit
seqgraphic_alignment_ds.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_SEQ_GRAPHIC___SEQGRAPHIC_ALIGNMENT_DS__HPP
2 #define GUI_WIDGETS_SEQ_GRAPHIC___SEQGRAPHIC_ALIGNMENT_DS__HPP
3 
4 
5 /* $Id: seqgraphic_alignment_ds.hpp 46423 2021-05-03 13:07:27Z shkeda $
6  * ===========================================================================
7  *
8  * PUBLIC DOMAIN NOTICE
9  * National Center for Biotechnology Information
10  *
11  * This software/database is a "United States Government Work" under the
12  * terms of the United States Copyright Act. It was written as part of
13  * the author's official duties as a United States Government employee and
14  * thus cannot be copyrighted. This software/database is freely available
15  * to the public for use. The National Library of Medicine and the U.S.
16  * Government have not placed any restriction on its use or reproduction.
17  *
18  * Although all reasonable efforts have been taken to ensure the accuracy
19  * and reliability of the software and data, the NLM and the U.S.
20  * Government do not and cannot warrant the performance or results that
21  * may be obtained by using this software or data. The NLM and the U.S.
22  * Government disclaim all warranties, express or implied, including
23  * warranties of performance, merchantability or fitness for any particular
24  * purpose.
25  *
26  * Please cite the author in any work or product based on this material.
27  *
28  * ===========================================================================
29  *
30  * Authors: Liangshou Wu
31  *
32  */
33 
40 #include <objmgr/tse_handle.hpp>
41 #include <gui/utils/extension.hpp>
42 
44 
46 
47 static const string kBamDataLoader = "CBAMDataLoader";
48 static const string kCSRADataLoader = "CCSRADataLoader";
49 
51  public CSGGenBankDS
52 {
53 public:
55  typedef vector< CConstRef<IAlnGraphicDataSource> > TAlnMgrVec;
56 
57  enum EDataLoader {
60  eLoader_CSRA
61  };
62 
63  CSGAlignmentDS(objects::CScope& scope, const objects::CSeq_id& id);
64 
65  virtual ~CSGAlignmentDS();
66 
67  /// keep instances of score methods here.
68  typedef list<CIRef<IScoringMethod> > TMethods;
69 
70  /// @param smear_align smear the alignments also depending on
71  /// flag 'adpative'
72  /// @param adaptive_smear if true, the alignments will be
73  /// smeared adaptively
74  void LoadCoverageGraph(const TSeqRange& range, TModelUnit window,
75  TJobToken token);
76 
77  void LoadAlignments(const TSeqRange& range, TModelUnit window,
78  int align_limit, bool smear_if_overlimit, TJobToken token);
79 
80  //void LoadAlignments(const TSeqRange& range, TModelUnit window,
81  // int smear_cutoff, TJobToken token);
82 
83  void CalcAlnStat(const TAlnMgrVec& aligns, const TSeqRange& range,
84  TModelUnit window,
85  TJobToken token);
86 
87  void LoadAlignFeats(const TSeqRange& range, TModelUnit window,
88  vector< CRef<CAlignGlyph> > aligns,
89  const vector<int>& projected_feats,
90  TJobToken token);
91 
92  IAlnExplorer::EAlignType GetAlignType(const CSeqGlyph* obj) const;
93  IAlnExplorer::EAlignType GetAlignType() const;
94 
95  const string& GetDataLoader() const;
96  bool IsBamLoader() const;
97  bool IsCSRALoader() const;
98 
99  /// This method might need object manager to connect to ID, and
100  /// it is a block call. Please make sure it is called in a background
101  /// thread to avoid blocking the main application.
102  /// when isFastConfig set to true, it indicates that that the call is used by seqconfig
103  /// this means that setting m_HasCoverageGraph and getting the actual type that are taking a long time
104  /// and not needed by seqconfig will be skipped (IAlnExplorer::fHomogenous will be returned)
105  IAlnExplorer::EAlignType InitAlignType(bool isFastConfig = false);
106 
107  /// Alignment scoring.
108  void InitAlignScore(CAlignGlyph* aln);
109  void InitAlignQualityScore(CAlignGlyph* aln,
110  const TAlnAnchorPair& align_pair, IAlnExplorer::EAlignType sc_type);
111  void InitAlignScoreCache(CAlignGlyph* aln,
112  const TAlnAnchorPair& align_pair, IAlnExplorer::EAlignType sc_type);
113 
114  void CalculateAlignmentScore(CSeqGlyph::TObjects& objs, TJobToken token);
115  void ResetAlnScoringJob();
116 
117  void SetDefaultScoringMethods(string dna_method, string protein_method);
118 
119  /// get all the existing align scoring methods.
120  const TMethods& GetScoringMethods(IAlnExplorer::EAlignType aln_type);
121 
123  //CRef<CScoreCache> GetScoreCache(const CAlignGlyph* aln) const;
124 
125  void GetAnnotNames(objects::SAnnotSelector& sel,
126  const TSeqRange& range, TAnnotNameTitleMap& names) const;
127 
128  void SetDNAScoringMethod(const string& method);
129  const string& GetDNAScoringMethod() const;
130  void SetProteinScoringMethod(const string& method);
131  const string& GetProteinScoringMethod() const;
132  bool IsValidProteinScoringMethod(const string& name);
133  bool IsValidDNAScoringMethod(const string& name);
134 
135  void SetEnableColoration(bool f);
136  bool GetEnableColoration() const;
137  void SetLinkMatePairs(bool f);
138  bool GetLinkMatePairs() const;
139 
140  virtual void ClearJobID(TJobID job_id);
141  virtual void DeleteAllJobs();
142 
143  void SetAnnotName(const string& name);
144  const string& GetAnnotName() const;
145 
146  void SetHasCoverageGraph(bool flag);
147  bool HasCoverageGraph() const;
148  bool HasQualityMap() const;
149 
150  void SetSortBy(const string& sortby);
151  const string& GetSortBy() const;
152 
153  void SetHideSra(CAlignmentConfig::EHideSraAlignments hideSra) { m_HideSra = hideSra; }
154  void SetUnalignedTailsMode(CAlignmentConfig::EUnalignedTailsMode tailsMode) { m_UnalignedTailsMode = tailsMode; }
155  void SetShowSecondPassAlignments(bool value = true) { m_ShowSecondPass = value; }
156 
157  double GetGraphCost(const TSeqRange& range) const;
158  bool IsGraphCached(const TSeqRange& range) const;
159 
160  double GetAlignmentCost(const TSeqRange& range) const;
161 
162  void SetLayoutPolicy(ILayoutPolicy* layout_policy);
163 
164  void SetRemotePath(const string& remote_path);
165  void EnablePileUpCache(bool enable, bool enable_icache);
166  void ClearCache();
167 
168  bool CanShowRange(const TSeqRange& range, int align_limit);
169  bool IsRangeCached(const TSeqRange& range) const;
170 
171  void SetDataHandle(const objects::CTSE_Handle& tse);
172  bool NeedReleaseMemory() const;
173  void ReleaseMemory();
174 
175  void SetMemoryLimit(Uint8 memory_limit);
176  void SetCgiMode(bool cgi_mode);
177 
178  void SetAlnDataLoader(EDataLoader data_loader);
179 private:
180  bool x_IsScoringJobRunning() const;
181  void x_DeleteScoringJob();
182  void x_InitScoringMethods(IAlnExplorer::EAlignType aln_type);
183  void x_GetGraphCacheKey(string& data_key) const;
184 private:
185 
186  string m_AnnotName;
187 
188  TMethods m_DNAMethods; ///< registered DNA scoring methods
189  TMethods m_ProteinMethods; ///< registered Protein scoring methods
190 
193  mutable set<TAlnAnchorPair> m_PartialAlnSet; // partial align_pairs
194 
195  string m_DNAMethod; ///< default scoring method for DNA alignments
196  string m_ProtMethod; ///< default scoring method for protein alignments
198 
199  string m_SortBy;
200 
201  bool m_Enabled; ///< is alignment score coloration enabled
202  bool m_LinkMatePairs;///< link mate pair alignments
203  bool m_HasCoverageGraph; ///< High level coverage graph?
204  bool m_HasQualityMap; ///< Has quality map? (e.g. cSRA alignments)
205 
206  TJobToken m_ScoreToken; ///< the scoring job token
207  TJobID m_ScoringJobID; ///< alignment scoring job id
209  CAlignmentConfig::EHideSraAlignments m_HideSra; ///< Flag, indicating whether to hide duplicates and/or bad reads
210  CAlignmentConfig::EUnalignedTailsMode m_UnalignedTailsMode; ///< Flag, indicating whether and how to display unaligned tails
211  bool m_ShowSecondPass = true; ///> Flag to show second-pass alignments (relevant to assembly to assembly alignments)
212  TSignedSeqPos m_MaxStartTail; ///< Max length of unaligned tail at the start of the sequence
213  TSignedSeqPos m_MaxEndTail; ///< Max length of unaligned tail at the end of the sequence
214 
215  mutable string m_DataLoader = "none"; // Data loader typename
216 
218  string m_RemotePath; ///< url to the remote data
219 
220  objects::CTSE_Handle m_DataHandle; ///< The last loaded data
221  Uint8 m_MemoryLimit = 2 * (Uint8)1073741824; ///< NeedReleaseMemory's default limit 2GB.
222 
223  bool m_HasPileUpCache = false;
224  bool m_CgiMode = false; ///< sviewer context
225  EDataLoader m_AlnDataLoader = eLoader_Unknown;
226 };
227 
228 
230  public CObject,
231  public ISGDataSourceType,
232  public IExtension
233 {
234 public:
235  /// @name IExtension interface implementation
236  /// @{
237  virtual string GetExtensionIdentifier() const;
238  virtual string GetExtensionLabel() const;
239  /// @}
240 
241  virtual ISGDataSource* CreateDS(SConstScopedObject& object) const;
242 
243  virtual bool IsSharable() const;
244 };
245 
246 
247 ///////////////////////////////////////////////////////////////////////////////
248 /// CSGAlignmentDS inline methods
249 ///
250 inline
252 {
253  return m_AlnType;
254 }
255 
256 inline
257 void CSGAlignmentDS::GetAnnotNames(objects::SAnnotSelector& sel,
258  const TSeqRange& range,
259  TAnnotNameTitleMap& names) const
260 {
263 }
264 
265 inline
266 void CSGAlignmentDS::SetDNAScoringMethod(const string& method)
267 {
268  m_DNAMethod = method;
269 }
270 
271 inline
273 {
274  return m_DNAMethod;
275 }
276 
277 inline
278 void CSGAlignmentDS::SetProteinScoringMethod(const string& method)
279 {
280  m_ProtMethod = method;
281 }
282 
283 inline
285 {
286  return m_ProtMethod;
287 }
288 
289 inline
291 {
292  m_Enabled = f;
293 }
294 
295 inline
297 {
298  return m_Enabled;
299 }
300 
301 inline
303 {
304  m_LinkMatePairs = f;
305 }
306 
307 inline
309 {
310  return m_LinkMatePairs;
311 }
312 
313 inline
314 void CSGAlignmentDS::SetAnnotName(const string& name)
315 {
316  m_AnnotName = name;
317 }
318 
319 inline
320 const string& CSGAlignmentDS::GetAnnotName() const
321 {
322  return m_AnnotName;
323 }
324 
325 inline
327 {
328  m_HasCoverageGraph = flag;
329 }
330 
331 inline
333 {
334  return m_HasCoverageGraph;
335 }
336 
337 inline
339 {
340  return m_HasQualityMap;
341 }
342 
343 inline
344 void CSGAlignmentDS::SetSortBy(const string& sortby)
345 {
346  m_SortBy = sortby;
347 }
348 
349 inline
350 const string& CSGAlignmentDS::GetSortBy() const
351 {
352  return m_SortBy;
353 }
354 
355 inline
357 {
359  return GetDataLoader() == kBamDataLoader;
360 
361  return (eLoader_BAM == m_AlnDataLoader);
362 }
363 
364 
365 inline
367 {
369  return GetDataLoader() == kCSRADataLoader;
370 
371  return (eLoader_CSRA == m_AlnDataLoader);
372 }
373 
374 inline
376 {
377  m_LayoutPolicy = layout_policy;
378 }
379 
380 inline
381 void CSGAlignmentDS::SetRemotePath(const string& remote_path)
382 {
383  m_RemotePath = remote_path;
384 }
385 
386 inline
387 void CSGAlignmentDS::SetDataHandle(const objects::CTSE_Handle& tse)
388 {
389  m_DataHandle = tse;
390 }
391 
392 inline
394 {
395  m_MemoryLimit = memory_limit;
396 }
397 
398 inline
399 void CSGAlignmentDS::SetCgiMode(bool cgi_mode)
400 {
401  m_CgiMode = cgi_mode;
402 }
403 
404 
405 inline
407 {
408  m_AlnDataLoader = data_loader;
409 }
410 
412 
413 #endif /* GUI_WIDGETS_SEQ_GRAPHIC___SEQGRAPHIC_ALIGNMENT_DS__HPP */
CConstRef –.
Definition: ncbiobj.hpp:1266
CObject –.
Definition: ncbiobj.hpp:180
CRef –.
Definition: ncbiobj.hpp:618
TJobToken m_ScoreToken
the scoring job token
void GetAnnotNames(objects::SAnnotSelector &sel, const TSeqRange &range, TAnnotNameTitleMap &names) const
bool m_LinkMatePairs
link mate pair alignments
IAlnExplorer::EAlignType GetAlignType() const
CSGAlignmentDS inline methods.
const string & GetProteinScoringMethod() const
CAlignmentConfig::EHideSraAlignments m_HideSra
Flag, indicating whether to hide duplicates and/or bad reads.
void SetEnableColoration(bool f)
map< TAlnAnchorPair, CIRef< ISGAlnScore > > TAlnScoreMap
bool GetEnableColoration() const
void SetDNAScoringMethod(const string &method)
TJobID m_ScoringJobID
alignment scoring job id
void RecalculateScore(CConstRef< CSeqGlyph > obj)
void SetSortBy(const string &sortby)
void SetRemotePath(const string &remote_path)
void SetCgiMode(bool cgi_mode)
TMethods m_DNAMethods
registered DNA scoring methods
TSignedSeqPos m_MaxEndTail
Max length of unaligned tail at the end of the sequence.
TSignedSeqPos m_MaxStartTail
> Flag to show second-pass alignments (relevant to assembly to assembly alignments)
const string & GetSortBy() const
string m_RemotePath
url to the remote data
CAlignmentConfig::EUnalignedTailsMode m_UnalignedTailsMode
Flag, indicating whether and how to display unaligned tails.
bool m_HasQualityMap
Has quality map? (e.g. cSRA alignments)
objects::CTSE_Handle m_DataHandle
The last loaded data.
Uint8 m_MemoryLimit
NeedReleaseMemory's default limit 2GB.
void SetLayoutPolicy(ILayoutPolicy *layout_policy)
TMethods m_ProteinMethods
registered Protein scoring methods
CRef< CSGAlignScoringJob > m_ScoringJob
void SetHasCoverageGraph(bool flag)
bool m_Enabled
is alignment score coloration enabled
void SetUnalignedTailsMode(CAlignmentConfig::EUnalignedTailsMode tailsMode)
void SetAnnotName(const string &name)
set< TAlnAnchorPair > m_PartialAlnSet
bool m_CgiMode
sviewer context
const string & GetAnnotName() const
list< CIRef< IScoringMethod > > TMethods
keep instances of score methods here.
CAlignGlyph::TAlnAnchorPair TAlnAnchorPair
CIRef< ILayoutPolicy > m_LayoutPolicy
void SetHideSra(CAlignmentConfig::EHideSraAlignments hideSra)
void SetMemoryLimit(Uint8 memory_limit)
bool m_HasCoverageGraph
High level coverage graph?
vector< CConstRef< IAlnGraphicDataSource > > TAlnMgrVec
string m_DNAMethod
default scoring method for DNA alignments
const string & GetDataLoader() const
void SetProteinScoringMethod(const string &method)
IAlnExplorer::EAlignType m_AlnType
void SetDataHandle(const objects::CTSE_Handle &tse)
const string & GetDNAScoringMethod() const
void SetShowSecondPassAlignments(bool value=true)
void SetAlnDataLoader(EDataLoader data_loader)
string m_ProtMethod
default scoring method for protein alignments
static void GetAnnotNames(const objects::CBioseq_Handle &handle, const TSeqRange &range, objects::SAnnotSelector &sel, TAnnotNameTitleMap &names)
bool m_Adaptive
adaptive/exact annot selector
int m_Depth
annotation resolving depth
CAppJobDispatcher::TJobID TJobID
virtual void ClearJobID(TJobID job_id)
virtual void DeleteAllJobs()
Remove waiting jobs from queue or cancel the unfinished jobs.
objects::CBioseq_Handle m_Handle
class CSeqGlyph defines an interface that wraps a rectilinear abstract object.
Definition: seq_glyph.hpp:82
list< CRef< CSeqGlyph > > TObjects
Definition: seq_glyph.hpp:85
IExtension IExtension interface represents an abstract pluggable component.
Definition: extension.hpp:57
class ILayoutPolicy defines the abstract interface required for generating layout based on a set of g...
ISGDataSourceFactory.
File Description:
char value[7]
Definition: config.c:431
static const struct name_t names[]
int TSignedSeqPos
Type for signed sequence position.
Definition: ncbimisc.hpp:887
pair< CConstRef< CObject >, int > TAlnAnchorPair
static void SetResolveDepth(objects::SAnnotSelector &sel, bool adaptive, int depth=-1)
help function for setting selector resolve depth.
Definition: utils.cpp:405
GLdouble TModelUnit
Definition: gltypes.hpp:48
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
#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 NCBI_GUIWIDGETS_SEQGRAPHIC_EXPORT
Definition: gui_export.h:536
range(_Ty, _Ty) -> range< _Ty >
bool SetMemoryLimit(size_t max_size, TLimitsPrintHandler handler=NULL, TLimitsPrintParameter parameter=NULL)
[UNIX only] Set memory limit.
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
static const string kCSRADataLoader
static const string kBamDataLoader
Modified on Thu Feb 29 12:24:26 2024 by modify_doxy.py rev. 669887