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

Go to the SVN repository for this file.

1 #include <ncbi_pch.hpp>
3 
5 BEGIN_SCOPE(cd_utils)
6 
8  :m_table(), m_masters(), m_cdRowIndexMap()
9 {
10 
11 }
12 
13 
14 void RowSourceTable::addEntry(int row, CCdCore* cd, int rowInCD, bool normal, bool scoped)
15 {
16  RowSource rs(cd, rowInCD, normal);
17  addEntry(row, rs, scoped);
18 }
19 
20 void RowSourceTable::addEntry(int row, RowSource rs, bool scoped)
21 {
23  if (scoped)
25  else
27  if (rs.rowInSrc == 0 && rs.normal)
28  {
29  m_masters.insert(row);
30  }
31  int uniRow = rs.rowInSrc;
32  if (!rs.normal)
33  uniRow += PENDING_ROW_START;
35 }
36 
37 void RowSourceTable::removeEntriesForCD(vector<int>& rows, CCdCore* cd)
38 {
39  if (isCDInScope(cd))
40  return; // can only do this if cd is not in scope
42  //vector<int> rows;
43  //getAllRowsForCD(cd, rows);
44  for ( unsigned int i = 0; i < rows.size(); i++)
45  {
46  m_masters.erase(rows[i]);
47  pair<RowSourceMap::iterator, RowSourceMap::iterator> range = m_table.equal_range(rows[i]);
48  for (RowSourceMap::iterator rit = range.first; rit != range.second; ++rit)
49  {
50  RowSource& rs = rit->second;
51  int uniRow = rs.rowInSrc;
52  if (!rs.normal)
53  uniRow += PENDING_ROW_START;
54  m_cdRowIndexMap.erase(makeCDRowKey(rs.cd, uniRow));
55  if ( rs.cd == cd)
56  {
57  m_table.erase(rit);
58  break;
59  }
60  else if (rs.wasMaster())
61  m_masters.insert(rows[i]);
62  }
63  }
64  return;
65 }
66 
67 /* buggy--does not work with pendings. Replace it with isRowInCD
68 void RowSourceTable::getAllRowsForCD(CCdCore* cd, vector<int>& rows)const
69 {
70  vector<int> cdRows;
71  int num = cd->GetNumRows();
72  for ( int i = 0; i < num; i++)
73  {
74  cdRows.push_back(i);
75  }
76  set<int> colRows;
77  convertFromCDRows(cd, cdRows, colRows);
78  for (set<int>::iterator sit = colRows.begin(); sit != colRows.end(); sit++)
79  {
80  rows.push_back(*sit);
81  }
82 }*/
83 
84 
85 bool RowSourceTable::isRowInCD(int row, CCdCore* cd) const
86 {
87  vector<RowSource> rss;
88  findEntries(row, rss);
89  for(unsigned int i = 0; i < rss.size(); i++)
90  {
91  if (rss[i].cd == cd)
92  return true;
93  }
94  return false;
95 }
96 
97 int RowSourceTable::findEntries(int row, vector<RowSource>& src, bool scopedOnly) const
98 {
99  pair<RowSourceMap::const_iterator, RowSourceMap::const_iterator> range = m_table.equal_range(row);
100  for (RowSourceMap::const_iterator rit = range.first; rit != range.second; ++rit)
101  {
102  if (scopedOnly)
103  {
104  if (isCDInScope(rit->second.cd))
105  src.push_back(rit->second);
106  }
107  else
108  src.push_back(rit->second);
109  }
110  return src.size();
111 }
112 
113 const RowSource& RowSourceTable::findEntry(int row) const
114 {
116  if (rcit != m_table.end())
117  {
118  return rcit->second;
119  }
120  else
121  return *(new RowSource());
122 }
123 
125 {
126  RowSourceMap::iterator rcit = m_table.find(row);
127  if (rcit != m_table.end())
128  {
129  return rcit->second;
130  }
131  else
132  return *(new RowSource());
133 }
134  //int findRowBySourceCD(const CCdCore* cd, vector<int> rows)const;
135  //int findRowBySource(const RowSource& rs)const;
136 bool RowSourceTable::isPending(int row)const
137 {
138  const RowSource& rs = findEntry(row);
139  if (rs.cd)
140  {
141  return !rs.normal;
142  }
143  else
144  return false;
145 }
146 
147 void RowSourceTable::getMasterRows(vector<int>& masters)
148 {
149  for (set<int>::iterator sit = m_masters.begin(); sit != m_masters.end(); sit++)
150  masters.push_back(*sit);
151 }
152 
153 int RowSourceTable::getCDs(vector<CCdCore*>& cds)
154 {
155  getCDsInScope(cds);
156  getCDsOutofScope(cds);
157  return cds.size();
158 }
159 
160 //get only CDs whose alignment rows are included
161 int RowSourceTable::getCDsInScope(vector<CCdCore*>& cds)
162 {
164  return cds.size();
165 }
166 
167 //get CDs which are only used to map row membership of duplicated SeqLoc
168 int RowSourceTable::getCDsOutofScope(vector<CCdCore*>& cds)
169 {
171  return cds.size();
172 }
173 
175 {
177  return sit != m_cdsInScope.end();
178 }
179 
181 {
182  return isCDInScope(rs.cd);
183 }
184 
185 void RowSourceTable::transferCDs(const set<CCdCore*>& cdSet, vector<CCdCore*>& cdVec)
186 {
187  for (set<CCdCore*>::const_iterator sit = cdSet.begin(); sit != cdSet.end(); sit++)
188  cdVec.push_back(*sit);
189 }
190 
192 {
193  m_table.clear();
194  m_masters.clear();
195 }
196 
197 //pending row starts at CCdCore::PENDING_ROW_START
198 string RowSourceTable::makeCDRowKey(CCdCore* cd, int row) const
199 {
200  return cd->GetAccession() + 'r' + NStr::IntToString(row);;
201 }
202 
203 void RowSourceTable::convertFromCDRows(CCdCore* cd, const vector<int>& cdRows, set<int>& colRows)const
204 {
205  string acc = cd->GetAccession();
206  for (unsigned int i = 0; i < cdRows.size(); i++)
207  {
209  if (rowIt != m_cdRowIndexMap.end())
210  colRows.insert(rowIt->second);
211  }
212 }
213 
215 {
217  if (rowIt != m_cdRowIndexMap.end())
218  return rowIt->second;
219  else
220  return -1;
221 }
222 
223 void RowSourceTable::convertToCDRows(const vector<int>& colRows, CDRowsMap& cdRows) const
224 {
225  for (unsigned int i = 0; i < colRows.size(); i++)
226  {
227  vector<RowSource> entries;
228  findEntries(colRows[i], entries);
229  for(unsigned int j = 0; j < entries.size(); j++)
230  {
231  int uniRow = entries[j].normal ? entries[j].rowInSrc : entries[j].rowInSrc + PENDING_ROW_START;
232  cdRows[entries[j].cd].push_back(uniRow);
233  }
234  }
235 }
236 
237 END_SCOPE(cd_utils)
string GetAccession(int &Version) const
Definition: cuCdCore.cpp:81
string makeCDRowKey(CCdCore *cd, int row) const
int getCDs(vector< CCdCore * > &cds)
void removeEntriesForCD(vector< int > &colRows, CCdCore *cd)
set< int > m_masters
int getCDsOutofScope(vector< CCdCore * > &cds)
void convertToCDRows(const vector< int > &colRows, CDRowsMap &cdRows) const
void transferCDs(const set< CCdCore * > &cdSet, vector< CCdCore * > &cdVec)
CDRowIndexMap m_cdRowIndexMap
set< CCdCore * > m_cdsInScope
RowSourceMap m_table
int findEntries(int row, vector< RowSource > &src, bool scopedOnly=false) const
int convertFromCDRow(CCdCore *cd, int cdRows) const
bool isCDInScope(CCdCore *cd) const
void addEntry(int row, CCdCore *cd, int rowInCD, bool normal=true, bool scoped=true)
void convertFromCDRows(CCdCore *cd, const vector< int > &cdRows, set< int > &colRows) const
bool isEntryInScope(const RowSource &rs) const
int getCDsInScope(vector< CCdCore * > &cds)
bool isRowInCD(int row, CCdCore *cd) const
const RowSource & findEntry(int row) const
set< CCdCore * > m_cdsOutofScope
bool isPending(int row) const
void getMasterRows(vector< int > &masters)
void erase(iterator pos)
Definition: map.hpp:167
container_type::const_iterator const_iterator
Definition: map.hpp:53
const_iterator end() const
Definition: map.hpp:152
iterator_bool insert(const value_type &val)
Definition: map.hpp:165
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: map.hpp:338
const_iterator_pair equal_range(const key_type &key) const
Definition: map.hpp:296
void clear()
Definition: map.hpp:309
const_iterator find(const key_type &key) const
Definition: map.hpp:293
void erase(iterator pos)
Definition: map.hpp:307
const_iterator end() const
Definition: map.hpp:292
iterator insert(const value_type &val)
Definition: map.hpp:305
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
void clear()
Definition: set.hpp:153
const_iterator find(const key_type &key) const
Definition: set.hpp:137
void erase(iterator pos)
Definition: set.hpp:151
const_iterator end() const
Definition: set.hpp:136
const int PENDING_ROW_START
Definition: cuCdCore.hpp:53
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5083
int i
range(_Ty, _Ty) -> range< _Ty >
bool wasMaster() const
CCdCore * cd
static wxAcceleratorEntry entries[3]
Modified on Sat Dec 02 09:22:13 2023 by modify_doxy.py rev. 669887