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

Go to the SVN repository for this file.

1 /* $Id: align_seq_table.cpp 47479 2023-05-02 13:24:02Z ucko $
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: Andrey Yazhuk
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
36 
37 #include <gui/objutils/label.hpp>
38 
39 #include <objmgr/util/sequence.hpp>
41 
42 
45 
46 ///////////////////////////////////////////////////////////////////////////////
47 /// CAlignSeqTableModel
48 wxString CAlignSeqTableModel::GetColumnType(int /*col_index*/) const
49 {
50  return wxT("string");
51 }
52 
53 
55 {
56  Clear();
57 
58  ITERATE( TIdVector, it, ids ){
59  IHitSeqId* id = *it;
60  CBioseq_Handle handle = ds.GetBioseqHandle(*id);
61 
62  SRow* row = new SRow();
63 
64  row->m_Id = id;
65  row->m_IdLabel = ds.GetLabel( *id );
66  row->m_Title = x_GetTitle( handle );
67  row->m_Organism = x_GetOrganism( handle );
68  row->m_Length = x_GetLength( handle );
69 
70  m_Rows.push_back(row);
71  }
72 
74 }
75 
76 
78 {
79  return handle ? sequence::CDeflineGenerator().GenerateDefline(handle) : "";
80 }
81 
82 
84 {
85  string str;
86  try {
87  const COrg_ref& ref = sequence::GetOrg_ref(handle);
88  ref.GetLabel(&str);
89  }
90  catch (CException&) {
91  }
92  return str;
93 }
94 
95 
97 {
98  string str = handle ? NStr::IntToString(handle.GetBioseqLength()) : "";
99  return str;
100 }
101 
102 
104 {
105  return static_cast<int>(m_Rows.size());
106 }
107 
108 static const unsigned int kAlignSeqColumnsNum = 4;
109 
111 {
112  return kAlignSeqColumnsNum;
113 }
114 
115 
116 wxVariant CAlignSeqTableModel::GetValueAt( int row, int col ) const
117 {
118  if( row >= 0 && row < GetNumRows() ){
119  const SRow& r = *m_Rows[row];
120  switch( col ){
121  case 0:
122  return ToWxString( r.m_IdLabel );
123  case 1:
124  return ToWxString( r.m_Title );
125  case 2:
126  return ToWxString( r.m_Organism );
127  case 3:
128  return ToWxString( r.m_Length );
129  default:
130  break;
131  }
132  }
133  return ToWxString( "Error" );
134 }
135 
136 static const wxString sColumns[kAlignSeqColumnsNum+1] = {
137  wxT("ID"),
138  wxT("Title"),
139  wxT("Organism"),
140  wxT("Length"),
141  wxT("")
142 };
143 
144 wxString CAlignSeqTableModel::GetColumnName( int col ) const
145 {
146  if( col >= 0 && col < kAlignSeqColumnsNum ){
147  return sColumns[col];
148  }
149 
151 }
152 
153 
155 {
156  for( int i = 0; i < GetNumRows(); i++ ){
157  delete m_Rows[i];
158  }
159  m_Rows.clear();
160 }
161 
162 
163 const IHitSeqId* CAlignSeqTableModel::GetId( int row ) const
164 {
165  if( row >= 0 && row < GetNumRows() ){
166  return m_Rows[row]->m_Id;
167  }
168 
169  return NULL;
170 }
171 
172 
USING_SCOPE(objects)
static const wxString sColumns[kAlignSeqColumnsNum+1]
static const unsigned int kAlignSeqColumnsNum
string x_GetOrganism(objects::CBioseq_Handle &handle) const
virtual wxString GetColumnName(int col_ix) const
Returns a default name for the column using spreadsheet conventions: A, B, C, ...
const IHitSeqId * GetId(int row) const
virtual wxString GetColumnType(int col_ix) const
CAlignSeqTableModel.
vector< SRow * > m_Rows
IHitMatrixDataSource::TIdVector TIdVector
string x_GetLength(objects::CBioseq_Handle &handle) const
virtual int GetNumColumns() const
Returns the number of columns in the model.
virtual wxVariant GetValueAt(int row, int column) const
string x_GetTitle(objects::CBioseq_Handle &handle) const
virtual int GetNumRows() const
Returns the number of rows in the model.
void Init(IHitMatrixDataSource &ds, const TIdVector &ids)
CBioseq_Handle –.
void GetLabel(string *label) const
Definition: Org_ref.cpp:57
virtual void x_FireDataChanged()
IHitMatrixDataSource - abstract Data Source for Hit Matrix Widget.
virtual objects::CBioseq_Handle GetBioseqHandle(const IHitSeqId &id)=0
virtual string GetLabel(const IHitSeqId &id)=0
IHitSeqId - abstract identifier of a sequence in an alignment.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
const COrg_ref & GetOrg_ref(const CBioseq_Handle &handle)
Return the org-ref associated with a given sequence.
Definition: sequence.cpp:264
TSeqPos GetBioseqLength(void) const
#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 string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
int i
#define wxT(x)
Definition: muParser.cpp:41
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
static const char * str(char *buf, int n)
Definition: stats.c:84
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Thu Mar 28 17:10:35 2024 by modify_doxy.py rev. 669887