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

Go to the SVN repository for this file.

1 /* $Id: alnmulti_model.cpp 45784 2020-11-25 16:01:31Z shkeda $
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 
39 
40 #include <corelib/ncbithr.hpp>
41 
44 
45 static const int kColorGradNumber = 64; /// number of gradient colors in alignment
46 
47  ////////////////////////////////////////////////////////////////////////////////
48 /// class CAlnMultiModel
49 
51 : m_Style(NULL),
52  m_StyleCatalog(NULL),
53  m_DataSource(NULL),
54  m_Listener(NULL),
55  m_MasterRow(NULL), // TODO: should we initialize CIRef?
56  m_AutoSort(false),
57  m_SortColumn(IAlignRow::eInvalid),
58  m_SortState(IAlnExplorer::eNotSupported),
59  m_EnableScoring(true),
60  m_ScoreCache(new CScoreCache()),
61  m_isDataReadSync(false)
62 {
66 
67  // for debugging only
68  /*CSimpleScoringMethod* method = new CSimpleScoringMethod();
69  method->CreateColorTable(32);
70  AddScoringMethod(method);
71  SetCurrentMethod(method->GetName());*/
72 }
73 
74 
76 {
78 
79  // setup Port
82  m_Port.EnableZoom(true, false);
83 
85 
86  SetPortLimits();
87 }
88 
89 
91 {
93  double min_scale = 1 / (max_sym_w * 0.75);
94  min_scale = max(min_scale, 0.01);
95  m_Port.SetMinScaleX(min_scale);
96 }
97 
98 
100 {
101  // we do not want to receive any updates
103 
104  // delete methods
106  m_Methods.clear();
107 
108  ClearRows();
109  delete m_Style;
110 }
111 
112 
113 // factory method for creation rows
115 {
117 
118  const IAlignRowHandle* handle = m_DataSource->GetRowHandle(row);
119 
120  _ASSERT(handle);
121 
122  // create CAlnVecRow
123  CAlnVecRow* p_row = new CAlnVecRow(*handle);
124 
125  // create Styles
127  p_row->SetDisplayStyle(style);
128 
129  p_row->SetScoreCache(m_ScoreCache);
131 
132  return p_row;
133 }
134 
135 
136 ////////////////////////////////////////////////////////////////////////////////
137 // IAlnMultiPaneParent implementation
139 {
141 }
142 
143 
145 {
146  return m_Style;
147 }
148 
149 
151 {
153 }
154 
155 
157 {
158  return x_GetRecordByRow(row).m_Row->GetRowState();
159 }
160 
161 
163  const SRowRecord* rec2)
164 {
165  return rec1->m_Line < rec2->m_Line;
166 }
167 
168 
169 /// changes visibility state for given vector of rows to "b_visible"
170 void CAlnMultiModel::SetVisible(vector<TNumrow> rows, bool b_visible,
171  bool b_invert_others)
172 {
173  int consensus_idx = m_DataSource->GetConsensusRow();
174 
175  // If we are set to not show consensus at all, hide it
176  // in all cases
177  if (consensus_idx >= 0 && !m_Style->m_ShowConsensus) {
178  vector<TNumrow>::iterator iter = std::find(rows.begin(), rows.end(), TNumrow(consensus_idx));
179 
180  if (!b_invert_others) {
181  if (b_visible) {
182  if (iter != rows.end())
183  rows.erase(iter);
184  }
185  }
186  else {
187  if (!b_visible) {
188  if (iter == rows.end())
189  rows.push_back(consensus_idx);
190  }
191  }
192  }
193 
194  size_t n_rows = rows.size();
195  if(n_rows || b_invert_others) {
196  vector<TNumrow> v_items;
197  TNumrow master_row = m_DataSource->GetAnchor();
198 
199  if(b_invert_others) { // all rows in alignment are affected
200  // by default set state for all rows to "! b_visible"
201  vector<bool> new_visible(GetNumRows(), ! b_visible);
202 
203  ITERATE(vector<TNumrow>, it, rows) {
204  new_visible[*it] = b_visible;
205  }
206 
207  vector<SRowRecord*> vis_recs;
208  vis_recs.reserve(b_visible ? rows.size()
209  : new_visible.size() - rows.size());
210 
211  for( TNumrow row = 0; row < (TNumrow) new_visible.size(); row++ ) { // for all rows
212  if(row != master_row && new_visible[row]) {
214  vis_recs.push_back(&rec);
215  }
216  }
217  // sort records by line number
218  sort(vis_recs.begin(), vis_recs.end(), SRowRecord::PRecLineLess);
219 
220  // copy row numbers to v_items
221  v_items.reserve(vis_recs.size());
222  ITERATE(vector<SRowRecord*>, it, vis_recs) {
223  IAlignRow* p_row = (*it)->m_Row;
224  v_items.push_back(p_row->GetRowNum());
225  }
226 
227  TNumrowModelImpl::SetItems(v_items, false, true);
228  }
229  else { // only "rows" will be affected
230  v_items.reserve(n_rows);
231  vector<TLine> v_indices;
232  v_indices.reserve(n_rows);
233 
234  ITERATE(vector<TNumrow>, it, rows) {
235  TNumrow row = *it;
237  bool b_old_vis = rec.IsVisible();
238 
239  if(b_old_vis != b_visible && row != master_row) {
240  // state needs to be changed
241  TLine line = rec.m_Line;
242  // clip line, it can be invalid
243  line = min(line, (TLine) m_vVisibleRows.size());
244  v_indices.push_back(line);
245  if(b_visible) {
246  v_items.push_back(row);
247  rec.m_Row->SetRowState(IAlignRow::fItemHidden, false);
248  }
249  }
250  }
251  if(b_visible) {
252  TNumrowModelImpl::InsertItems(v_items, v_indices, false);
253  } else {
254  TNumrowModelImpl::DeleteItems(v_indices, false);
255  }
256  }
258 
259  if(x_UsingAutoSort()) {
260  x_DoUpdateRowsOrder(); // applying sorting
261  }
262 
263  SetPortLimits();
265 
266  }
267 }
268 
270 {
271  return m_Port;
272 }
273 
275 {
276  return m_Port;
277 }
278 
280 {
281  return (TNumrow) m_vVisibleRows.size();
282 }
283 
285 {
286  return SLM_GetFocusedItemIndex();
287 }
288 
289 bool CAlnMultiModel::IsItemSelected(int index) const
290 {
291  return SLM_IsItemSelected(index);
292 }
293 
295 {
296  return x_GetRowByLine(i_line);
297 }
298 
300 {
302  return rec.IsVisible() ? rec.m_Line : -1;
303 }
304 
306 {
307  return m_MasterRow.GetPointerOrNull();
308 }
309 
310 
312 {
314 }
315 
316 
318 {
319  const TModelRect& rcL = m_Port.GetModelLimitsRect();
320  if(Y < rcL.Top() || Y > rcL.Bottom())
321  return -1;
322  else {
323  vector<int>::const_iterator it = lower_bound(m_vVisibleRowPos.begin(), m_vVisibleRowPos.end(), Y);
324  return int(it - m_vVisibleRowPos.begin()) - 1;
325  }
326 }
327 
328 int CAlnMultiModel::GetLinePosY(int index) const
329 {
330  if (m_vVisibleRowPos.empty())
331  return 0;
332  return m_vVisibleRowPos[index];
333 }
334 
336 {
337  const IAlignRow* row = x_GetRowByLine(line);
338  if (!row)
339  return 0;
340  return row->GetHeightPixels();
341 }
342 
343 
345 {
346  return true;
347 }
348 
349 
351 {
352  vector<TNumrow> nothing;
353  SetVisible(nothing, false, true); // hide nothing and make other visible
354 }
355 
356 
358 {
359  m_AutoSort = b_en;
360 }
361 
362 
364 {
365  m_AutoSort = true;
366 
369 }
370 
371 
372 // override this function in a derived class
374 {
375  m_SortColumn = type;
378  } else {
380  }
381 
382  size_t n = m_vVisibleRows.size();
383 
384  switch(m_SortColumn) {
385  case IAlignRow::eDescr:
386  case IAlignRow::eTaxLabel:
388  case IAlignRow::eCountry:
390  case IAlignRow::eHost:
392  {
393  CPairSorter<SRowRecord*, string> sorter(ascending);
395  data.reserve(n);
396 
397  for (size_t i = 0; i < n; ++i) {
398  SRowRecord* rec = m_vVisibleRows[i];
399  IAlignRow* row = rec->m_Row;
400  string s;
401  if (row)
402  row->GetColumnText(type, s);
403  data.emplace_back(rec, s);
404  }
405 
406  sorter.Sort(data);
407 
408  for( size_t i = 0; i < n; ++i) {
409  m_vVisibleRows[i] = data[i].first;
410  }
413  return true; // sorted
414  }
417  //case IAlignRow::eAlignmentScore:
418  {
419  CPairSorter<SRowRecord*, float> sorter(ascending);
421  data.reserve(n);
422  const TModelRect& rc_vis = m_Port.GetVisibleRect();
423  for (size_t i = 0; i < n; ++i) {
424  SRowRecord* rec = m_vVisibleRows[i];
425  IAlignRow* row = rec->m_Row;
426  auto val = row ? row->GetColumnAsFloat(type) : 0.;
427  data.emplace_back(rec, val);
428  }
429  sorter.Sort(data);
430  for (size_t i = 0; i < n; ++i) {
431  m_vVisibleRows[i] = data[i].first;
432  }
435  return true; // sorted
436  }
437  case IAlignRow::eStart:
438  case IAlignRow::eEnd:
440  case IAlignRow::eSeqEnd:
443  case IAlignRow::eInvalid: {
444  CPairSorter<SRowRecord*, TSeqPos> sorter(ascending);
446  data.reserve(n);
447  const TModelRect& rc_vis = m_Port.GetVisibleRect();
448  for (size_t i = 0; i < n; ++i) {
449  SRowRecord* rec = m_vVisibleRows[i];
450  IAlignRow* row = rec->m_Row;
451  TSeqPos pos = 0xFFFFFFFF;
452  if (row)
453  pos = (m_SortColumn == IAlignRow::eInvalid) ? row->GetRowNum() : row->GetColumnAsSeqPos(type, rc_vis);
454  data.emplace_back(rec, pos);
455  }
456 
457  sorter.Sort(data);
458 
459  for (size_t i = 0; i < n; ++i) {
460  m_vVisibleRows[i] = data[i].first;
461  }
464  return true; // sorted
465  }
466  default:
467  break;
468  }
469 
470  return false; // did not do anything
471 }
472 
473 
475 {
477  return m_SortState;
478  } else {
479  switch(type) {
480  case IAlignRow::eDescr:
481  case IAlignRow::eStart:
482  case IAlignRow::eEnd:
484  case IAlignRow::eSeqEnd:
488  case IAlignRow::eCountry:
490  case IAlignRow::eHost:
494  //case IAlignRow::eAlignmentScore:
497  default:
499  }
500  }
501 }
502 
503 
505 {
506  return m_ShownElements;
507 }
508 
509 
511 {
512  m_ShownElements = shown_mask;
513 }
514 
515 
516 /// Moves specified rows into a specified postion.
517 /// order can be changed only for visible rows, hidden will be ignored.
518 /// This operation cancel Auto Sorting mode.
519 void CAlnMultiModel::SetRowOrder(const vector<TNumrow>& rows, int pos)
520 {
521  m_AutoSort = false; // cancel auto sorting
522 
523  int n_vis = (int) m_vVisibleRows.size();
524  if(pos >= 0 && pos < n_vis) {
525  vector<SRowRecord*> new_vis(n_vis, (SRowRecord*)NULL);
526  // new container to replace m_vVisibleRows
527 
528  // move specified rows to new_order and replace them with NULL in m_vVisibleRows
529  int i = 0, line = pos;
530  for( ; i < (int) rows.size() && line < n_vis; i++ ) {
531  TNumrow row = rows[i];
532  SRowRecord* p_rec = &x_GetRecordByRow(row);
533 
534  if(p_rec->IsVisible()) {
535  new_vis[line] = p_rec;
536  m_vVisibleRows[p_rec->m_Line] = NULL; // remove from m_vVisibleRows
537  line++;
538  }
539  }
540 
541  // move the rest of the rows (those that are not NULL) preserving existing order
542  // move first "pos" elements and insert them before "pos" position
543  i = 0; // current postion in m_vVisibleRow
544  int ins_i = 0; // insertion position in new_vis
545  while(ins_i < pos) {
546  for( ; m_vVisibleRows[i] == NULL && i < n_vis; i++ ) { // skip
547  }
548  _ASSERT(i < n_vis);
549  new_vis[ins_i++] = m_vVisibleRows[i++];
550  }
551  // copy the rest of rows to new_vis after "line"
552  ins_i = line;
553  while(ins_i < n_vis) {
554  for( ; m_vVisibleRows[i] == NULL && i < n_vis; i++ ) { // skip
555  }
556  _ASSERT(i < n_vis);
557  new_vis[ins_i++] = m_vVisibleRows[i++];
558  }
559 
560  // assign new_vis to m_vVisibleRows
561  m_vVisibleRows = new_vis;
562 
565  }
566 }
567 
568 
570 {
571  m_DataSource = ds;
572 
573  if(m_DataSource) {
574  //TODO m_DataSource->SetGapChar('-');
576 
577  if (m_Style != NULL)
579  }
580 
582 
583  UpdateOnDataChanged(); // before it called Widget's version of function
584 }
585 
586 
588 {
589  m_Listener = listener;
590 }
591 
592 
593 ////////////////////////////////////////////////////////////////////////////////
594 /// Update handlers
595 
597 {
599 /*
600  NON_CONST_ITERATE(TRowToRecMap, it, m_RowToRec) {
601  // Exception when element is not initialized possible. JIRA : GB-1255
602  if (*it) delete (*it)->m_Row;
603  delete *it;
604  }
605  m_RowToRec.clear();
606 */
607 
608  m_MasterRow.Reset();
610  m_vVisibleRows.clear();
611  m_vVisibleRowPos.clear();
612 
613  m_RowToRec.clear();
614 }
615 
616 
617 /// Creates IAlignRow objects for each row in the data source.
619 {
620 // _ASSERT(CThread::GetSelf() == 0);
621  if(m_DataSource) {
622  _ASSERT(m_RowToRec.size() == 0); // && m_MasterRow == NULL);
623 
624  const int aln_rows_n = m_DataSource->GetNumRows();
625  int pane_rows_n = aln_rows_n; // rows shown in align pane (Master row is not counted)
626 
627  TNumrow MasterRow = -1;
628  int consensus_idx = m_DataSource->GetConsensusRow();
629 
630  //int consensus_idx = m_DataSource->GetConsensusRow();
631  // if (consensus_idx >= 0 && m_Style->m_ShowConsensus) {
632  // m_DataSource->SetAnchor(consensus_idx);
633  // }
634 
635  if (m_DataSource->IsSetAnchor()) {
636  MasterRow = m_DataSource->GetAnchor();
637  const IAlignRowHandle* handle = m_DataSource->GetRowHandle(MasterRow);
638  m_ConsensusRow->SetHandle(handle);
639  --pane_rows_n;
640  }
641 
642  TRowRecVector vVisibleRows;
643  vector<int> vVisibleRowPos;
644  TRowToRecMap RowToRec;
645  try
646  {
647 
648 // m_vVisibleRows.resize(pane_rows_n);
649 // m_vVisibleRowPos.resize(pane_rows_n);
650 
651  vVisibleRows.resize(pane_rows_n);
652  vVisibleRowPos.resize(pane_rows_n);
653 
654  TLine i_line = 0;
655  RowToRec.resize(aln_rows_n);
656  //m_RowToRec.resize(aln_rows_n);
657 
658  for( TNumrow row = 0; row < aln_rows_n; row++ ) {
659  // call a factory method to create a row instance
660  IAlignRow* p_row = 0;
661  // since RADAR might have multiple update events
662  // RADAR codes retains m_MasterRow to avoid rebuilding tracks on every update event
663  if (row == MasterRow && m_MasterRow)
664  p_row = m_MasterRow;
665  else
666  p_row = x_CreateRow(row);
667  // TODO: Do we need same logic as for master row here?
668  if (row == consensus_idx)
669  m_DataConsensusRow = p_row;
670 // m_RowToRec[row] = SRowRecord(p_row, i_line);
671  RowToRec[row] = SRowRecord(p_row, i_line);
672 
673  if(row == MasterRow) {
674  m_MasterRow = p_row;
675  //m_RowToRec[row].m_Row->SetRowState(IAlignRow::fItemHidden, true);
676  RowToRec[row].m_Row->SetRowState(IAlignRow::fItemHidden, true);
677  } else {
678  vVisibleRows[i_line] = &RowToRec[row];
679  //m_vVisibleRows[i_line] = &m_RowToRec[row];
680  i_line++;
681  }
682  }
683  } catch (CException& e) {
684  // if error in the loop all results discarded
685  this->ClearRows();
686  NCBI_THROW(CCoreException, eNullPtr, "Failed to create alignment rows: " + e.GetMsg());
687  } catch (std::exception& e) {
688  // if error in the loop all results discarded
689  this->ClearRows();
690  NCBI_THROW(CCoreException, eNullPtr, "Failed to create alignment rows: " + string(e.what()));
691  }
692 
693  m_vVisibleRows.swap(vVisibleRows);
694  m_vVisibleRowPos.swap(vVisibleRowPos);
695  m_RowToRec.swap(RowToRec);
696 
697  if(x_UsingAutoSort()) {
698  x_DoUpdateRowsOrder(); // applying sorting
699  }
700 
701  // updating CSelListModelImpl
702  TNumrowModelImpl::TItemVector vItems(pane_rows_n);
703  for( size_t i = 0; i < m_vVisibleRows.size(); i++ ) {
704  vItems[i] = m_vVisibleRows[i]->m_Row->GetRowNum();
705  }
706  TNumrowModelImpl::SetItems(vItems, false, false);
707 
709  }
710 }
711 
713 {
716 }
717 
718 
720 {
721  return false; // nothing has been changed
722 }
723 
724 
726 {
727  _ASSERT(x_UsingAutoSort()); // must be called only when auto sorting is enabled
728 
729  // reme
730  TIndex i_focused = SLM_GetFocusedItemIndex();
731  const SRowRecord* p_rec = (i_focused >= 0) ? m_vVisibleRows[i_focused] : NULL;
732 
733  if(x_SortRows()) {
735 
736  // restore focus
737  int line = p_rec ? p_rec->m_Line : -1;
738  SLM_FocusItem(line);
739  }
740 }
741 
742 
744 {
745  for(size_t i = 0; i < m_vVisibleRows.size(); i++ ) {
746  SRowRecord& rec = *m_vVisibleRows[i];
747  rec.m_Line = (int) i;
748  }
749 }
750 
751 
753 {
755  IAlignRow* row = it->m_Row.GetPointer();
756 
757  TNumrow row_num = row->GetRowNum();
758  const CRowDisplayStyle* style = m_StyleCatalog->GetStyleForRow(row_num);
759  row->SetDisplayStyle(style);
760 
761  row->UpdateOnStyleChanged();
762  }
764 
766  SetPortLimits();
767 }
768 
769 
771 {
773  SetPortLimits();
774 }
775 
776 
777 /// recalculates vertical positions of row objects based on their order,
778 /// visibility and height
780 {
781  int N = (int) m_vVisibleRows.size();
782  m_vVisibleRowPos.resize(N);
783  for( int total_H = 0, i = 0; i < N; i++ ) {
784  IAlignRow* pRow = x_GetRowByLine(i);
785  m_vVisibleRowPos[i] = total_H;
786  total_H += pRow->GetHeightPixels();
787  }
788 }
789 
790 
792 {
793  if (m_DataSource) {
794  double Start = m_DataSource->GetAlnStart();
795  double Stop = m_DataSource->GetAlnStop();
796 
797  double H = 0;
798  int iLast = (int) m_vVisibleRows.size() - 1;
799  if(iLast >= 0)
800  H = GetLinePosY(iLast) + GetLineHeight(iLast);
801 
802  m_Port.SetModelLimitsRect(TModelRect(Start, H - 1, Stop + 1, 0));
803  } else {
804  m_Port.SetModelLimitsRect(TModelRect(0, -1, 0, 0));
805  }
806 }
807 
808 
810 {
812 }
813 
814 
816 {
817  //Anchor the row to make it "Master"
818  m_DataSource->SetAnchor(new_master_row);
819 
820  // rearrange Row objects and items
821  IAlignRow* pNewMaster = NULL;
822  if(new_master_row != -1) { // remove row from the Align pane
823  SRowRecord& rec = x_GetRecordByRow(new_master_row);
824  pNewMaster = rec.m_Row;
825 
826  rec.m_Row->SetRowState(IAlignRow::fItemHidden, true);
827 
828  const IAlignRowHandle* handle = m_DataSource->GetRowHandle(new_master_row);
829  m_ConsensusRow->SetHandle(handle);
830 
831  vector<int> vDelItems;
832  vDelItems.push_back(rec.m_Line);
833  DeleteItems(vDelItems, false);
834  }
835  else {
837  }
838 
839  if(m_MasterRow) { // insert current Master into Align pane
840  TNumrow row = m_MasterRow->GetRowNum();
842  TLine line = min(rec.m_Line, (TLine) m_vVisibleRows.size());
843 
844  rec.m_Row->SetRowState(IAlignRow::fItemHidden, false);
845  InsertItem(line, m_MasterRow->GetRowNum(), false);
846  }
847 
848  m_MasterRow = pNewMaster;
849 
850  // update rows - they may be affected by this change
852  IAlignRow* row = it->m_Row.GetPointer();
853  row->UpdateOnAnchorChanged();
854  }
855 
856  if(x_UsingAutoSort()) {
857  x_DoUpdateRowsOrder(); // applying sorting
858  }
860 
861  SetPortLimits(); // set new limits
862 
864  return true;
865 }
866 
867 
869 {
870  ClearRows();
871 
872  if(m_DataSource) {
873  CreateRows();
874  SetPortLimits();
875  }
876 
878 
881  }
882 }
883 
884 
886 {
887  // this can be eliminated if scores are saved in seq coords
888  if(m_EnableScoring) {
890  }
891 }
892 
893 
895 {
898  }
899 }
900 
901 
903 {
904  return m_AutoSort;
905 }
906 
907 
909 {
910  if (m_vVisibleRows.empty())
911  return 0;
912  _ASSERT(index >= 0 && (size_t) index < m_vVisibleRows.size());
913  SRowRecord* p_rec = m_vVisibleRows[index];
914  return static_cast<IAlignRow*>(p_rec->m_Row);
915 }
916 
917 
919 {
920  if (m_vVisibleRows.empty())
921  return 0;
922  _ASSERT(index >= 0 && (size_t)index < m_vVisibleRows.size());
923  SRowRecord* p_rec = m_vVisibleRows[index];
924  return static_cast<IAlignRow*>(p_rec->m_Row);
925 }
926 
927 
929 {
930  CIRef<IScoringMethod> ref(method);
931  TMethods::const_iterator it = std::find(m_Methods.begin(), m_Methods.end(), ref);
932  if(it == m_Methods.end()) {
933  m_Methods.push_back(ref);
934  return true;
935  }
936  return false;
937 }
938 
939 
941 {
942  return m_Methods;
943 }
944 
945 
946 bool CAlnMultiModel::SetCurrentMethod(const string& name, const TSeqRange& range)
947 {
948  ITERATE(TMethods, it, m_Methods) {
949  CIRef<IScoringMethod> method = *it;
950  if(method->GetName() == name) { // found it
953  return true;
954  }
955  }
956  return false;
957 }
958 
959 
961 {
964 }
965 
966 
968 {
969  if(m_DataSource) {
970  switch(m_DataSource->GetAlignType()) {
971  case IAlnExplorer::fDNA:
972  return m_Style->m_DefDNAMethod;
974  return m_Style->m_DefProteinMethod;
975  default:
976  break;
977  }
978  }
979  return "";
980 }
981 
982 
983 void CAlnMultiModel::SetDefaultMethod(const string& method_name)
984 {
985  if(m_DataSource) {
986  switch(m_DataSource->GetAlignType()) {
987  case IAlnExplorer::fDNA:
988  m_Style->m_DefDNAMethod = method_name;
989  break;
991  m_Style->m_DefProteinMethod = method_name;
992  break;
993  default:
994  break;
995  }
996  } else _ASSERT(false);
997 }
998 
999 
1000 void CAlnMultiModel::OnScoringProgress(float progress, const string& msg)
1001 {
1002  if(m_Listener) {
1003  m_Listener->OnScoringProgress(progress, msg);
1004  }
1005 }
1006 
1007 
1009 {
1010  if(m_Listener) {
1012  }
1013 }
1014 
1015 
1017 {
1018  return m_ScoreCache->GetScoringMethod();
1019 }
1020 
1021 
1023 {
1025 }
1026 
1027 
1029 {
1030  return m_ScoreCache->GetScoringMethod();
1031 }
1032 
1033 
1034 ////////////////////////////////////////////////////////////////////////////////
1035 // CSelListModelImpl virtual functions
1036 
1038 {
1039  if (m_MasterRow)
1040  m_MasterRow->SetRowState(IAlignRow::fItemSelected, bSelect);
1041 
1043 }
1044 
1046 {
1047  if (m_MasterRow)
1049  (index == kMasterRowIndex) ? true : false);
1050 
1052 }
1053 
1055 {
1056  if (m_MasterRow && index == kMasterRowIndex) {
1057  bool selected = (m_MasterRow->GetRowState()&IAlignRow::fItemSelected) != 0;
1058  m_MasterRow->SetRowState(IAlignRow::fItemSelected, !selected);
1059  }
1060  else
1062 }
1063 
1064 void CAlnMultiModel::x_SelectItem(TIndex index, bool b_sel)
1065 {
1066  if (m_vVisibleRows.empty())
1067  return;
1068  m_vVisibleRows[index]->m_Row->SetRowState(IAlignRow::fItemSelected, b_sel);
1069 }
1070 
1071 
1073 {
1074  if (m_vVisibleRows.empty())
1075  return false;
1076  return m_vVisibleRows[index]->IsSelected();
1077 }
1078 
1079 
1080 // returns number of visible rows (lines)
1082 {
1083  return (TIndex) m_vVisibleRows.size();
1084 }
1085 
1086 
1088 {
1089  _ASSERT(x_GetRowByLine(index));
1090  TNumrow row = x_GetRowByLine(index)->GetRowNum();
1091  return row;
1092 }
1093 
1094 
1096 {
1097  size_t entries_n = v_entries.size();
1098  m_vVisibleRows.resize(entries_n);
1099  for( size_t i = 0; i < entries_n; i++ ) {
1100  TNumrow row = v_entries[i].first;
1101  SRowRecord& rec = m_RowToRec[row];
1102  rec.m_Line = (int) i;
1103  rec.m_Row->SetRowState(IAlignRow::fItemSelected, v_entries[i].second);
1104  rec.m_Row->SetRowState(IAlignRow::fItemHidden, false);
1105 
1106  m_vVisibleRows[i] = &rec;
1107  }
1108 }
1109 
1110 
1112 {
1113  SRowRecord& rec = m_RowToRec[item];
1114  return rec.IsVisible() ? rec.m_Line : -1;
1115 }
1116 
1117 
1119 {
1120  TNumrow row = entry.first;
1121  SRowRecord& p_rec = m_RowToRec[row];
1122  p_rec.m_Row->SetRowState(IAlignRow::fItemSelected, entry.second);
1123  p_rec.m_Line = index;
1124  m_vVisibleRows.insert(m_vVisibleRows.begin() + index, &p_rec);
1125 }
1126 
1127 
1129 {
1131 }
1132 
1133 
1135 {
1136  m_vVisibleRows[index]->m_Row->SetRowState(IAlignRow::fItemHidden, true);
1137  m_vVisibleRows[index]->m_Row->SetRowState(IAlignRow::fItemSelected, false);
1138  m_vVisibleRows[index] = NULL;
1139 }
1140 
1141 
1143 {
1144  int shift = 0;
1145  int count = (int) m_vVisibleRows.size();
1146  for(int i = 0; i < count; i++ ) {
1147  if(m_vVisibleRows[i]) {
1148  if(shift >0) {
1149  m_vVisibleRows[i - shift] = m_vVisibleRows[i];
1150  m_vVisibleRows[i - shift]->m_Line = i - shift;
1151  }
1152  } else shift++;
1153  }
1154  m_vVisibleRows.resize(m_vVisibleRows.size() - shift);
1155 }
1156 
1157 
1159 {
1160  for( size_t i = 0; i < m_vVisibleRows.size(); i++ ) {
1161  if (m_vVisibleRows[i]) { // Exception when element is not initialized possible. JIRA : GB-1255
1162  m_vVisibleRows[i]->m_Row->SetRowState(IAlignRow::fItemHidden, true);
1163  m_vVisibleRows[i]->m_Row->SetRowState(IAlignRow::fItemSelected, false);
1164  }
1165  }
1166 
1167  m_vVisibleRows.clear();
1168 }
1169 
1171 {
1172  // do nothing
1173 }
1174 
1175 
1176 
USING_SCOPE(objects)
static const int kColorGradNumber
virtual void x_CompleteInsertion()
performs update after all items have been inserted
virtual void EnableBackgroundProcessing(bool en)
virtual bool CanChangeMasterRow() const
changes Master (Anchor) and performs necessary updates
virtual void CreateConsensus(void)
Creates consenus row if it is not already created.
virtual void OnScoringFinished()
SRowRecord & x_GetRecordByRow(TNumrow row)
virtual int GetLineByRowNum(TNumrow row) const
virtual void SetDefaultMethod(const string &method_name)
virtual void x_UpdateMinScale()
CScoreCache::IListener * m_Listener
const CRowStyleCatalog * m_StyleCatalog
virtual void UpdateSortOrder(void)
enables auto sorting of rows, sorts rows using x_SortRows() and performs necessary updates
virtual bool AddScoringMethod(IScoringMethod *method)
adds scoring method; model assumes ownership of the method, it will be deleted automatically
CAlnMultiModel()
number of gradient colors in alignment
virtual CWidgetDisplayStyle * GetDisplayStyle()
virtual TNumrow GetLinesCount() const
NUmber of visible lines.
TSortState m_SortState
TRowRecVector m_vVisibleRows
line number SRowRecord* for visible rows
virtual string GetDefaultMethod(void)
bool m_EnableScoring
scoring support
virtual TSortState GetColumnSortState(TColumnType type)
returns sorting state for the specified column
virtual int GetLineByModelY(int Y) const
CIRef< IAlignRow > m_DataConsensusRow
IAligRow corresponding to consensus in the data.
virtual const IScoringMethod * GetCurrentMethod() const
virtual TIndex x_GetItemIndex(const TItem &item)
virtual void x_ClearItems(void)
virtual void x_CreateDisplayStyle()
void SetPortLimits(void)
virtual int GetLineHeight(TLine line) const
@ kMasterRowIndex
dummy master row index used in selection logic
virtual void x_UpdateOnCoordsChanged()
virtual void UpdateOnScoringChanged(const TSeqRange &range=TSeqRange::GetEmpty())
virtual void Init()
virtual IAlignRow * GetConsensusRow()
virtual void x_DoUpdateRowPositions(void)
recalculates vertical coordinates of row objects
CRef< CScoreCache > m_ScoreCache
virtual void x_InsertItem(TIndex index, const TItemEntry &entry)
inserts item, but does not updates all data structures
virtual void OnScoringProgress(float progress, const string &msg)
virtual void CreateRows(void)
Creates IAlignRow objects for each row in the data source.
virtual void x_EraseMarkedItems(void)
deletes all marked items in a single pass, performs neccessary updates
const size_t GetNumRows() const
Get number of rows registered in model.
virtual void EnableAutoSorting(bool b_en)
enables auto sorting but does not perform any updates
vector< SRowRecord > TRowToRecMap
virtual void SLM_InvertSingleItem(TIndex index)
virtual void SetRowOrder(const vector< TNumrow > &rows, int pos=0)
disables auto sorting, reorders rows in alignment so that rows from the given vector appear in the sp...
virtual int GetFocusedItemIndex() const
virtual TItem x_GetItem(TIndex index) const
virtual void SetStyleCatalog(const CRowStyleCatalog *catalog)
virtual void ClearRows(void)
Update handlers.
virtual bool IsRendererFocused()
virtual void UpdateOnRowHChanged(void)
updates model after row height changed
virtual void SetListener(CScoreCache::IListener *listener)
TColumnType m_SortColumn
virtual IAlignRow * GetMasterRow()
list< CIRef< IScoringMethod > > TMethods
virtual bool SetMasterRow(TNumrow new_row)
virtual IAlignRow * GetRowByLine(TLine line)
all Y coordinates are OpenGL Viewport coordinates (not widget coords) "index" is a line index (not ro...
virtual bool IsItemSelected(int index) const
virtual bool x_SortRows(void)
This is a sorting callback automatically invoked by CAlnMultiModel when necessary.
virtual void SetShownElements(int shown_mask)
CRef< CConsensusRow > m_ConsensusRow
int GetRowState(TNumrow row) const
returns a combination of IAlignRow::EState flags
virtual void UpdateOnStyleChanged(void)
vector< int > m_vVisibleRowPos
bottom positions for visible rows[line]
virtual void x_UpdateOnVisibilityChanged(void)
CWidgetDisplayStyle * m_Style
virtual bool x_IsItemSelected(TIndex index) const
virtual void x_SetEntries(const TEntryVector &v_entries)
TMethods m_Methods
registered scoring methods
virtual IAlignRow * x_CreateRow(TNumrow row)
factory method for creating IAlignRow instances
TRowToRecMap m_RowToRec
map storing records for all rows
virtual void x_SelectItem(TIndex index, bool b_sel)
updates line numbers in SRowRecords
virtual int GetLinePosY(TLine line) const
IAlignRow * x_GetRowByLine(int Index)
virtual void UpdateOnDataChanged()
virtual ~CAlnMultiModel()
virtual void SLM_SelectAll(bool bSelect)
virtual void x_MarkItemForErase(TIndex index)
mark item for deletion
virtual bool x_UsingAutoSort() const
IAlignRow::TColumnType TColumnType
bool m_AutoSort
sorting support
void SetVisible(vector< TNumrow > rows, bool b_visible, bool b_invert_others=false)
makes specified rows visible/hidden, if b_invert_others == "true" then visibility of all rows not in ...
virtual const TMethods & GetMethods()
CIRef< IAlignRow > m_MasterRow
IAligRow corresponding to Anchor.
virtual void ResetCurrentMethod()
virtual void SetDataSource(IAlnMultiDataSource *p_ds)
virtual int GetShownElements()
returns mask of shown elements - header, ruler, master row, alignment, track matrix
virtual void x_DoUpdateRowsOrder(void)
performs sorting by invoking x_SortRows() and updates line numbers
virtual bool SortByColumn(TColumnType type, bool ascending)
sorts visible rows by specified column, return "false" if sorting is not supported (nothin happened)
vector< SRowRecord * > TRowRecVector
IAlnMultiDataSource * m_DataSource
virtual bool SetCurrentMethod(const string &name, const TSeqRange &range=TSeqRange::GetEmpty())
void x_DoUpdateRowLines(void)
CGlPane & GetAlignPort()
virtual TIndex x_GetItemsCount() const
virtual void SLM_SelectSingleItem(TIndex index)
class CAlnVecRow - implementation of IAlignRow for CAlnVec-based alignments.
Definition: align_row.hpp:82
void SetConsensus(CConsensusRow *crow)
Definition: align_row.hpp:90
virtual void SetDisplayStyle(const CRowDisplayStyle *style)
Definition: align_row.cpp:322
virtual void SetScoreCache(CScoreCache *cache)
Definition: align_row.cpp:135
Class CConsensusRow - Simple interface to a row that represents the consensus for rendering purposes.
void SetHandle(const IAlignRowHandle *h)
CCoreException –.
Definition: ncbiexpt.hpp:1476
class CGlPane
Definition: glpane.hpp:62
CPairSorter.
vector< TPair > TPairVector
void Sort(TPairVector &data)
CRowDisplayStyle is a base class representing a display style for IAlignRow.
CRowStyleCatalog is a collection of CRowDisplayStyle-s assigned to rows in alignment.
const CRowDisplayStyle * GetStyleForRow(TNumrow row) const
virtual void OnScoringFinished()=0
virtual void OnScoringProgress(float progress, const string &msg)=0
const IScoringAlignment * GetAlignment() const
void SetScoringMethod(IScoringMethod *method)
void SetAlignment(const IScoringAlignment *aln)
void CalculateScores(const TSeqRange &range=TSeqRange::GetEmpty())
Recalculate scores using current method; resets scores if no method is selected.
IScoringMethod * GetScoringMethod()
void EnableBackgoundProcessing(bool en)
Definition: aln_scoring.cpp:97
void SetListener(IListener *listener)
Definition: aln_scoring.cpp:91
void SetGradNumber(int grad_n)
Sets the number of score gradations.
void InsertItems(const TItemVector &v_items, const TIndexVector &v_indices, bool b_update)
vector< TItem > TItemVector
void DeleteItems(const TIndexVector &vIndices, bool b_update)
bool InsertItem(TIndex index, const TItem &item, bool b_update)
vector< TItemEntry > TEntryVector
virtual void SLM_SelectAll(bool bSelect=true)
virtual bool SLM_IsItemSelected(TIndex index) const
virtual void SLM_FocusItem(TIndex index)
virtual void SLM_InvertSingleItem(TIndex index)
virtual TIndex SLM_GetFocusedItemIndex() const
virtual void SLM_SelectSingleItem(TIndex index)
void SetItems(const TItemVector &vItems, bool b_update, bool b_keep_selection=false)
pair< TItem, bool > TItemEntry
CWidgetDisplayStyle is a collection of display properties common for all rows in the CAlnMultiWidget.
string m_DefProteinMethod
default scoring method for DNA alignments
CGlTextureFont m_SeqFont
text font (description, positions etc.)
IAlignRowHandle provides an abstract way to access alignment row data.
Definition: alnmulti_ds.hpp:59
Interface IAlignRow - abstracts row rendering in Multiple Alignment Widget.
Definition: ialign_row.hpp:67
virtual int GetRowNum() const =0
Returns index of row in IAlnMultiDataSource.
virtual void SetRowState(int mask, bool b_set)=0
Set/Clear Row State.
virtual int GetHeightPixels() const =0
Returns height of the row in pixels.
@ ePctIdentity
% identity to consensus or anchor
Definition: ialign_row.hpp:91
@ eIsolationSource
Definition: ialign_row.hpp:87
@ eCollectionDate
Definition: ialign_row.hpp:89
@ ePctCoverage
% coverage to anchor
Definition: ialign_row.hpp:92
@ eMismatches
% number of mismatches to anchor/consensus
Definition: ialign_row.hpp:93
Alignment explorer interface.
IAlnMultiDataSource - interface to a data source representing an abstract multiple alignment.
virtual IAlnExplorer::EAlignType GetAlignType() const =0
virtual const IAlignRowHandle * GetRowHandle(TNumrow row) const =0
virtual bool IsDataReadSync() const
virtual TSeqPos GetAlnStart(void) const =0
virtual int GetConsensusRow() const =0
returns index of the Consensus row or -1 if it doesn't exist
virtual bool CanChangeAnchor(void) const =0
virtual TNumrow GetNumRows(void) const =0
number of rows in alignment
virtual TSeqPos GetAlnStop(void) const =0
virtual bool SetAnchor(TNumrow anchor)=0
virtual bool IsSetAnchor(void) const =0
Anchoring methods.
virtual TNumrow GetAnchor(void) const =0
virtual void SetCreateConsensus(bool b)=0
virtual void CreateConsensus()=0
IAlnExplorer::TNumrow TNumrow
IScoringMethod represents an abstract algorithm for calculating alignment scores and assigning colors...
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
static int type
Definition: getdata.c:31
static const char * catalog
Definition: stats.c:19
#define H(x, y, z)
Definition: md4.c:180
char data[12]
Definition: iconv.c:80
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 NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NULL
Definition: ncbistd.hpp:225
#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
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
void SetModelLimitsRect(const TModelRect &R)
Definition: glpane.hpp:342
T Top() const
Definition: glrect.hpp:84
T Bottom() const
Definition: glrect.hpp:82
TModelRect & GetModelLimitsRect(void)
Definition: glpane.hpp:347
void SetAdjustmentPolicy(int adjust_x, int adjust_y)
Definition: glpane.hpp:383
void EnableZoom(bool en_x, bool en_y)
Definition: glpane.hpp:462
virtual TModelUnit GetMetric(EMetric metric, const char *text=NULL, int len=-1) const
TModelRect & GetVisibleRect(void)
Definition: glpane.hpp:357
void SetMinScaleX(TModelUnit scale)
Definition: glpane.hpp:442
CGlRect< TModelUnit > TModelRect
Definition: gltypes.hpp:54
void SetOriginType(EOriginType type_x, EOriginType type_y)
Definition: glpane.hpp:377
@ eOriginTop
Definition: glpane.hpp:75
@ eOriginLeft
Definition: glpane.hpp:72
@ fShiftToLimits
Definition: glpane.hpp:92
@ fAdjustAll
Definition: glpane.hpp:94
@ eMetric_MaxCharWidth
Definition: glfont.hpp:86
TObjectType * GetPointer(void) THROWS_NONE
Get pointer,.
Definition: ncbiobj.hpp:998
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
TObjectType * GetPointerOrNull(void) THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:986
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
int i
yy_size_t n
range(_Ty, _Ty) -> range< _Ty >
constexpr auto sort(_Init &&init)
Multi-threading – classes, functions, and features.
T max(T x_, T y_)
T min(T x_, T y_)
#define row(bind, expected)
Definition: string_bind.c:73
SRowRecord is a record representing a single alignment row.
CIRef< IAlignRow > m_Row
row object ptr
static bool PRecLineLess(const SRowRecord *rec1, const SRowRecord *rec2)
TLine m_Line
visual line index
Definition: type.c:6
#define _ASSERT
#define N
Definition: crc32.c:57
Modified on Wed May 01 14:23:17 2024 by modify_doxy.py rev. 669887