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

Go to the SVN repository for this file.

1 /* $Id: phytree_format.cpp 90371 2020-06-08 15:55:15Z grichenk $
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  * Author: Greg Boratyn, Irena Zaretskaya
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 #include <corelib/ncbidbg.hpp>
32 
35 #include <objmgr/util/sequence.hpp>
37 
42 
43 
46 
47 
48 // query node colors
49 static const string s_kQueryNodeColor = "255 0 0";
50 static const string s_kQueryNodeBgColor = "255 255 0";
51 static const string s_kSeqOfTypeNodeBgColor = "204 255 204";
52 static const string s_kSeqFromVerifiedMatNodeBgColor = "181 228 240";
53 
54 static const string s_kSeqQueryNodeBgColor = " 255 200 87";
55 static const string s_kSeqReferenceDBNodeBgColor = "114 168 101";
56 static const string s_kSeqKmerBlastNodeBgColor = "83 149 208";
57 static const string s_kBranchColor = "0 0 0 ";
58 
59 
62 
63 // tree leaf label for unknown taxonomy
64 static const string s_kUnknown = "unknown";
65 
66 // initial value for collapsed subtree feature
67 static const string s_kSubtreeDisplayed = "0";
68 static const string s_kNodeSize = "0";
69 
70 // feature value for query nodes
71 const string CPhyTreeFormatter::kNodeInfoQuery = "query";
72 
73 // feature value for sequences from type
74 const string CPhyTreeFormatter::kNodeInfoSeqFromType = "sequence_from_type";
75 
76 const string CPhyTreeFormatter::kNodeInfoSeqFromVerifiedMat = "sequence_from_verified_material";
77 
78 const string CPhyTreeFormatter::kNodeInfoSeqReferenceDB = "sequence_reference_db";
79 
80 const string CPhyTreeFormatter::kNodeInfoSeqKmerBlast = "sequence_KmerBlast";
81 
82 
83 
84 
85 
86 
88  ELabelType label_type,
89  bool mark_query_node,
90  ILinkoutDB* linkoutDB,
91  int linkoutType)
92 
93 {
94  x_Init();
95  m_LinkoutDB = linkoutDB;
96  m_LinkoutType = linkoutType;
97  CRef<CBioTreeContainer> btc = guide_tree_calc.GetSerialTree();
98  vector<int> mark_leaves;
99  if (mark_query_node) {
100  mark_leaves.push_back(0);
101  }
102  x_InitTreeFeatures(*btc, guide_tree_calc.GetSeqIds(),
103  *guide_tree_calc.GetScope(),
104  label_type, mark_leaves,
106  m_SeqTypeMap,
107  m_SimpleTree,
108  m_LinkoutDB,
109  m_LinkoutType);
110 
112 }
113 
114 
116  const vector<int>& mark_leaves,
117  ELabelType label_type)
118 {
119  x_Init();
120 
121  CRef<CBioTreeContainer> btc = guide_tree_calc.GetSerialTree();
122  x_InitTreeFeatures(*btc, guide_tree_calc.GetSeqIds(),
123  *guide_tree_calc.GetScope(),
124  label_type, mark_leaves,
126  m_SeqTypeMap,
127  m_SimpleTree,
128  m_LinkoutDB,
129  m_LinkoutType);
130 
132 }
133 
134 
136  vector<string>& seq_ids,
137  ELabelType label_type,
138  ILinkoutDB* linkoutDB,
139  int linkoutType,
140  string mv_build_name)
141 {
142  x_Init();
143  vector<int> mark_leaves;
144  m_LinkoutDB = linkoutDB;
145  m_LinkoutType = linkoutType;
146  m_MapViewerBuildName = mv_build_name;
147 
148  CRef<CBioTreeContainer> btc = guide_tree_calc.GetSerialTree();
149  x_InitTreeFeatures(*btc, guide_tree_calc.GetSeqIds(),
150  *guide_tree_calc.GetScope(),
151  label_type, mark_leaves,
153  m_SeqTypeMap,
154  m_SimpleTree,
155  m_LinkoutDB,
156  m_LinkoutType);
157 
158  x_MarkLeavesBySeqId(*btc, seq_ids, *guide_tree_calc.GetScope());
159 
161 }
162 
163 
166 {
167  x_Init();
168 
169  x_InitTreeLabels(btc,lblType);
171 }
172 
173 
175  const vector< CRef<CSeq_id> >& seqids,
176  CScope& scope,
178  bool mark_query_node)
179 {
180  x_Init();
181  vector<int> mark_leaves;
182  if (mark_query_node) {
183  mark_leaves.push_back(0);
184  }
185  x_InitTreeFeatures(btc, seqids, scope, lbl_type, mark_leaves,
187  m_SeqTypeMap,
188  m_SimpleTree,
189  m_LinkoutDB,
190  m_LinkoutType);
191 
193 }
194 
196  map < string, int > &seqTypeMap,
197  ELabelType lbl_type,
198  bool simpleTree)
199 {
200 
201  x_Init();
202  m_SeqTypeMap = seqTypeMap;
203  m_SimpleTree = simpleTree;
204  CRef<CBioTreeContainer> btc = guide_tree_calc.GetSerialTree();
205  //Query
206  vector<int> mark_leaves;
207  mark_leaves.push_back(0);
208 
209  x_InitTreeFeatures(*btc, guide_tree_calc.GetSeqIds(),
210  *guide_tree_calc.GetScope(),
211  lbl_type, mark_leaves,
213  m_SeqTypeMap,
214  m_SimpleTree,
215  m_LinkoutDB,
216  m_LinkoutType);
217 
219 }
220 
222  : m_Dyntree(tree)
223 {
224  x_Init();
225 }
226 
227 
230 {
231  switch (format) {
232  case eNewick: return PrintNewickTree(out);
233  case eNexus : return PrintNexusTree(out);
234  case eASN : return WriteTree(out);
235  }
236 
237  return false;
238 }
239 
241 {
243 
244  return true;
245 }
246 
247 
249 {
250  // an array of labels is needed for Nexus format, here it is discarded
251  vector<string> labels;
252  x_PrintNewickTree(ostr, *m_Dyntree.GetTreeNode(), labels);
253  ostr << NcbiEndl;
254  return true;
255 }
256 
258  const string& tree_name)
259 {
260  // generate tree in Newick format and collect leaf labels
261  vector<string> labels; // tree leaf labels
262  CNcbiOstrstream buff;
263  x_PrintNewickTree(buff, *m_Dyntree.GetTreeNode(), labels, false);
264 
265  CNcbiOstrstreamToString s(buff);
266  string tree(s);
267 
268  // print tree in nexus format using the labels and tree generated above
269  ostr << "#NEXUS"
270  << NcbiEndl << NcbiEndl;
271 
272  ostr << "BEGIN TAXA;" << NcbiEndl
273  << " DIMENSIONS ntax=" << labels.size() << ";" << NcbiEndl
274  << " TAXLABELS";
275  ITERATE (vector<string>, it, labels) {
276  ostr << " " << *it;
277  }
278  ostr << ";" << NcbiEndl;
279  ostr << "ENDBLOCK;" << NcbiEndl << NcbiEndl;
280 
281  ostr << "BEGIN TREES;" << NcbiEndl
282  << " TREE " << tree_name << " = " << tree
283  << NcbiEndl
284  << "ENDBLOCK;" << NcbiEndl;
285 
286  return true;
287 }
288 
289 
291 {
293 }
294 
296 {
297  string outFileName = "tmp/treeTraverse.txt";
298  CNcbiOfstream ostr(outFileName.c_str());
299 
300  CPhyTreeNodeAnalyzer groupper
305  m_Dyntree,&ostr));
306 
307  if (!groupper.GetError().empty()) {
308  NCBI_THROW(CPhyTreeFormatterException, eTraverseProblem,
309  groupper.GetError());
310  }
311  x_AddFeaturesForInnerNodes(groupper);
312 }
313 
315 {
316 
317  switch (method) {
318 
319  // Do nothing
320  case eNone:
321  break;
322 
323  // Collapse all subtrees with common blast name
324  case eByBlastName :
325  {
326  FullyExpand();
327 
328  CPhyTreeNodeGroupper groupper
332  m_Dyntree));
333 
334  if (!groupper.GetError().empty()) {
335  NCBI_THROW(CPhyTreeFormatterException, eTraverseProblem,
336  groupper.GetError());
337  }
338  x_CollapseSubtrees(groupper);
339  break;
340  }
341 
342  //Fully expand the tree
343  case eFullyExpanded :
344  FullyExpand();
345  break;
346 
347  case eCollapseToViewPort:
349  break;
350 
351  default:
352  NCBI_THROW(CPhyTreeFormatterException, eInvalidOptions,
353  "Invalid tree simplify mode");
354  }
355 
356  m_SimplifyMode = method;
357 }
358 
360 {
361  CBioTreeDynamic::CBioNode* node = x_GetBioNode(node_id);
362 
363  if (x_IsExpanded(*node)) {
364 
365  // Collapsing
366  x_Collapse(*node);
367 
368  // Track labels in order to select proper color for collapsed node
373  m_Dyntree));
374 
375  if (!tracker.GetError().empty()) {
376  NCBI_THROW(CPhyTreeFormatterException, eTraverseProblem,
377  tracker.GetError());
378  }
379 
381  string label = it->first;
382  ++it;
383  for (; it != tracker.End(); ++it) {
384  label += ", " + it->first;
385  }
386  node->SetFeature(GetFeatureTag(eLabelId), label);
387  if (tracker.GetNumLabels() == 1) {
388  node->SetFeature(GetFeatureTag(eNodeColorId),
389  tracker.Begin()->second);
390  }
391  if (tracker.FoundQueryNode()) {
393  }
394  else if (tracker.FoundSeqFromType()) {
396  }
397  else if (tracker.FoundSeqFromVerifiedMat()) {
399  }
400  else if (tracker.FoundSeqReferenceDB()) {
402  }
403  else if (tracker.FoundSeqKmerBlast()) {
405  }
406  int leafCount = tracker.GetLeafCount();
407  if(leafCount != 0) {
408  node->SetFeature(GetFeatureTag(eLeafCountId),NStr::IntToString(leafCount));
409  }
410  }
411  else {
412 
413  // Expanding
414  x_Expand(*node);
415  node->SetFeature(GetFeatureTag(eNodeColorId), "");
416  }
417 
419  return x_IsExpanded(*node);
420 }
421 
422 // Traverse tree from new root up to old root and change parents to children
423 // @param node Parent of new root
424 // @param fid Feature id for node's distance (child's edge length)
425 void s_RerootUpstream(CBioTreeDynamic::CBioNode* node, TBioTreeFeatureId fid)
426 {
427  _ASSERT(node);
428 
429  CBioTreeDynamic::CBioNode* parent
430  = (CBioTreeDynamic::CBioNode*)node->GetParent();
431 
432  if (!parent) {
433  return;
434  }
435 
436  s_RerootUpstream(parent, fid);
437 
438  parent->GetValue().features.SetFeature(fid,
439  node->GetValue().features.GetFeatureValue(fid));
440 
441  node = parent->DetachNode(node);
442  node->AddNode(parent);
443 }
444 
445 void CPhyTreeFormatter::RerootTree(int new_root_id)
446 {
447  CBioTreeDynamic::CBioNode* node = x_GetBioNode(new_root_id);
448 
449  // Collapsed node cannot be a root, so a parent node will be a new
450  // root if such node is selected
451  if (node && x_IsLeafEx(*node) && node->GetParent()) {
452  node = (CBioTreeDynamic::CBioNode*)node->GetParent();
453  }
454 
455  // if new root is already a root, do nothing
456  if (!node->GetParent()) {
457  return;
458  }
459 
460  // tree is deleted when new dyntree root is set, hence the old
461  // root node must be copied and its children moved
462  CBioTreeDynamic::CBioNode* old_root = m_Dyntree.GetTreeNodeNonConst();
463 
464  // get old root children
465  vector<CBioTreeDynamic::CBioNode*> children;
466  CBioTreeDynamic::CBioNode::TParent::TNodeList_I it
467  = old_root->SubNodeBegin();
468 
469  for(; it != old_root->SubNodeEnd();it++) {
470  children.push_back((CBioTreeDynamic::CBioNode*)*it);
471  }
472  NON_CONST_ITERATE (vector<CBioTreeDynamic::CBioNode*>, ch, children) {
473  old_root->DetachNode(*ch);
474  }
475 
476  // copy old root node and attach old root's children
477  CBioTreeDynamic::CBioNode* new_old_root
478  = new CBioTreeDynamic::CBioNode(*old_root);
479  ITERATE (vector<CBioTreeDynamic::CBioNode*>, ch, children) {
480  new_old_root->AddNode(*ch);
481  }
482 
483  // detach new root from the tree
484  CBioTreeDynamic::CBioNode* parent
485  = (CBioTreeDynamic::CBioNode*)node->GetParent();
486  node = parent->DetachNode(node);
487 
488  // replace child - parent relationship in all parents of the new root
490 
491  // make new root's parent its child and set new tree root
492  node->AddNode(parent);
493  m_Dyntree.SetTreeNode(node);
494  parent->SetFeature(GetFeatureTag(eDistId),
495  node->GetFeature(GetFeatureTag(eDistId)));
496 
497  node->SetFeature(GetFeatureTag(eDistId), "0");
498 }
499 
501 {
502  CBioTreeDynamic::CBioNode* node = x_GetBioNode(root_id);
503  _ASSERT(node);
504 
505  // If a collapsed node is clicked, then it needs to be expanded
506  // in order to show the subtree
507  bool collapsed = false;
508  if (!x_IsExpanded(*node)) {
509  collapsed = true;
510  x_Expand(*node);
512  }
513 
514  // replace root, unused part of the tree will be deleted
515  CBioTreeDynamic::CBioNode::TParent* parent = node->GetParent();
516  if (parent) {
517  parent->DetachNode(node);
518  m_Dyntree.SetTreeNode(node);
519  }
520 
521  return collapsed;
522 }
523 
525 {
526  CSingleBlastNameExaminer examiner
529  return examiner.IsSingleBlastName();
530 }
531 
532 
534 {
539 
541  m_LinkoutDB = NULL;
542  m_LinkoutType = 0;
543  m_SimpleTree = false;
544 }
545 
546 
547 CBioTreeDynamic::CBioNode* CPhyTreeFormatter::x_GetBioNode(TBioTreeNodeId id,
548  bool throw_if_null)
549 {
552  CBioNodeFinder(id));
553 
554  if (!finder.GetNode() && throw_if_null) {
555  NCBI_THROW(CPhyTreeFormatterException, eNodeNotFound, (string)"Node "
556  + NStr::IntToString(id) + (string)" not found");
557  }
558 
559  return finder.GetNode();
560 }
561 
562 bool CPhyTreeFormatter::x_IsExpanded(const CBioTreeDynamic::CBioNode& node)
563 {
564  return node.GetFeature(GetFeatureTag(eTreeSimplificationTagId))
566 }
567 
568 bool CPhyTreeFormatter::x_IsLeafEx(const CBioTreeDynamic::CBioNode& node)
569 {
570  return node.IsLeaf() || !x_IsExpanded(node);
571 }
572 
573 void CPhyTreeFormatter::x_Collapse(CBioTreeDynamic::CBioNode& node)
574 {
575  node.SetFeature(GetFeatureTag(eTreeSimplificationTagId), "1");
576 }
577 
578 void CPhyTreeFormatter::x_Expand(CBioTreeDynamic::CBioNode& node)
579 {
580  node.SetFeature(GetFeatureTag(eTreeSimplificationTagId),
582  node.SetFeature(GetFeatureTag(eLeafCountId), NStr::IntToString(0));
583 }
584 
585 
586 //TO DO: Input parameter should be an interface for future groupping options
588 {
589  for (CPhyTreeNodeGroupper::CLabeledNodes_I it=groupper.Begin();
590  it != groupper.End(); ++it) {
591  x_Collapse(*it->GetNode());
592  it->GetNode()->SetFeature(GetFeatureTag(eLabelId), it->GetLabel());
593  it->GetNode()->SetFeature(GetFeatureTag(eNodeColorId), it->GetColor());
594 
595  CQueryNodeChecker query_checker
596  = TreeDepthFirstTraverse(*it->GetNode(),
598 
599  if (query_checker.HasQueryNode()) {
600  x_MarkNode(it->GetNode(), s_kQueryNodeBgColor);
601  }
602  else if (query_checker.HasSeqFromType()) {
603  x_MarkNode(it->GetNode(), s_kSeqOfTypeNodeBgColor);
604  }
605  else if (query_checker.HasSeqFromVerifiedMat()) {
607  }
608  else if (query_checker.HasSeqReferenceDB()) {
610  }
611  else if (query_checker.HasSeqKmerBlast()) {
612  x_MarkNode(it->GetNode(), s_kSeqKmerBlastNodeBgColor);
613  }
614  int leafCount = query_checker.GetLeafCount();
615  if(leafCount != 0) {
616  it->GetNode()->SetFeature(GetFeatureTag(eLeafCountId), NStr::IntToString(leafCount));
617  }
618  }
619 }
620 
621 static void s_InitFeatures(CPhyTreeNodeAnalyzer::TLeafNodeInfoMap nodeMap, string &title, int &leafCount, string &nodeColor)
622 {
623 
624  leafCount = 0;
625 
626  if(nodeMap.size() <= 2) {
628  title = it->first;
629  leafCount = it->second.size();
630  if(nodeMap.size() == 1) { // one blast name
631  nodeColor = it->second[0].nodeColor;
632  }
633  else if(nodeMap.size() == 2) {
634  it++;
635  if(leafCount > it->second.size()) {//if first leafcont > than second
636  title += " and " + it->first;
637  }
638  else {
639 
640  title = it->first + " and " + title;
641  }
642  leafCount += it->second.size();
643  }
644  }
645  else {
646  title = "Multiple organisms";
647  for (auto it = nodeMap.begin(); it != nodeMap.end(); ++it) {
648  vector <CPhyTreeNodeAnalyzer::TLeafNodeInfo> vecInf = it->second;
649  leafCount += vecInf.size();
650  }
651  }
652 }
653 
654 
656 {
657  for (CPhyTreeNodeAnalyzer::CLabeledNodes_I it=groupper.Begin();
658  it != groupper.End(); ++it) {
659 
660  CPhyTreeNodeAnalyzer::TLeafNodeInfoMap *leafInfoMap = it->GetLeafInfoMap();
661  if(leafInfoMap && !(*leafInfoMap).empty()) {
662  string label,nodeColor;
663  int leafCount;
664  s_InitFeatures(*leafInfoMap,label,leafCount,nodeColor);
665  it->GetNode()->SetFeature(GetFeatureTag(eLabelId), label);
666  it->GetNode()->SetFeature(GetFeatureTag(eLeafCountId), NStr::IntToString(leafCount));
667  if(!nodeColor.empty()) {
668  it->GetNode()->SetFeature(GetFeatureTag(eNodeColorId), nodeColor);
669  }
670  }
671 
672  CQueryNodeChecker query_checker
673  = TreeDepthFirstTraverse(*it->GetNode(),
675 
676  if (query_checker.HasQueryNode()) {
677  x_MarkNode(it->GetNode(), s_kQueryNodeBgColor);
678  }
679  else if (query_checker.HasSeqFromType()) {
680  x_MarkNode(it->GetNode(), s_kSeqOfTypeNodeBgColor);
681  }
682  else if (query_checker.HasSeqFromVerifiedMat()) {
684  }
685  else if (query_checker.HasSeqReferenceDB()) {
687  }
688  else if (query_checker.HasSeqKmerBlast()) {
689  x_MarkNode(it->GetNode(), s_kSeqKmerBlastNodeBgColor);
690  }
691  delete leafInfoMap;
692  }
693 }
694 
695 void CPhyTreeFormatter::x_MarkNode(CBioTreeDynamic::CBioNode* node,
696  const string& color)
697 {
698  node->SetFeature(GetFeatureTag(eLabelBgColorId), color);
699 }
700 
701 
702 //Recusrive
704  const CBioTreeDynamic::CBioNode& node,
705  vector<string>& labels,
706  bool name_subtrees /* = true */,
707  bool is_outer_node /* = true */)
708 {
709 
710  string label;
711 
712  if (!node.IsLeaf()) {
713  ostr << '(';
714  for (CBioTreeDynamic::CBioNode::TNodeList_CI it = node.SubNodeBegin(); it != node.SubNodeEnd(); ++it) {
715  if (it != node.SubNodeBegin())
716  ostr << ", ";
717  x_PrintNewickTree(ostr, (CBioTreeDynamic::CBioNode&)**it, labels,
718  name_subtrees, false);
719  }
720  ostr << ')';
721  }
722 
723  if (!is_outer_node) {
724  label = node.GetFeature(GetFeatureTag(eLabelId));
725  if (node.IsLeaf() || !label.empty()) {
726  for (size_t i=0;i < label.length();i++)
727  if (!isalpha(label.at(i)) && !isdigit(label.at(i)))
728  label.at(i) = '_';
729  if (node.IsLeaf() || name_subtrees) {
730  ostr << label;
731  labels.push_back(label);
732  }
733  }
734  ostr << ':' << node.GetFeature(GetFeatureTag(eDistId));
735  }
736  else
737  ostr << ';';
738 }
739 
742 {
743 
744  NON_CONST_ITERATE (CNodeSet::Tdata, node, btc.SetNodes().Set()) {
745  if ((*node)->CanGetFeatures()) {
746  string blastName = "",accNbr;
747  //int id = (*node)->GetId();
748  CRef< CNodeFeature > label_feature_node;
749  CRef< CNodeFeature > selected_feature_node;
750  int featureSelectedID = eLabelId;
751  if (lblType == eSeqId || lblType == eSeqIdAndBlastName) {
752 // featureSelectedID = s_kSeqIdId;
753  featureSelectedID = eAccessionNbrId;
754  }
755  else if (lblType == eTaxName || lblType == eTaxNameAndAccession) {
756  featureSelectedID = eOrganismId;
757  }
758  else if (lblType == eSeqTitle) {
759  featureSelectedID = eTitleId;
760  }
761  else if (lblType == eBlastName) {
762  featureSelectedID = eBlastNameId;
763  }
764  else if (lblType == eCommonName) {
765  featureSelectedID = eCommonNameID;
766  }
767 
769  (*node)->SetFeatures().Set()) {
770 
771 
772  //typedef list< CRef< CNodeFeature > > Tdata
773 
774  if ((*node_feature)->GetFeatureid() == eLabelId) {
775  label_feature_node = *node_feature;
776  }
777  //If label typ = GI and blast name - get blast name here
778  if ((*node_feature)->GetFeatureid() == eBlastNameId &&
779  lblType == eSeqIdAndBlastName) {
780  blastName = (*node_feature)->GetValue();
781  }
782  if ((*node_feature)->GetFeatureid() == eAccessionNbrId &&
783  lblType == eTaxNameAndAccession) {
784  accNbr = (*node_feature)->GetValue();
785  }
786  if ((*node_feature)->GetFeatureid() == featureSelectedID) {
787  // a terminal node
788  // figure out which sequence this corresponds to
789  // from the numerical id we stuck in as a label
790  selected_feature_node = *node_feature;
791  }
792  }
793  if(label_feature_node.NotEmpty() && selected_feature_node.NotEmpty())
794  {
795  string label = selected_feature_node->GetValue();
796  if(lblType == eSeqIdAndBlastName) {
797  //concatinate with blastName
798  label = label + "(" + blastName + ")";
799  }
800  if(lblType == eTaxNameAndAccession) {
801  //concatinate with accession number
802  label = label + "(" + accNbr + ")";
803  }
804  //label_feature_node->SetValue(label);
805  label_feature_node->ResetValue();
806  label_feature_node->SetValue() = label;
807  }
808  }
809  }
810 }
811 
812 
813 
815 {
816  return m_Dyntree.GetTreeNode()->GetValue().GetId();
817 }
818 
819 
820 CBioTreeDynamic::CBioNode* CPhyTreeFormatter::GetNode(TBioTreeNodeId id)
821 {
822  return x_GetBioNode(id, false);
823 }
824 
825 
826 CBioTreeDynamic::CBioNode* CPhyTreeFormatter::GetNonNullNode(TBioTreeNodeId id)
827 {
828  return x_GetBioNode(id, true);
829 }
830 
831 
833 {
836 
837  return btc;
838 }
839 
840 // Get SeqID string from CBioseq_Handle such as gi|36537373
841 // If getGIFirst tries to get gi. If gi does not exist tries to get be 'Best ID'
842 string CPhyTreeFormatter::x_GetSeqIDString(CBioseq_Handle& handle, bool get_gi_first)
843 {
844  CSeq_id_Handle seq_id_handle;
845  bool get_best_id = true;
846 
847  if(get_gi_first) {
848  try {
849  seq_id_handle = sequence::GetId(handle, sequence::eGetId_ForceGi);
850  if(seq_id_handle.IsGi()) {
851  get_best_id = false;
852  }
853  }
854  // This exception is handled by the calling sequence::GetId() below
855  catch(CException&) {}
856  }
857 
858  if(get_best_id) {
859  seq_id_handle = sequence::GetId(handle, sequence::eGetId_Best);
860  }
861  CConstRef<CSeq_id> seq_id = seq_id_handle.GetSeqId();
862  m_TreeSeqIDs.push_back(seq_id);
863  string id_string;
864  (*seq_id).GetLabel(&id_string);
865 
866  return id_string;
867 }
868 
869 
870 // Generate Blast Name-based colors for tree leaves
871 // TO DO: This needs to be redesigned
872 #define MAX_NODES_TO_COLOR 24
873 static string s_GetBlastNameColor(
874  CPhyTreeFormatter::TBlastNameColorMap& blast_name_color_map,
875  string blast_tax_name)
876 {
877  string color = "";
878 
879  //This should be rewritten in more elegant way
880  string colors[MAX_NODES_TO_COLOR]
881  = {"0 0 255", "0 255 0", "191 159 0", "30 144 255",
882  "255 0 255", "223 11 95", "95 79 95", "143 143 47",
883  "0 100 0", "128 0 0", "175 127 255", "119 136 153",
884  "255 69 0", "205 102 0", "0 250 154", "173 255 47",
885  "139 0 0", "255 131 250", "155 48 255", "205 133 0",
886  "127 255 212", "255 222 173", "221 160 221", "200 100 0"};
887 
888 
889  unsigned int i = 0;
890  for(;i < blast_name_color_map.size();i++) {
891  pair<string, string>& map_item = blast_name_color_map[i];
892 
893  if(map_item.first == blast_tax_name) {
894  color = map_item.second;
895  break;
896  }
897  }
898 
899  if(color == "") { //blast name not in the map
900  if(blast_name_color_map.size() >= MAX_NODES_TO_COLOR) {
901  i = MAX_NODES_TO_COLOR - 1;
902  }
903  color = colors[i];
904  blast_name_color_map.push_back(make_pair(blast_tax_name, color));
905  }
906  return color;
907 }
908 
909 
910 
912  const vector< CRef<CSeq_id> >& seqids,
913  CScope& scope,
915  const vector<int>& mark_leaves,
916  TBlastNameColorMap& bcolormap,
917  map < string, int> &seqTypeMap,
918  bool simpleTree,
919  ILinkoutDB* linkoutDB,
920  int linkoutType)
921 {
922  CTaxon1 tax;
923 
924  bool success = tax.Init();
925  if (!success) {
926  NCBI_THROW(CPhyTreeFormatterException, eTaxonomyError,
927  "Problem initializing taxonomy information.");
928  }
929 
930  sequence::CDeflineGenerator defgen;
931 
932  // Come up with some labels for the terminal nodes
933  int num_rows = (int)seqids.size();
934  vector<string> labels(num_rows);
935  vector<string> organisms(num_rows);
936  vector<string> accession_nbrs(num_rows);
937  vector<string> titles(num_rows);
938  vector<string> blast_names(num_rows);
939  vector<string> tax_node_colors(num_rows);
940  vector<CBioseq_Handle> bio_seq_handles(num_rows);
941  vector<string> common_names(num_rows);
942 
943  for (int i=0;i < num_rows;i++) {
944  bio_seq_handles[i] = scope.GetBioseqHandle(*seqids[i]);
945  TTaxId tax_id = ZERO_TAX_ID;
946  try{
947  const COrg_ref& org_ref = sequence::GetOrg_ref(bio_seq_handles[i]);
948  organisms[i] = org_ref.GetTaxname();
949 
950  common_names[i] = org_ref.GetCommon();
951  common_names[i] = (common_names[i].empty()) ? organisms[i] : common_names[i];
952 
953  tax_id = org_ref.GetTaxId();
954  if (success) {
955  tax.GetBlastName(tax_id, blast_names[i]);
956  }
957 
958  if (!success || blast_names[i].empty()) {
959  blast_names[i] = s_kUnknown;
960  }
961  }
962  catch(CException&) {
963  organisms[i] = s_kUnknown;
964  blast_names[i]= s_kUnknown;
965  common_names[i] = s_kUnknown;
966  }
967 
968  try{
969  titles[i] = defgen.GenerateDefline(bio_seq_handles[i]);
970  }
971  catch(CException&) {
972  titles[i] = s_kUnknown;
973  }
974 
975  CSeq_id_Handle accession_handle = sequence::GetId(bio_seq_handles[i],
977 
978  CConstRef<CSeq_id> id = accession_handle.GetSeqId();
979  if (id->Which() == CSeq_id::e_General){
980  const CDbtag& dtg = id->GetGeneral();
981  accession_nbrs[i] = CAlignFormatUtil::GetGnlID(dtg);
982  }
983  if (accession_nbrs[i].empty()) {
984  accession_nbrs[i] = id->GetSeqIdString(true);
985  }
986 
987  tax_node_colors[i] = s_GetBlastNameColor(bcolormap,
988  blast_names[i]);
989 
990  switch (label_type) {
991  case eTaxName:
992  labels[i] = organisms[i];
993  break;
994 
995  case eSeqTitle:
996  labels[i] = titles[i];
997  break;
998 
999  case eBlastName:
1000  labels[i] = blast_names[i];
1001  break;
1002 
1003  case eSeqId:
1004  labels[i] = accession_nbrs[i];
1005  break;
1006 
1007  case eSeqIdAndBlastName:
1008  labels[i] = accession_nbrs[i] + "(" + blast_names[i] + ")";
1009  break;
1010 
1011  case eTaxNameAndAccession:
1012  labels[i] = organisms[i] + "(" + accession_nbrs[i] + ")";
1013  break;
1014 
1015  case eCommonName:
1016  labels[i] = common_names[i];
1017  break;
1018  }
1019 
1020  if (labels[i].empty()) {
1021  CSeq_id_Handle best_id_handle = sequence::GetId(bio_seq_handles[i],
1023 
1024  CConstRef<CSeq_id> best_id = best_id_handle.GetSeqId();
1025  (*best_id).GetLabel(&labels[i]);
1026  }
1027 
1028  }
1029 
1030  // Add attributes to terminal nodes
1045  GetFeatureTag(eLeafCountId), btc);
1048 
1050  GetFeatureTag(eNodeSizeID), btc);
1052  GetFeatureTag(eEdgeColorID), btc);
1053  int num_leaves = 0;
1054  NON_CONST_ITERATE (CNodeSet::Tdata, node, btc.SetNodes().Set()) {
1055  if(simpleTree) {
1057  }
1058  if ((*node)->CanGetFeatures()) {
1060  (*node)->SetFeatures().Set()) {
1061  if ((*node_feature)->GetFeatureid() == eLabelId) {
1062  // a terminal node
1063  // figure out which sequence this corresponds to
1064  // from the numerical id we stuck in as a label
1065 
1066  string label_id = (*node_feature)->GetValue();
1067  unsigned int seq_number;
1068  if(!isdigit((unsigned char) label_id[0])) {
1069  const char* ptr = label_id.c_str();
1070  // For some reason there is "N<number>" now,
1071  // not numerical any more. Need to skip "N"
1072  seq_number = NStr::StringToInt((string)++ptr);
1073  }
1074  else {
1075  seq_number = NStr::StringToInt(
1076  (*node_feature)->GetValue());
1077  }
1078 
1079  if ((int)seq_number >= num_rows) {
1080  NCBI_THROW(CPhyTreeFormatterException, eInvalidInput,
1081  "Number of Seq-ids is smaller than number "
1082  "of tree leaves");
1083  }
1084  num_leaves++;
1085 
1086  // Replace numeric label with real label
1087  (*node_feature)->SetValue(labels[seq_number]);
1088 
1089  //Gets gi, if cnnot gets best id
1090  string id_string = x_GetSeqIDString(bio_seq_handles[seq_number],true);
1091 
1092  x_AddFeature(eSeqIdId, id_string, node);
1093 
1094 
1095  // add organism attribute if possible
1096  if (!organisms[seq_number].empty()) {
1097  x_AddFeature(eOrganismId, organisms[seq_number], node);
1098  }
1099 
1100  // add seq-title attribute if possible
1101  if (!titles[seq_number].empty()) {
1102  x_AddFeature(eTitleId, titles[seq_number], node);
1103  }
1104  // add blast-name attribute if possible
1105  if (!accession_nbrs[seq_number].empty()) {
1106  x_AddFeature(eAccessionNbrId, accession_nbrs[seq_number],
1107  node);
1108  }
1109  // add blast-name attribute if possible
1110  if (!blast_names[seq_number].empty()) {
1111  x_AddFeature(eBlastNameId, blast_names[seq_number],
1112  node);
1113  }
1114  // add common name attribute if possible
1115  if (!common_names[seq_number].empty()) {
1116  x_AddFeature(eCommonNameID, common_names[seq_number], node);
1117  }
1118 
1120  node);
1121  if (seqTypeMap.empty()) {
1123  tax_node_colors[seq_number], node);
1124  }
1125 
1126  int seqType = eSeqTypeNotFound;
1127  if (!seqTypeMap.empty()) {
1128  seqType = x_FindSeqType(seqTypeMap,id_string);
1129  }
1130  // mark query node
1131  if (!mark_leaves.empty()
1132  && binary_search(mark_leaves.begin(),
1133  mark_leaves.end(), seq_number)) {
1134 
1135  // color for query node
1136  if(seqType == eSeqTypeQuery) {
1139  }
1140  else {
1142  s_kQueryNodeBgColor, node);
1143  }
1145  s_kQueryNodeColor, node);
1146 
1148 
1149  }
1150  // mark sequence of type, unless the node represents query
1151  else if(linkoutDB) {
1152  int seqLinkout = linkoutDB->GetLinkout(*seqids[seq_number],"");
1153  string nodeInfo,bgColor;
1154  if(seqLinkout & eFromType) {
1156  nodeInfo = kNodeInfoSeqFromType;
1157  }
1158  else if(seqLinkout & eFromVerifiedMaterial) {
1160  nodeInfo = kNodeInfoSeqFromVerifiedMat;
1161  }
1162  // color for "linkout" node
1163  if(!bgColor.empty()) {
1165  x_AddFeature(eNodeInfoId,nodeInfo,node);
1166  }
1167  }
1168  else if (!seqTypeMap.empty()) {
1169  int seqType = x_FindSeqType(seqTypeMap,id_string);
1170  string nodeInfo,bgColor;
1171  if(seqType == eSeqTypeReferenceDB) {
1173  nodeInfo = kNodeInfoSeqReferenceDB;
1174  }
1175  else if(seqType == eSeqTypeKmerBlast) {
1177  nodeInfo = kNodeInfoSeqKmerBlast;
1178  }
1179  //color for ReferenceDB KmerBlast
1180  if(!bgColor.empty()) {
1182  x_AddFeature(eNodeInfoId,nodeInfo,node);
1183  }
1184  }
1185 
1186  // done with this node
1187  break;
1188  }
1189  else if(simpleTree) {
1191  break;
1192  }
1193  }
1195  }
1196  else if(simpleTree) {
1198  }
1199  }
1200 
1201  if ((int)num_rows != num_leaves) {
1202  NCBI_THROW(CPhyTreeFormatterException, eInvalidInput, "There are more Seq-ids"
1203  " then tree leaves");
1204  }
1205 }
1206 
1207 int CPhyTreeFormatter::x_FindSeqType(map<string, int > &seqTypeMap, string idString)
1208 {
1209  int seqType = eSeqTypeNotFound;
1210  map<string, int>::const_iterator iter = seqTypeMap.find(idString);
1211  if ( iter != seqTypeMap.end() ){
1212  seqType = iter->second;
1213  }
1214  return seqType;
1215 }
1216 
1217 
1219  vector<string>& ids,
1220  CScope& scope)
1221 {
1222 
1223  vector< pair< CNode*, CSeq_id_Handle> > nodes;
1224  NON_CONST_ITERATE (CNodeSet::Tdata, node, btc.SetNodes().Set()) {
1225  if ((*node)->CanGetFeatures()) {
1227  (*node)->SetFeatures().Set()) {
1228 
1229  if ((*node_feature)->GetFeatureid() == eSeqIdId
1230  || (*node_feature)->GetFeatureid() == eAccessionNbrId) {
1231 
1232  pair<CNode*, CSeq_id_Handle> p;
1233  p.first = node->GetNonNullPointer();
1234  CSeq_id sid((*node_feature)->GetValue(),CSeq_id::fParse_Default);
1235  p.second = CSeq_id_Handle::GetHandle(sid);
1236  nodes.push_back(p);
1237  }
1238  }
1239  }
1240  }
1241 
1242  ITERATE (vector<string>, sid, ids) {
1243  CSeq_id seqid(*sid);
1244  CSeq_id_Handle idhandle = CSeq_id_Handle::GetHandle(seqid);
1245  pair<CNode*, CSeq_id_Handle> p(nullptr, idhandle);
1246  vector< pair<CNode*, CSeq_id_Handle> >::iterator node;
1247 
1248  for (node = nodes.begin();node != nodes.end();++node) {
1249 
1250  if (scope.IsSameBioseq(idhandle, node->second,
1252 
1253  // set features
1254  // color for query node
1256  x_AddFeature(eNodeInfoId, kNodeInfoQuery, node->first);
1257 
1258  break;
1259  }
1260  }
1261  }
1262 }
1263 
1264 
1265 // Add feature descriptor in bio tree
1266 void CPhyTreeFormatter::x_AddFeatureDesc(int id, const string& desc,
1267  CBioTreeContainer& btc)
1268 {
1269  CRef<CFeatureDescr> feat_descr(new CFeatureDescr);
1270  feat_descr->SetId(id);
1271  feat_descr->SetName(desc);
1272  btc.SetFdict().Set().push_back(feat_descr);
1273 }
1274 
1275 
1276 // Add feature to a node in bio tree
1277 void CPhyTreeFormatter::x_AddFeature(int id, const string& value,
1278  CNodeSet::Tdata::iterator iter)
1279 {
1280  CRef<CNodeFeature> node_feature(new CNodeFeature);
1281  node_feature->SetFeatureid(id);
1282  node_feature->SetValue(value);
1283  (*iter)->SetFeatures().Set().push_back(node_feature);
1284 }
1285 
1286 // Add feature to a node in bio tree
1287 void CPhyTreeFormatter::x_AddFeature(int id, const string& value, CNode* node)
1288 {
1289  CRef<CNodeFeature> node_feature(new CNodeFeature);
1290  node_feature->SetFeatureid(id);
1291  node_feature->SetValue(value);
1292  node->SetFeatures().Set().push_back(node_feature);
1293 }
1294 
1295 
1297 CPhyTreeFormatter::CExpander::operator()(CBioTreeDynamic::CBioNode& node,
1298  int delta)
1299 {
1300  if (delta == 0 || delta == 1) {
1301  if (node.GetFeature(GetFeatureTag(eTreeSimplificationTagId))
1302  != s_kSubtreeDisplayed && !node.IsLeaf()) {
1303 
1304  node.SetFeature(GetFeatureTag(eTreeSimplificationTagId),
1306 
1307  node.SetFeature(GetFeatureTag(eNodeColorId), "");
1308 
1309  node.SetFeature(GetFeatureTag(eLeafCountId), NStr::IntToString(0));
1310  }
1311  }
1312  return eTreeTraverse;
1313 }
Things for representing and manipulating bio trees.
Char outFileName[2000]
Definition: bzip2recover.c:63
static const char * bgColor
static string GetGnlID(const objects::CDbtag &dtg)
Return ID for GNL label.
CBioseq_Handle –.
Definition: Dbtag.hpp:53
CFeatureDescr –.
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CNodeFeature –.
Definition: NodeFeature.hpp:66
CNode –.
Definition: Node.hpp:66
TTaxId GetTaxId() const
Definition: Org_ref.cpp:72
Computaion of distance-based phylognetic tree.
CRef< CBioTreeContainer > GetSerialTree(void) const
Get serial tree.
const vector< CRef< CSeq_id > > & GetSeqIds(void) const
Get seq-ids of sequences used in tree construction.
CRef< CScope > GetScope(void)
Get scope.
Guide tree exceptions.
Tree visitor, finds BioTreeDynamic node by id.
CBioTreeDynamic::CBioNode * GetNode(void)
Get pointer to found node.
Tree visitor class, expands all nodes and corrects node colors.
ETreeTraverseCode operator()(CBioTreeDynamic::CBioNode &node, int delta)
Expand subtree.
Tree visitor for checking whether a subtree contains a query node.
bool HasSeqFromType(void) const
Check if an examined subtree has a sequence from type.
bool HasQueryNode(void) const
Check if an examined subtree has a query node.
bool IsSingleBlastName(void) const
Check if all sequences in examined tree have the same Blast Name.
ETreeSimplifyMode m_SimplifyMode
Current tree simplification mode.
void x_InitTreeFeatures(CBioTreeContainer &btc, const vector< CRef< CSeq_id > > &seqids, CScope &scope, ELabelType label_type, const vector< int > &mark_leaves, TBlastNameColorMap &bcolormap, map< string, int > &seqTypeMap, bool simpleTree=false, ILinkoutDB *linkoutDB=NULL, int linkoutType=0)
Create and initialize tree features.
static void x_AddFeature(int id, const string &value, CNodeSet::Tdata::iterator iter)
Add feature to tree node.
void x_MarkNode(CBioTreeDynamic::CBioNode *node, const string &color)
Mark node.
void RerootTree(int new_root_id)
Reroot tree.
void x_Init(void)
Init class attributes to default values.
static const string kNodeInfoSeqFromType
Node feature "node-info" value for sequences from type.
static string GetFeatureTag(EFeatureID feat)
Get tree feature tag.
int GetRootNodeID(void)
Get tree root node id.
CBioTreeDynamic m_Dyntree
Stores tree data.
ILinkoutDB * m_LinkoutDB
string x_GetSeqIDString(CBioseq_Handle &handle, bool get_gi_first)
static void x_Expand(CBioTreeDynamic::CBioNode &node)
Expand node (show subtree)
bool WriteTreeAs(CNcbiOstream &out, ETreeFormat format)
Write tree structure to stream in selected format.
void FullyExpand(void)
Fully expand tree.
CPhyTreeFormatter(CPhyTreeCalc &guide_tree_calc, ELabelType lbl_type=eSeqId, bool mark_query_node=true, ILinkoutDB *linkoutDB=NULL, int linkoutType=0)
Constructor.
TBlastNameColorMap m_BlastNameColorMap
Blast Name to color map.
CBioTreeDynamic::CBioNode * GetNonNullNode(TBioTreeNodeId id)
Get pointer to the node with given id and throw exception if node not found.
bool ExpandCollapseSubtree(int node_id)
Expand or collapse subtree rooted in given node.
static const string kNodeInfoSeqKmerBlast
vector< TBlastNameToColor > TBlastNameColorMap
@ eLabelId
Node label.
@ eLabelBgColorId
Color for backgroud of node label.
@ eNodeInfoId
Used for denoting query nodes.
@ eTitleId
Sequence title.
@ eTreeSimplificationTagId
Is subtree collapsed.
@ eLabelColorId
Node label color.
@ eNodeColorId
Node color.
@ eOrganismId
Taxonomic organism id (for sequence)
@ eBlastNameId
Sequence Blast Name.
@ eAccessionNbrId
Sequence accession.
@ eDistId
Edge length from parent to this node.
@ eAlignIndexId
Index of sequence in Seq_align.
@ eSeqIdId
Sequence id.
static void x_Collapse(CBioTreeDynamic::CBioNode &node)
Collapse node (do not show subtree)
static const string kNodeInfoSeqReferenceDB
CBioTreeDynamic::CBioNode * x_GetBioNode(TBioTreeNodeId id, bool throw_if_null=true)
Find pointer to a BioTreeDynamic node with given numerical id.
void x_AddFeaturesForInnerNodes(CPhyTreeNodeAnalyzer &groupper)
bool PrintNewickTree(CNcbiOstream &ostr)
Write tree in Newick format to stream.
ELabelType
Information shown as labels in the guide tree.
bool WriteTree(CNcbiOstream &out)
Write tree structure to stream.
map< string, int > m_SeqTypeMap
bool IsSingleBlastName(void)
Check whether tree is composed of sequences with the same Blast Name.
void x_CollapseSubtrees(CPhyTreeNodeGroupper &groupper)
Collapse given subtrees.
void CollapseToViewPort(void)
CBioTreeDynamic::CBioNode * GetNode(TBioTreeNodeId id)
Get pointer to the node with given id.
static int x_FindSeqType(map< string, int > &seqTypeMap, string idString)
ETreeSimplifyMode
Tree simplification modes.
@ eFullyExpanded
Tree fully expanded.
@ eNone
No simplification mode.
@ eCollapseToViewPort
collapse to viewport
@ eByBlastName
Subtrees that contain sequences with the the same Blast Name are collapsed.
void x_PrintNewickTree(CNcbiOstream &ostr, const CBioTreeDynamic::CBioNode &node, vector< string > &labels, bool name_subtrees=true, bool is_outer_node=true)
Generates tree in Newick format, recursive.
void x_InitTreeLabels(CBioTreeContainer &btc, ELabelType lbl_type)
Init tree leaf labels with selected labels type.
void x_MarkLeavesBySeqId(CBioTreeContainer &btc, vector< string > &ids, CScope &scope)
Mark leave nodes corresponding to sequences with given sequence ids.
bool ShowSubtree(int root_id)
Show subtree.
static const string kNodeInfoSeqFromVerifiedMat
static bool x_IsLeafEx(const CBioTreeDynamic::CBioNode &node)
Check if node is a leaf or collapsed.
CRef< CBioTreeContainer > GetSerialTree(void)
Get serialized tree.
static void x_AddFeatureDesc(int id, const string &desc, CBioTreeContainer &btc)
Add feature descriptor to tree.
static bool x_IsExpanded(const CBioTreeDynamic::CBioNode &node)
Check if node is expanded (subtree shown)
ETreeFormat
Output formats.
vector< CConstRef< CSeq_id > > m_TreeSeqIDs
static const string kNodeInfoQuery
Node feature "node-info" value for query nodes.
void SimplifyTree(ETreeSimplifyMode method)
Group nodes according to user-selected scheme and collapse subtrees composed of nodes that belong to ...
bool PrintNexusTree(CNcbiOstream &ostr, const string &tree_name="Blast_guide_tree")
Write tree in Nexus format to stream.
Tree visitor, finds all labels and node colors for leafes.
TLabelColorMap::iterator TLabelColorMap_I
CLabeledNodes_I End()
CLabeledNodes::iterator CLabeledNodes_I
CLabeledNodes_I Begin(void)
const string & GetError(void) const
This file provides tree visitor classes and functions for node groupping and simplification of phylog...
CLabeledNodes_I End()
CLabeledNodes::iterator CLabeledNodes_I
CLabeledNodes_I Begin(void)
const string & GetError(void) const
CScope –.
Definition: scope.hpp:92
bool Init(void)
Definition: taxon1.cpp:101
bool GetBlastName(TTaxId tax_id, string &blast_name_out)
Definition: taxon1.cpp:1405
setting up scope
Definition: ilinkoutdb.hpp:43
virtual int GetLinkout(TGi gi, const string &mv_build_name)=0
Retrieve the Linkout for a given GI.
size_type size() const
Definition: map.hpp:148
container_type::iterator iterator
Definition: map.hpp:54
const_iterator begin() const
Definition: map.hpp:151
const_iterator end() const
Definition: map.hpp:152
bool empty() const
Definition: map.hpp:149
const_iterator find(const key_type &key) const
Definition: map.hpp:153
static const Colors colors
Definition: cn3d_colors.cpp:50
API (CDeflineGenerator) for computing sequences' titles ("definitions").
Blast defline related defines.
@ eFromType
Identifies sequences from type (Entrez query: sequence from type[filter])
@ eFromVerifiedMaterial
Identifies sequences from verified material (Entrez query: 177353[BioProject])
std::ofstream out("events_result.xml")
main entry point for tests
#define ZERO_TAX_ID
Definition: ncbimisc.hpp:1115
#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
SStrictId_Tax::TId TTaxId
Taxon id type.
Definition: ncbimisc.hpp:1048
#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
#define MSerial_AsnText
I/O stream manipulators –.
Definition: serialbase.hpp:696
CConstRef< CSeq_id > GetSeqId(void) const
bool IsGi(void) const
static CSeq_id_Handle GetHandle(const CSeq_id &id)
Normal way of getting a handle, works for any seq-id.
@ fParse_Default
By default in ParseIDs and IsValid, allow raw parsable non-numeric accessions and plausible local acc...
Definition: Seq_id.hpp:102
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,...
const COrg_ref & GetOrg_ref(const CBioseq_Handle &handle)
Return the org-ref associated with a given sequence.
Definition: sequence.cpp:264
@ eGetId_Best
return the "best" gi (uses FindBestScore(), with CSeq_id::CalculateScore() as the score function
Definition: sequence.hpp:101
@ eGetId_ForceGi
return only a gi-based seq-id
Definition: sequence.hpp:99
CBioseq_Handle GetBioseqHandle(const CSeq_id &id)
Get bioseq handle by seq-id.
Definition: scope.cpp:95
bool IsSameBioseq(const CSeq_id_Handle &id1, const CSeq_id_Handle &id2, EGetBioseqFlag get_flag)
Check if two seq-ids are resolved to the same Bioseq.
Definition: scope.cpp:168
@ eGetBioseq_All
Search bioseq, load if not loaded yet.
Definition: scope.hpp:128
bool NotEmpty(void) const THROWS_NONE
Check if CRef is not empty – pointing to an object and has a non-null value.
Definition: ncbiobj.hpp:726
#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 NcbiEndl
Definition: ncbistre.hpp:548
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
Definition: ncbistre.hpp:500
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
Definition: ncbistr.cpp:630
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
Fun TreeDepthFirstTraverse(TTreeNode &tree_node, Fun func)
Depth-first tree traversal algorithm.
Definition: ncbi_tree.hpp:504
ETreeTraverseCode
Tree traverse code returned by the traverse predicate function.
Definition: ncbi_tree.hpp:51
unsigned int TBioTreeNodeId
Tree node id. Every node has its unique id in the tree.
Definition: bio_tree.hpp:63
unsigned int TBioTreeFeatureId
Feature Id.
Definition: bio_tree.hpp:60
TBioTreeNode * GetTreeNodeNonConst()
Definition: bio_tree.hpp:408
void BioTreeConvert2Container(TBioTreeContainer &tree_container, const TDynamicTree &dyn_tree)
Convert Dynamic tree to ASN.1 BioTree container.
void BioTreeConvertContainer2Dynamic(TDynamicTree &dyn_tree, const TBioTreeContainer &tree_container, bool preserve_node_ids=false)
Convert ASN.1 BioTree container to dynamic tree.
const TBioTreeNode * GetTreeNode() const
Definition: bio_tree.hpp:406
void SetTreeNode(TBioTreeNode *node)
Assign new top level tree node.
Definition: bio_tree.hpp:611
@ eTreeTraverse
Keep traversal.
Definition: ncbi_tree.hpp:52
static const char label[]
void SetNodes(TNodes &value)
Assign a value to Nodes data member.
void SetFdict(TFdict &value)
Assign a value to Fdict data member.
void SetFeatures(TFeatures &value)
Assign a value to Features data member.
Definition: Node_.cpp:56
list< CRef< CNodeFeature > > Tdata
list< CRef< CNode > > Tdata
Definition: NodeSet_.hpp:89
const TTaxname & GetTaxname(void) const
Get the Taxname member data.
Definition: Org_ref_.hpp:372
const TCommon & GetCommon(void) const
Get the Common member data.
Definition: Org_ref_.hpp:419
E_Choice Which(void) const
Which variant is currently selected.
Definition: Seq_id_.hpp:746
@ e_General
for other databases
Definition: Seq_id_.hpp:105
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
n background color
int i
constexpr bool empty(list< Ts... >) noexcept
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
int isalpha(Uchar c)
Definition: ncbictype.hpp:61
int isdigit(Uchar c)
Definition: ncbictype.hpp:64
NCBI C++ auxiliary debug macros.
static Format format
Definition: njn_ioutil.cpp:53
Int4 delta(size_t dimension_, const Int4 *score_)
static const string s_kSeqFromVerifiedMatNodeBgColor
static const string s_kSeqKmerBlastNodeBgColor
USING_SCOPE(objects)
static const string s_kUnknown
static const string s_kQueryNodeBgColor
static const string s_kSeqQueryNodeBgColor
static void s_InitFeatures(CPhyTreeNodeAnalyzer::TLeafNodeInfoMap nodeMap, string &title, int &leafCount, string &nodeColor)
static const string s_kSeqOfTypeNodeBgColor
map< int, string > linkotTypeToBGColor
static const string s_kNodeSize
static const string s_kBranchColor
static const string s_kSeqReferenceDBNodeBgColor
static const string s_kSubtreeDisplayed
#define MAX_NODES_TO_COLOR
void s_RerootUpstream(CBioTreeDynamic::CBioNode *node, TBioTreeFeatureId fid)
map< int, string > seqTypeToBGColor
static string s_GetBlastNameColor(CPhyTreeFormatter::TBlastNameColorMap &blast_name_color_map, string blast_tax_name)
static const string s_kQueryNodeColor
#define _ASSERT
Modified on Sun Apr 14 05:29:29 2024 by modify_doxy.py rev. 669887